Skip to content

Commit 7517375

Browse files
committed
components: factor the offset-table uname fingerprint into a helper
qemu_tcg_iret and entrybleed each composed "<release> <version>" and matched it against a per-build offset table, but only qemu_tcg_iret trimmed the trailing space a 64-char-clipped Ubuntu HWE uname can leave. Add kasld_uname_fingerprint() (compose + trim) beside kasld_uname in sysroot.h and call it from both; each keeps its own uname fetch and failure policy, so only the compose+trim is shared and entrybleed picks up the trim.
1 parent 62b6b6d commit 7517375

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/components/entrybleed.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ static int detect_kernel_version(void) {
280280
exit(kasld_disp_absent("not a 64-bit kernel"));
281281
}
282282

283-
snprintf(kernel_version, KERNEL_VERSION_SIZE_BUFFER, "%s %s", u.release,
284-
u.version);
283+
kasld_uname_fingerprint(kernel_version, KERNEL_VERSION_SIZE_BUFFER, &u);
285284

286285
unsigned long i;
287286
for (i = 0; i < ARRAY_SIZE(offsets); i++) {

src/components/qemu_tcg_iret.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,17 @@ static const struct kernel_info offsets[] = {
162162

163163
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
164164

165-
/* Index into offsets[] whose full uname matches this kernel, or -1. Trailing
166-
* whitespace is trimmed before comparing: a long Ubuntu HWE version clipped at
167-
* utsname's 64-char field can end on a space, and the table stores fingerprints
168-
* trimmed the same way, so the live uname is trimmed to match. */
165+
/* Index into offsets[] whose full uname matches this kernel, or -1. The
166+
* fingerprint (compose + trailing-space trim) is built by
167+
* kasld_uname_fingerprint(); see its comment for why the trim matters. */
169168
static int match_known_kernel(void) {
170169
struct utsname u;
171170
char v[512];
172-
size_t n;
173171
unsigned long i;
174172

175173
if (kasld_uname(&u) != 0)
176174
return -1;
177-
snprintf(v, sizeof(v), "%s %s", u.release, u.version);
178-
for (n = strlen(v); n > 0 && v[n - 1] == ' '; n--)
179-
v[n - 1] = '\0';
175+
kasld_uname_fingerprint(v, sizeof(v), &u);
180176
for (i = 0; i < ARRAY_SIZE(offsets); i++)
181177
if (strcmp(v, offsets[i].kernel_version) == 0)
182178
return (int)i;

src/include/kasld/sysroot.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,18 @@ __attribute__((unused)) static int kasld_uname(struct utsname *u) {
146146
return rc;
147147
}
148148

149+
/* Compose "<release> <version>" into buf and trim trailing spaces. Offset-table
150+
* components match this full-uname build fingerprint against per-build entries;
151+
* a long Ubuntu HWE version is clipped at utsname.version's 64-char field and
152+
* can end on a space, so trimming keeps the live string equal to the (also
153+
* trimmed) stored fingerprint. The caller passes the utsname (from kasld_uname)
154+
* so each component keeps its own uname fetch and failure policy. */
155+
__attribute__((unused)) static void
156+
kasld_uname_fingerprint(char *buf, size_t n, const struct utsname *u) {
157+
size_t i;
158+
snprintf(buf, n, "%s %s", u->release, u->version);
159+
for (i = strlen(buf); i > 0 && buf[i - 1] == ' '; i--)
160+
buf[i - 1] = '\0';
161+
}
162+
149163
#endif /* KASLD_SYSROOT_H */

0 commit comments

Comments
 (0)