Skip to content

Commit dab2b4c

Browse files
blucarppt
authored andcommitted
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>
1 parent e947433 commit dab2b4c

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tools/testing/selftests/liveupdate/liveupdate.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,46 @@ TEST_F(liveupdate_device, prevent_double_preservation)
386386
ASSERT_EQ(close(session_fd2), 0);
387387
}
388388

389+
/*
390+
* Test Case: Create Session with No Null Termination
391+
*
392+
* Verifies that filling the entire 64-byte name field with non-null characters
393+
* (no '\0' terminator) is rejected by the kernel with EINVAL.
394+
*/
395+
TEST_F(liveupdate_device, create_session_no_null_termination)
396+
{
397+
struct liveupdate_ioctl_create_session args = {};
398+
399+
self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
400+
if (self->fd1 < 0 && errno == ENOENT)
401+
SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
402+
ASSERT_GE(self->fd1, 0);
403+
404+
/* Fill entire name field with 'X', no null terminator */
405+
args.size = sizeof(args);
406+
memset(args.name, 'X', sizeof(args.name));
407+
408+
EXPECT_LT(ioctl(self->fd1, LIVEUPDATE_IOCTL_CREATE_SESSION, &args), 0);
409+
EXPECT_EQ(errno, EINVAL);
410+
}
411+
412+
/*
413+
* Test Case: Create Session with Empty Name
414+
*
415+
* Verifies that creating a session with an empty string name fails
416+
* with EINVAL.
417+
*/
418+
TEST_F(liveupdate_device, create_session_empty_name)
419+
{
420+
int session_fd;
421+
422+
self->fd1 = open(LIVEUPDATE_DEV, O_RDWR);
423+
if (self->fd1 < 0 && errno == ENOENT)
424+
SKIP(return, "%s does not exist", LIVEUPDATE_DEV);
425+
ASSERT_GE(self->fd1, 0);
426+
427+
session_fd = create_session(self->fd1, "");
428+
EXPECT_EQ(session_fd, -EINVAL);
429+
}
430+
389431
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)