Page MenuHomeFreeBSD

D62088.1795754649.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D62088.1795754649.diff

diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h
--- a/stand/common/bootstrap.h
+++ b/stand/common/bootstrap.h
@@ -319,13 +319,26 @@
const char *c_name;
const char *c_desc;
bootblk_cmd_t *c_fn;
+ int c_flags;
+
+/* Fail closed: we need to declare commands to be lockdown-safe. */
+#define CMDF_LOCKDOWN 0x0001
};
-#define COMMAND_SET(tag, key, desc, func) \
+static inline bool
+command_permitted(const struct bootblk_command *cmd)
+{
+ return (true);
+}
+
+#define COMMAND_SET_FLAGS(tag, key, desc, func, flags) \
static bootblk_cmd_t func; \
- static struct bootblk_command _cmd_ ## tag = { key, desc, func }; \
+ static struct bootblk_command _cmd_ ## tag = { key, desc, func, flags }; \
DATA_SET(Xcommand_set, _cmd_ ## tag)
+#define COMMAND_SET(tag, key, desc, func) \
+ COMMAND_SET_FLAGS(tag, key, desc, func, 0)
+
SET_DECLARE(Xcommand_set, struct bootblk_command);
/*
diff --git a/stand/common/interp.c b/stand/common/interp.c
--- a/stand/common/interp.c
+++ b/stand/common/interp.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
@@ -178,7 +182,7 @@
interp_builtin_cmd(int argc, char *argv[])
{
int result;
- struct bootblk_command *cmd;
+ const struct bootblk_command *cmd;
if (argc < 1)
return (CMD_OK);
@@ -189,7 +193,12 @@
result = CMD_ERROR;
cmd = interp_lookup_cmd(argv[0]);
- if (cmd != NULL && cmd->c_fn) {
+
+ if (cmd != NULL && !command_permitted(cmd)) {
+ snprintf(command_errbuf, sizeof(command_errbuf),
+ "%s is denied by security policy", argv[0]);
+ result = CMD_ERROR;
+ } else if (cmd != NULL && cmd->c_fn) {
TSENTER2(argv[0]);
result = cmd->c_fn(argc, argv);
TSEXIT();
@@ -203,7 +212,13 @@
* Return true if the builtin command exists
*/
bool
-interp_has_builtin_cmd(const char *cmd)
+interp_has_builtin_cmd(const char *name)
{
- return (interp_lookup_cmd(cmd) != NULL);
+ const struct bootblk_command *cmd;
+
+ cmd = interp_lookup_cmd(name);
+ if (cmd == NULL)
+ return (false);
+
+ return (command_permitted(cmd));
}
diff --git a/stand/common/interp_forth.c b/stand/common/interp_forth.c
--- a/stand/common/interp_forth.c
+++ b/stand/common/interp_forth.c
@@ -68,7 +68,7 @@
static void
bf_command(FICL_VM *vm)
{
- char *name, *line, *tail, *cp;
+ char *name, *line = NULL, *tail, *cp;
size_t len;
struct bootblk_command **cmdp;
bootblk_cmd_t *cmd;
@@ -82,8 +82,17 @@
/* Find our command structure */
cmd = NULL;
SET_FOREACH(cmdp, Xcommand_set) {
- if (((*cmdp)->c_name != NULL) && !strcmp(name, (*cmdp)->c_name))
+ if (((*cmdp)->c_name != NULL) &&
+ !strcmp(name, (*cmdp)->c_name)) {
+ if (!command_permitted(*cmdp)) {
+ snprintf(command_errbuf, sizeof(command_errbuf),
+ "%s is denied by security policy", name);
+ result = CMD_ERROR;
+ goto failed;
+ }
+
cmd = (*cmdp)->c_fn;
+ }
}
if (cmd == NULL)
panic("callout for unknown command '%s'", name);
@@ -135,6 +144,7 @@
result=BF_PARSE;
}
+failed:
switch (result) {
case CMD_CRIT:
printf("%s\n", command_errmsg);

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 27, 4:44 AM (19 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42035347
Default Alt Text
D62088.1795754649.diff (3 KB)

Event Timeline