<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/binfmt_elf.c, branch linux-6.10.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.10.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.10.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2024-09-12T09:12:50Z</updated>
<entry>
<title>ELF: fix kernel.randomize_va_space double read</title>
<updated>2024-09-12T09:12:50Z</updated>
<author>
<name>Alexey Dobriyan</name>
</author>
<published>2024-06-21T18:54:50Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1cf8cd80903073440b6ea055811d04edd24fe4f7'/>
<id>urn:sha1:1cf8cd80903073440b6ea055811d04edd24fe4f7</id>
<content type='text'>
[ Upstream commit 2a97388a807b6ab5538aa8f8537b2463c6988bd2 ]

ELF loader uses "randomize_va_space" twice. It is sysctl and can change
at any moment, so 2 loads could see 2 different values in theory with
unpredictable consequences.

Issue exactly one load for consistent value across one exec.

Signed-off-by: Alexey Dobriyan &lt;adobriyan@gmail.com&gt;
Link: https://lore.kernel.org/r/3329905c-7eb8-400a-8f0a-d87cff979b5b@p183
Signed-off-by: Kees Cook &lt;kees@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>Merge tag 'mm-nonmm-stable-2024-05-19-11-56' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm</title>
<updated>2024-05-19T21:02:03Z</updated>
<author>
<name>Linus Torvalds</name>
</author>
<published>2024-05-19T21:02:03Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=eb6a9339efeb6f3d2b5c86fdf2382cdc293eca2c'/>
<id>urn:sha1:eb6a9339efeb6f3d2b5c86fdf2382cdc293eca2c</id>
<content type='text'>
Pull non-mm updates from Andrew Morton:
 "Mainly singleton patches, documented in their respective changelogs.
  Notable series include:

   - Some maintenance and performance work for ocfs2 in Heming Zhao's
     series "improve write IO performance when fragmentation is high".

   - Some ocfs2 bugfixes from Su Yue in the series "ocfs2 bugs fixes
     exposed by fstests".

   - kfifo header rework from Andy Shevchenko in the series "kfifo:
     Clean up kfifo.h".

   - GDB script fixes from Florian Rommel in the series "scripts/gdb:
     Fixes for $lx_current and $lx_per_cpu".

   - After much discussion, a coding-style update from Barry Song
     explaining one reason why inline functions are preferred over
     macros. The series is "codingstyle: avoid unused parameters for a
     function-like macro""

* tag 'mm-nonmm-stable-2024-05-19-11-56' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (62 commits)
  fs/proc: fix softlockup in __read_vmcore
  nilfs2: convert BUG_ON() in nilfs_finish_roll_forward() to WARN_ON()
  scripts: checkpatch: check unused parameters for function-like macro
  Documentation: coding-style: ask function-like macros to evaluate parameters
  nilfs2: use __field_struct() for a bitwise field
  selftests/kcmp: remove unused open mode
  nilfs2: remove calls to folio_set_error() and folio_clear_error()
  kernel/watchdog_perf.c: tidy up kerneldoc
  watchdog: allow nmi watchdog to use raw perf event
  watchdog: handle comma separated nmi_watchdog command line
  nilfs2: make superblock data array index computation sparse friendly
  squashfs: remove calls to set the folio error flag
  squashfs: convert squashfs_symlink_read_folio to use folio APIs
  scripts/gdb: fix detection of current CPU in KGDB
  scripts/gdb: make get_thread_info accept pointers
  scripts/gdb: fix parameter handling in $lx_per_cpu
  scripts/gdb: fix failing KGDB detection during probe
  kfifo: don't use "proxy" headers
  media: stih-cec: add missing io.h
  media: rc: add missing io.h
  ...
</content>
</entry>
<entry>
<title>fs/coredump: Enable dynamic configuration of max file note size</title>
<updated>2024-05-08T16:53:00Z</updated>
<author>
<name>Allen Pais</name>
</author>
<published>2024-05-06T19:37:00Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4bbf9c3b53e637eb3a14ee27b996300ce88e752a'/>
<id>urn:sha1:4bbf9c3b53e637eb3a14ee27b996300ce88e752a</id>
<content type='text'>
Introduce the capability to dynamically configure the maximum file
note size for ELF core dumps via sysctl.

Why is this being done?
We have observed that during a crash when there are more than 65k mmaps
in memory, the existing fixed limit on the size of the ELF notes section
becomes a bottleneck. The notes section quickly reaches its capacity,
leading to incomplete memory segment information in the resulting coredump.
This truncation compromises the utility of the coredumps, as crucial
information about the memory state at the time of the crash might be
omitted.

This enhancement removes the previous static limit of 4MB, allowing
system administrators to adjust the size based on system-specific
requirements or constraints.

Eg:
$ sysctl -a | grep core_file_note_size_limit
kernel.core_file_note_size_limit = 4194304

$ sysctl -n kernel.core_file_note_size_limit
4194304

$echo 519304 &gt; /proc/sys/kernel/core_file_note_size_limit

$sysctl -n kernel.core_file_note_size_limit
519304

Attempting to write beyond the ceiling value of 16MB
$echo 17194304 &gt; /proc/sys/kernel/core_file_note_size_limit
bash: echo: write error: Invalid argument

Signed-off-by: Vijay Nag &lt;nagvijay@microsoft.com&gt;
Signed-off-by: Allen Pais &lt;apais@linux.microsoft.com&gt;
Link: https://lore.kernel.org/r/20240506193700.7884-1-apais@linux.microsoft.com
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>regset: use kvzalloc() for regset_get_alloc()</title>
<updated>2024-04-26T04:07:03Z</updated>
<author>
<name>Douglas Anderson</name>
</author>
<published>2024-02-05T17:26:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6b839b3b76cf17296ebd4a893841f32cae08229c'/>
<id>urn:sha1:6b839b3b76cf17296ebd4a893841f32cae08229c</id>
<content type='text'>
While browsing through ChromeOS crash reports, I found one with an
allocation failure that looked like this:

  chrome: page allocation failure: order:7,
          mode:0x40dc0(GFP_KERNEL|__GFP_COMP|__GFP_ZERO),
	  nodemask=(null),cpuset=urgent,mems_allowed=0
  CPU: 7 PID: 3295 Comm: chrome Not tainted
          5.15.133-20574-g8044615ac35c #1 (HASH:1162 1)
  Hardware name: Google Lazor (rev3 - 8) with KB Backlight (DT)
  Call trace:
  ...
  warn_alloc+0x104/0x174
  __alloc_pages+0x5f0/0x6e4
  kmalloc_order+0x44/0x98
  kmalloc_order_trace+0x34/0x124
  __kmalloc+0x228/0x36c
  __regset_get+0x68/0xcc
  regset_get_alloc+0x1c/0x28
  elf_core_dump+0x3d8/0xd8c
  do_coredump+0xeb8/0x1378
  get_signal+0x14c/0x804
  ...

An order 7 allocation is (1 &lt;&lt; 7) contiguous pages, or 512K. It's not
a surprise that this allocation failed on a system that's been running
for a while.

More digging showed that it was fairly easy to see the order 7
allocation by just sending a SIGQUIT to chrome (or other processes) to
generate a core dump. The actual amount being allocated was 279,584
bytes and it was for "core_note_type" NT_ARM_SVE.

There was quite a bit of discussion [1] on the mailing lists in
response to my v1 patch attempting to switch to vmalloc. The overall
conclusion was that we could likely reduce the 279,584 byte allocation
by quite a bit and Mark Brown has sent a patch to that effect [2].
However even with the 279,584 byte allocation gone there are still
65,552 byte allocations. These are just barely more than the 65,536
bytes and thus would require an order 5 allocation.

An order 5 allocation is still something to avoid unless necessary and
nothing needs the memory here to be contiguous. Change the allocation
to kvzalloc() which should still be efficient for small allocations
but doesn't force the memory subsystem to work hard (and maybe fail)
at getting a large contiguous chunk.

[1] https://lore.kernel.org/r/20240201171159.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid
[2] https://lore.kernel.org/r/20240203-arm64-sve-ptrace-regset-size-v1-1-2c3ba1386b9e@kernel.org

Link: https://lkml.kernel.org/r/20240205092626.v2.1.Id9ad163b60d21c9e56c2d686b0cc9083a8ba7924@changeid
Signed-off-by: Douglas Anderson &lt;dianders@chromium.org&gt;
Reviewed-by: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Cc: Christian Brauner &lt;brauner@kernel.org&gt;
Cc: Dave Martin &lt;Dave.Martin@arm.com&gt;
Cc: Eric Biederman &lt;ebiederm@xmission.com&gt;
Cc: Jan Kara &lt;jack@suse.cz&gt;
Cc: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Mark Brown &lt;broonie@kernel.org&gt;
Cc: Matthew Wilcox (Oracle) &lt;willy@infradead.org&gt;
Cc: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Will Deacon &lt;will@kernel.org&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>binfmt_elf: Leave a gap between .bss and brk</title>
<updated>2024-04-24T19:20:35Z</updated>
<author>
<name>Kees Cook</name>
</author>
<published>2024-02-17T06:25:44Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2a5eb9995528441447d33838727f6ec1caf08139'/>
<id>urn:sha1:2a5eb9995528441447d33838727f6ec1caf08139</id>
<content type='text'>
Currently the brk starts its randomization immediately after .bss,
which means there is a chance that when the random offset is 0, linear
overflows from .bss can reach into the brk area. Leave at least a single
page gap between .bss and brk (when it has not already been explicitly
relocated into the mmap range).

Reported-by:  &lt;y0un9n132@gmail.com&gt;
Closes: https://lore.kernel.org/linux-hardening/CA+2EKTVLvc8hDZc+2Yhwmus=dzOUG5E4gV7ayCbu0MPJTZzWkw@mail.gmail.com/
Link: https://lore.kernel.org/r/20240217062545.1631668-2-keescook@chromium.org
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>binfmt_elf: Only report padzero() errors when PROT_WRITE</title>
<updated>2023-10-04T02:48:44Z</updated>
<author>
<name>Kees Cook</name>
</author>
<published>2023-09-29T03:24:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f9c0a39d95301a36baacfd3495374c6128d662fa'/>
<id>urn:sha1:f9c0a39d95301a36baacfd3495374c6128d662fa</id>
<content type='text'>
Errors with padzero() should be caught unless we're expecting a
pathological (non-writable) segment. Report -EFAULT only when PROT_WRITE
is present.

Additionally add some more documentation to padzero(), elf_map(), and
elf_load().

Cc: Eric Biederman &lt;ebiederm@xmission.com&gt;
Cc: Alexander Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Christian Brauner &lt;brauner@kernel.org&gt;
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Suggested-by: Eric Biederman &lt;ebiederm@xmission.com&gt;
Tested-by: Pedro Falcato &lt;pedro.falcato@gmail.com&gt;
Signed-off-by: Sebastian Ott &lt;sebott@redhat.com&gt;
Link: https://lore.kernel.org/r/20230929032435.2391507-5-keescook@chromium.org
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>binfmt_elf: Use elf_load() for library</title>
<updated>2023-10-04T02:48:43Z</updated>
<author>
<name>Kees Cook</name>
</author>
<published>2023-09-29T03:24:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d5ca24f639588811af57ceac513183fa2004bd3a'/>
<id>urn:sha1:d5ca24f639588811af57ceac513183fa2004bd3a</id>
<content type='text'>
While load_elf_library() is a libc5-ism, we can still replace most of
its contents with elf_load() as well, further simplifying the code.

Some historical context:
- libc4 was a.out and used uselib (a.out support has been removed)
- libc5 was ELF and used uselib (there may still be users)
- libc6 is ELF and has never used uselib

Cc: Alexander Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Christian Brauner &lt;brauner@kernel.org&gt;
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Suggested-by: Eric Biederman &lt;ebiederm@xmission.com&gt;
Tested-by: Pedro Falcato &lt;pedro.falcato@gmail.com&gt;
Signed-off-by: Sebastian Ott &lt;sebott@redhat.com&gt;
Link: https://lore.kernel.org/r/20230929032435.2391507-4-keescook@chromium.org
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>binfmt_elf: Use elf_load() for interpreter</title>
<updated>2023-09-29T16:54:27Z</updated>
<author>
<name>Kees Cook</name>
</author>
<published>2023-09-29T03:24:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8b04d32678e3c46b8a738178e0e55918eaa3be17'/>
<id>urn:sha1:8b04d32678e3c46b8a738178e0e55918eaa3be17</id>
<content type='text'>
Handle arbitrary memsz&gt;filesz in interpreter ELF segments, instead of
only supporting it in the last segment (which is expected to be the
BSS).

Cc: Eric Biederman &lt;ebiederm@xmission.com&gt;
Cc: Alexander Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Christian Brauner &lt;brauner@kernel.org&gt;
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Reported-by: Pedro Falcato &lt;pedro.falcato@gmail.com&gt;
Closes: https://lore.kernel.org/lkml/20221106021657.1145519-1-pedro.falcato@gmail.com/
Tested-by: Pedro Falcato &lt;pedro.falcato@gmail.com&gt;
Signed-off-by: Sebastian Ott &lt;sebott@redhat.com&gt;
Link: https://lore.kernel.org/r/20230929032435.2391507-3-keescook@chromium.org
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>binfmt_elf: elf_bss no longer used by load_elf_binary()</title>
<updated>2023-09-29T16:54:27Z</updated>
<author>
<name>Kees Cook</name>
</author>
<published>2023-09-29T03:24:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8ed2ef21ff564cf4a25c098ace510ee6513c9836'/>
<id>urn:sha1:8ed2ef21ff564cf4a25c098ace510ee6513c9836</id>
<content type='text'>
With the BSS handled generically via the new filesz/memsz mismatch
handling logic in elf_load(), elf_bss no longer needs to be tracked.
Drop the variable.

Cc: Eric Biederman &lt;ebiederm@xmission.com&gt;
Cc: Alexander Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Christian Brauner &lt;brauner@kernel.org&gt;
Cc: linux-fsdevel@vger.kernel.org
Cc: linux-mm@kvack.org
Suggested-by: Eric Biederman &lt;ebiederm@xmission.com&gt;
Tested-by: Pedro Falcato &lt;pedro.falcato@gmail.com&gt;
Signed-off-by: Sebastian Ott &lt;sebott@redhat.com&gt;
Link: https://lore.kernel.org/r/20230929032435.2391507-2-keescook@chromium.org
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>binfmt_elf: Support segments with 0 filesz and misaligned starts</title>
<updated>2023-09-29T16:54:27Z</updated>
<author>
<name>Eric W. Biederman</name>
</author>
<published>2023-09-29T03:24:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=585a018627b4d7ed37387211f667916840b5c5ea'/>
<id>urn:sha1:585a018627b4d7ed37387211f667916840b5c5ea</id>
<content type='text'>
Implement a helper elf_load() that wraps elf_map() and performs all
of the necessary work to ensure that when "memsz &gt; filesz" the bytes
described by "memsz &gt; filesz" are zeroed.

An outstanding issue is if the first segment has filesz 0, and has a
randomized location. But that is the same as today.

In this change I replaced an open coded padzero() that did not clear
all of the way to the end of the page, with padzero() that does.

I also stopped checking the return of padzero() as there is at least
one known case where testing for failure is the wrong thing to do.
It looks like binfmt_elf_fdpic may have the proper set of tests
for when error handling can be safely completed.

I found a couple of commits in the old history
https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git,
that look very interesting in understanding this code.

commit 39b56d902bf3 ("[PATCH] binfmt_elf: clearing bss may fail")
commit c6e2227e4a3e ("[SPARC64]: Missing user access return value checks in fs/binfmt_elf.c and fs/compat.c")
commit 5bf3be033f50 ("v2.4.10.1 -&gt; v2.4.10.2")

Looking at commit 39b56d902bf3 ("[PATCH] binfmt_elf: clearing bss may fail"):
&gt;  commit 39b56d902bf35241e7cba6cc30b828ed937175ad
&gt;  Author: Pavel Machek &lt;pavel@ucw.cz&gt;
&gt;  Date:   Wed Feb 9 22:40:30 2005 -0800
&gt;
&gt;     [PATCH] binfmt_elf: clearing bss may fail
&gt;
&gt;     So we discover that Borland's Kylix application builder emits weird elf
&gt;     files which describe a non-writeable bss segment.
&gt;
&gt;     So remove the clear_user() check at the place where we zero out the bss.  I
&gt;     don't _think_ there are any security implications here (plus we've never
&gt;     checked that clear_user() return value, so whoops if it is a problem).
&gt;
&gt;     Signed-off-by: Pavel Machek &lt;pavel@suse.cz&gt;
&gt;     Signed-off-by: Andrew Morton &lt;akpm@osdl.org&gt;
&gt;     Signed-off-by: Linus Torvalds &lt;torvalds@osdl.org&gt;

It seems pretty clear that binfmt_elf_fdpic with skipping clear_user() for
non-writable segments and otherwise calling clear_user(), aka padzero(),
and checking it's return code is the right thing to do.

I just skipped the error checking as that avoids breaking things.

And notably, it looks like Borland's Kylix died in 2005 so it might be
safe to just consider read-only segments with memsz &gt; filesz an error.

Reported-by: Sebastian Ott &lt;sebott@redhat.com&gt;
Reported-by: Thomas Weißschuh &lt;linux@weissschuh.net&gt;
Closes: https://lkml.kernel.org/r/20230914-bss-alloc-v1-1-78de67d2c6dd@weissschuh.net
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Link: https://lore.kernel.org/r/87sf71f123.fsf@email.froward.int.ebiederm.org
Tested-by: Pedro Falcato &lt;pedro.falcato@gmail.com&gt;
Signed-off-by: Sebastian Ott &lt;sebott@redhat.com&gt;
Link: https://lore.kernel.org/r/20230929032435.2391507-1-keescook@chromium.org
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
</feed>
