]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
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)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 26 May 2021 13:39:17 +0000 (15:39 +0200)
BugLink: https://bugs.launchpad.net/bugs/1929615
[ 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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/vfio/mdev/mdev_sysfs.c

index f32c582611eb64d10b8d951f328b630a6118d127..ca9476883f15027a682c2cbada674cad96078e8f 100644 (file)
@@ -105,6 +105,7 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
                return ERR_PTR(-ENOMEM);
 
        type->kobj.kset = parent->mdev_types_kset;
+       type->parent = parent;
 
        ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL,
                                   "%s-%s", dev_driver_string(parent->dev),
@@ -132,7 +133,6 @@ static struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
        }
 
        type->group = group;
-       type->parent = parent;
        return type;
 
 attrs_failed: