selftests: ublk: Reject excess backing files
Subsystems (3)
PATCH 1/1 selftests: ublk: Reject excess backing files
kublk stores at most MAX_BACK_FILES backing file arguments. The argument parser currently stops collecting paths when that limit is reached and silently ignores any remaining paths.
Reject the command instead so that a test cannot accidentally run with fewer backing files than requested. Add a regression test that exercises the error without requiring a ublk device.
--- tools/testing/selftests/ublk/Makefile | 4 +++- tools/testing/selftests/ublk/kublk.c | 5 +++++ tools/testing/selftests/ublk/test_cli_01.sh | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/ublk/test_cli_01.sh
tools/testing/selftests/ublk/Makefile +3 -1
@@ -7,7 +7,9 @@ endif LDLIBS += -lpthread -lm -luring -TEST_PROGS := test_generic_02.sh +TEST_PROGS := test_cli_01.sh + +TEST_PROGS += test_generic_02.sh TEST_PROGS += test_generic_03.sh TEST_PROGS += test_generic_06.sh TEST_PROGS += test_generic_07.sh
tools/testing/selftests/ublk/kublk.c +5 -0
@@ -2525,6 +2525,11 @@ int main(int argc, char *argv[])while (i < argc && ctx.nr_files <MAX_BACK_FILES ) { ctx.files[ctx.nr_files++] = argv[i++]; } +if (i < argc) { +fprintf (stderr,"too many backing files (maximum is %d)\n" , +MAX_BACK_FILES ); +return -EINVAL ; + } ops =ublk_find_tgt (ctx.tgt_type);if (ops && ops->parse_cmd_line) {
tools/testing/selftests/ublk/test_cli_01.sh new file +15 -0
@@ -0,0 +1,15 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +UBLK_PROG="$(dirname "$0")/kublk" +expected="too many backing files (maximum is 4)" + +if output=$("${UBLK_PROG}" add -t stripe a b c d e 2>&1); then + echo "kublk accepted more than four backing files" + exit 1 +fi + +if [ "${output}" != "${expected}" ]; then + echo "unexpected error: ${output}" + exit 1 +fi
base-commit: 893e11787f78e43b534e252249ac3fff4d1333f8
Signature · 1 line
2.54.0 (Apple Git-157)
Quoted 8 lines · Ruben Sutton
kublk stores at most
MAX_BACK_FILESbacking file arguments. The argument parser currently stops collecting paths when that limit is reached and silently ignores any remaining paths.Reject the command instead so that a test cannot accidentally run with fewer backing files than requested. Add a regression test that exercises the error without requiring a ublk device.
There are already plenty of ways to break kublk (try kublk add --unrecognized_long_opt). It's a test helper, not a hardened production-ready ublk server.
Quoted 2 lines
Fixes 6aecda00b7d1 ("selftests: ublk: add kernel selftests for ublk")
Definitely don't think a Fixes tag is warranted.
Best,
Caleb
Quoted 67 lines
Assisted-by LLMSigned-off-by Ruben Sutton <[email protected]>--- tools/testing/selftests/ublk/Makefile | 4 +++- tools/testing/selftests/ublk/kublk.c | 5 +++++ tools/testing/selftests/ublk/test_cli_01.sh | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/ublk/test_cli_01.shtools/testing/selftests/ublk/Makefile +3
-1@@ -7,7 +7,9 @@ endif LDLIBS += -lpthread -lm -luring -TEST_PROGS := test_generic_02.sh +TEST_PROGS := test_cli_01.sh + +TEST_PROGS += test_generic_02.sh TEST_PROGS += test_generic_03.sh TEST_PROGS += test_generic_06.sh TEST_PROGS += test_generic_07.shtools/testing/selftests/ublk/kublk.c +5
-0@@ -2525,6 +2525,11 @@ int main(int argc, char *argv[])while (i < argc && ctx.nr_files <MAX_BACK_FILES ) { ctx.files[ctx.nr_files++] = argv[i++]; } +if (i < argc) { +fprintf (stderr,"too many backing files (maximum is %d)\n" , +MAX_BACK_FILES ); +return -EINVAL ; + } ops =ublk_find_tgt (ctx.tgt_type);if (ops && ops->parse_cmd_line) {tools/testing/selftests/ublk/test_cli_01.sh new file +15
-0@@ -0,0 +1,15 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +UBLK_PROG="$(dirname "$0")/kublk" +expected="too many backing files (maximum is 4)" + +if output=$("${UBLK_PROG}" add -t stripe a b c d e 2>&1); then + echo "kublk accepted more than four backing files" + exit 1 +fi + +if [ "${output}" != "${expected}" ]; then + echo "unexpected error: ${output}" + exit 1 +fibase-commit:
893e11787f78e43b534e252249ac3fff4d1333f8--
2.54.0 (Apple Git-157)