mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: ublk: Reject excess backing files
@ 2026-09-09 13:24 Ruben Sutton
  2026-09-09 15:28 ` Caleb Sander Mateos
  0 siblings, 1 reply; 2+ messages in thread
From: Ruben Sutton @ 2026-09-09 13:24 UTC (permalink / raw)
  To: Ming Lei, Shuah Khan
  Cc: linux-block, linux-kselftest, linux-kernel, Ruben Sutton

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)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] selftests: ublk: Reject excess backing files
  2026-09-09 13:24 [PATCH] selftests: ublk: Reject excess backing files Ruben Sutton
@ 2026-09-09 15:28 ` Caleb Sander Mateos
  0 siblings, 0 replies; 2+ messages in thread
From: Caleb Sander Mateos @ 2026-09-09 15:28 UTC (permalink / raw)
  To: Ruben Sutton
  Cc: Ming Lei, Shuah Khan, linux-block, linux-kselftest, linux-kernel

On Wed, Sep 9, 2026 at 7:17 AM Ruben Sutton <ruben@scstudios.tech> wrote:
>
> 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.

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.

>
> Fixes: 6aecda00b7d1 ("selftests: ublk: add kernel selftests for ublk")

Definitely don't think a Fixes tag is warranted.

Best,
Caleb

> 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)
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-09 15:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-09 13:24 [PATCH] selftests: ublk: Reject excess backing files Ruben Sutton
2026-09-09 15:28 ` Caleb Sander Mateos

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®