Skip to content

Commit 1b9c05d

Browse files
committed
inference/kaslr_ceiling: use compile-time macros to prevent repeated ceiling application
Replace ctx->arch->kaslr_base_max/min (live values refreshed from layout each convergence pass) with the static KASLR_BASE_MAX/MIN macros. The ceiling is a one-shot computation against the original arch window; using the already-tightened runtime value caused kaslr_ceiling to fire up to MAX_INFERENCE_PASSES (8) times.
1 parent db29fc0 commit 1b9c05d

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/inference/kaslr_ceiling.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ static void kaslr_ceiling_run(struct kasld_analysis_ctx *ctx) {
9494
if (kernel_size == 0)
9595
return;
9696

97-
unsigned long kaslr_max = ctx->arch->kaslr_base_max;
98-
unsigned long kaslr_min = ctx->arch->kaslr_base_min;
99-
unsigned long kaslr_align = ctx->arch->kaslr_align;
97+
/* Use compile-time arch constants, not the live ctx->arch values.
98+
* ctx->arch->kaslr_base_max is refreshed from layout each convergence
99+
* pass, so using it would re-apply the ceiling subtraction on an already-
100+
* tightened bound and fire multiple times. The ceiling is a one-shot
101+
* computation against the original KASLR window. */
102+
const unsigned long kaslr_max = KASLR_BASE_MAX;
103+
const unsigned long kaslr_min = KASLR_BASE_MIN;
104+
const unsigned long kaslr_align = KASLR_ALIGN;
100105

101106
if (kernel_size < kaslr_max - kaslr_min) {
102107
/* Valid base range: [KASLR_BASE_MIN, KASLR_BASE_MAX - kernel_size].
@@ -112,9 +117,9 @@ static void kaslr_ceiling_run(struct kasld_analysis_ctx *ctx) {
112117
}
113118

114119
#if PHYS_VIRT_DECOUPLED
115-
unsigned long phys_max = ctx->arch->phys_kaslr_base_max;
116-
unsigned long phys_min = ctx->arch->phys_kaslr_base_min;
117-
unsigned long phys_align = ctx->arch->phys_kaslr_align;
120+
const unsigned long phys_max = KASLR_PHYS_MAX;
121+
const unsigned long phys_min = KASLR_PHYS_MIN;
122+
const unsigned long phys_align = KASLR_PHYS_ALIGN;
118123

119124
if (phys_max > phys_min && kernel_size < phys_max - phys_min) {
120125
unsigned long new_phys_max = (phys_max - kernel_size) & ~(phys_align - 1);

0 commit comments

Comments
 (0)