2017-12-01 15:08:58 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
2017-12-01 15:09:01 -08:00
|
|
|
|
2020-11-18 21:45:19 +01:00
|
|
|
|
2017-12-01 15:08:58 -08:00
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
2017-12-01 15:08:58 -08:00
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:53 +02:00
|
|
|
|
2020-09-25 17:56:42 -07:00
|
|
|
|
2018-07-11 20:36:40 -07:00
|
|
|
|
2017-12-01 15:08:58 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 10:07:54 -07:00
|
|
|
|
|
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
2018-06-26 10:07:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-18 21:45:18 +01:00
|
|
|
|
2020-09-14 17:11:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-18 21:45:18 +01:00
|
|
|
|
2021-03-29 20:59:53 -07:00
|
|
|
|
|
|
|
|
|
2020-11-18 21:45:18 +01:00
|
|
|
|
2020-11-18 21:45:19 +01:00
|
|
|
|
|
|
|
|
|
2021-03-29 20:59:53 -07:00
|
|
|
|
2020-11-18 21:45:18 +01:00
|
|
|
|
|
|
|
|
|
2017-12-01 15:08:58 -08:00
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
2019-04-25 15:59:49 +02:00
|
|
|
|
2019-04-25 15:59:55 +02:00
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
2017-12-01 15:08:58 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
2019-04-25 15:59:45 +02:00
|
|
|
|
2017-12-01 15:09:01 -08:00
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-11 20:36:40 -07:00
|
|
|
|
2018-07-11 20:36:42 -07:00
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-17 19:13:30 -08:00
|
|
|
|
|
|
|
|
|
2018-06-26 10:07:54 -07:00
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-25 17:56:42 -07:00
|
|
|
|
|
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
|
|
|
|
|
2020-09-14 17:11:54 -07:00
|
|
|
|
|
|
|
|
|
2017-12-01 15:08:58 -08:00
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
2019-04-25 15:59:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-14 17:11:54 -07:00
|
|
|
|
|
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 11:22:54 -08:00
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
|
|
|
|
|
2017-12-01 15:08:59 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 11:22:54 -08:00
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-01-23 11:22:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-21 23:46:02 -07:00
|
|
|
|
2018-01-23 11:22:54 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-01 15:09:01 -08:00
|
|
|
|
2018-03-27 18:22:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-11-04 15:30:37 +02:00
|
|
|
|
2018-03-27 18:22:00 -07:00
|
|
|
|
|
|
|
|
|
2019-10-10 15:18:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-14 14:19:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-02 15:17:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-02 15:17:16 +03:00
|
|
|
|
2019-04-25 15:59:53 +02:00
|
|
|
|
2021-06-02 15:17:29 +03:00
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:55 +02:00
|
|
|
|
2019-04-25 15:59:53 +02:00
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:49 +02:00
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
2019-04-25 15:59:49 +02:00
|
|
|
|
2019-08-17 16:28:20 +03:00
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
2019-04-25 15:59:52 +02:00
|
|
|
|
netdevsim: fix panic in nsim_dev_take_snapshot_write()
nsim_dev_take_snapshot_write() uses nsim_dev and nsim_dev->dummy_region.
So, during this function, these data shouldn't be removed.
But there is no protecting stuff in this function.
There are two similar cases.
1. reload case
reload could be called during nsim_dev_take_snapshot_write().
When reload is being executed, nsim_dev_reload_down() is called and it
calls nsim_dev_reload_destroy(). nsim_dev_reload_destroy() calls
devlink_region_destroy() to destroy nsim_dev->dummy_region.
So, during nsim_dev_take_snapshot_write(), nsim_dev->dummy_region()
would be removed.
At this point, snapshot_write() would access freed pointer.
In order to fix this case, take_snapshot file will be removed before
devlink_region_destroy().
The take_snapshot file will be re-created by ->reload_up().
2. del_device_store case
del_device_store() also could call nsim_dev_reload_destroy()
during nsim_dev_take_snapshot_write(). If so, panic would occur.
This problem is actually the same problem with the first case.
So, this problem will be fixed by the first case's solution.
Test commands:
modprobe netdevsim
while :
do
echo 1 > /sys/bus/netdevsim/new_device &
echo 1 > /sys/bus/netdevsim/del_device &
devlink dev reload netdevsim/netdevsim1 &
echo 1 > /sys/kernel/debug/netdevsim/netdevsim1/take_snapshot &
done
Splat looks like:
[ 45.564513][ T975] general protection fault, probably for non-canonical address 0xdffffc000000003a: 0000 [#1] SMP DEI
[ 45.566131][ T975] KASAN: null-ptr-deref in range [0x00000000000001d0-0x00000000000001d7]
[ 45.566135][ T975] CPU: 1 PID: 975 Comm: bash Not tainted 5.5.0+ #322
[ 45.569020][ T975] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 45.569026][ T975] RIP: 0010:__mutex_lock+0x10a/0x14b0
[ 45.570518][ T975] Code: 08 84 d2 0f 85 7f 12 00 00 44 8b 0d 10 23 65 02 45 85 c9 75 29 49 8d 7f 68 48 b8 00 00 00 0f
[ 45.570522][ T975] RSP: 0018:ffff888046ccfbf0 EFLAGS: 00010206
[ 45.572305][ T975] RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 45.572308][ T975] RDX: 000000000000003a RSI: ffffffffac926440 RDI: 00000000000001d0
[ 45.576843][ T975] RBP: ffff888046ccfd70 R08: ffffffffab610645 R09: 0000000000000000
[ 45.576847][ T975] R10: ffff888046ccfd90 R11: ffffed100d6360ad R12: 0000000000000000
[ 45.578471][ T975] R13: dffffc0000000000 R14: ffffffffae1976c0 R15: 0000000000000168
[ 45.578475][ T975] FS: 00007f614d6e7740(0000) GS:ffff88806c400000(0000) knlGS:0000000000000000
[ 45.581492][ T975] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 45.582942][ T975] CR2: 00005618677d1cf0 CR3: 000000005fb9c002 CR4: 00000000000606e0
[ 45.584543][ T975] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 45.586633][ T975] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 45.589889][ T975] Call Trace:
[ 45.591445][ T975] ? devlink_region_snapshot_create+0x55/0x4a0
[ 45.601250][ T975] ? mutex_lock_io_nested+0x1380/0x1380
[ 45.602817][ T975] ? mutex_lock_io_nested+0x1380/0x1380
[ 45.603875][ T975] ? mark_held_locks+0xa5/0xe0
[ 45.604769][ T975] ? _raw_spin_unlock_irqrestore+0x2d/0x50
[ 45.606147][ T975] ? __mutex_unlock_slowpath+0xd0/0x670
[ 45.607723][ T975] ? crng_backtrack_protect+0x80/0x80
[ 45.613530][ T975] ? wait_for_completion+0x390/0x390
[ 45.615152][ T975] ? devlink_region_snapshot_create+0x55/0x4a0
[ 45.616834][ T975] devlink_region_snapshot_create+0x55/0x4a0
[ ... ]
Fixes: 4418f862d675 ("netdevsim: implement support for devlink region and snapshots")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-02-01 16:43:13 +00:00
|
|
|
|
2021-06-02 15:17:14 +03:00
|
|
|
|
2021-06-02 15:17:26 +03:00
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
|
|
|
|
|
2020-12-09 14:57:39 +01:00
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:51 +02:00
|
|
|
|
2019-04-25 15:59:53 +02:00
|
|
|
|
2019-04-25 15:59:54 +02:00
|
|
|
|
2019-06-04 15:40:43 +02:00
|
|
|
|
2020-09-25 13:46:08 -07:00
|
|
|
|
2019-08-09 13:05:12 +02:00
|
|
|
|
|
|
|
|
|
2019-10-06 08:30:01 +02:00
|
|
|
|
|
|
|
|
|
2019-08-15 15:46:33 +02:00
|
|
|
|
2019-10-10 15:18:50 +02:00
|
|
|
|
2020-02-25 11:45:26 +01:00
|
|
|
|
|
|
|
|
|
2020-03-30 22:38:23 +03:00
|
|
|
|
2020-03-30 22:38:20 +03:00
|
|
|
|
|
|
|
|
|
2021-06-17 14:36:32 +03:00
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
2020-09-25 17:56:42 -07:00
|
|
|
|
|
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-25 17:56:42 -07:00
|
|
|
|
2020-09-25 17:56:47 -07:00
|
|
|
|
2020-07-09 17:42:48 -07:00
|
|
|
|
|
|
|
|
|
2021-03-14 14:19:32 +02:00
|
|
|
|
2021-06-02 15:17:18 +03:00
|
|
|
|
2019-04-25 15:59:49 +02:00
|
|
|
|
|
|
|
|
|
2021-06-02 15:17:18 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-03 11:49:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:50 +02:00
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:53 +02:00
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:54 +02:00
|
|
|
|
2021-06-02 15:17:16 +03:00
|
|
|
|
2019-04-25 15:59:54 +02:00
|
|
|
|
|
|
|
|
|
2021-06-02 15:17:16 +03:00
|
|
|
|
2019-04-25 15:59:54 +02:00
|
|
|
|
2018-03-27 18:22:00 -07:00
|
|
|
|
2019-10-03 11:49:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-03 11:49:26 +02:00
|
|
|
|
|
|
|
|
|
2018-03-27 18:22:00 -07:00
|
|
|
|
2021-06-02 15:17:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-02 15:17:15 +03:00
|
|
|
|
2021-06-02 15:17:14 +03:00
|
|
|
|
2021-06-02 15:17:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 10:07:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:44 +02:00
|
|
|
|
2019-04-25 15:59:45 +02:00
|
|
|
|
|
|
|
|
|
2019-04-25 15:59:48 +02:00
|
|
|
|
|
|
|
|
|
2019-10-05 08:10:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-02 15:17:14 +03:00
|
|
|
|
2019-04-25 15:59:45 +02:00
|
|
|
|
2021-06-02 15:17:14 +03:00
|
|
|
|
2019-04-25 15:59:45 +02:00
|
|
|
|
2020-02-01 16:43:04 +00:00
|
|
|
|
|
|
|
|
|
netdevsim: fix using uninitialized resources
When module is being initialized, __init() calls bus_register() and
driver_register().
These functions internally create various resources and sysfs files.
The sysfs files are used for basic operations(add/del device).
/sys/bus/netdevsim/new_device
/sys/bus/netdevsim/del_device
These sysfs files use netdevsim resources, they are mostly allocated
and initialized in ->probe() function, which is nsim_dev_probe().
But, sysfs files could be executed before ->probe() is finished.
So, accessing uninitialized data would occur.
Another problem is very similar.
/sys/bus/netdevsim/new_device internally creates sysfs files.
/sys/devices/netdevsim<id>/new_port
/sys/devices/netdevsim<id>/del_port
These sysfs files also use netdevsim resources, they are mostly allocated
and initialized in creating device routine, which is nsim_bus_dev_new().
But they also could be executed before nsim_bus_dev_new() is finished.
So, accessing uninitialized data would occur.
To fix these problems, this patch adds flags, which means whether the
operation is finished or not.
The flag variable 'nsim_bus_enable' means whether netdevsim bus was
initialized or not.
This is protected by nsim_bus_dev_list_lock.
The flag variable 'nsim_bus_dev->init' means whether nsim_bus_dev was
initialized or not.
This could be used in {new/del}_port_store() with no lock.
Test commands:
#SHELL1
modprobe netdevsim
while :
do
echo "1 1" > /sys/bus/netdevsim/new_device
echo "1 1" > /sys/bus/netdevsim/del_device
done
#SHELL2
while :
do
echo 1 > /sys/devices/netdevsim1/new_port
echo 1 > /sys/devices/netdevsim1/del_port
done
Splat looks like:
[ 47.508954][ T1008] general protection fault, probably for non-canonical address 0xdffffc0000000021: 0000 I
[ 47.510793][ T1008] KASAN: null-ptr-deref in range [0x0000000000000108-0x000000000000010f]
[ 47.511963][ T1008] CPU: 2 PID: 1008 Comm: bash Not tainted 5.5.0+ #322
[ 47.512823][ T1008] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[ 47.514041][ T1008] RIP: 0010:__mutex_lock+0x10a/0x14b0
[ 47.514699][ T1008] Code: 08 84 d2 0f 85 7f 12 00 00 44 8b 0d 10 23 65 02 45 85 c9 75 29 49 8d 7f 68 48 b8 00 00 00 0f
[ 47.517163][ T1008] RSP: 0018:ffff888059b4fbb0 EFLAGS: 00010206
[ 47.517802][ T1008] RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 0000000000000000
[ 47.518941][ T1008] RDX: 0000000000000021 RSI: ffffffff85926440 RDI: 0000000000000108
[ 47.519732][ T1008] RBP: ffff888059b4fd30 R08: ffffffffc073fad0 R09: 0000000000000000
[ 47.520729][ T1008] R10: ffff888059b4fd50 R11: ffff88804bb38040 R12: 0000000000000000
[ 47.521702][ T1008] R13: dffffc0000000000 R14: ffffffff871976c0 R15: 00000000000000a0
[ 47.522760][ T1008] FS: 00007fd4be05a740(0000) GS:ffff88806c800000(0000) knlGS:0000000000000000
[ 47.523877][ T1008] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 47.524627][ T1008] CR2: 0000561c82b69cf0 CR3: 0000000065dd6004 CR4: 00000000000606e0
[ 47.527662][ T1008] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 47.528604][ T1008] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 47.529531][ T1008] Call Trace:
[ 47.529874][ T1008] ? nsim_dev_port_add+0x50/0x150 [netdevsim]
[ 47.530470][ T1008] ? mutex_lock_io_nested+0x1380/0x1380
[ 47.531018][ T1008] ? _kstrtoull+0x76/0x160
[ 47.531449][ T1008] ? _parse_integer+0xf0/0xf0
[ 47.531874][ T1008] ? kernfs_fop_write+0x1cf/0x410
[ 47.532330][ T1008] ? sysfs_file_ops+0x160/0x160
[ 47.532773][ T1008] ? kstrtouint+0x86/0x110
[ 47.533168][ T1008] ? nsim_dev_port_add+0x50/0x150 [netdevsim]
[ 47.533721][ T1008] nsim_dev_port_add+0x50/0x150 [netdevsim]
[ 47.534336][ T1008] ? sysfs_file_ops+0x160/0x160
[ 47.534858][ T1008] new_port_store+0x99/0xb0 [netdevsim]
[ 47.535439][ T1008] ? del_port_store+0xb0/0xb0 [netdevsim]
[ 47.536035][ T1008] ? sysfs_file_ops+0x112/0x160
[ 47.536544][ T1008] ? sysfs_kf_write+0x3b/0x180
[ 47.537029][ T1008] kernfs_fop_write+0x276/0x410
[ 47.537548][ T1008] ? __sb_start_write+0x215/0x2e0
[ 47.538110][ T1008] vfs_write+0x197/0x4a0
[ ... ]
Fixes: f9d9db47d3ba ("netdevsim: add bus attributes to add new and delete devices")
Fixes: 794b2c05ca1c ("netdevsim: extend device attrs to support port addition and deletion")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2020-02-01 16:42:54 +00:00
|
|
|
|
2019-04-25 15:59:45 +02:00
|
|
|
|
2019-04-25 15:59:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|