From: Yu Kuai <yukuai3@xxxxxxxxxx> 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()") Signed-off-by: Yu Kuai <yukuai3@xxxxxxxxxx> --- tests/throtl/004 | 37 +++++++++++++++++++++++++++++++++++ tests/throtl/004.out | 4 ++++ tests/throtl/rc | 46 +++++++++++++++++++++++++++++++++----------- 3 files changed, 76 insertions(+), 11 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..f2567c0 --- /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_test_by_configfs power=1; then + return 1; + fi + + _set_limits wbps=$((1024 * 1024)) + + { + sleep 0.1 + _issue_io write 10M 1 + } & + + pid=$! + echo "$pid" > $TEST_DIR/cgroup.procs + + sleep 1 + echo 0 > /sys/kernel/config/nullb/$devname/power + wait "$pid" + + _clean_up_test + echo "Test complete" +} diff --git a/tests/throtl/004.out b/tests/throtl/004.out new file mode 100644 index 0000000..03331fe --- /dev/null +++ b/tests/throtl/004.out @@ -0,0 +1,4 @@ +Running throtl/004 +dd: error writing '/dev/nullb0': Input/output error +1 +Test complete diff --git a/tests/throtl/rc b/tests/throtl/rc index 871102c..f70e250 100644 --- a/tests/throtl/rc +++ b/tests/throtl/rc @@ -30,6 +30,21 @@ _set_up_test() { return 0; } +_set_up_test_by_configfs() { + if ! _init_null_blk nr_devices=0; then + return 1; + fi + + if ! _configure_null_blk $devname "$*"; then + return 1; + fi + + echo +io > $CG/cgroup.subtree_control + mkdir $TEST_DIR + + return 0; +} + _clean_up_test() { rmdir $TEST_DIR echo -io > $CG/cgroup.subtree_control @@ -46,23 +61,32 @@ _remove_limits() { echo "$dev rbps=max wbps=max riops=max wiops=max" > $TEST_DIR/io.max } +_issue_io() +{ + start_time=$(date +%s.%N) + + if [ "$1" == "read" ]; then + dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none + elif [ "$1" == "write" ]; then + dd of=/dev/$devname 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. _test_io() { { - sleep 0.1 - start_time=$(date +%s.%N) + rw=$1 + bs=$2 + count=$3 - if [ "$1" == "read" ]; then - dd if=/dev/$devname of=/dev/null bs="$2" count="$3" iflag=direct status=none - elif [ "$1" == "write" ]; then - dd of=/dev/$devname 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" + sleep 0.1 + _issue_io "$rw" "$bs" "$count" } & pid=$! -- 2.39.2