Skip to content

Commit b27ee76

Browse files
YongjiXiemstsirkin
authored andcommitted
vduse: Fix NULL pointer dereference on sysfs access
The control device has no drvdata. So we will get a NULL pointer dereference when accessing control device's msg_timeout attribute via sysfs: [ 132.841881][ T3644] BUG: kernel NULL pointer dereference, address: 00000000000000f8 [ 132.850619][ T3644] RIP: 0010:msg_timeout_show (drivers/vdpa/vdpa_user/vduse_dev.c:1271) [ 132.869447][ T3644] dev_attr_show (drivers/base/core.c:2094) [ 132.870215][ T3644] sysfs_kf_seq_show (fs/sysfs/file.c:59) [ 132.871164][ T3644] ? device_remove_bin_file (drivers/base/core.c:2088) [ 132.872082][ T3644] kernfs_seq_show (fs/kernfs/file.c:164) [ 132.872838][ T3644] seq_read_iter (fs/seq_file.c:230) [ 132.873578][ T3644] ? __vmalloc_area_node (mm/vmalloc.c:3041) [ 132.874532][ T3644] kernfs_fop_read_iter (fs/kernfs/file.c:238) [ 132.875513][ T3644] __kernel_read (fs/read_write.c:440 (discriminator 1)) [ 132.876319][ T3644] kernel_read (fs/read_write.c:459) [ 132.877129][ T3644] kernel_read_file (fs/kernel_read_file.c:94) [ 132.877978][ T3644] kernel_read_file_from_fd (include/linux/file.h:45 fs/kernel_read_file.c:186) [ 132.879019][ T3644] __do_sys_finit_module (kernel/module.c:4207) [ 132.879930][ T3644] __ia32_sys_finit_module (kernel/module.c:4189) [ 132.880930][ T3644] do_int80_syscall_32 (arch/x86/entry/common.c:112 arch/x86/entry/common.c:132) [ 132.881847][ T3644] entry_INT80_compat (arch/x86/entry/entry_64_compat.S:419) To fix it, don't create the unneeded attribute for control device anymore. Fixes: c8a6153 ("vduse: Introduce VDUSE - vDPA Device in Userspace") Reported-by: kernel test robot <[email protected]> Cc: [email protected] Signed-off-by: Xie Yongji <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent dbd29e0 commit b27ee76

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,9 +1345,9 @@ static int vduse_create_dev(struct vduse_dev_config *config,
13451345

13461346
dev->minor = ret;
13471347
dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT;
1348-
dev->dev = device_create(vduse_class, NULL,
1349-
MKDEV(MAJOR(vduse_major), dev->minor),
1350-
dev, "%s", config->name);
1348+
dev->dev = device_create_with_groups(vduse_class, NULL,
1349+
MKDEV(MAJOR(vduse_major), dev->minor),
1350+
dev, vduse_dev_groups, "%s", config->name);
13511351
if (IS_ERR(dev->dev)) {
13521352
ret = PTR_ERR(dev->dev);
13531353
goto err_dev;
@@ -1596,7 +1596,6 @@ static int vduse_init(void)
15961596
return PTR_ERR(vduse_class);
15971597

15981598
vduse_class->devnode = vduse_devnode;
1599-
vduse_class->dev_groups = vduse_dev_groups;
16001599

16011600
ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse");
16021601
if (ret)

0 commit comments

Comments
 (0)