new file mode 100755
@@ -0,0 +1,37 @@
+#!/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
+
+test() {
+ echo "Running ${TEST_NAME}"
+
+ if ! _set_up_throtl; then
+ return 1;
+ fi
+
+ _throtl_set_limits wbps=$((1024 * 1024))
+
+ {
+ sleep 0.1
+ _throtl_issue_io write 10M 1
+ } &
+
+ local pid=$!
+ echo "$pid" > "$CGROUP2_DIR/$THROTL_DIR/cgroup.procs"
+
+ sleep 0.6
+ echo 0 > "/sys/kernel/config/nullb/$THROTL_DEV/power"
+ wait "$pid"
+
+ _clean_up_throtl
+ echo "Test complete"
+}
new file mode 100644
@@ -0,0 +1,4 @@
+Running throtl/004
+dd: error writing '/dev/dev_nullb': Input/output error
+1
+Test complete
@@ -57,6 +57,24 @@ _throtl_remove_limits() {
"$CGROUP2_DIR/$THROTL_DIR/io.max"
}
+_throtl_issue_io() {
+ local start_time
+ local end_time
+ local elapsed
+
+ start_time=$(date +%s.%N)
+
+ if [ "$1" == "read" ]; then
+ dd if=/dev/$THROTL_DEV of=/dev/null bs="$2" count="$3" iflag=direct status=none
+ elif [ "$1" == "write" ]; then
+ dd of=/dev/$THROTL_DEV if=/dev/zero bs="$2" count="$3" oflag=direct status=none
+ fi
+
+ end_time=$(date +%s.%N)
+ elapsed=$(echo "$end_time - $start_time" | bc)
+ printf "%.0f\n" "$elapsed"
+}
+
# Create an asynchronous thread and bind it to the specified blk-cgroup, issue
# IO and then print time elapsed to the second, blk-throttle limits should be
# set before this function.
@@ -64,22 +82,12 @@ _throtl_test_io() {
local pid
{
- local start_time
- local end_time
- local elapsed
+ local rw=$1
+ local bs=$2
+ local count=$3
sleep 0.1
- start_time=$(date +%s.%N)
-
- if [ "$1" == "read" ]; then
- dd if=/dev/$THROTL_DEV of=/dev/null bs="$2" count="$3" iflag=direct status=none
- elif [ "$1" == "write" ]; then
- dd of=/dev/$THROTL_DEV if=/dev/zero bs="$2" count="$3" oflag=direct status=none
- fi
-
- end_time=$(date +%s.%N)
- elapsed=$(echo "$end_time - $start_time" | bc)
- printf "%.0f\n" "$elapsed"
+ _throtl_issue_io "$rw" "$bs" "$count"
} &
pid=$!