new file mode 100755
@@ -0,0 +1,79 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2024 Yu Kuai
+#
+# Test delete the disk while IO is throttled, regerssion test for
+# commit 884f0e84f1e3 ("blk-throttle: fix UAF by deleteing timer in blk_throtl_exit()")
+# commit 8f9e7b65f833 ("block: cancel all throttled bios in del_gendisk()")
+
+. tests/throtl/rc
+
+DESCRIPTION="delete disk while IO is throttled"
+QUICK=1
+
+CG=/sys/fs/cgroup
+TEST_DIR=$CG/blktests_throtl
+devname=nullb0
+dev=""
+
+set_up_test() {
+ if ! _init_null_blk nr_devices=0; then
+ return 1;
+ fi
+
+ if ! _configure_null_blk $devname power=1; then
+ return 1;
+ fi
+
+ dev=$(cat /sys/block/$devname/dev)
+ echo +io > $CG/cgroup.subtree_control
+ mkdir $TEST_DIR
+
+ return 0;
+}
+
+clean_up_test() {
+ rmdir $TEST_DIR
+ echo -io > $CG/cgroup.subtree_control
+ _exit_null_blk
+}
+
+config_throtl() {
+ limit=$((1024 * 1024))
+ echo "$dev wbps=$limit" > $TEST_DIR/io.max
+}
+
+test_io() {
+ config_throtl
+
+ {
+ sleep 0.1
+ start_time=$(date +%s.%N)
+
+ dd of=/dev/$devname if=/dev/zero bs=10M count=1 oflag=direct status=none
+
+ end_time=$(date +%s.%N)
+ elapsed=$(echo "$end_time - $start_time" | bc)
+ printf "%.0f\n" "$elapsed"
+ } &
+
+ pid=$!
+ echo $! > $TEST_DIR/cgroup.procs
+
+ sleep 1
+ echo 0 > /sys/kernel/config/nullb/$devname/power
+ wait $pid
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ if ! set_up_test; then
+ return 1;
+ fi
+
+ test_io
+
+ clean_up_test
+ echo "Test complete"
+}
new file mode 100644
@@ -0,0 +1,4 @@
+Running throtl/004
+dd: error writing '/dev/nullb0': Input/output error
+1
+Test complete