Message ID | 20240904011837.2010444-1-lihongbo22@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [-next] vfio/mdev: Constify struct kobj_type | expand |
On Wed, Sep 04, 2024 at 09:18:37AM +0800, Hongbo Li wrote: > This 'struct kobj_type' is not modified. It is only used in > kobject_init_and_add() which takes a 'const struct kobj_type *ktype' > parameter. > > Constifying this structure and moving it to a read-only section, > and this can increase over all security. > > ``` > [Before] > text data bss dec hex filename > 2372 600 0 2972 b9c drivers/vfio/mdev/mdev_sysfs.o > > [After] > text data bss dec hex filename > 2436 568 0 3004 bbc drivers/vfio/mdev/mdev_sysfs.o > ``` > > Signed-off-by: Hongbo Li <lihongbo22@huawei.com> > --- > drivers/vfio/mdev/mdev_sysfs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Jason
On Wed, 4 Sep 2024 09:18:37 +0800 Hongbo Li <lihongbo22@huawei.com> wrote: > This 'struct kobj_type' is not modified. It is only used in > kobject_init_and_add() which takes a 'const struct kobj_type *ktype' > parameter. > > Constifying this structure and moving it to a read-only section, > and this can increase over all security. > > ``` > [Before] > text data bss dec hex filename > 2372 600 0 2972 b9c drivers/vfio/mdev/mdev_sysfs.o > > [After] > text data bss dec hex filename > 2436 568 0 3004 bbc drivers/vfio/mdev/mdev_sysfs.o > ``` > > Signed-off-by: Hongbo Li <lihongbo22@huawei.com> > --- > drivers/vfio/mdev/mdev_sysfs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c > index 9d2738e10c0b..e44bb44c581e 100644 > --- a/drivers/vfio/mdev/mdev_sysfs.c > +++ b/drivers/vfio/mdev/mdev_sysfs.c > @@ -160,7 +160,7 @@ static void mdev_type_release(struct kobject *kobj) > put_device(type->parent->dev); > } > > -static struct kobj_type mdev_type_ktype = { > +static const struct kobj_type mdev_type_ktype = { > .sysfs_ops = &mdev_type_sysfs_ops, > .release = mdev_type_release, > .default_groups = mdev_type_groups, Applied to vfio next branch for v6.12. Thanks! Alex
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index 9d2738e10c0b..e44bb44c581e 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -160,7 +160,7 @@ static void mdev_type_release(struct kobject *kobj) put_device(type->parent->dev); } -static struct kobj_type mdev_type_ktype = { +static const struct kobj_type mdev_type_ktype = { .sysfs_ops = &mdev_type_sysfs_ops, .release = mdev_type_release, .default_groups = mdev_type_groups,
This 'struct kobj_type' is not modified. It is only used in kobject_init_and_add() which takes a 'const struct kobj_type *ktype' parameter. Constifying this structure and moving it to a read-only section, and this can increase over all security. ``` [Before] text data bss dec hex filename 2372 600 0 2972 b9c drivers/vfio/mdev/mdev_sysfs.o [After] text data bss dec hex filename 2436 568 0 3004 bbc drivers/vfio/mdev/mdev_sysfs.o ``` Signed-off-by: Hongbo Li <lihongbo22@huawei.com> --- drivers/vfio/mdev/mdev_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)