Skip to contentSkip to conversation

initramfs_test: exercise the oversized CPIO namesize guard

PATCH In review Avi Weiss 2 participants 2 messages Oct 27 – Nov 4 VFS

lore
Share & tools
lore

Avi Weiss

author
#0 lore raw

PATCH 1/1 initramfs_test: exercise the oversized CPIO namesize guard

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")
---
 init/initramfs_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
init/initramfs_test.c +3 -1
index 1154547721ea..32d4d3e4e6c7 100644
@@ -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

Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 1 line · Avi Weiss

initramfs_test_fname_path_max() uses a directory with a nonzero body.

Hmm, indeed, that doesn't make much sense.

Quoted 2 lines

Such entries are skipped even without the namesize > PATH_MAX check, so the test does not detect removal of that check.

This is phrased a bit cryptically: the existing test *does* exercise the name_len > PATH_MAX check, but you're right that removal of that check would still see the the entry skipped due to the subsequent if (S_ISREG(mode) || !body_len) filter.

Quoted 4 lines

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.

I don't think adding the early fname termination makes sense in the context of the test.