null_blk: reset throttled state before device setup
PATCH 1/1 null_blk: reset throttled state before device setup
The NULLB_DEV_FL_THROTTLED flag is set at power on when mbps is set, and is never cleared. Since commit 00a8cdb84fcb ("null_blk: remove NULLB_DEV_FL_CONFIGURED on turning off nullb device") mbps can change when the device is off. After a change to 0, the stale THROTTLED flag sends I/O into the throttled I/O handler, whose hrtimer_active() runs on an uninitialized timer, dereferencing a NULL pointer. A crash happens at power on, as the first I/O that triggers the NULL dereference is partition scanning I/O. This sequence triggers the crash:
echo 100 > mbps; echo 1 > power; echo 0 > power; echo 0 > mbps; echo 1 > power
Clear the flag at the start of null_add_dev(), as is done in commit 5a4236bf2262 ("null_blk: reset cache state before device setup") for NULLB_DEV_FL_CACHE. It is set again when mbps is set.
--- drivers/block/null_blk/main.c | 1 + 1 file changed, 1 insertion(+)
drivers/block/null_blk/main.c +1 -0
@@ -1977,6 +1977,7 @@ static int null_add_dev(struct nullb_device *dev)if (rv)return rv;clear_bit (NULLB_DEV_FL_CACHE , &dev->flags); +clear_bit (NULLB_DEV_FL_THROTTLED , &dev->flags); nullb =kzalloc_node (sizeof (*nullb),GFP_KERNEL , dev->home_node);if (!nullb) {
base-commit: e6ac1da6a53c5f670bf09e60a2500d15be68d2fc
Signature · 1 line
2.53.0