Skip to content
This repository was archived by the owner on Nov 15, 2025. It is now read-only.

Commit 8419064

Browse files
committed
efi: add more logging for all EFI variable reads
1 parent 002914e commit 8419064

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/basic/efivars.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,21 @@ int efi_get_variable(
6969
return 0;
7070
}
7171

72-
if (DEBUG_LOGGING)
72+
if (DEBUG_LOGGING) {
73+
log_debug("Reading EFI variable %s.", p);
7374
begin = now(CLOCK_MONOTONIC);
75+
}
7476

7577
fd = open(p, O_RDONLY|O_NOCTTY|O_CLOEXEC);
7678
if (fd < 0)
7779
return log_debug_errno(errno, "open(\"%s\") failed: %m", p);
7880

7981
if (fstat(fd, &st) < 0)
80-
return -errno;
82+
return log_debug_errno(errno, "fstat(\"%s\") failed: %m", p);
8183
if (st.st_size < 4)
82-
return -ENODATA;
84+
return log_debug_errno(SYNTHETIC_ERRNO(ENODATA), "EFI variable %s is shorter than 4 bytes, refusing.", p);
8385
if (st.st_size > 4*1024*1024 + 4)
84-
return -E2BIG;
86+
return log_debug_errno(SYNTHETIC_ERRNO(E2BIG), "EFI variable %s is ridiculously large, refusing.", p);
8587

8688
if (ret_value || ret_attribute) {
8789
/* The kernel ratelimits reads from the efivarfs because EFI is inefficient, and we'll
@@ -96,7 +98,7 @@ int efi_get_variable(
9698
n = read(fd, &a, sizeof(a));
9799
if (n >= 0)
98100
break;
99-
log_debug_errno(errno, "read from \"%s\" failed: %m", p);
101+
log_debug_errno(errno, "Reading from \"%s\" failed: %m", p);
100102
if (errno != EINTR)
101103
return -errno;
102104
if (try >= EFI_N_RETRIES)
@@ -106,7 +108,8 @@ int efi_get_variable(
106108
}
107109

108110
if (n != sizeof(a))
109-
return -EIO;
111+
return log_debug_errno(SYNTHETIC_ERRNO(EIO),
112+
"Read %zi bytes from EFI variable %s, expected %zu.", n, p, sizeof(a));
110113
}
111114

112115
if (ret_value) {
@@ -116,7 +119,7 @@ int efi_get_variable(
116119

117120
n = read(fd, buf, (size_t) st.st_size - 4);
118121
if (n < 0)
119-
return -errno;
122+
return log_debug_errno(errno, "Failed to read value of EFI variable %s: %m", p);
120123
assert(n <= st.st_size - 4);
121124

122125
/* Always NUL terminate (3 bytes, to properly protect UTF-16, even if truncated in the middle of a character) */

0 commit comments

Comments
 (0)