|
31 | 31 | #define _GNU_SOURCE |
32 | 32 | #include "include/kasld/api.h" |
33 | 33 | #include "include/kasld/cli.h" |
| 34 | +#include "include/kasld/constraint.h" |
34 | 35 | #include <errno.h> |
35 | 36 | #include <linux/perf_event.h> |
36 | 37 | #include <poll.h> |
@@ -266,25 +267,30 @@ int main(void) { |
266 | 267 | kasld_result_sample(KASLD_TYPE_VIRT, REGION_KERNEL_TEXT, addr, NULL, |
267 | 268 | CONF_PARSED); |
268 | 269 |
|
269 | | - /* On large-page arches the lowest sampled IP also yields a speculative base |
270 | | - * GUESS: flooring it to KASLR_VIRT_ALIGN lands on the image base whenever the |
271 | | - * lowest sampled function sits in the base's own slot — the common case on a |
272 | | - * busy system, where low text executes constantly. It overshoots by one slot |
273 | | - * only when the base's slot holds nothing the sampler caught (un-executed |
274 | | - * head/entry text on an idle, freshly booted kernel). So emit it as a base |
275 | | - * pin, but at CONF_HEURISTIC: "the floored slot is the base" is a heuristic, |
276 | | - * so the pin sits BELOW the sound floor and shapes the speculative LIKELY |
277 | | - * window only — never the guaranteed one, which keeps the sound interior |
278 | | - * upper bound above. Region KERNEL_IMAGE so the value is read as _text |
279 | | - * directly, with no _stext head-gap subtraction. kasld_floor_text_base |
280 | | - * preserves the sub-alignment residue so the floor never drops below _text. |
| 270 | + /* On large-page arches the lowest sampled IP also brackets the base from |
| 271 | + * below. Flooring it to the KASLR grid lands on the base's own slot whenever |
| 272 | + * the lowest sampled function sits there — the common case on a busy system, |
| 273 | + * where low text executes constantly — and overshoots by exactly one slot |
| 274 | + * when the base's slot holds nothing the sampler caught (un-executed |
| 275 | + * head/entry text on an idle, freshly booted kernel). So the base is the |
| 276 | + * floored slot or one slot below it: a LOWER bound of floor - one slot. |
| 277 | + * |
| 278 | + * Emit it on the constraint channel rather than as a positional base pin. |
| 279 | + * The bound value sits one slot below _text, which the anchor rules — which |
| 280 | + * read a base witness as a located address — would misread as text; a |
| 281 | + * constraint is not an address, so they never see it. At CONF_HEURISTIC the |
| 282 | + * bound sits below the sound floor and shapes the speculative LIKELY window |
| 283 | + * only, never the guaranteed one; combined with the interior sample's sound |
| 284 | + * upper bound (base <= floored, via grid alignment) it brackets the base to |
| 285 | + * two slots, which an agreeing exact pin collapses to one. |
281 | 286 | * |
282 | 287 | * Gated to KASLR_VIRT_ALIGN >= 2 MiB: on fine-granule arches the lowest |
283 | | - * sampled IP can sit many slots above the base, so flooring it is not a |
284 | | - * within-one-slot guess; there the interior upper bound is the only claim. */ |
| 288 | + * sampled IP can sit many slots above the base, so "within one slot" does not |
| 289 | + * hold; there the interior upper bound is the only claim. */ |
285 | 290 | #if KASLR_VIRT_ALIGN >= 2 * MB |
286 | | - kasld_result_base(KASLD_TYPE_VIRT, REGION_KERNEL_IMAGE, |
287 | | - kasld_floor_text_base(addr), NULL, CONF_HEURISTIC); |
| 291 | + kasld_emit_constraint(Q_VIRT_IMAGE_BASE, C_LOWER_BOUND, |
| 292 | + kasld_floor_text_base(addr) - KASLR_VIRT_ALIGN, |
| 293 | + CONF_HEURISTIC); |
288 | 294 | #endif |
289 | 295 |
|
290 | 296 | return 0; |
|
0 commit comments