CVE-2024-53142
Severity CVSS v4.0:
Pending analysis
Type:
CWE-787
Out-of-bounds Write
Publication date:
06/12/2024
Last modified:
14/12/2024
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
initramfs: avoid filename buffer overrun<br />
<br />
The initramfs filename field is defined in<br />
Documentation/driver-api/early-userspace/buffer-format.rst as:<br />
<br />
37 cpio_file := ALGN(4) + cpio_header + filename + "\0" + ALGN(4) + data<br />
...<br />
55 ============= ================== =========================<br />
56 Field name Field size Meaning<br />
57 ============= ================== =========================<br />
...<br />
70 c_namesize 8 bytes Length of filename, including final \0<br />
<br />
When extracting an initramfs cpio archive, the kernel&#39;s do_name() path<br />
handler assumes a zero-terminated path at @collected, passing it<br />
directly to filp_open() / init_mkdir() / init_mknod().<br />
<br />
If a specially crafted cpio entry carries a non-zero-terminated filename<br />
and is followed by uninitialized memory, then a file may be created with<br />
trailing characters that represent the uninitialized memory. The ability<br />
to create an initramfs entry would imply already having full control of<br />
the system, so the buffer overrun shouldn&#39;t be considered a security<br />
vulnerability.<br />
<br />
Append the output of the following bash script to an existing initramfs<br />
and observe any created /initramfs_test_fname_overrunAA* path. E.g.<br />
./reproducer.sh | gzip >> /myinitramfs<br />
<br />
It&#39;s easiest to observe non-zero uninitialized memory when the output is<br />
gzipped, as it&#39;ll overflow the heap allocated @out_buf in __gunzip(),<br />
rather than the initrd_start+initrd_size block.<br />
<br />
---- reproducer.sh ----<br />
nilchar="A" # change to "\0" to properly zero terminate / pad<br />
magic="070701"<br />
ino=1<br />
mode=$(( 0100777 ))<br />
uid=0<br />
gid=0<br />
nlink=1<br />
mtime=1<br />
filesize=0<br />
devmajor=0<br />
devminor=1<br />
rdevmajor=0<br />
rdevminor=0<br />
csum=0<br />
fname="initramfs_test_fname_overrun"<br />
namelen=$(( ${#fname} + 1 )) # plus one to account for terminator<br />
<br />
printf "%s%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%s" \<br />
$magic $ino $mode $uid $gid $nlink $mtime $filesize \<br />
$devmajor $devminor $rdevmajor $rdevminor $namelen $csum $fname<br />
<br />
termpadlen=$(( 1 + ((4 - ((110 + $namelen) & 3)) % 4) ))<br />
printf "%.s${nilchar}" $(seq 1 $termpadlen)<br />
---- reproducer.sh ----<br />
<br />
Symlink filename fields handled in do_symlink() won&#39;t overrun past the<br />
data segment, due to the explicit zero-termination of the symlink<br />
target.<br />
<br />
Fix filename buffer overrun by aborting the initramfs FSM if any cpio<br />
entry doesn&#39;t carry a zero-terminator at the expected (name_len - 1)<br />
offset.
Impact
Base Score 3.x
7.80
Severity 3.x
HIGH
Vulnerable products and versions
CPE | From | Up to |
---|---|---|
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 2.6.12 (including) | 4.19.325 (excluding) |
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 4.20 (including) | 6.6.64 (excluding) |
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.7 (including) | 6.11.11 (excluding) |
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.12 (including) | 6.12.2 (excluding) |
To consult the complete list of CPE names with products and versions, see this page
References to Advisories, Solutions, and Tools
- https://git.kernel.org/stable/c/1a423bbbeaf9e3e20c4686501efd9b661fe834db
- https://git.kernel.org/stable/c/49d01e736c3045319e030d1e75fb983011abaca7
- https://git.kernel.org/stable/c/6983b8ac787b3add5571cda563574932a59a99bb
- https://git.kernel.org/stable/c/bb7ac96670ab1d8d681015f9d66e45dad579af4d
- https://git.kernel.org/stable/c/c509b1acbd867d9e09580fe059a924cb5825afb1
- https://git.kernel.org/stable/c/d3df9f26cff97beaa5643e551031795d5d5cddbe
- https://git.kernel.org/stable/c/e017671f534dd3f568db9e47b0583e853d2da9b5
- https://git.kernel.org/stable/c/f892ddcf9f645380c358e73653cb0900f6bc9eb8
- https://git.kernel.org/stable/c/fb83b093f75806333b6f4ae29b158d2e0e3ec971