[PATCH] initramfs_test: exercise the oversized CPIO namesize guard

From: Avi Weiss

Date: Tue Oct 27 2026 - 04:52:46 EST


initramfs_test_fname_path_max() uses a directory with a nonzero body.
Such entries are skipped even without the namesize > PATH_MAX check,
so the test does not detect removal of that check.

Use a regular file and terminate the archived pathname early after
fill_cpio() has encoded the oversized namesize. This allows the test
to detect a missing parser check without relying on VFS pathname
length limits.

Fixes: aaf76839616a ("initramfs_test: kunit test for cpio.filesize > PATH_MAX")
Signed-off-by: Avi Weiss <thnkslprpt@xxxxxxxxx>
---
init/initramfs_test.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/init/initramfs_test.c b/init/initramfs_test.c
index 1154547721ea..32d4d3e4e6c7 100644
--- a/init/initramfs_test.c
+++ b/init/initramfs_test.c
@@ -474,7 +474,7 @@ static void __init initramfs_test_fname_path_max(struct kunit *test)
struct initramfs_test_cpio c[] = { {
.magic = "070701",
.ino = 1,
- .mode = S_IFDIR | 0777,
+ .mode = S_IFREG | 0777,
.nlink = 1,
.namesize = sizeof(tbufs->fname_oversize),
.fname = tbufs->fname_oversize,
@@ -495,6 +495,8 @@ static void __init initramfs_test_fname_path_max(struct kunit *test)
sizeof("fname_oversize") - 1);
memcpy(tbufs->fname_ok, "fname_ok", sizeof("fname_ok") - 1);
len = fill_cpio(c, ARRAY_SIZE(c), false, tbufs->cpio_src);
+ /* keep namesize oversized, but give VFS a short pathname */
+ tbufs->cpio_src[CPIO_HDRLEN + sizeof("fname_oversize") - 1] = '\0';

/* unpack skips over fname_oversize instead of returning an error */
err = unpack_to_rootfs(tbufs->cpio_src, len);

base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
--
2.43.0