<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/fs/binfmt_flat.c, branch v6.6.132</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.132</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=v6.6.132'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2025-02-17T08:40:16+00:00</updated>
<entry>
<title>binfmt_flat: Fix integer overflow bug on 32 bit systems</title>
<updated>2025-02-17T08:40:16+00:00</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@linaro.org</email>
</author>
<published>2024-12-04T12:07:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d17ca8f2dfcf423c439859995910a20e38b86f00'/>
<id>urn:sha1:d17ca8f2dfcf423c439859995910a20e38b86f00</id>
<content type='text'>
commit 55cf2f4b945f6a6416cc2524ba740b83cc9af25a upstream.

Most of these sizes and counts are capped at 256MB so the math doesn't
result in an integer overflow.  The "relocs" count needs to be checked
as well.  Otherwise on 32bit systems the calculation of "full_data"
could be wrong.

	full_data = data_len + relocs * sizeof(unsigned long);

Fixes: c995ee28d29d ("binfmt_flat: prevent kernel dammage from corrupted executable headers")
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter &lt;dan.carpenter@linaro.org&gt;
Acked-by: Nicolas Pitre &lt;npitre@baylibre.com&gt;
Link: https://lore.kernel.org/r/5be17f6c-5338-43be-91ef-650153b975cb@stanley.mountain
Signed-off-by: Kees Cook &lt;kees@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>binfmt_flat: Fix corruption when not offsetting data start</title>
<updated>2024-08-19T04:04:30+00:00</updated>
<author>
<name>Kees Cook</name>
<email>kees@kernel.org</email>
</author>
<published>2024-08-07T19:51:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=49df34d2b7da9e57c839555a2f7877291ce45ad1'/>
<id>urn:sha1:49df34d2b7da9e57c839555a2f7877291ce45ad1</id>
<content type='text'>
[ Upstream commit 3eb3cd5992f7a0c37edc8d05b4c38c98758d8671 ]

Commit 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
introduced a RISC-V specific variant of the FLAT format which does
not allocate any space for the (obsolete) array of shared library
pointers. However, it did not disable the code which initializes the
array, resulting in the corruption of sizeof(long) bytes before the DATA
segment, generally the end of the TEXT segment.

Introduce MAX_SHARED_LIBS_UPDATE which depends on the state of
CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET to guard the initialization of
the shared library pointer region so that it will only be initialized
if space is reserved for it.

Fixes: 04d82a6d0881 ("binfmt_flat: allow not offsetting data start")
Co-developed-by: Stefan O'Rear &lt;sorear@fastmail.com&gt;
Signed-off-by: Stefan O'Rear &lt;sorear@fastmail.com&gt;
Reviewed-by: Damien Le Moal &lt;dlemoal@kernel.org&gt;
Acked-by: Greg Ungerer &lt;gerg@linux-m68k.org&gt;
Link: https://lore.kernel.org/r/20240807195119.it.782-kees@kernel.org
Signed-off-by: Kees Cook &lt;kees@kernel.org&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>binfmt_flat: Remove shared library support</title>
<updated>2022-04-22T17:57:18+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2022-04-20T14:58:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=70578ff3367dd4ad8f212a9b5c05cffadabf39a8'/>
<id>urn:sha1:70578ff3367dd4ad8f212a9b5c05cffadabf39a8</id>
<content type='text'>
In a recent discussion[1] it was reported that the binfmt_flat library
support was only ever used on m68k and even on m68k has not been used
in a very long time.

The structure of binfmt_flat is different from all of the other binfmt
implementations because of this shared library support and it made
life and code review more effort when I refactored the code in fs/exec.c.

Since in practice the code is dead remove the binfmt_flat shared library
support and make maintenance of the code easier.

[1] https://lkml.kernel.org/r/81788b56-5b15-7308-38c7-c7f2502c4e15@linux-m68k.org

Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Reviewed-by: Damien Le Moal &lt;damien.lemoal@opensource.wdc.com&gt;
Acked-by: Vladimir Murzin &lt;vladimir.murzin@arm.com&gt; # ARM
Tested-by: Patrice Chotard &lt;patrice.chotard@foss.st.com&gt;
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
Link: https://lore.kernel.org/r/87levzzts4.fsf_-_@email.froward.int.ebiederm.org
</content>
</entry>
<entry>
<title>binfmt_flat: Drop vestiges of coredump support</title>
<updated>2022-04-20T02:31:43+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2022-04-19T14:16:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=8d005269c50d6fba836eb04b989cd526375627cd'/>
<id>urn:sha1:8d005269c50d6fba836eb04b989cd526375627cd</id>
<content type='text'>
There is the briefest start of coredump support in binfmt_flat. It
is actually a pain to maintain as binfmt_flat is not built on most
architectures so it is easy to overlook.

Since the support does not do anything remove it.

Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Reviewed-by: Niklas Cassel &lt;niklas.cassel@wdc.com&gt;
Acked-by: Greg Ungerer &lt;gerg@linux-m68k.org&gt;
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
Link: https://lore.kernel.org/r/87mtgh17li.fsf_-_@email.froward.int.ebiederm.org
</content>
</entry>
<entry>
<title>binfmt_flat: do not stop relocating GOT entries prematurely on riscv</title>
<updated>2022-04-18T22:02:50+00:00</updated>
<author>
<name>Niklas Cassel</name>
<email>niklas.cassel@wdc.com</email>
</author>
<published>2022-04-14T09:10:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6045ab5fea4c849153ebeb0acb532da5f29d69c4'/>
<id>urn:sha1:6045ab5fea4c849153ebeb0acb532da5f29d69c4</id>
<content type='text'>
bFLT binaries are usually created using elf2flt.

The linker script used by elf2flt has defined the .data section like the
following for the last 19 years:

.data : {
	_sdata = . ;
	__data_start = . ;
	data_start = . ;
	*(.got.plt)
	*(.got)
	FILL(0) ;
	. = ALIGN(0x20) ;
	LONG(-1)
	. = ALIGN(0x20) ;
	...
}

It places the .got.plt input section before the .got input section.
The same is true for the default linker script (ld --verbose) on most
architectures except x86/x86-64.

The binfmt_flat loader should relocate all GOT entries until it encounters
a -1 (the LONG(-1) in the linker script).

The problem is that the .got.plt input section starts with a GOTPLT header
(which has size 16 bytes on elf64-riscv and 8 bytes on elf32-riscv), where
the first word is set to -1. See the binutils implementation for riscv [1].

This causes the binfmt_flat loader to stop relocating GOT entries
prematurely and thus causes the application to crash when running.

Fix this by skipping the whole GOTPLT header, since the whole GOTPLT header
is reserved for the dynamic linker.

The GOTPLT header will only be skipped for bFLT binaries with flag
FLAT_FLAG_GOTPIC set. This flag is unconditionally set by elf2flt if the
supplied ELF binary has the symbol _GLOBAL_OFFSET_TABLE_ defined.
ELF binaries without a .got input section should thus remain unaffected.

Tested on RISC-V Canaan Kendryte K210 and RISC-V QEMU nommu_virt_defconfig.

[1] https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/elfnn-riscv.c;hb=binutils-2_38#l3275

Cc: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Niklas Cassel &lt;niklas.cassel@wdc.com&gt;
Reviewed-by: Damien Le Moal &lt;damien.lemoal@opensource.wdc.com&gt;
Link: https://lore.kernel.org/r/20220414091018.896737-1-niklas.cassel@wdc.com
Fixed-by: kernel test robot &lt;lkp@intel.com&gt;
Link: https://lore.kernel.org/lkml/202204182333.OIUOotK8-lkp@intel.com
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
</content>
</entry>
<entry>
<title>coredump: Don't compile flat_core_dump when coredumps are disabled</title>
<updated>2022-03-09T16:37:07+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2022-03-09T16:37:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f833116ad2c3eabf9c739946170e07825cca67ed'/>
<id>urn:sha1:f833116ad2c3eabf9c739946170e07825cca67ed</id>
<content type='text'>
Recently the kernel test robot reported:
&gt; In file included from include/linux/kernel.h:29,
&gt;                     from fs/binfmt_flat.c:21:
&gt;    fs/binfmt_flat.c: In function 'flat_core_dump':
&gt; &gt;&gt; fs/binfmt_flat.c:121:50: error: invalid use of undefined type 'struct coredump_params'
&gt;      121 |                 current-&gt;comm, current-&gt;pid, cprm-&gt;siginfo-&gt;si_signo);
&gt;          |                                                  ^~
&gt;    include/linux/printk.h:418:33: note: in definition of macro 'printk_index_wrap'
&gt;      418 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
&gt;          |                                 ^~~~~~~~~~~
&gt;    include/linux/printk.h:499:9: note: in expansion of macro 'printk'
&gt;      499 |         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
&gt;          |         ^~~~~~
&gt;    fs/binfmt_flat.c:120:9: note: in expansion of macro 'pr_warn'
&gt;      120 |         pr_warn("Process %s:%d received signr %d and should have core dumped\n",
&gt;          |         ^~~~~~~
&gt;    At top level:
&gt;    fs/binfmt_flat.c:118:12: warning: 'flat_core_dump' defined but not used [-Wunused-function]
&gt;      118 | static int flat_core_dump(struct coredump_params *cprm)
&gt;          |            ^~~~~~~~~~~~~~

The little dinky do nothing function flat_core_dump has always been
compiled unconditionally.  With my change to move coredump_params into
coredump.h coredump_params reasonably becomes unavailable when
coredump support is not compiled in.  Fix this old issue by simply not
compiling flat_core_dump when coredump support is not supported.

Fixes: a99a3e2efaf1 ("coredump: Move definition of struct coredump_params into coredump.h")
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</content>
</entry>
<entry>
<title>coredump: Move definition of struct coredump_params into coredump.h</title>
<updated>2022-03-08T18:50:58+00:00</updated>
<author>
<name>Eric W. Biederman</name>
<email>ebiederm@xmission.com</email>
</author>
<published>2022-01-31T17:50:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a99a3e2efaf1f4454eb5c9176f47e66de075b134'/>
<id>urn:sha1:a99a3e2efaf1f4454eb5c9176f47e66de075b134</id>
<content type='text'>
Move the definition of struct coredump_params into coredump.h where
it belongs.

Remove the slightly errorneous comment explaining why struct
coredump_params was declared in binfmts.h.

Signed-off-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
</content>
</entry>
<entry>
<title>binfmt: move more stuff undef CONFIG_COREDUMP</title>
<updated>2022-03-02T00:16:27+00:00</updated>
<author>
<name>Alexey Dobriyan</name>
<email>adobriyan@gmail.com</email>
</author>
<published>2022-02-13T19:25:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=d65bc29be0ae4ca2368df25dc6f6247aefb57f07'/>
<id>urn:sha1:d65bc29be0ae4ca2368df25dc6f6247aefb57f07</id>
<content type='text'>
struct linux_binfmt::core_dump and struct min_coredump::min_coredump
are used under CONFIG_COREDUMP only. Shrink those embedded configs
a bit.

Signed-off-by: Alexey Dobriyan &lt;adobriyan@gmail.com&gt;
Signed-off-by: Kees Cook &lt;keescook@chromium.org&gt;
Link: https://lore.kernel.org/r/YglbIFyN+OtwVyjW@localhost.localdomain
</content>
</entry>
<entry>
<title>binfmt: remove in-tree usage of MAP_EXECUTABLE</title>
<updated>2021-06-29T17:53:50+00:00</updated>
<author>
<name>David Hildenbrand</name>
<email>david@redhat.com</email>
</author>
<published>2021-06-29T02:38:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a4eec6a3dfb7a6257ddcacf15e9428fe5834ffd4'/>
<id>urn:sha1:a4eec6a3dfb7a6257ddcacf15e9428fe5834ffd4</id>
<content type='text'>
Ever since commit e9714acf8c43 ("mm: kill vma flag VM_EXECUTABLE and
mm-&gt;num_exe_file_vmas"), VM_EXECUTABLE is gone and MAP_EXECUTABLE is
essentially completely ignored.  Let's remove all usage of MAP_EXECUTABLE.

[akpm@linux-foundation.org: fix blooper in fs/binfmt_aout.c. per David]

Link: https://lkml.kernel.org/r/20210421093453.6904-3-david@redhat.com
Signed-off-by: David Hildenbrand &lt;david@redhat.com&gt;
Acked-by: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Reviewed-by: Kees Cook &lt;keescook@chromium.org&gt;
Cc: Alexander Shishkin &lt;alexander.shishkin@linux.intel.com&gt;
Cc: Alexander Viro &lt;viro@zeniv.linux.org.uk&gt;
Cc: Arnaldo Carvalho de Melo &lt;acme@kernel.org&gt;
Cc: Borislav Petkov &lt;bp@alien8.de&gt;
Cc: Catalin Marinas &lt;catalin.marinas@arm.com&gt;
Cc: Don Zickus &lt;dzickus@redhat.com&gt;
Cc: Feng Tang &lt;feng.tang@intel.com&gt;
Cc: Greg Ungerer &lt;gerg@linux-m68k.org&gt;
Cc: "H. Peter Anvin" &lt;hpa@zytor.com&gt;
Cc: Ingo Molnar &lt;mingo@redhat.com&gt;
Cc: Jiri Olsa &lt;jolsa@redhat.com&gt;
Cc: Kevin Brodsky &lt;Kevin.Brodsky@arm.com&gt;
Cc: Mark Rutland &lt;mark.rutland@arm.com&gt;
Cc: Michal Hocko &lt;mhocko@suse.com&gt;
Cc: Mike Rapoport &lt;rppt@kernel.org&gt;
Cc: Namhyung Kim &lt;namhyung@kernel.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>binfmt_flat: allow not offsetting data start</title>
<updated>2021-04-18T23:56:37+00:00</updated>
<author>
<name>Damien Le Moal</name>
<email>damien.lemoal@wdc.com</email>
</author>
<published>2021-04-17T01:10:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=04d82a6d0881ef1ab1e9f66f10805177ee2fb1e8'/>
<id>urn:sha1:04d82a6d0881ef1ab1e9f66f10805177ee2fb1e8</id>
<content type='text'>
Commit 2217b9826246 ("binfmt_flat: revert "binfmt_flat: don't offset
the data start"") restored offsetting the start of the data section by
a number of words defined by MAX_SHARED_LIBS. As a result, since
MAX_SHARED_LIBS is never 0, a gap between the text and data sections
always exists. For architectures which cannot support a such gap
between the text and data sections (e.g. riscv nommu), flat binary
programs cannot be executed.

To allow an architecture to request no data start offset to allow for
contiguous text and data sections for binaries flagged with
FLAT_FLAG_RAM, introduce the new config option
CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET. Using this new option, the
macro DATA_START_OFFSET_WORDS is conditionally defined in binfmt_flat.c
to MAX_SHARED_LIBS for architectures tolerating or needing the data
start offset (CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET disabled case)
and to 0 when CONFIG_BINFMT_FLAT_NO_DATA_START_OFFSET is enabled.
DATA_START_OFFSET_WORDS is used in load_flat_file() to calculate the
data section length and start position.

Signed-off-by: Damien Le Moal &lt;damien.lemoal@wdc.com&gt;
Signed-off-by: Greg Ungerer &lt;gerg@linux-m68k.org&gt;
</content>
</entry>
</feed>
