From: David Disseldorp <ddiss@suse.de>
To: linux-fsdevel@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
David Disseldorp <ddiss@suse.de>
Subject: [PATCH] initramfs_test: kunit test for cpio.filesize > PATH_MAX
Date: Thu, 15 Jan 2026 00:45:46 +1100 [thread overview]
Message-ID: <20260114134546.1691-1-ddiss@suse.de> (raw)
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
next reply other threads:[~2026-01-14 13:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-14 13:45 David Disseldorp [this message]
2026-01-14 13:50 ` [PATCH v2] initramfs_test: kunit test for cpio.filesize > PATH_MAX David Disseldorp
2026-01-14 15:46 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260114134546.1691-1-ddiss@suse.de \
--to=ddiss@suse.de \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox