Commit aaadb75
null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'
[ Upstream commit a2db328 ]
Writing 'power' and 'submit_queues' concurrently will trigger kernel
panic:
Test script:
modprobe null_blk nr_devices=0
mkdir -p /sys/kernel/config/nullb/nullb0
while true; do echo 1 > submit_queues; echo 4 > submit_queues; done &
while true; do echo 1 > power; echo 0 > power; done
Test result:
BUG: kernel NULL pointer dereference, address: 0000000000000148
Oops: 0000 [#1] PREEMPT SMP
RIP: 0010:__lock_acquire+0x41d/0x28f0
Call Trace:
<TASK>
lock_acquire+0x121/0x450
down_write+0x5f/0x1d0
simple_recursive_removal+0x12f/0x5c0
blk_mq_debugfs_unregister_hctxs+0x7c/0x100
blk_mq_update_nr_hw_queues+0x4a3/0x720
nullb_update_nr_hw_queues+0x71/0xf0 [null_blk]
nullb_device_submit_queues_store+0x79/0xf0 [null_blk]
configfs_write_iter+0x119/0x1e0
vfs_write+0x326/0x730
ksys_write+0x74/0x150
This is because del_gendisk() can concurrent with
blk_mq_update_nr_hw_queues():
nullb_device_power_store nullb_apply_submit_queues
null_del_dev
del_gendisk
nullb_update_nr_hw_queues
if (!dev->nullb)
// still set while gendisk is deleted
return 0
blk_mq_update_nr_hw_queues
dev->nullb = NULL
Fix this problem by resuing the global mutex to protect
nullb_device_power_store() and nullb_update_nr_hw_queues() from configfs.
Fixes: 45919fb ("null_blk: Enable modifying 'submit_queues' after an instance has been configured")
Reported-and-tested-by: Yi Zhang <yi.zhang@redhat.com>
Closes: https://lore.kernel.org/all/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Zhu Yanjun <yanjun.zhu@linux.dev>
Link: https://lore.kernel.org/r/20240523153934.1937851-1-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
(cherry picked from commit a2db328)
[Harshit: CVE-2024-36478; Resolve conflicts due to missing commit:
e440626 ("null_blk: pass queue_limits to blk_mq_alloc_disk") in
6.6.y]
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent b2b0220 commit aaadb75
1 file changed
+26
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
396 | 402 | | |
397 | 403 | | |
398 | 404 | | |
399 | 405 | | |
400 | 406 | | |
401 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
402 | 414 | | |
403 | 415 | | |
404 | 416 | | |
| |||
444 | 456 | | |
445 | 457 | | |
446 | 458 | | |
| 459 | + | |
| 460 | + | |
447 | 461 | | |
448 | 462 | | |
449 | | - | |
| 463 | + | |
| 464 | + | |
450 | 465 | | |
451 | 466 | | |
452 | 467 | | |
453 | | - | |
| 468 | + | |
454 | 469 | | |
455 | 470 | | |
456 | 471 | | |
457 | 472 | | |
458 | 473 | | |
459 | 474 | | |
460 | | - | |
461 | 475 | | |
462 | 476 | | |
463 | | - | |
464 | 477 | | |
465 | 478 | | |
466 | 479 | | |
467 | 480 | | |
468 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
469 | 484 | | |
470 | 485 | | |
471 | 486 | | |
| |||
2153 | 2168 | | |
2154 | 2169 | | |
2155 | 2170 | | |
2156 | | - | |
2157 | 2171 | | |
2158 | | - | |
2159 | | - | |
| 2172 | + | |
2160 | 2173 | | |
2161 | | - | |
| 2174 | + | |
2162 | 2175 | | |
2163 | 2176 | | |
2164 | | - | |
2165 | 2177 | | |
2166 | 2178 | | |
2167 | 2179 | | |
| |||
2185 | 2197 | | |
2186 | 2198 | | |
2187 | 2199 | | |
2188 | | - | |
2189 | 2200 | | |
2190 | | - | |
2191 | 2201 | | |
2192 | 2202 | | |
2193 | 2203 | | |
| |||
2236 | 2246 | | |
2237 | 2247 | | |
2238 | 2248 | | |
| 2249 | + | |
2239 | 2250 | | |
| 2251 | + | |
2240 | 2252 | | |
2241 | 2253 | | |
2242 | 2254 | | |
| |||
0 commit comments