Commit Graph

87 Commits

Author SHA1 Message Date
Mintsuki
455aeb4967 lib/elf: Remove arbitrary program header count limit 2026-02-19 20:37:36 +01:00
Mintsuki
2b7bc64e27 lib/elf: Use overflow-safe pattern for phdr bounds check in _elsewhere functions 2026-02-10 11:10:03 +01:00
Mintsuki
2b2d1d7be0 lib/elf: Add NUL-termination check before strcmp in section name lookup 2026-02-10 11:10:02 +01:00
Mintsuki
e53486af14 lib/elf: Check phdr table end against file_size after overflow validation 2026-02-10 11:10:02 +01:00
Mintsuki
179fe0b76a lib/elf: Reject invalid ELF class for RISC-V and LoongArch 2026-02-10 11:10:02 +01:00
Mintsuki
acfb614165 lib/elf, lib/pe: Reject non-power-of-2 alignment values 2026-02-10 11:10:02 +01:00
Mintsuki
30e4d660ed lib/elf: Check for p_vaddr + p_memsz overflow in PHDR processing 2026-02-10 10:58:04 +01:00
Mintsuki
e3b8f542a2 lib/elf: Reject relocatable ELFs with dynamic entries outside PT_LOAD segments 2026-02-10 10:58:04 +01:00
Mintsuki
6fa65b6a2c lib/elf: Reject relocations when symtab/strtab vaddr translation fails 2026-02-10 10:58:04 +01:00
Mintsuki
cb9ad5aa93 lib/elf: Move program header validation before first phdr access 2026-02-10 10:58:04 +01:00
Mintsuki
d80c72848c lib/elf: Validate section header offsets against file size in elf64_load_section 2026-02-10 10:58:03 +01:00
Mintsuki
0d3d27e61f lib/elf: Validate p_offset + p_filesz against file size in all ELF loaders 2026-02-10 10:58:03 +01:00
Mintsuki
f87b32e39a lib/elf: Add overflow check on p_paddr + p_memsz in load_elsewhere 2026-02-10 10:58:03 +01:00
Mintsuki
36acac62a8 lib/elf: Fix relocation bounds check overflow for large r_addr values 2026-02-10 10:58:03 +01:00
Mintsuki
c304878cb7 lib/elf: Treat p_align of 0 as 1 to avoid division by zero 2026-02-10 10:58:03 +01:00
Mintsuki
bb315e95fd elf: Validate shstrndx is within section header bounds 2026-01-14 18:40:49 +01:00
Mintsuki
3db3f0971a misc: Replace some integer overflow check patterns with builtin functions 2025-12-28 00:13:26 +01:00
Mintsuki
8ebc72c65a lib/elf: Add several bounds checks and misc bug fixes 2025-12-26 13:58:25 +01:00
Mintsuki
a648d763e6 lib/elf: Only add bss span to mem to skip if highest address PHDR
Fixes #504
2025-06-07 06:44:04 +02:00
Marvin Friedrich
76446d0c28 lib/elf: Print name of unresolved symbol on panic 2025-03-19 11:44:51 +01:00
czapek
8b01ea3430 lib: Add support for loading PE images (#442)
* lib: Add support for loading PE images

* lib/pe: Use standard integer types

* lib/pe: Fix section alignment

* lib/pe: Properly iterate base relocation blocks

* lib/pe: Add missing machine types

* protos/limine: Add kernel format detection logic

* lib/pe: Fix integer to pointer conversion errors

* lib/elf: Add previously removed check

* lib/pe: Fix base relocation block iteration code

* lib/pe: Add missing machine types to pe_bits
2025-01-08 00:35:15 +01:00
mintsuki
0c2f0ddebe build: Remove custom __riscv64 define in favour of built-in __riscv define
We do not support non-64-bit RISC-V anyways
2024-08-11 20:25:01 +02:00
Keegan Saunders
d9a2fb95a9 Add LoongArch support 2024-07-31 23:05:27 -04:00
mintsuki
bc365ad065 lib/elf: Apply a slide of 0xffffffff80000000 - min_vaddr instead of always 0xffffffff80000000 for relocatable kernels loaded low 2024-07-06 18:44:54 +02:00
mintsuki
0ca3f172bf lib/elf: Relax ELF file type checks in elf*_load_elsewhere() 2024-06-28 07:48:15 +02:00
mintsuki
2923125d90 lib/elf: Add additional ELF type sanity checks 2024-06-27 13:59:19 +02:00
mintsuki
5df8ca77c1 lib/elf: Only assume relocatable if ELF type is ET_DYN 2024-06-26 20:19:10 +02:00
mintsuki
6b3d0e5966 lib/elf: Minor rework of dynamic segment parsing 2024-06-11 17:13:29 +02:00
mintsuki
00b3025fd3 lib/elf: Fix bug where the wrong struct was checked in elf64_load() 2024-06-10 00:25:21 +02:00
mintsuki
33db129c84 lib/elf: Reject relocatable ELFs in elf*_load_elsewhere() 2024-06-09 21:34:55 +02:00
mintsuki
70a0460a6e lib/elf: Do not check for DT_RELAENT size for DT_PLTREL entries 2024-06-09 00:19:30 +02:00
mintsuki
8d5f6d1504 lib/elf: Panic on unresolved symbols, unless marked weak 2024-06-08 23:37:35 +02:00
mintsuki
d14075daed lib/elf: Ignore PT_LOAD PHDRs with 0 memsz 2024-06-08 01:19:42 +02:00
mintsuki
ffe25e3808 lib/elf: Stop parsing PT_DYNAMIC once DT_NULL reached 2024-06-05 11:30:57 +02:00
mintsuki
e6a742e8d0 lib/elf: Panic if ELF file contains DT_NEEDED tags 2024-06-04 03:09:08 +02:00
mintsuki
d694902642 lib/elf: Check if DT_PLTREL is DT_RELA 2024-06-04 03:02:55 +02:00
mintsuki
7a596fa9fe lib/elf: Use __builtin_popcountll instead of __builtin_popcountg 2024-06-04 02:43:26 +02:00
mintsuki
77143b153c lib/elf: Use __builtin_popcountg instead of __builtin_popcount 2024-06-04 02:31:01 +02:00
mintsuki
3ce1415a3a lib/elf: Free allocated RELA structs for RELR 2024-06-04 02:11:06 +02:00
mintsuki
54e8882328 lib/elf: Fix a GCC uninitialised var warning 2024-06-04 02:06:03 +02:00
mintsuki
9789274c6d lib/elf: Add RELR support 2024-06-04 01:45:04 +02:00
mintsuki
5a7052d135 lib/elf: Add more and better sanity checks 2024-06-03 22:34:45 +02:00
mintsuki
04f6957f17 lib/elf: Add support for R_*_NONE relocations 2024-06-03 03:29:14 +02:00
mintsuki
89bc8aad5e lib/elf: Optimise is_relocatable() a bit 2024-06-03 02:28:21 +02:00
mintsuki
4c4d79b7fe lib/elf: Move R_AARCH64_ABS64 case where it makes more sense 2024-06-03 01:53:23 +02:00
mintsuki
4b101ddb75 lib/elf: Remove stray semicolon in apply_relocations() 2024-06-03 01:03:10 +02:00
mintsuki
c9cbc359e7 lib/elf: aarch64: Support ABS64 reloc/add r_addend in JUMP_SLOT/GLOB_DAT relocs 2024-06-03 00:42:59 +02:00
mintsuki
77a8af1d0a lib/elf: More sound calculation of relocs_i 2024-06-03 00:14:58 +02:00
mintsuki
6b1e6d88dd lib/elf: Add support for GLOB_DAT, JUMP_SLOT, and 64 relocation types 2024-06-03 00:03:33 +02:00
mintsuki
1811c7f8b7 lib/elf: Do not perform any additional checks if an ELF is both ET_DYN and has a PT_DYNAMIC segment 2024-05-24 10:01:46 +02:00