18 Commits

Author SHA1 Message Date
Kevin Tsai
6affe6bda8 fix: [common] Fix Coverity issues in in ElfLib
- Uninitialized scalar variable (CWE-457) on SegAlignment

Signed-off-by: Kevin Tsai <kevin.tsai@intel.com>
2025-04-28 07:11:20 -07:00
Guo Dong
8d32ccbcdf Enhance ELF loading
Current implementation only supports the case that ELF file doesn't reload.
If the ELF file has to be reload (e.g.: to meet alignment requirement), SBL
need copy it to a different location and run.
Recently EDKII updated universal payload ELF image link script, and the new
ELF text alignment was changed to 0x1000 from 0x40. Mostly the default file
load location could not meet this requirement. So enhancement SBL to copy
it to a new location for this case.

Signed-off-by: Guo Dong <guo.dong@intel.com>
2025-03-20 13:46:34 -07:00
randylintw
df1f7b8c58 fix: IsElfFormat doesn't correctly check the ELF header (#2036) (#2038)
Verify on booting with universal payload.

Signed-off-by: Randy <randy.lin@intel.com>
2023-10-03 12:15:12 -04:00
tsaikevin
462a0c32ea fix: [Common] Fix coverity issues (#1989)
Addressed coverity issues
- Untrusted loop bound (CWE 606)
- Uninitialized pointer read (CWE 457)
Defined Elf file max section, program numbers and size

Signed-off-by: Kevin Tsai <kevin.tsai@intel.com>
2023-08-10 17:46:46 -07:00
Kevin Tsai
877ac9ffc9 fix: [Common] Fix Coverity issues
Resolved below issues.
Untrusted pointer read(CWE 129)
Operands don't affect result(CWE 569)
Unchecked return value(CWE 252)
Logically dead code(CWE 561)
Unused value(CWE 563)
Unintended sign extension(CWE 194)
Out-of-bounds access(CWE 119)

Signed-off-by: Kevin Tsai <kevin.tsai@intel.com>
2023-07-27 15:51:26 -07:00
Bruno Achauer
3f0beb9fa3 Ensure that ELF images are loaded at their preferred address (#1833)
Currently, loading an ELF image will relocate the image (to its
preferred load address) only if there is at least one ELF segment
that is not completely contained in the file loaded (i.e. the memory
segment size is larger than the size inside the file. This behavior
is generally triggered by the segment that contains the .bss section).

Consequently, images that contain initialized data only (e.g. QNX IFS
files) don't get relocated, and will usually crash when jumping to the
image entry point.

This change checks whether the ELF image is already loaded at the
preferred address, and forces image relocation if not.

Signed-off-by: Bruno Achauer <bruno.achauer@intel.com>
2023-02-21 08:40:13 -08:00
Mike Crowe
990e3e81e6 Use LF line endings in the repository
Convert the line endings stored for all text files in the repository to
LF. The majority previously used DOS-style CRLF line endings. Add a
.gitattributes file to enforce this and treat certain extensions as
never being text files.

Update PatchCheck.py to insist on LF line endings rather than CRLF.
However, its other checks fail on this commit due to lots of
pre-existing complaints that it only notices because the line endings
have changed.

Silicon/QemuSocPkg/FspBin/Patches/0001-Build-QEMU-FSP-2.0-binaries.patch
needs to be treated as binary since it contains a mixture of line
endings.

This change has implications depending on the client platform you are
using the repository from:

* Windows

The usual configuration for Git on Windows means that text files will
be checked out to the work tree with DOS-style CRLF line endings. If
that's not the case then you can configure Git to do so for the entire
machine with:

 git config --global core.autocrlf true

or for just the repository with:

 git config core.autocrlf true

Line endings will be normalised to LF when they are committed to the
repository. If you commit a text file with only LF line endings then it
will be converted to CRLF line endings in your work tree.

* Linux, MacOS and other Unices

The usual configuration for Git on such platforms is to check files out
of the repository with LF line endings. This is probably the right thing
for you. In the unlikely even that you are using Git on Unix but editing
or compiling on Windows for some reason then you may need to tweak your
configuration to force the use of CRLF line endings as described above.

* General

For more information see
https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings .

Fixes: https://github.com/slimbootloader/slimbootloader/issues/1400
Signed-off-by: Mike Crowe <mac@mcrowe.com>
2021-11-10 12:46:42 -08:00
James Gutbub
95482aa01a Resolve KW possible NULL refs in ElfLib
KW scan reported a couple errors regarding
Sec*Shdr value, need to check if they are
NULL before using these values.

Signed-off-by: James Gutbub <james.gutbub@intel.com>
2021-10-05 13:32:41 -07:00
Maurice Ma
9f31593b58 Add Universal Payload library support
Universal Payload uses ELF format. As a result, the ELF loading
library has been enhanced to handle more complicated cases. The
Universal Payload library added an abstract layer on top of
ELF lib to make it easer to use by SBL. OsLoader and Stage2 were
modified to work with the new library interfaces.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2021-10-04 11:59:55 -07:00
Aiden Park
236a800284 Support ELF32/64 format payloads regardless of operation mode
This allows to load and execute ELF32 or ELF64 format payloads
regardless of Ia32 or X64 SBL operation modes.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2021-05-24 09:04:14 -07:00
Aiden Park
b884702aca Fix ELF image loading failure (#700)
This will fix invalid offset calculation of ELF program header.

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-04-29 23:07:11 -07:00
Aiden Park
70af774d71 Support 64-bit ELF loading (#687)
This will load and execute 64-bit ELF image.
- Load image from ELF program header
- 32-bit ELF on IA32 only. 64-bit ELF on X64 only
- TBD: Relocate ELF

Signed-off-by: Aiden Park <aiden.park@intel.com>
2020-04-20 16:58:49 -07:00
Maurice Ma
faa172e67e Add missing header files in INF
In order to sync up with EDK201911 stable release, it is required
to add missing header files in the INF file. Otherwise, the build
will throw warnings. This patch added the missing headers in INF
files.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
2020-02-03 15:49:48 -08:00
Aiden Park
b24fd2759c Cosmetic: Convert LF to CRLF
This will fully support PatchCheck.py.
- Remove all trailing whitespace
- Convert LF to CRLF by default
- Update EFI_D_* to DEBUG_*
- Re-enable CRLF check in PatchCheck.py

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-12-02 16:21:19 -08:00
Markus Schuetterle
c1117a2be5 Add support for ELF type: Shared object file
SBL only support ELF type: EXEC (Executable file)
This changes also allow loading ELF type: DYN (Shared object file)

This is required to boot recent ACRN Hypervisor.

Signed-off-by: Markus Schuetterle <markus.schuetterle@intel.com>
2019-07-31 07:56:15 -07:00
Aiden Park
0066eccdb3 Re-implement ElfLib for ELF32 format image (#193)
The previous implementation has a little confusion in license header.
To avoid further annoying, simply re-implement ElfLib.
- 32bits, little-endian, executable elf only supported
- elf32.h/elf_common.h from BaseTools/Source/C/GenFw
- LoadElfImage() interface changed

Signed-off-by: Aiden Park <aiden.park@intel.com>
2019-06-17 16:58:08 -07:00
Guo Dong
5e10bd1e07 Update BSD license to BSD+Patent license
To align with EDK2, update file license
to use BSD+Patent license

Signed-off-by: Guo Dong <guo.dong@intel.com>
2019-06-13 10:46:49 -07:00
Aiden Park
76db3e9714 Support ELF format payload
In order to support ELF format payload in Stage2, ElfLib is separated
from MultibootLib.

Additionally,
- Load ONLY Executable/Loadable segments
- Keep LoadElfSymtab function for future use
- Mark ELF syms flag as 'not supported' in MultibootInfo

Change-Id: Iec1ca6770ffeff9222b71327216cc6176ea1e925
Signed-off-by: Aiden Park <aiden.park@intel.com>
2018-10-30 17:41:41 -07:00