Note: I don't know what milestone this should be filed under.
Note: this is about the elf loader failing to properly size and zero BSS memory for statically linked ELF format binary files.
In binfmt-elf.c,
1) added a MODIFICATIONS section as a change log at the head of the source file;
2) in the elf_load_binary() function, the BSS area beyond the end of the DATA section not calculated correctly.
a) Added automatic variable memsize and set its value to the sum of eppnt->p_memsz + ELF_PAGEOFFSET(eppnt->p_vaddr);
b) Adjust the computed memsize via ELF_PAGEALIGN(memsize)
c) test if size < memsize then assign size the adjusted memsize value
3) In the calculation of the final BSS page of mapped memory, regress the calculation of elf_bss_bias with the elf_bss + load_bias calculation (as per kernel version 2.6 source), and use the explicit calculation in the parameter passed to clear_user()
4) test if elf_bss < elf_brk, and if so, explicitly call clear_user for (elf_brk-elf_bss) bytes (which includes all of the actual BSS area) - previously, this was never called, leaving core garbage in BSS which confounds program use of the variable data allocated there.
5) possibly unnecessary: allocate and assign value to (possibly no longer used) parameter type_pruned_pointer_no_more = (size_t)bprm->buf;
Correction is derived from the 2.6 kernel ELF loader source.
I don't really know how to submit patches, and can recreate the diff file as I suspect is needed.
Also, the changes include a possibly unnecessary restoration of a structure variable, and its assignment. The fact that the structure still has the member getting the assignment suggests it may be useful to restore its assignment.
Development done with gcc-12 on OpenSUSE Leap 15.6 to support binary execution of statically linked ELF binary compiler frontend/backend/driver/inline optimizer modules from approximately 1998 (copyright banner) time period.
I welcome your advice on how to improve the patch proposal.
Further info - this change is with respect to ibcs-us-4.2.1. For base reference to earlier kernel-based version of ibcs, I used ibcs-3.9.3 running in the following Linux:
eer@sled11:/etc> uname -a
Linux sled11 3.0.76-0.11-pae #1 SMP Fri Jun 14 08:21:43 UTC 2013 (ccab990) i686 i686 i386 GNU/Linux