Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: liveupdate: add test for double preservation

Verify that a file can only be preserved once across all active sessions.
Attempting to preserve it a second time, whether in the same or a
different session, should fail with EBUSY.

Link: https://lore.kernel.org/20260326163943.574070-4-pasha.tatashin@soleen.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Cc: David Matlack <dmatlack@google.com>
Cc: Pratyush Yadav <pratyush@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
e3e613a3 bc3a5763

+41
+41
tools/testing/selftests/liveupdate/liveupdate.c
··· 345 345 ASSERT_EQ(close(session_fd), 0); 346 346 } 347 347 348 + /* 349 + * Test Case: Prevent Double Preservation 350 + * 351 + * Verifies that a file (memfd) can only be preserved once across all active 352 + * sessions. Attempting to preserve it a second time, whether in the same or 353 + * a different session, should fail with EBUSY. 354 + */ 355 + TEST_F(liveupdate_device, prevent_double_preservation) 356 + { 357 + int session_fd1, session_fd2, mem_fd; 358 + int ret; 359 + 360 + self->fd1 = open(LIVEUPDATE_DEV, O_RDWR); 361 + if (self->fd1 < 0 && errno == ENOENT) 362 + SKIP(return, "%s does not exist", LIVEUPDATE_DEV); 363 + ASSERT_GE(self->fd1, 0); 364 + 365 + session_fd1 = create_session(self->fd1, "double-preserve-session-1"); 366 + ASSERT_GE(session_fd1, 0); 367 + session_fd2 = create_session(self->fd1, "double-preserve-session-2"); 368 + ASSERT_GE(session_fd2, 0); 369 + 370 + mem_fd = memfd_create("test-memfd", 0); 371 + ASSERT_GE(mem_fd, 0); 372 + 373 + /* First preservation should succeed */ 374 + ASSERT_EQ(preserve_fd(session_fd1, mem_fd, 0x1111), 0); 375 + 376 + /* Second preservation in a different session should fail with EBUSY */ 377 + ret = preserve_fd(session_fd2, mem_fd, 0x2222); 378 + EXPECT_EQ(ret, -EBUSY); 379 + 380 + /* Second preservation in the same session (different token) should fail with EBUSY */ 381 + ret = preserve_fd(session_fd1, mem_fd, 0x3333); 382 + EXPECT_EQ(ret, -EBUSY); 383 + 384 + ASSERT_EQ(close(mem_fd), 0); 385 + ASSERT_EQ(close(session_fd1), 0); 386 + ASSERT_EQ(close(session_fd2), 0); 387 + } 388 + 348 389 TEST_HARNESS_MAIN