Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178009480
D62086.1795753787.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
D62086.1795753787.diff
View Options
diff --git a/share/man/man7/Makefile b/share/man/man7/Makefile
--- a/share/man/man7/Makefile
+++ b/share/man/man7/Makefile
@@ -44,6 +44,7 @@
MLINKS= intro.7 miscellaneous.7
MLINKS+= growfs.7 growfs_fstab.7
MLINKS+= freebsd-base.7 pkgbase.7
+MLINKS+= secureboot.7 lockdown.7
MLINKS+= security.7 securelevel.7
MLINKS+= c.7 c78.7
MLINKS+= c.7 c89.7
diff --git a/share/man/man7/secureboot.7 b/share/man/man7/secureboot.7
--- a/share/man/man7/secureboot.7
+++ b/share/man/man7/secureboot.7
@@ -10,8 +10,9 @@
.Dt SECUREBOOT 7
.Os
.Sh NAME
-.Nm secureboot
-.Nd introduction to secureboot on FreeBSD
+.Nm secureboot ,
+.Nm lockdown
+.Nd introduction to secureboot and lockdown on FreeBSD
.Sh DESCRIPTION
This man page documents how to build a functional
.Fx
@@ -38,18 +39,46 @@
during
.Cm buildworld .
.Pp
+Secureboot only checks that
+.Xr loader.efi 8
+is signed by a trusted key, not which version it is.
+Any older loader signed with the same keys remains bootable, and it may lack
+some of the policies described below or have bugs that have since been fixed.
+If the keys were ever used to sign such a loader, either revoke it by adding its
+hash to the
+.Va dbx
+database, or generate and enroll new keys before relying on these policies.
+The same applies to any other image signed with those keys, such as an EFI
+shell or another boot loader, as it could be used to boot the system without
+them.
+.Pp
In an ideal world, loader is in turn requiring signatures for all of the files
that it loads, as well.
Deployment of
.Xr veriexec 8
is the recommended path to next stage verification.
.Ss Loader Policies
+If secureboot is enforced, then the loader enters lockdown, and the
+.Va boot_lockdown
+.Xr kenv 1
+variable will be set to
+.Dq YES .
+Once in effect, lockdown cannot be turned off, and
+.Va boot_lockdown
+cannot be overridden or unset by
+.Xr loader.conf 5
+or at the loader prompt.
+Note that the kernel will allow
+.Va boot_lockdown
+to be overridden or unset.
+.Pp
The are currently no policies enabled by
.Xr loader.efi 8
when secureboot is enforced.
.Ss Kernel Policies
The are currently no policies enabled by the kernel when secureboot is enforced.
.Sh SEE ALSO
+.Xr kenv 1 ,
.Xr veriexec 4 ,
.Xr build 7 ,
.Xr efisign 8 ,
diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h
--- a/stand/common/bootstrap.h
+++ b/stand/common/bootstrap.h
@@ -76,6 +76,10 @@
int kern_pread(readin_handle_t fd, vm_offset_t dest, size_t len, off_t off);
void *alloc_pread(readin_handle_t fd, off_t off, size_t len);
+void loader_init_lockdown(bool enable);
+void loader_set_lockdown(void);
+bool loader_in_lockdown(void);
+
/* bcache.c */
void bcache_init(size_t nblks, size_t bsize);
void bcache_add_dev(int);
diff --git a/stand/common/misc.c b/stand/common/misc.c
--- a/stand/common/misc.c
+++ b/stand/common/misc.c
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* All rights reserved.
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Klara, Inc. under sponsorship
+ * from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,10 +28,14 @@
* SUCH DAMAGE.
*/
+#include <assert.h>
#include <string.h>
#include <stand.h>
#include <bootstrap.h>
+static bool boot_lockdown;
+static bool boot_lockdown_initialized;
+
/*
* Concatenate the (argc) elements of (argv) into a single string, and return
* a copy of same.
@@ -233,3 +241,67 @@
return false;
}
#endif
+
+static void
+loader_latch_lockdown(void)
+{
+ boot_lockdown = true;
+}
+
+static int
+loader_lockdown_env(struct env_var *ev, int flags, const void *val)
+{
+ /* Lockdown cannot be disabled once it's enabled. */
+ if (boot_lockdown)
+ return (EPERM);
+
+ /* e.g., `set boot_lockdown` with no value */
+ if (val == NULL)
+ return (EINVAL);
+
+ if (strcasecmp(val, "no") != 0)
+ loader_latch_lockdown();
+
+ return (env_setenv(ev->ev_name, flags | EV_NOHOOK, val, NULL, NULL));
+}
+
+static void
+loader_set_lockdown_env(const char *val)
+{
+ env_setenv("boot_lockdown", EV_VOLATILE, val, loader_lockdown_env,
+ env_nounset);
+}
+
+/*
+ * Every loader calls this early, before anything has a chance to set
+ * boot_lockdown, so that it always has our hook in place. Otherwise, a
+ * boot_lockdown set before then would never reach the hook.
+ */
+void
+loader_init_lockdown(bool enable)
+{
+ assert(!boot_lockdown_initialized);
+ boot_lockdown_initialized = true;
+
+ /*
+ * This creates boot_lockdown with our hook rather than calling it, so
+ * we latch lockdown ourselves.
+ */
+ loader_set_lockdown_env(enable ? "YES" : "NO");
+ if (enable)
+ loader_latch_lockdown();
+}
+
+void
+loader_set_lockdown(void)
+{
+ /* boot_lockdown already exists, so this goes through our hook. */
+ loader_set_lockdown_env("YES");
+}
+
+bool
+loader_in_lockdown(void)
+{
+ assert(boot_lockdown_initialized);
+ return (boot_lockdown);
+}
diff --git a/stand/efi/include/efilib.h b/stand/efi/include/efilib.h
--- a/stand/efi/include/efilib.h
+++ b/stand/efi/include/efilib.h
@@ -73,6 +73,7 @@
/* libefi.c */
void *efi_get_table(EFI_GUID *tbl);
EFI_STATUS OpenProtocolByHandle(EFI_HANDLE, EFI_GUID *, void **);
+bool efi_secureboot_enabled(void);
static inline EFI_STATUS
efi_exit_boot_services(UINTN key)
diff --git a/stand/efi/libefi/libefi.c b/stand/efi/libefi/libefi.c
--- a/stand/efi/libefi/libefi.c
+++ b/stand/efi/libefi/libefi.c
@@ -1,6 +1,10 @@
/*-
* Copyright (c) 2000 Doug Rabson
* All rights reserved.
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * Portions of this software were developed by Klara, Inc. under sponsorship
+ * from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -54,3 +58,31 @@
return (BS->OpenProtocol(handle, protocol, interface, IH, NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL));
}
+
+bool
+efi_secureboot_enabled(void)
+{
+ EFI_STATUS rv;
+ size_t sz;
+ static int sb_enabled = -1;
+ uint8_t secureboot = 0, setupmode = 0;
+
+ if (sb_enabled == -1) {
+ sz = sizeof(secureboot);
+ rv = efi_global_getenv("SecureBoot", &secureboot, &sz);
+ if (rv == EFI_SUCCESS) {
+ /*
+ * SetupMode *should* be there, but we're happy to
+ * assume that it's 0 if it's somehow omitted.
+ */
+ sz = sizeof(setupmode);
+ (void)efi_global_getenv("SetupMode", &setupmode, &sz);
+ } else {
+ secureboot = 0;
+ }
+
+ sb_enabled = secureboot && !setupmode;
+ }
+
+ return (!!sb_enabled);
+}
diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c
--- a/stand/efi/loader/main.c
+++ b/stand/efi/loader/main.c
@@ -1350,6 +1350,8 @@
/* Report the RSDP early. */
acpi_detect();
+ loader_init_lockdown(efi_secureboot_enabled());
+
#ifdef LOADER_VERIEXEC
/* tell boot_setenv to be careful */
set_check_restricted(true);
diff --git a/stand/i386/loader/main.c b/stand/i386/loader/main.c
--- a/stand/i386/loader/main.c
+++ b/stand/i386/loader/main.c
@@ -137,6 +137,7 @@
heap_bottom = (void *)end;
}
setheap(heap_bottom, heap_top);
+ loader_init_lockdown(false);
/*
* Now that malloc is usable, allocate a buffer for tslog and start
diff --git a/stand/kboot/kboot/main.c b/stand/kboot/kboot/main.c
--- a/stand/kboot/kboot/main.c
+++ b/stand/kboot/kboot/main.c
@@ -397,6 +397,7 @@
*/
heapbase = host_getmem(heapsize);
setheap(heapbase, heapbase + heapsize);
+ loader_init_lockdown(false);
/*
* Set up console so we get error messages.
diff --git a/stand/libsa/environment.c b/stand/libsa/environment.c
--- a/stand/libsa/environment.c
+++ b/stand/libsa/environment.c
@@ -232,6 +232,7 @@
* except if they need to be checked for boot_setenv()
*/
const char *allowed[] = {
+ "boot_lockdown",
"boot_multicons",
"boot_mutemsgs",
"boot_safe",
diff --git a/stand/powerpc/ofw/main.c b/stand/powerpc/ofw/main.c
--- a/stand/powerpc/ofw/main.c
+++ b/stand/powerpc/ofw/main.c
@@ -171,6 +171,7 @@
* safe.
*/
init_heap();
+ loader_init_lockdown(false);
/*
* Set up console.
diff --git a/stand/uboot/main.c b/stand/uboot/main.c
--- a/stand/uboot/main.c
+++ b/stand/uboot/main.c
@@ -460,6 +460,7 @@
uboot_heap_start = round_page((uintptr_t)end);
uboot_heap_end = uboot_heap_start + HEAP_SIZE;
setheap((void *)uboot_heap_start, (void *)uboot_heap_end);
+ loader_init_lockdown(false);
/*
* Set up console.
diff --git a/stand/userboot/userboot/main.c b/stand/userboot/userboot/main.c
--- a/stand/userboot/userboot/main.c
+++ b/stand/userboot/userboot/main.c
@@ -171,6 +171,7 @@
* alloc() is usable.
*/
setheap((void *)mallocbuf, (void *)(mallocbuf + sizeof(mallocbuf)));
+ loader_init_lockdown(false);
/*
* Hook up the console
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 27, 4:29 AM (19 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42035056
Default Alt Text
D62086.1795753787.diff (8 KB)
Attached To
Mode
D62086: loader: efi: check secureboot status, plumb it into kenv
Attached
Detach File
Event Timeline