* [PATCH] initramfs_test: kunit test for cpio.filesize > PATH_MAX
@ 2026-01-14 13:45 David Disseldorp
2026-01-14 13:50 ` [PATCH v2] " David Disseldorp
0 siblings, 1 reply; 3+ messages in thread
From: David Disseldorp @ 2026-01-14 13:45 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Al Viro, Christian Brauner, David Disseldorp
initramfs unpack skips over cpio entries where namesize > PATH_MAX,
instead of returning an error. Add coverage for this behaviour.
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
init/initramfs_test.c | 47 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/init/initramfs_test.c b/init/initramfs_test.c
index 5d2db455e60c5..83f2f14387298 100644
--- a/init/initramfs_test.c
+++ b/init/initramfs_test.c
@@ -447,6 +447,52 @@ static void __init initramfs_test_fname_pad(struct kunit *test)
kfree(tbufs);
}
+static void __init initramfs_test_fname_path_max(struct kunit *test)
+{
+ char *err;
+ size_t len;
+ struct kstat st0, st1;
+ char fdata[] = "this file data will not be unpacked";
+ struct test_fname_path_max {
+ char fname_oversize[PATH_MAX + 1];
+ char fname_ok[PATH_MAX];
+ char cpio_src[(CPIO_HDRLEN + PATH_MAX + 3 + sizeof(fdata)) * 2];
+ } *tbufs = kzalloc(sizeof(struct test_fname_path_max), GFP_KERNEL);
+ struct initramfs_test_cpio c[] = { {
+ .magic = "070701",
+ .ino = 1,
+ .mode = S_IFDIR | 0777,
+ .nlink = 1,
+ .namesize = sizeof(tbufs->fname_oversize),
+ .fname = tbufs->fname_oversize,
+ .filesize = sizeof(fdata),
+ .data = fdata,
+ }, {
+ .magic = "070701",
+ .ino = 2,
+ .mode = S_IFDIR | 0777,
+ .nlink = 1,
+ .namesize = sizeof(tbufs->fname_ok),
+ .fname = tbufs->fname_ok,
+ } };
+
+ memset(tbufs->fname_oversize, '/', sizeof(tbufs->fname_oversize) - 1);
+ memset(tbufs->fname_ok, '/', sizeof(tbufs->fname_ok) - 1);
+ memcpy(tbufs->fname_oversize, "fname_oversize",
+ sizeof("fname_oversize") - 1);
+ memcpy(tbufs->fname_ok, "fname_ok", sizeof("fname_ok") - 1);
+ len = fill_cpio(c, ARRAY_SIZE(c), tbufs->cpio_src);
+
+ /* unpack skips over fname_oversize instead of returning an error */
+ err = unpack_to_rootfs(tbufs->cpio_src, len);
+ KUNIT_EXPECT_NULL(test, err);
+
+ KUNIT_EXPECT_EQ(test, init_stat("fname_oversize", &st0, 0), -ENOENT);
+ KUNIT_EXPECT_EQ(test, init_stat("fname_ok", &st1, 0), 0);
+
+ kfree(tbufs);
+}
+
/*
* The kunit_case/_suite struct cannot be marked as __initdata as this will be
* used in debugfs to retrieve results after test has run.
@@ -459,6 +505,7 @@ static struct kunit_case __refdata initramfs_test_cases[] = {
KUNIT_CASE(initramfs_test_hardlink),
KUNIT_CASE(initramfs_test_many),
KUNIT_CASE(initramfs_test_fname_pad),
+ KUNIT_CASE(initramfs_test_fname_path_max),
{},
};
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2] initramfs_test: kunit test for cpio.filesize > PATH_MAX
2026-01-14 13:45 [PATCH] initramfs_test: kunit test for cpio.filesize > PATH_MAX David Disseldorp
@ 2026-01-14 13:50 ` David Disseldorp
2026-01-14 15:46 ` Christian Brauner
0 siblings, 1 reply; 3+ messages in thread
From: David Disseldorp @ 2026-01-14 13:50 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Al Viro, Christian Brauner, David Disseldorp
initramfs unpack skips over cpio entries where namesize > PATH_MAX,
instead of returning an error. Add coverage for this behaviour.
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
v2:
- clean up created directory
init/initramfs_test.c | 48 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/init/initramfs_test.c b/init/initramfs_test.c
index 5d2db455e60c5..beb6e3cf78081 100644
--- a/init/initramfs_test.c
+++ b/init/initramfs_test.c
@@ -447,6 +447,53 @@ static void __init initramfs_test_fname_pad(struct kunit *test)
kfree(tbufs);
}
+static void __init initramfs_test_fname_path_max(struct kunit *test)
+{
+ char *err;
+ size_t len;
+ struct kstat st0, st1;
+ char fdata[] = "this file data will not be unpacked";
+ struct test_fname_path_max {
+ char fname_oversize[PATH_MAX + 1];
+ char fname_ok[PATH_MAX];
+ char cpio_src[(CPIO_HDRLEN + PATH_MAX + 3 + sizeof(fdata)) * 2];
+ } *tbufs = kzalloc(sizeof(struct test_fname_path_max), GFP_KERNEL);
+ struct initramfs_test_cpio c[] = { {
+ .magic = "070701",
+ .ino = 1,
+ .mode = S_IFDIR | 0777,
+ .nlink = 1,
+ .namesize = sizeof(tbufs->fname_oversize),
+ .fname = tbufs->fname_oversize,
+ .filesize = sizeof(fdata),
+ .data = fdata,
+ }, {
+ .magic = "070701",
+ .ino = 2,
+ .mode = S_IFDIR | 0777,
+ .nlink = 1,
+ .namesize = sizeof(tbufs->fname_ok),
+ .fname = tbufs->fname_ok,
+ } };
+
+ memset(tbufs->fname_oversize, '/', sizeof(tbufs->fname_oversize) - 1);
+ memset(tbufs->fname_ok, '/', sizeof(tbufs->fname_ok) - 1);
+ memcpy(tbufs->fname_oversize, "fname_oversize",
+ sizeof("fname_oversize") - 1);
+ memcpy(tbufs->fname_ok, "fname_ok", sizeof("fname_ok") - 1);
+ len = fill_cpio(c, ARRAY_SIZE(c), tbufs->cpio_src);
+
+ /* unpack skips over fname_oversize instead of returning an error */
+ err = unpack_to_rootfs(tbufs->cpio_src, len);
+ KUNIT_EXPECT_NULL(test, err);
+
+ KUNIT_EXPECT_EQ(test, init_stat("fname_oversize", &st0, 0), -ENOENT);
+ KUNIT_EXPECT_EQ(test, init_stat("fname_ok", &st1, 0), 0);
+ KUNIT_EXPECT_EQ(test, init_rmdir("fname_ok"), 0);
+
+ kfree(tbufs);
+}
+
/*
* The kunit_case/_suite struct cannot be marked as __initdata as this will be
* used in debugfs to retrieve results after test has run.
@@ -459,6 +506,7 @@ static struct kunit_case __refdata initramfs_test_cases[] = {
KUNIT_CASE(initramfs_test_hardlink),
KUNIT_CASE(initramfs_test_many),
KUNIT_CASE(initramfs_test_fname_pad),
+ KUNIT_CASE(initramfs_test_fname_path_max),
{},
};
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] initramfs_test: kunit test for cpio.filesize > PATH_MAX
2026-01-14 13:50 ` [PATCH v2] " David Disseldorp
@ 2026-01-14 15:46 ` Christian Brauner
0 siblings, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2026-01-14 15:46 UTC (permalink / raw)
To: linux-fsdevel, David Disseldorp; +Cc: Christian Brauner, Al Viro
On Thu, 15 Jan 2026 00:50:52 +1100, David Disseldorp wrote:
> initramfs unpack skips over cpio entries where namesize > PATH_MAX,
> instead of returning an error. Add coverage for this behaviour.
>
>
Thanks, I like the test for cpio unpacking. I think that's very valuable.
---
Applied to the vfs-7.0.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.0.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.0.misc
[1/1] initramfs_test: kunit test for cpio.filesize > PATH_MAX
https://git.kernel.org/vfs/vfs/c/5b6e22a5d937
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-14 15:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 13:45 [PATCH] initramfs_test: kunit test for cpio.filesize > PATH_MAX David Disseldorp
2026-01-14 13:50 ` [PATCH v2] " David Disseldorp
2026-01-14 15:46 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox