[LTP] [PATCH v2 4/5] syscalls: add listns01 test for EFAULT on invalid address
Cyril Hrubis
chrubis@suse.cz
Fri Mar 20 11:39:47 CET 2026
Hi!
> +++ b/testcases/kernel/syscalls/listns/listns01.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2026 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * Test listns() EFAULT error handling with invalid buffer pointers.
> + *
> + * Verify that listns() returns EFAULT when given a completely invalid
> + * address or a NULL pointer as the output buffer.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include "tst_test.h"
> +#include "lapi/syscalls.h"
> +#include "lapi/listns.h"
> +
> +static struct tcase {
> + const char *desc;
> + uintptr_t bad_ptr_val;
> + size_t nr_ids;
> +} tcases[] = {
> + {
> + .desc = "completely invalid pointer",
^
Just "invalid pointer"
Keep messages short and to the point.
> + .bad_ptr_val = 0xdeadbeef,
We do have a tst_get_bad_addr() function to generate an address that is
100% sure to be invalid on any platform.
> + .nr_ids = 10,
This is the same for bot cases, no need to put it into the struct.
> + },
> + {
> + .desc = "NULL buffer",
> + .bad_ptr_val = 0,
> + .nr_ids = 10,
> + },
> +};
> +
> +static void verify_listns(unsigned int n)
> +{
> + struct tcase *tc = &tcases[n];
> + struct listns_req req = { .size = NS_ID_REQ_SIZE_VER0 };
> +
> + TST_EXP_FAIL2(listns(&req, (uint64_t *)tc->bad_ptr_val, tc->nr_ids, 0),
> + EFAULT, "listns() %s", tc->desc);
> +}
> +
> +static void setup(void)
> +{
> + struct listns_req req = { .size = NS_ID_REQ_SIZE_VER0 };
> +
> + tst_syscall(__NR_listns, &req, NULL, 0, 0);
> +}
> +
> +static struct tst_test test = {
> + .tcnt = ARRAY_SIZE(tcases),
> + .test = verify_listns,
> + .setup = setup,
> +};
>
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list