From: Ruben Sutton <ruben@scstudios.tech>
To: Ming Lei <tom.leiming@gmail.com>, Shuah Khan <shuah@kernel.org>
Cc: linux-block@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, Ruben Sutton <ruben@scstudios.tech>
Subject: [PATCH] selftests: ublk: Reject excess backing files
Date: Wed, 9 Sep 2026 23:24:12 +1000 [thread overview]
Message-ID: <20260909132412.8965-1-ruben@scstudios.tech> (raw)
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.
Fixes: 6aecda00b7d1 ("selftests: ublk: add kernel selftests for ublk")
Assisted-by: LLM
Signed-off-by: Ruben Sutton <ruben@scstudios.tech>
---
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
diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile
index 5daf36c6c3..28ce542d4e 100644
--- a/tools/testing/selftests/ublk/Makefile
+++ b/tools/testing/selftests/ublk/Makefile
@@ -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
diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index 2400b46157..3af2f10ca8 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -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) {
diff --git a/tools/testing/selftests/ublk/test_cli_01.sh b/tools/testing/selftests/ublk/test_cli_01.sh
new file mode 100755
index 0000000000..e937b8e20b
--- /dev/null
+++ b/tools/testing/selftests/ublk/test_cli_01.sh
@@ -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
--
2.54.0 (Apple Git-157)
next reply other threads:[~2026-09-09 13:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 13:24 Ruben Sutton [this message]
2026-09-09 15:28 ` Caleb Sander Mateos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260909132412.8965-1-ruben@scstudios.tech \
--to=ruben@scstudios.tech \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=tom.leiming@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®