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 v6 6/7] drivers: pinctrl: configure pinctrl based on policy name
Date: Tue, 24 Mar 2026 10:52:39 +0100 [thread overview]
Message-ID: <20260324-v2026-02-0-topic-sconfig_console-v6-6-f0eb6af2cc06@pengutronix.de> (raw)
In-Reply-To: <20260324-v2026-02-0-topic-sconfig_console-v6-0-f0eb6af2cc06@pengutronix.de>
When using security policies to disable console input on the default
console, it might be more advantagous to also disable the RX pin hard
in pinctrl, so that if there is a software error with the security
policy implementation input does not reach to system and cannot be
exploited.
An example devicetree could look like this:
/ {
chosen {
stdout-path = &uart3;
};
};
&uart3 {
pinctrl-names = "default", "barebox,policy-devel-default";
pinctrl-0 = <&pinctrl_uart3_tx_only>;
pinctrl-1 = <&pinctrl_uart3_interactive>;
status = "okay";
};
&iomuxc {
pinctrl_uart3_interactive: uart3ingrp {
fsl,pins = <MX8MP_IOMUXC_SD1_DATA6__UART3_DCE_TX 0x140>,
<MX8MP_IOMUXC_SD1_DATA7__UART3_DCE_RX 0x140>;
};
pinctrl_uart3_tx_only: uart3txgrp {
fsl,pins = <MX8MP_IOMUXC_SD1_DATA6__UART3_DCE_TX 0x140>,
<MX8MP_IOMUXC_SD1_DATA7__GPIO2_IO09 0x140>;
};
};
This would apply the devel pinmux on selecting the devel config and the
default on every other security policy configuration.
A Kconfig option to enable this feature has been chosen, because parsing
pinctrl and mapping the names is a lot of string operations, that could
increase boottime for a feature, that is maybe not needed for everyone.
Signed-off-by: Fabian Pflug <f.pflug@pengutronix.de>
---
drivers/pinctrl/pinctrl.c | 73 +++++++++++++++++++++++++++++++++++++++++++++--
security/Kconfig.policy | 12 ++++++++
2 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index 01567aa5ae..eb4103c5fd 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -10,11 +10,22 @@
#include <linux/overflow.h>
#include <errno.h>
#include <of.h>
+#include <security/config.h>
+#include <security/policy.h>
struct pinctrl {
struct device_node consumer_np;
};
+LIST_HEAD(pinctrl_devices_name_list);
+
+struct pinctrl_devices_name_info {
+ struct device_node *node;
+ const char *name;
+ struct list_head list;
+};
+
+
static LIST_HEAD(pinctrl_consumer_list);
struct pinctrl_state {
@@ -218,15 +229,48 @@ int pinctrl_select_state(struct pinctrl *pinctrl, struct pinctrl_state *state)
return ret;
}
+static void of_pinctrl_policy_update_or_add(struct device_node *np, const char *name)
+{
+ struct pinctrl_devices_name_info *dev;
+
+ list_for_each_entry(dev, &pinctrl_devices_name_list, list) {
+ if (dev->node == np) {
+ free_const(dev->name);
+ dev->name = xstrdup_const(name);
+ return;
+ }
+ }
+ dev = xzalloc(sizeof(*dev));
+ dev->node = np;
+ dev->name = xstrdup_const(name);
+ list_add(&dev->list, &pinctrl_devices_name_list);
+}
+
int of_pinctrl_select_state(struct device_node *np, const char *name)
{
struct pinctrl *pinctrl = of_pinctrl_get(np);
- struct pinctrl_state *state;
+ struct pinctrl_state *state = NULL;
if (!of_find_property(np, "pinctrl-0", NULL))
return 0;
- state = pinctrl_lookup_state(pinctrl, name);
+ if (IS_ENABLED(CONFIG_SECURITY_POLICY_PINCTRL)) {
+ const struct security_policy *active_policy = security_policy_get_active();
+
+ of_pinctrl_policy_update_or_add(np, name);
+
+ if (active_policy && active_policy->name && name) {
+ char *policy_pinctrl;
+
+ policy_pinctrl = basprintf("barebox,policy-%s-%s",
+ active_policy->name,
+ name);
+ state = pinctrl_lookup_state(pinctrl, policy_pinctrl);
+ free(policy_pinctrl);
+ }
+ }
+ if (IS_ERR_OR_NULL(state))
+ state = pinctrl_lookup_state(pinctrl, name);
if (IS_ERR(state))
return PTR_ERR(state);
@@ -331,3 +375,28 @@ void of_pinctrl_unregister_consumer(struct device *dev)
}
}
#endif
+
+static int pinctrl_change_policy(struct notifier_block *nb,
+ unsigned long _ignored,
+ void *_data)
+{
+ struct pinctrl_devices_name_info *dev;
+
+ list_for_each_entry(dev, &pinctrl_devices_name_list, list) {
+ of_pinctrl_select_state(dev->node, dev->name);
+ }
+ return 0;
+}
+
+static struct notifier_block pinctrl_policy_notifier = {
+ .notifier_call = pinctrl_change_policy
+};
+
+static int pinctrl_policy_init(void)
+{
+ if (!IS_ENABLED(CONFIG_SECURITY_POLICY_PINCTRL))
+ return 0;
+
+ return notifier_chain_register(&sconfig_name_notifier, &pinctrl_policy_notifier);
+}
+pure_initcall(pinctrl_policy_init);
diff --git a/security/Kconfig.policy b/security/Kconfig.policy
index e778327b0d..2c8e8399a0 100644
--- a/security/Kconfig.policy
+++ b/security/Kconfig.policy
@@ -69,6 +69,18 @@ config SECURITY_POLICY_DEFAULT_PERMISSIVE
A security policy should always be selected, either early on by
board code or via CONFIG_SECURITY_POLICY_INIT.
+config SECURITY_POLICY_PINCTRL
+ bool "Update pinctrl based on policy-name"
+ help
+ When selecting a pinctrl with the name <pinctrlname>, if there exists
+ a pinctrl with the name barebox,policy-<policyname>-<pinctrlname>,
+ then this pinctrl will be used instead.
+ This could be used for example to disable the RX (and TX) Pin in
+ lockdown mode for the console or disable the usage of SPI.
+
+ Enabling this option does increase the boottime.
+ If unsure, say N.
+
config SECURITY_POLICY_PATH
string
depends on SECURITY_POLICY
--
2.47.3
next prev parent reply other threads:[~2026-03-24 9:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 9:52 [PATCH v6 0/7] Add helper for security policies Fabian Pflug
2026-03-24 9:52 ` [PATCH v6 1/7] of: add of_property_write_string_array() Fabian Pflug
2026-03-24 9:52 ` [PATCH v6 2/7] security: policy: sanity check parameters Fabian Pflug
2026-03-24 14:35 ` Ahmad Fatoum
2026-03-24 9:52 ` [PATCH v6 3/7] security: policy: remove global active_policy var Fabian Pflug
2026-03-24 9:52 ` [PATCH v6 4/7] security: policy: add notifier chain for name change Fabian Pflug
2026-03-24 9:52 ` [PATCH v6 5/7] common: bootm: add policy to commandline Fabian Pflug
2026-03-24 14:34 ` Ahmad Fatoum
2026-03-24 9:52 ` Fabian Pflug [this message]
2026-03-24 9:52 ` [PATCH v6 7/7] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
2026-03-24 14:57 ` Ahmad Fatoum
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=20260324-v2026-02-0-topic-sconfig_console-v6-6-f0eb6af2cc06@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