Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178009361
D62095.1795753483.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D62095.1795753483.diff
View Options
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
@@ -84,6 +84,12 @@
subcommands that modify it
.Pq Cm addr , alias , mknode , mkprop , rm , No and Cm prop No with a value
are denied.
+.It
+.Ic chain
+is denied unless the loader was built with
+.Xr veriexec 8
+support, in which case the image must verify.
+On i386, chaining from a device rather than a file is denied.
.El
.Pp
Independent of secureboot, if the loader is built with
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
@@ -2041,12 +2041,29 @@
char *name, *path;
void *buf;
int fd;
+#ifdef LOADER_VERIEXEC_VECTX
+ struct vectx *vctx;
+ int verror;
+#endif
if (argc < 2) {
command_errmsg = "wrong number of arguments";
return (CMD_ERROR);
}
+#ifndef LOADER_VERIEXEC
+ /*
+ * Firmware only verifies the image if secureboot is enforced, and
+ * lockdown may be requested without it, so we need veriexec to vouch
+ * for the image.
+ */
+ if (loader_in_lockdown()) {
+ command_errmsg =
+ "chain without veriexec is denied by security policy";
+ return (CMD_ERROR);
+ }
+#endif
+
name = argv[1];
if ((fd = open(name, O_RDONLY)) < 0) {
@@ -2054,7 +2071,19 @@
return (CMD_ERROR);
}
-#ifdef LOADER_VERIEXEC
+#ifdef LOADER_VERIEXEC_VECTX
+ /*
+ * Verify the bytes as we read them, rather than trusting a second read
+ * to return the same contents that we verified.
+ */
+ vctx = vectx_open(fd, name, VE_MUST, 0L, NULL, &verror, __func__);
+ if (verror) {
+ sprintf(command_errbuf, "can't verify: %s", name);
+ free(vctx);
+ close(fd);
+ return (CMD_ERROR);
+ }
+#elif defined(LOADER_VERIEXEC)
if (verify_file(fd, name, 0, VE_MUST, __func__) < 0) {
sprintf(command_errbuf, "can't verify: %s", name);
close(fd);
@@ -2064,6 +2093,9 @@
if (fstat(fd, &st) < 0) {
command_errmsg = "stat failed";
+#ifdef LOADER_VERIEXEC_VECTX
+ free(vctx);
+#endif
close(fd);
return (CMD_ERROR);
}
@@ -2071,15 +2103,35 @@
status = BS->AllocatePool(EfiLoaderCode, (UINTN)st.st_size, &buf);
if (status != EFI_SUCCESS) {
command_errmsg = "failed to allocate buffer";
+#ifdef LOADER_VERIEXEC_VECTX
+ free(vctx);
+#endif
close(fd);
return (CMD_ERROR);
}
+#ifdef LOADER_VERIEXEC_VECTX
+ if (vectx_read(vctx, buf, st.st_size) != st.st_size) {
+ command_errmsg = "error while reading the file";
+ (void)BS->FreePool(buf);
+ free(vctx);
+ close(fd);
+ return (CMD_ERROR);
+ }
+ verror = vectx_close(vctx, __func__);
+ if (verror) {
+ sprintf(command_errbuf, "can't verify: %s", name);
+ (void)BS->FreePool(buf);
+ close(fd);
+ return (CMD_ERROR);
+ }
+#else
if (read(fd, buf, st.st_size) != st.st_size) {
command_errmsg = "error while reading the file";
(void)BS->FreePool(buf);
close(fd);
return (CMD_ERROR);
}
+#endif
close(fd);
status = BS->LoadImage(FALSE, IH, NULL, buf, st.st_size, &loaderhandle);
(void)BS->FreePool(buf);
@@ -2169,7 +2221,12 @@
return (CMD_ERROR); /* not reached */
}
-COMMAND_SET(chain, "chain", "chain load file", command_chain);
+/*
+ * Lockdown-safe only because the image must be verified by veriexec; without
+ * veriexec, command_chain() refuses to run in lockdown.
+ */
+COMMAND_SET_FLAGS(chain, "chain", "chain load file", command_chain,
+ CMDF_LOCKDOWN);
#if defined(LOADER_NET_SUPPORT)
extern struct in_addr servip;
diff --git a/stand/i386/loader/chain.c b/stand/i386/loader/chain.c
--- a/stand/i386/loader/chain.c
+++ b/stand/i386/loader/chain.c
@@ -1,6 +1,10 @@
/*-
* Copyright 2015 Toomas Soome <tsoome@me.com>
* 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
@@ -53,7 +57,13 @@
*/
#define SECTOR_SIZE (512)
-COMMAND_SET(chain, "chain", "chain load boot block from device", command_chain);
+/*
+ * Lockdown-safe only because the image must be verified by veriexec; without
+ * veriexec, or for the device form that veriexec cannot verify,
+ * command_chain() refuses to run in lockdown.
+ */
+COMMAND_SET_FLAGS(chain, "chain", "chain load boot block from device",
+ command_chain, CMDF_LOCKDOWN);
static int
command_chain(int argc, char *argv[])
@@ -76,6 +86,25 @@
return (CMD_ERROR);
}
+ len = strlen(argv[1]);
+ if (loader_in_lockdown()) {
+#ifndef LOADER_VERIEXEC
+ command_errmsg =
+ "chain without veriexec is denied by security policy";
+ return (CMD_ERROR);
+#else
+ /*
+ * veriexec only verifies regular files, so a boot block read
+ * straight from a device would go unchecked.
+ */
+ if (argv[1][len-1] == ':') {
+ command_errmsg =
+ "chain from a device is denied by security policy";
+ return (CMD_ERROR);
+ }
+#endif
+ }
+
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
command_errmsg = "open failed";
@@ -99,7 +128,6 @@
}
#endif
#endif
- len = strlen(argv[1]);
if (argv[1][len-1] != ':') {
if (fstat(fd, &st) == -1) {
command_errmsg = "stat failed";
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 27, 4:24 AM (19 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42035154
Default Alt Text
D62095.1795753483.diff (5 KB)
Attached To
Mode
D62095: loader: allow chain in lockdown only with veriexec
Attached
Detach File
Event Timeline