selftests/liveupdate: add test cases for LIVEUPDATE_IOCTL_CREATE_SESSION calls with invalid length

Verify that LIVEUPDATE_IOCTL_CREATE_SESSION ioctl which provide a name
that is an empty string or too long are not allowed.

Cc: stable@vger.kernel.org

Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Link: https://lore.kernel.org/r/20260429212221.814107-3-luca.boccassi@gmail.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
This commit is contained in:
Luca Boccassi 2026-04-29 22:21:15 +01:00 committed by Mike Rapoport (Microsoft)
parent e947433cd0
commit dab2b4c66a

View File

@ -386,4 +386,46 @@ TEST_F(liveupdate_device, prevent_double_preservation)
ASSERT_EQ(close(session_fd2), 0);
}
/*
* Test Case: Create Session with No Null Termination
*
* Verifies that filling the entire 64-byte name field with non-null characters
* (no '\0' terminator) is rejected by the kernel with EINVAL.
*/
TEST_F(liveupdate_device, create_session_no_null_termination)
{
struct liveupdate_ioctl_create_session args = {};
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);
/* Fill entire name field with 'X', no null terminator */
args.size = sizeof(args);
memset(args.name, 'X', sizeof(args.name));
EXPECT_LT(ioctl(self->fd1, LIVEUPDATE_IOCTL_CREATE_SESSION, &args), 0);
EXPECT_EQ(errno, EINVAL);
}
/*
* Test Case: Create Session with Empty Name
*
* Verifies that creating a session with an empty string name fails
* with EINVAL.
*/
TEST_F(liveupdate_device, create_session_empty_name)
{
int session_fd;
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 = create_session(self->fd1, "");
EXPECT_EQ(session_fd, -EINVAL);
}
TEST_HARNESS_MAIN