Skip to content

Commit e460b23

Browse files
committed
intel: parse platform-prefixed ME fw_version
1 parent 46c02e1 commit e460b23

4 files changed

Lines changed: 39 additions & 3 deletions

File tree

include/silicon_parsers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ typedef struct {
2727

2828
void bythos_parse_iommu_cmdline(const char *text, bythos_iommu_cmdline_t *cmdline);
2929
bool bythos_extract_microcode_revision(const char *text, char *buffer, size_t size);
30+
bool bythos_parse_me_version(const char *text, char *out, size_t size);
3031
bythos_cpu_vendor_t bythos_cpu_vendor(void);
3132
/* returns: 1 = all zeros, 0 = non-zero, -1 = not found */
3233
int bythos_pcr_zero_check(const char *buf, unsigned int pcr_num);

src/check_me_version.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ size_t bythos_check_me_version(check_result_t *results, size_t max_results) {
3535
buf[--len] = '\0';
3636
}
3737

38-
unsigned int a = 0, b = 0, c = 0, d = 0;
39-
if (sscanf(buf, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
38+
char version[64] = {0};
39+
if (!bythos_parse_me_version(buf, version, sizeof(version))) {
4040
EMIT_SKIP_PARSE("Intel ME version", "ME version");
4141
return used;
4242
}
4343

4444
char detail[BYTHOS_DETAIL_MAX];
45-
snprintf(detail, sizeof(detail), "%u.%u.%u.%u; compare against Intel SA advisories", a, b, c, d);
45+
snprintf(detail, sizeof(detail), "%s; compare against Intel SA advisories", version);
4646
results[used++] = make_result("Intel ME version", CHECK_OK, detail);
4747

4848
return used;

src/silicon_parsers.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,25 @@ bool bythos_extract_microcode_revision(const char *text, char *buffer, size_t si
210210

211211
return false;
212212
}
213+
214+
bool bythos_parse_me_version(const char *text, char *out, size_t size) {
215+
if (text == NULL || out == NULL || size == 0) {
216+
return false;
217+
}
218+
219+
unsigned int platform, major, minor, hotfix, build;
220+
221+
/* mei sysfs fw_version is <platform>:<major>.<minor>.<hotfix>.<build> */
222+
if (sscanf(text, "%u:%u.%u.%u.%u", &platform, &major, &minor, &hotfix, &build) == 5) {
223+
snprintf(out, size, "%u.%u.%u.%u", major, minor, hotfix, build);
224+
return true;
225+
}
226+
227+
/* tolerate a bare version without the platform prefix */
228+
if (sscanf(text, "%u.%u.%u.%u", &major, &minor, &hotfix, &build) == 4) {
229+
snprintf(out, size, "%u.%u.%u.%u", major, minor, hotfix, build);
230+
return true;
231+
}
232+
233+
return false;
234+
}

tests/silicon_parsers.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ int main(void) {
117117
bythos_parse_memory_encryption_flags("flags : sme\n", NULL);
118118
}
119119

120+
{
121+
char me_ver[64] = {0};
122+
assert_true("me_version_colon_form",
123+
bythos_parse_me_version("0:21.2.21.2081", me_ver, sizeof(me_ver)));
124+
assert_true("me_version_strips_platform", strcmp(me_ver, "21.2.21.2081") == 0);
125+
assert_true("me_version_dot_form",
126+
bythos_parse_me_version("21.2.21.2081", me_ver, sizeof(me_ver)));
127+
assert_false("me_version_garbage",
128+
bythos_parse_me_version("not-a-version", me_ver, sizeof(me_ver)));
129+
assert_false("me_version_null",
130+
bythos_parse_me_version(NULL, me_ver, sizeof(me_ver)));
131+
}
132+
120133
printf("silicon parsers ok\n");
121134
return 0;
122135
}

0 commit comments

Comments
 (0)