Re: [PATCH] selftests: ublk: Reject excess backing files

From: Caleb Sander Mateos

Date: Wed Sep 09 2026 - 13:15:50 EST


On Wed, Sep 9, 2026 at 7:17 AM Ruben Sutton <ruben@xxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxx>
> ---
> 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)
>
>