Skip to content

Commit 847ab17

Browse files
committed
syslog: read the captured /var/log/dmesg under KASLD_SYSROOT
mmap_syslog tried klogctl first unconditionally, so during offline analysis of a captured tree (KASLD_SYSROOT set) every dmesg component read the live HOST kernel log instead of the analysed tree. Skip klogctl when a sysroot is set and read the captured /var/log/dmesg; with no sysroot the klogctl-first live path is unchanged (the file stays the fallback when klogctl is denied). Fixes replay/offline correctness for all dmesg_search components at one point. dmesg_backtrace: drop its now-duplicated sysroot branch and just call mmap_syslog.
1 parent 0ce5b3c commit 847ab17

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

src/components/dmesg_backtrace.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,20 +338,17 @@ static void on_line(char *line, void *vctx) {
338338

339339
/* Walk every line of the kernel log in order, calling fn(line, ctx) per line.
340340
*
341-
* A single source is used so line order — hence dump-block structure — is
342-
* preserved: under KASLD_SYSROOT the captured /var/log/dmesg (klogctl would
343-
* read the live host, not the analysed tree); otherwise klogctl, with the file
344-
* as fallback. The mapping is left to be reclaimed at process exit — these
345-
* components are one-shot (the same convention as the shared dmesg helper).
346-
* Returns 0 on success, -1 if no source is accessible. */
341+
* mmap_syslog gives a single ordered source so line order — hence dump-block
342+
* structure — is preserved: klogctl on a live system, or the captured
343+
* /var/log/dmesg under KASLD_SYSROOT (mmap_syslog handles that redirect). The
344+
* mapping is left to be reclaimed at process exit — these components are
345+
* one-shot. Returns 0 on success, -1 if no source is accessible. */
347346
typedef void (*line_fn)(char *line, void *ctx);
348347
static int foreach_dmesg_line(line_fn fn, void *ctx) {
349348
char *buf;
350349
int size;
351350

352-
int rc = kasld_sysroot() ? read_dmesg_log_file(&buf, &size)
353-
: mmap_syslog(&buf, &size);
354-
if (rc != 0 || size <= 0)
351+
if (mmap_syslog(&buf, &size) != 0 || size <= 0)
355352
return -1;
356353

357354
/* The mmap allocation is page-rounded strictly above `size`, so buf[size] is

src/include/syslog.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ static int read_dmesg_log_file(char **buffer, int *size) {
7373
static int mmap_syslog(char **buffer, int *size) {
7474
int alloc;
7575

76+
/* Offline analysis: under KASLD_SYSROOT, klogctl() would read the live HOST
77+
* kernel log, not the analysed tree, so read the captured /var/log/dmesg
78+
* instead. With no sysroot set (the normal case) this falls through to the
79+
* klogctl-first path below (the live ring buffer is authoritative; the file
80+
* is only the fallback when klogctl is denied). */
81+
if (kasld_sysroot())
82+
return read_dmesg_log_file(buffer, size);
83+
7684
*size = klogctl(SYSLOG_ACTION_SIZE_BUFFER, 0, 0);
7785
if (*size == -1) {
7886
perror("[-] klogctl(SYSLOG_ACTION_SIZE_BUFFER)");

src/rules/x86_64_la57_from_directmap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ int rule_x86_64_la57_from_directmap(const struct evidence_set *ev,
103103
snprintf(c->origin, ORIGIN_LEN, "x86_64_la57_from_directmap");
104104
}
105105
} else {
106-
/* L4: raise the virt_page_offset floor to the L4 VAS start. */
106+
/* L4: raise the virt_page_offset floor to the L4 VAS start. Deliberately
107+
* the canonical half floor (0xffff800000000000), NOT __PAGE_OFFSET_BASE_L4
108+
* (0xffff888000000000): the PTI LDT remap sits at 0xffff880000000000, and
109+
* pre-v4.17 kernels based the directmap at 0xffff880000000000 — a higher
110+
* floor would reject legitimate / older-kernel bases. Do not "tighten" this
111+
* to __PAGE_OFFSET_BASE_L4; see proc_cpuinfo.c for the full rationale. */
107112
if (n < out_max) {
108113
struct constraint *c = &out[n++];
109114
memset(c, 0, sizeof(*c));

0 commit comments

Comments
 (0)