Commit a2db328
null_blk: fix null-ptr-dereference while configuring 'power' and 'submit_queues'
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 <[email protected]>
Closes: https://lore.kernel.org/all/CAHj4cs9LgsHLnjg8z06LQ3Pr5cax-+Ps+xT7AP7TPnEjStuwZA@mail.gmail.com/
Signed-off-by: Yu Kuai <[email protected]>
Reviewed-by: Zhu Yanjun <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>1 parent 4a482e6 commit a2db328
1 file changed
+26
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
417 | 423 | | |
418 | 424 | | |
419 | 425 | | |
420 | 426 | | |
421 | 427 | | |
422 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
423 | 435 | | |
424 | 436 | | |
425 | 437 | | |
| |||
468 | 480 | | |
469 | 481 | | |
470 | 482 | | |
| 483 | + | |
| 484 | + | |
471 | 485 | | |
472 | 486 | | |
473 | | - | |
| 487 | + | |
| 488 | + | |
474 | 489 | | |
475 | 490 | | |
476 | 491 | | |
477 | | - | |
| 492 | + | |
478 | 493 | | |
479 | 494 | | |
480 | 495 | | |
481 | 496 | | |
482 | 497 | | |
483 | 498 | | |
484 | | - | |
485 | 499 | | |
486 | 500 | | |
487 | | - | |
488 | 501 | | |
489 | 502 | | |
490 | 503 | | |
491 | 504 | | |
492 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
493 | 508 | | |
494 | 509 | | |
495 | 510 | | |
| |||
1932 | 1947 | | |
1933 | 1948 | | |
1934 | 1949 | | |
1935 | | - | |
1936 | 1950 | | |
1937 | | - | |
1938 | | - | |
| 1951 | + | |
1939 | 1952 | | |
1940 | | - | |
| 1953 | + | |
1941 | 1954 | | |
1942 | 1955 | | |
1943 | | - | |
1944 | 1956 | | |
1945 | 1957 | | |
1946 | 1958 | | |
| |||
1969 | 1981 | | |
1970 | 1982 | | |
1971 | 1983 | | |
1972 | | - | |
1973 | 1984 | | |
1974 | | - | |
1975 | 1985 | | |
1976 | 1986 | | |
1977 | 1987 | | |
| |||
2020 | 2030 | | |
2021 | 2031 | | |
2022 | 2032 | | |
| 2033 | + | |
2023 | 2034 | | |
| 2035 | + | |
2024 | 2036 | | |
2025 | 2037 | | |
2026 | 2038 | | |
| |||
0 commit comments