netdevsim: fix stack-out-of-bounds in nsim_dev_debugfs_init()
Subsystems (3)
PATCH 2/5 netdevsim: fix stack-out-of-bounds in nsim_dev_debugfs_init()
When netdevsim dev is being created, a debugfs directory is created. The variable "dev_ddir_name" is 16bytes device name pointer and device name is "netdevsim<dev id>".
The maximum dev id length is 10.
So, 16bytes for device name isn't enough.
Test commands:
modprobe netdevsim
echo "1000000000 0" > /sys/bus/netdevsim/new_deviceSplat looks like:
[ 90.624922][ T1000] BUG: KASAN: stack-out-of-bounds in number+0x824/0x880 [ 90.626999][ T1000] Write of size 1 at addr ffff8880b7f47988 by task bash/1000 [ 90.627798][ T1000] [ 90.628076][ T1000] CPU: 0 PID: 1000 Comm: bash Not tainted 5.5.0-rc5+ #270 [ 90.628806][ T1000] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 90.629752][ T1000] Call Trace: [ 90.630080][ T1000] dump_stack+0x96/0xdb [ 90.630512][ T1000] ? number+0x824/0x880 [ 90.630939][ T1000] print_address_description.constprop.5+0x1be/0x360 [ 90.631610][ T1000] ? number+0x824/0x880 [ 90.632038][ T1000] ? number+0x824/0x880 [ 90.632469][ T1000] __kasan_report+0x12a/0x16f [ 90.632939][ T1000] ? number+0x824/0x880 [ 90.633397][ T1000] kasan_report+0xe/0x20 [ 90.633954][ T1000] number+0x824/0x880 [ 90.634513][ T1000] ? put_dec+0xa0/0xa0 [ 90.635047][ T1000] ? rcu_read_lock_sched_held+0x90/0xc0 [ 90.636469][ T1000] vsnprintf+0x63c/0x10b0 [ 90.637187][ T1000] ? pointer+0x5b0/0x5b0 [ 90.637871][ T1000] ? mark_lock+0x11d/0xc40 [ 90.638591][ T1000] sprintf+0x9b/0xd0 [ 90.639164][ T1000] ? scnprintf+0xe0/0xe0 [ 90.639802][ T1000] nsim_dev_probe+0x63c/0xbf0 [netdevsim]
[ ... ]
--- drivers/net/netdevsim/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/netdevsim/dev.c +1 -1
@@ -88,7 +88,7 @@ static const struct file_operations nsim_dev_take_snapshot_fops = {static int nsim_dev_debugfs_init (struct nsim_dev *nsim_dev) { -char dev_ddir_name[16 ]; +char dev_ddir_name[32 ];sprintf (dev_ddir_name,DRV_NAME "%u" , nsim_dev->nsim_bus_dev->dev.id); nsim_dev->ddir =debugfs_create_dir (dev_ddir_name, nsim_dev_ddir);
Signature · 1 line
2.17.1
Quoted 34 lines · Taehee Yoo
When netdevsim dev is being created, a debugfs directory is created. The variable "
dev_ddir_name" is 16bytes device name pointer and device name is "netdevsim<dev id>".
The maximum dev id length is 10.
So, 16bytes for device name isn't enough.Test commands:
modprobe netdevsim echo "1000000000 0" > /sys/bus/netdevsim/new_deviceSplat looks like:
[ 90.624922][ T1000] BUG: KASAN: stack-out-of-bounds in number+0x824/0x880 [ 90.626999][ T1000] Write of size 1 at addr ffff8880b7f47988 by task bash/1000 [ 90.627798][ T1000] [ 90.628076][ T1000] CPU: 0 PID: 1000 Comm: bash Not tainted 5.5.0-rc5+ #270 [ 90.628806][ T1000] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 90.629752][ T1000] Call Trace: [ 90.630080][ T1000] dump_stack+0x96/0xdb [ 90.630512][ T1000] ? number+0x824/0x880 [ 90.630939][ T1000] print_address_description.constprop.5+0x1be/0x360 [ 90.631610][ T1000] ? number+0x824/0x880 [ 90.632038][ T1000] ? number+0x824/0x880 [ 90.632469][ T1000] __kasan_report+0x12a/0x16f [ 90.632939][ T1000] ? number+0x824/0x880 [ 90.633397][ T1000] kasan_report+0xe/0x20 [ 90.633954][ T1000] number+0x824/0x880 [ 90.634513][ T1000] ? put_dec+0xa0/0xa0 [ 90.635047][ T1000] ? rcu_read_lock_sched_held+0x90/0xc0 [ 90.636469][ T1000] vsnprintf+0x63c/0x10b0 [ 90.637187][ T1000] ? pointer+0x5b0/0x5b0 [ 90.637871][ T1000] ? mark_lock+0x11d/0xc40 [ 90.638591][ T1000] sprintf+0x9b/0xd0 [ 90.639164][ T1000] ? scnprintf+0xe0/0xe0 [ 90.639802][ T1000] nsim_dev_probe+0x63c/0xbf0 [netdevsim]
Quoted 3 lines
[ ... ]
Fixes 83c9e13aa39a ("netdevsim: add software driver for testing offloads")
The correct Fixes tag is:
Quoted 10 lines
Signed-off-by Taehee Yoo <[email protected]>--- drivers/net/netdevsim/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/netdevsim/dev.c +0
-0
drivers/net/netdevsim/dev.c static const struct file_operations nsim_dev_take_snapshot_fops = { · line 91
Quoted 5 lines
drivers/net/netdevsim/dev.c +1
-1@@ -88,7 +88,7 @@ static const struct file_operations nsim_dev_take_snapshot_fops = {static int nsim_dev_debugfs_init (struct nsim_dev *nsim_dev) { -char dev_ddir_name[16 ]; +char dev_ddir_name[32 ];
nit: it'd be tempting to size this to the correct value
(20? or sizeof(DRV_NAME) + 10) rather than the arbitrary 32, perhaps?
Quoted 2 lines
drivers/net/netdevsim/dev.c +0
-0sprintf (dev_ddir_name,DRV_NAME "%u" , nsim_dev->nsim_bus_dev->dev.id); nsim_dev->ddir =debugfs_create_dir (dev_ddir_name, nsim_dev_ddir);
Quoted 1 line · Jakub Kicinski
Hi Jakub,
Thank you for your review!
Quoted 37 lines · Taehee Yoo
Quoted 36 lines
When netdevsim dev is being created, a debugfs directory is created. The variable "
dev_ddir_name" is 16bytes device name pointer and device name is "netdevsim<dev id>".
The maximum dev id length is 10.
So, 16bytes for device name isn't enough.Test commands:
modprobe netdevsim echo "1000000000 0" > /sys/bus/netdevsim/new_deviceSplat looks like:
[ 90.624922][ T1000] BUG: KASAN: stack-out-of-bounds in number+0x824/0x880 [ 90.626999][ T1000] Write of size 1 at addr ffff8880b7f47988 by task bash/1000 [ 90.627798][ T1000] [ 90.628076][ T1000] CPU: 0 PID: 1000 Comm: bash Not tainted 5.5.0-rc5+ #270 [ 90.628806][ T1000] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 90.629752][ T1000] Call Trace: [ 90.630080][ T1000] dump_stack+0x96/0xdb [ 90.630512][ T1000] ? number+0x824/0x880 [ 90.630939][ T1000] print_address_description.constprop.5+0x1be/0x360 [ 90.631610][ T1000] ? number+0x824/0x880 [ 90.632038][ T1000] ? number+0x824/0x880 [ 90.632469][ T1000] __kasan_report+0x12a/0x16f [ 90.632939][ T1000] ? number+0x824/0x880 [ 90.633397][ T1000] kasan_report+0xe/0x20 [ 90.633954][ T1000] number+0x824/0x880 [ 90.634513][ T1000] ? put_dec+0xa0/0xa0 [ 90.635047][ T1000] ? rcu_read_lock_sched_held+0x90/0xc0 [ 90.636469][ T1000] vsnprintf+0x63c/0x10b0 [ 90.637187][ T1000] ? pointer+0x5b0/0x5b0 [ 90.637871][ T1000] ? mark_lock+0x11d/0xc40 [ 90.638591][ T1000] sprintf+0x9b/0xd0 [ 90.639164][ T1000] ? scnprintf+0xe0/0xe0 [ 90.639802][ T1000] nsim_dev_probe+0x63c/0xbf0 [netdevsim][ ... ]
Quoted 6 lines
Quoted 1 line
Fixes 83c9e13aa39a ("netdevsim: add software driver for testing offloads")The correct Fixes tag is:
Fixes ab1d0cc004d7 ("netdevsim: change debugfs tree topology")
Thank you! I will fix the Fixes tag.
Quoted 11 lines
Quoted 11 lines
Signed-off-by Taehee Yoo <[email protected]>--- drivers/net/netdevsim/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/netdevsim/dev.c +0
-0@@ -88,7 +88,7 @@ static const struct file_operations nsim_dev_take_snapshot_fops = {
Quoted 9 lines
drivers/net/netdevsim/dev.c static const struct file_operations nsim_dev_take_snapshot_fops = { · line 91
Quoted 4 lines
drivers/net/netdevsim/dev.c +1
-1static int nsim_dev_debugfs_init (struct nsim_dev *nsim_dev) { -char dev_ddir_name[16 ]; +char dev_ddir_name[32 ];nit: it'd be tempting to size this to the correct value
(20? orsizeof(DRV_NAME)+ 10) rather than the arbitrary 32, perhaps?
I agree with this. This is more correct.
I will fix this too.
Thank you
Taehee Yoo.