From: Fabian Pflug <f.pflug@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>,
Sascha Hauer <s.hauer@pengutronix.de>
Cc: Fabian Pflug <f.pflug@pengutronix.de>
Subject: [PATCH v5 5/7] common: bootm: add policy to commandline
Date: Fri, 20 Mar 2026 08:17:31 +0100 [thread overview]
Message-ID: <20260320-v2026-02-0-topic-sconfig_console-v5-5-2efcaa7cb03e@pengutronix.de> (raw)
In-Reply-To: <20260320-v2026-02-0-topic-sconfig_console-v5-0-2efcaa7cb03e@pengutronix.de>
If security policies are used, then the variable bootm.provide_policy
can be set to automatically append the currently selected security
policy to the kernel commandline with the prefix
barebox.security.policy=
This allows the the system to behave different based on the selected
security policy.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
common/bootm.c | 24 ++++++++++++++++++++++++
include/bootm.h | 5 +++++
2 files changed, 29 insertions(+)
diff --git a/common/bootm.c b/common/bootm.c
index d43079bb81..68631c392d 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -22,6 +22,7 @@
#include <uncompress.h>
#include <zero_page.h>
#include <security/config.h>
+#include <security/policy.h>
static LIST_HEAD(handler_list);
static struct sconfig_notifier_block sconfig_notifier;
@@ -75,6 +76,7 @@ static int bootm_dryrun;
static int bootm_earlycon;
static int bootm_provide_machine_id;
static int bootm_provide_hostname;
+static int bootm_provide_policy;
static int bootm_verbosity;
static int bootm_efi_mode = BOOTM_EFI_AVAILABLE;
@@ -97,6 +99,7 @@ void bootm_data_init_defaults(struct bootm_data *data)
data->appendroot = bootm_appendroot;
data->provide_machine_id = bootm_provide_machine_id;
data->provide_hostname = bootm_provide_hostname;
+ data->provide_policy = bootm_provide_policy;
data->verbose = bootm_verbosity;
data->dryrun = bootm_dryrun;
data->efi_boot = bootm_efi_mode;
@@ -118,6 +121,7 @@ void bootm_data_restore_defaults(const struct bootm_data *data)
bootm_appendroot = data->appendroot;
bootm_provide_machine_id = data->provide_machine_id;
bootm_provide_hostname = data->provide_hostname;
+ bootm_provide_policy = data->provide_policy;
bootm_verbosity = data->verbose;
bootm_dryrun = data->dryrun;
bootm_efi_mode = data->efi_boot;
@@ -759,6 +763,21 @@ int bootm_boot(struct bootm_data *bootm_data)
free(hostname_bootarg);
}
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY) && bootm_data->provide_policy) {
+ char *policy_bootargs;
+ const struct security_policy *active_policy = security_policy_get_active();
+
+ if (active_policy && !active_policy->name) {
+ pr_err("Providing policy is enabled but policy has no name\n");
+ ret = -EINVAL;
+ goto err_out;
+ }
+
+ policy_bootargs = basprintf("barebox.security.policy=%s", active_policy->name);
+ globalvar_add_simple("linux.bootargs.dyn.policy", policy_bootargs);
+ free(policy_bootargs);
+ }
+
pr_info("\nLoading %s '%s'", file_type_to_string(data->kernel_type),
data->os_file);
if (data->kernel_type == filetype_uimage &&
@@ -967,6 +986,8 @@ static int bootm_init(void)
globalvar_add_simple_bool("bootm.earlycon", &bootm_earlycon);
globalvar_add_simple_bool("bootm.provide_machine_id", &bootm_provide_machine_id);
globalvar_add_simple_bool("bootm.provide_hostname", &bootm_provide_hostname);
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY))
+ globalvar_add_simple_bool("bootm.provide_policy", &bootm_provide_policy);
if (IS_ENABLED(CONFIG_BOOTM_INITRD)) {
globalvar_add_simple("bootm.initrd", NULL);
globalvar_add_simple("bootm.initrd.loadaddr", NULL);
@@ -1030,3 +1051,6 @@ BAREBOX_MAGICVAR(global.bootm.root_dev, "bootm default root device (overrides de
BAREBOX_MAGICVAR(global.bootm.root_param, "bootm root parameter name (normally 'root' for root=/dev/...)");
BAREBOX_MAGICVAR(global.bootm.provide_machine_id, "If true, append systemd.machine_id=$global.machine_id to Kernel command line");
BAREBOX_MAGICVAR(global.bootm.provide_hostname, "If true, append systemd.hostname=$global.hostname to Kernel command line");
+#ifdef CONFIG_SECURITY_POLICY
+BAREBOX_MAGICVAR(global.bootm.provide_policy, "Add barebox.security.policy= option to Kernel");
+#endif
diff --git a/include/bootm.h b/include/bootm.h
index 21feb1ca98..a712010b2b 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -46,6 +46,11 @@ struct bootm_data {
* of global.hostname to Kernel.
*/
bool provide_hostname;
+ /*
+ * provide_policy - if true, try to add barebox.security.policy= with
+ * with value of currently selected policy
+ */
+ bool provide_policy;
enum bootm_efi_mode efi_boot;
unsigned long initrd_address;
unsigned long os_address;
--
2.47.3
next prev parent reply other threads:[~2026-03-20 7:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-20 7:17 [PATCH v5 0/7] Add helper for security policies Fabian Pflug
2026-03-20 7:17 ` [PATCH v5 1/7] of: add of_property_write_string_array() Fabian Pflug
2026-03-20 7:17 ` [PATCH v5 2/7] security: policy: sanity check parameters Fabian Pflug
2026-03-20 7:17 ` [PATCH v5 3/7] security: policy: remove global active_policy var Fabian Pflug
2026-03-20 7:29 ` Ahmad Fatoum
2026-03-20 7:17 ` [PATCH v5 4/7] security: policy: add notifier chain for name change Fabian Pflug
2026-03-20 7:17 ` Fabian Pflug [this message]
2026-03-20 7:17 ` [PATCH v5 6/7] drivers: pinctrl: configure pinctrl based on policy name Fabian Pflug
2026-03-20 7:17 ` [PATCH v5 7/7] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260320-v2026-02-0-topic-sconfig_console-v5-5-2efcaa7cb03e@pengutronix.de \
--to=f.pflug@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox