]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer
authorJason Gunthorpe <jgg@nvidia.com>
Tue, 6 Apr 2021 19:40:25 +0000 (16:40 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 08:49:56 +0000 (10:49 +0200)
commitb9748088b86a7ea14c67191fc287900e13ded21c
tree6c466d1031cedc45aec304ab8f01db7290e9f8b4
parent20fd22bd6e4b233eafb2db12758f37520d239973
vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer

[ Upstream commit b5a1f8921d5040bb788492bf33a66758021e4be5 ]

There is a small race where the parent is NULL even though the kobj has
already been made visible in sysfs.

For instance the attribute_group is made visible in sysfs_create_files()
and the mdev_type_attr_show() does:

    ret = attr->show(kobj, type->parent->dev, buf);

Which will crash on NULL parent. Move the parent setup to before the type
pointer leaves the stack frame.

Fixes: 7b96953bc640 ("vfio: Mediated device Core driver")
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Message-Id: <2-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/vfio/mdev/mdev_sysfs.c