1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

chid-fundamental: not all SMBIOS fields are available on all systems

And the CHID documentation says that CHIDs that require fields that are
not available on the local system should not be generated. Follow that,
and generate a NULL CHID in that case (which we generally ignore
otherwise).
This commit is contained in:
Lennart Poettering 2024-12-20 12:02:33 +01:00
parent 06ffa66a5b
commit d1bbfaeba5

View File

@ -28,7 +28,11 @@
#include "memory-util-fundamental.h" #include "memory-util-fundamental.h"
#include "sha1-fundamental.h" #include "sha1-fundamental.h"
static void get_chid(const char16_t *const smbios_fields[static _CHID_SMBIOS_FIELDS_MAX], uint32_t mask, EFI_GUID *ret_chid) { static void get_chid(
const char16_t *const smbios_fields[static _CHID_SMBIOS_FIELDS_MAX],
uint32_t mask,
EFI_GUID *ret_chid) {
assert(mask != 0); assert(mask != 0);
assert(ret_chid); assert(ret_chid);
const EFI_GUID namespace = { UINT32_C(0x12d8ff70), UINT16_C(0x7f4c), UINT16_C(0x7d4c), {} }; /* Swapped to BE */ const EFI_GUID namespace = { UINT32_C(0x12d8ff70), UINT16_C(0x7f4c), UINT16_C(0x7d4c), {} }; /* Swapped to BE */
@ -38,13 +42,22 @@ static void get_chid(const char16_t *const smbios_fields[static _CHID_SMBIOS_FIE
sha1_process_bytes(&namespace, sizeof(namespace), &ctx); sha1_process_bytes(&namespace, sizeof(namespace), &ctx);
for (unsigned i = 0; i < _CHID_SMBIOS_FIELDS_MAX; i++) for (unsigned i = 0; i < _CHID_SMBIOS_FIELDS_MAX; i++) {
if ((mask >> i) & 1) { if (!((mask >> i) & 1))
if (i > 0) continue;
sha1_process_bytes(L"&", 2, &ctx);
sha1_process_bytes(smbios_fields[i], strlen16(smbios_fields[i]) * sizeof(char16_t), &ctx); if (!smbios_fields[i]) {
/* If some SMBIOS field is missing, don't generate the CHID, as per spec */
memzero(ret_chid, sizeof(EFI_GUID));
return;
} }
if (i > 0)
sha1_process_bytes(L"&", 2, &ctx);
sha1_process_bytes(smbios_fields[i], strlen16(smbios_fields[i]) * sizeof(char16_t), &ctx);
}
uint8_t hash[SHA1_DIGEST_SIZE]; uint8_t hash[SHA1_DIGEST_SIZE];
sha1_finish_ctx(&ctx, hash); sha1_finish_ctx(&ctx, hash);
@ -111,9 +124,12 @@ void chid_calculate(const char16_t *const smbios_fields[static _CHID_SMBIOS_FIEL
assert(smbios_fields); assert(smbios_fields);
assert(ret_chids); assert(ret_chids);
for (size_t i = 0; i < CHID_TYPES_MAX; i++) for (size_t i = 0; i < CHID_TYPES_MAX; i++) {
if (chid_smbios_table[i] != 0) if (chid_smbios_table[i] == 0) {
get_chid(smbios_fields, chid_smbios_table[i], &ret_chids[i]);
else
memzero(&ret_chids[i], sizeof(EFI_GUID)); memzero(&ret_chids[i], sizeof(EFI_GUID));
continue;
}
get_chid(smbios_fields, chid_smbios_table[i], &ret_chids[i]);
}
} }