From: Yu Kuai <yukuai3@xxxxxxxxxx> Test delete the disk while IO is throttled, regression 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()") Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx> --- tests/throtl/004 | 37 +++++++++++++++++++++++++++++++++++++ tests/throtl/004.out | 4 ++++ tests/throtl/rc | 36 ++++++++++++++++++++++-------------- 3 files changed, 63 insertions(+), 14 deletions(-) create mode 100755 tests/throtl/004 create mode 100644 tests/throtl/004.out diff --git a/tests/throtl/004 b/tests/throtl/004 new file mode 100755 index 0000000..6e28612 --- /dev/null +++ b/tests/throtl/004 @@ -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" +} diff --git a/tests/throtl/004.out b/tests/throtl/004.out new file mode 100644 index 0000000..e76ec3a --- /dev/null +++ b/tests/throtl/004.out @@ -0,0 +1,4 @@ +Running throtl/004 +dd: error writing '/dev/dev_nullb': Input/output error +1 +Test complete diff --git a/tests/throtl/rc b/tests/throtl/rc index 2ddbac8..2e26fd2 100644 --- a/tests/throtl/rc +++ b/tests/throtl/rc @@ -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=$! -- 2.39.2