From: David Disseldorp <ddiss@suse.de>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org,
Al Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH v3 8/9] initramfs: fix hardlink hash leak without TRAILER
Date: Wed, 27 Nov 2024 17:35:36 +1100 [thread overview]
Message-ID: <20241127173536.76815a5b.ddiss@suse.de> (raw)
In-Reply-To: <20241107002044.16477-10-ddiss@suse.de>
On Thu, 7 Nov 2024 11:17:27 +1100, David Disseldorp wrote:
> Covered in Documentation/driver-api/early-userspace/buffer-format.rst ,
> initramfs archives can carry an optional "TRAILER!!!" entry which serves
> as a boundary for collecting and associating hardlinks with matching
> inode and major / minor device numbers.
>
> Although optional, if hardlinks are found in an archive without a
> subsequent "TRAILER!!!" entry then the hardlink state hash table is
> leaked
One further leak is possible if extraction ends prior to fput(wfile)
in CopyFile state, e.g. due to lack of data:
nilchar="\0"
data="123456789ABCDEF"
magic="070701"
ino=1
mode=$(( 0100777 ))
uid=0
gid=0
nlink=1
mtime=1
filesize=$(( ${#data} + 20 )) # too much
devmajor=0
devminor=1
rdevmajor=0
rdevminor=0
csum=0
fname="initramfs_test_archive_overrun"
namelen=$(( ${#fname} + 1 )) # plus one to account for terminator
printf "%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%s" \
$magic $ino $mode $uid $gid $nlink $mtime $filesize \
$devmajor $devminor $rdevmajor $rdevminor $namelen $csum $fname
termpadlen=$(( 1 + ((4 - ((110 + $namelen) & 3)) % 4) ))
printf "%.s${nilchar}" $(seq 1 $termpadlen)
# $filesize reaches 20 bytes beyond end of data
printf "%s" "$data"
bash data_repro.sh|gzip >> initramfs
unreferenced object 0xffff8fdb0192e000 (size 176):
comm "kworker/u8:0", pid 11, jiffies 4294892503
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 00 00 00 00 1e 80 5d 00 ..............].
80 7d a1 a7 ff ff ff ff 10 b1 2f 02 db 8f ff ff .}......../.....
backtrace (crc 807bd733):
[<00000000e68e8b32>] kmem_cache_alloc_noprof+0x11e/0x260
[<00000000a6f24fcd>] alloc_empty_file+0x45/0x120
[<00000000130beec8>] path_openat+0x2f/0xf30
[<0000000024613ad7>] do_filp_open+0xa7/0x110
[<000000005f4f0158>] file_open_name+0x118/0x180
[<0000000003ed573f>] filp_open+0x27/0x50
[<0000000091ec9e44>] do_name+0xc4/0x2b0
[<000000008e084ec8>] write_buffer+0x22/0x40
[<000000002ea2ff4b>] flush_buffer+0x2f/0x90
[<000000009085f8b5>] gunzip+0x25a/0x310
[<000000000c1c83c3>] unpack_to_rootfs+0x176/0x2a0
[<00000000c966fda5>] do_populate_rootfs+0x6a/0x180
[<0000000051fb877d>] async_run_entry_fn+0x31/0x120
[<00000000a3ee305f>] process_scheduled_works+0xbe/0x310
[<0000000083c835bb>] worker_thread+0x100/0x240
[<000000006ea2f0b3>] kthread+0xc8/0x100
Not sure whether others are interested in seeing these kinds of
leak-on-malformed-archive bugs fixed, but I'll send through a v4 with a
fix + unit test for it.
next prev parent reply other threads:[~2024-11-27 6:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 0:17 [PATCH v2 0/9] initramfs: kunit tests and cleanups David Disseldorp
2024-11-07 0:17 ` [PATCH v3 1/9] init: add initramfs_internal.h David Disseldorp
2024-11-07 0:17 ` [PATCH v3 2/9] initramfs_test: kunit tests for initramfs unpacking David Disseldorp
2024-11-09 0:25 ` kernel test robot
2024-11-07 0:17 ` [PATCH v3 3/9] vsprintf: add simple_strntoul David Disseldorp
2024-11-07 0:17 ` [PATCH v3 4/9] initramfs: avoid memcpy for hex header fields David Disseldorp
2024-11-07 0:17 ` [PATCH v3 5/9] initramfs: remove extra symlink path buffer David Disseldorp
2024-11-07 0:17 ` [PATCH v3 6/9] initramfs: merge header_buf and name_buf David Disseldorp
2024-11-07 0:17 ` [PATCH v3 7/9] initramfs: reuse name_len for dir mtime tracking David Disseldorp
2024-11-07 0:17 ` [PATCH v3 8/9] initramfs: fix hardlink hash leak without TRAILER David Disseldorp
2024-11-27 6:35 ` David Disseldorp [this message]
2024-11-07 0:17 ` [PATCH v3 9/9] initramfs: avoid static buffer for error message David Disseldorp
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=20241127173536.76815a5b.ddiss@suse.de \
--to=ddiss@suse.de \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kselftest@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