Skip to content

Commit a529199

Browse files
committed
Update code comments
1 parent c9061b2 commit a529199

3 files changed

Lines changed: 15 additions & 21 deletions

File tree

src/inference/config_max_offset_bound.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// With 16 MiB max_offset: 256 slots (256 × 64 KiB). A 256× reduction.
1717
//
1818
// MIPS: same masking pattern; CONFIG_RANDOMIZE_BASE_MAX_OFFSET default is
19-
// arch/mips/Kconfig-defined. MIPS64 KASLR is not deployed in production
20-
// (MIPS H6 confirmed), so LoongArch is the primary target in practice.
19+
// arch/mips/Kconfig-defined. MIPS64 KASLR is not deployed in production,
20+
// so LoongArch is the primary target in practice.
2121
//
2222
// If the config file is unreadable or the option is absent, this plugin is a
2323
// no-op. The plugin is naturally a no-op on architectures that do not set

src/inference/kaslr_ceiling.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* tiny stub files, placeholder symlinks, and partial downloads that would
5555
* produce wildly wrong kernel-size estimates. */
5656
#define MIN_VMLINUZ_BYTES (512UL * 1024)
57-
#define MIN_SYSMAP_BYTES (256UL * 1024)
57+
#define MIN_SYSMAP_BYTES (256UL * 1024)
5858

5959
/* stat() requires only execute permission on the parent directory, not read
6060
* permission on the file itself. */
@@ -64,7 +64,7 @@
6464
* arch/arm64/include/asm/image.h) places image_size as a u64 LE field at
6565
* byte offset 16, preceded by MZ magic at offset 0. Returns 0 on failure. */
6666
static unsigned long estimate_from_image_header(const char *release) {
67-
const char * const paths[] = {
67+
const char *const paths[] = {
6868
"/boot/Image-%s",
6969
"/boot/vmlinuz-%s",
7070
NULL,
@@ -86,14 +86,10 @@ static unsigned long estimate_from_image_header(const char *release) {
8686
continue;
8787

8888
uint64_t image_size =
89-
((uint64_t)hdr[16]) |
90-
((uint64_t)hdr[17] << 8) |
91-
((uint64_t)hdr[18] << 16) |
92-
((uint64_t)hdr[19] << 24) |
93-
((uint64_t)hdr[20] << 32) |
94-
((uint64_t)hdr[21] << 40) |
95-
((uint64_t)hdr[22] << 48) |
96-
((uint64_t)hdr[23] << 56);
89+
((uint64_t)hdr[16]) | ((uint64_t)hdr[17] << 8) |
90+
((uint64_t)hdr[18] << 16) | ((uint64_t)hdr[19] << 24) |
91+
((uint64_t)hdr[20] << 32) | ((uint64_t)hdr[21] << 40) |
92+
((uint64_t)hdr[22] << 48) | ((uint64_t)hdr[23] << 56);
9793

9894
if (image_size < MIN_VMLINUZ_BYTES)
9995
continue;
@@ -142,13 +138,12 @@ static unsigned long estimate_kernel_size(void) {
142138
return 0;
143139

144140
unsigned long from_hdr = estimate_from_image_header(uts.release);
145-
unsigned long vmlinuz = estimate_from_vmlinuz(uts.release);
146-
unsigned long sysmap = estimate_from_sysmap(uts.release);
141+
unsigned long vmlinuz = estimate_from_vmlinuz(uts.release);
142+
unsigned long sysmap = estimate_from_sysmap(uts.release);
147143

148144
/* Discard the header value if it falls below a known lower bound. */
149-
if (from_hdr > 0 &&
150-
((vmlinuz > 0 && from_hdr < vmlinuz) ||
151-
(sysmap > 0 && from_hdr < sysmap)))
145+
if (from_hdr > 0 && ((vmlinuz > 0 && from_hdr < vmlinuz) ||
146+
(sysmap > 0 && from_hdr < sysmap)))
152147
from_hdr = 0;
153148

154149
if (from_hdr)

src/inference/min_offset_from_image_size.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// sound: the kernel cannot load within the forbidden zone, and the zone
2424
// extends at least gap bytes from KASLR_BASE_MIN.
2525
//
26-
// LoongArch extension (see LoongArch H4):
26+
// LoongArch extension:
2727
// When kernel_length ≥ CONFIG_RANDOMIZE_BASE_MAX_OFFSET, every offset
2828
// drawn from [0, max_offset) satisfies offset < kernel_length, so the
2929
// bump always fires. On LoongArch the bump is an assignment (not an
@@ -37,8 +37,8 @@
3737
// and setting text_base_max = KASLR_BASE_MIN + ALIGN(gap) could exclude
3838
// the true text base if gap underestimates by more than one KERNEL_ALIGN
3939
// step. Implementing the bilateral pin soundly requires exact kernel_length
40-
// (e.g. from /boot/Image header — see riscv64_fdt_kaslr_seed §6 for the
41-
// Image-header approach; a LoongArch variant is a future enhancement).
40+
// (e.g. from /boot/Image header — see riscv64_fdt_kaslr_seed inference for
41+
// the Image-header approach; a LoongArch variant is a future enhancement).
4242
//
4343
// Note: config_max_offset_bound (PRE_COLLECTION) sets
4444
// text_base_max = KASLR_BASE_MIN + max_offset.
@@ -48,7 +48,6 @@
4848
//
4949
// Phase: POST_COLLECTION — requires TEXT and DATA results from components.
5050
// Applicable: MIPS (32-bit and 64-bit), LoongArch.
51-
// See MIPS H7, LoongArch H4.
5251
// ---
5352
// <bcoles@gmail.com>
5453

0 commit comments

Comments
 (0)