[PATCH v3 02/10] selftests: liveupdate: Add tests for preserve and retrieve user argument
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Tue Nov 3 17:03:23 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] selftests/liveupdate: zero min_arg.arg in preserve_memfd_with_arg()
--
commit 0eae9757b9fca17ee60f5d085e6dce0d9304a977
Author: Pasha Tatashin <pasha.tatashin at soleen.com>
selftests: liveupdate: Add tests for preserve and retrieve user argument
This commit adds libliveupdate helpers for passing user arguments to
LIVEUPDATE_SESSION_PRESERVE_FD and LIVEUPDATE_SESSION_RETRIEVE_FD, and adds
the preserve_memfd_with_arg test case to verify memfd argument validation and
legacy struct size handling.
> diff --git a/tools/testing/selftests/liveupdate/liveupdate.c b/tools/testing/selftests/liveupdate/liveupdate.c
> index 2dedd5fc2534f..4c4272167635b 100644
> --- a/tools/testing/selftests/liveupdate/liveupdate.c
> +++ b/tools/testing/selftests/liveupdate/liveupdate.c
[ ... ]
> @@ -530,4 +531,47 @@ TEST_F(liveupdate_device, preserve_many_files)
> ASSERT_EQ(close(session_fd), 0);
> }
>
> +/*
> + * Test Case: Preserve MemFD with User Argument
> + *
> + * Verifies that passing a non-zero user argument to memfd preservation fails
> + * with -EOPNOTSUPP, while passing a zero argument or using the minimum struct
> + * size without the arg field succeeds.
> + */
> +TEST_F(liveupdate_device, preserve_memfd_with_arg)
> +{
> + struct liveupdate_session_preserve_fd min_arg = {};
> + int session_fd, mem_fd1, mem_fd2;
> +
> + self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
> + if (self->fd1 < 0 && errno == ENOENT)
> + SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
> + ASSERT_GE(self->fd1, 0);
> +
> + session_fd = luo_create_session(self->fd1, "preserve-arg-test");
> + ASSERT_GE(session_fd, 0);
> +
> + mem_fd1 = memfd_create("arg-memfd-1", 0);
> + ASSERT_GE(mem_fd1, 0);
> +
> + /* Non-zero arg is not supported by memfd handler */
> + EXPECT_EQ(luo_session_preserve_fd_arg(session_fd, mem_fd1, 0x1111, 1),
> + -EOPNOTSUPP);
> +
> + /* Legacy struct size (up to token) should zero-fill arg and succeed */
> + min_arg.size = offsetof(struct liveupdate_session_preserve_fd, arg);
> + min_arg.fd = mem_fd1;
> + min_arg.token = 0x1111;
> + ASSERT_EQ(ioctl(session_fd, LIVEUPDATE_SESSION_PRESERVE_FD, &min_arg), 0);
[Severity: Low]
In preserve_memfd_with_arg, min_arg is zero-initialized at declaration:
struct liveupdate_session_preserve_fd min_arg = {};
Because min_arg.arg is already 0 in userspace memory when ioctl() is called
with LIVEUPDATE_SESSION_PRESERVE_FD, the call would still see min_arg.arg == 0
even if the kernel read the entire struct from userspace instead of truncating
at min_arg.size and zero-filling the trailing arg field.
Should min_arg.arg be set to a non-zero value before the ioctl() call so that
this subtest verifies the kernel ignores bytes beyond min_arg.size and
zero-fills arg?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103010216.3447716-1-dmatlack@google.com?part=2
More information about the kexec
mailing list