提交 869448ed 编写于 作者: J Jason Gunthorpe 提交者: Yang Yingliang

vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer

stable inclusion
from linux-4.19.191
commit 6af3de26ee2b42ff5104a0a0f048df82e37fbc82

--------------------------------

[ Upstream commit b5a1f892 ]

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: 7b96953b ("vfio: Mediated device Core driver")
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Reviewed-by: NKevin Tian <kevin.tian@intel.com>
Reviewed-by: NMax Gurtovoy <mgurtovoy@nvidia.com>
Reviewed-by: NCornelia Huck <cohuck@redhat.com>
Signed-off-by: NJason Gunthorpe <jgg@nvidia.com>
Message-Id: <2-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>
Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 7c843900
...@@ -108,6 +108,7 @@ struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, ...@@ -108,6 +108,7 @@ struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
type->kobj.kset = parent->mdev_types_kset; type->kobj.kset = parent->mdev_types_kset;
type->parent = parent;
ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL, ret = kobject_init_and_add(&type->kobj, &mdev_type_ktype, NULL,
"%s-%s", dev_driver_string(parent->dev), "%s-%s", dev_driver_string(parent->dev),
...@@ -135,7 +136,6 @@ struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent, ...@@ -135,7 +136,6 @@ struct mdev_type *add_mdev_supported_type(struct mdev_parent *parent,
} }
type->group = group; type->group = group;
type->parent = parent;
return type; return type;
attrs_failed: attrs_failed:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册