Debian Codegraph @

src/core/efi-random.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <fcntl.h>
4 #include <sys/stat.h>
5
6 #include "chattr-util.h"
7 #include "efi-random.h"
8 #include "efivars.h"
9 #include "fd-util.h"
10 #include "log.h"
11
12 void lock_down_efi_variables(void) {
13 _cleanup_close_ int fd = -EBADF;
14 int r;
15
16 fd = open(EFIVAR_PATH(EFI_LOADER_VARIABLE_STR("LoaderSystemToken")), O_RDONLY|O_CLOEXEC);
17 if (fd < 0) {
18 if (errno != ENOENT)
19 log_warning_errno(errno, "Unable to open LoaderSystemToken EFI variable, ignoring: %m");
20 return;
21 }
22
23 /* Paranoia: let's restrict access modes of these a bit, so that unprivileged users can't use them to
24 * identify the system or gain too much insight into what we might have credited to the entropy
25 * pool. */
26 r = chattr_fd(fd, 0, FS_IMMUTABLE_FL);
27 if (r < 0)
28 log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from LoaderSystemToken EFI variable, ignoring: %m");
29 if (fchmod(fd, 0600) < 0)
30 log_warning_errno(errno, "Failed to reduce access mode of LoaderSystemToken EFI variable, ignoring: %m");
31 }