mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Fabian Pflug <f.pflug@pengutronix.de>,
	BAREBOX <barebox@lists.infradead.org>,
	Sascha Hauer <s.hauer@pengutronix.de>
Subject: Re: [PATCH v3 4/5] security: configure pinctrl based on policy name
Date: Wed, 18 Mar 2026 12:43:20 +0100	[thread overview]
Message-ID: <810b68c0-35fe-479e-8b62-a517ee2a50cf@pengutronix.de> (raw)
In-Reply-To: <20260318-v2026-02-0-topic-sconfig_console-v3-4-e26055294723@pengutronix.de>

Hi,

On 3/18/26 10:22, Fabian Pflug wrote:
> 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";
> 	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 configuration.

The barebox,policy- pattern should be documented in Documentation/devicetree/bindings/

> -	pinctrl_select_state_default(dev);
> +
> +	if (IS_ENABLED(CONFIG_SECURITY_POLICY_PINCTRL)) {
> +		char *policy_pinctrl;
> +
> +		policy_pinctrl = basprintf("barebox,policy-%s", active_policy->name);
> +		if (IS_ERR(pinctrl_get_select(dev, policy_pinctrl)))
> +			pinctrl_select_state_default(dev);
> +		free(policy_pinctrl);
> +	} else
> +		pinctrl_select_state_default(dev);

I think this logic should go somewhere so that pinctrl_select_state_default
can make use of it as there are drivers that call
pinctrl_select_state_default() tha would be unaffected.

Also kernel coding stye is to use braces in else if the if clause
has them.

>  	of_clk_set_defaults(dev->of_node, false);
>  
>  	list_add(&dev->active, &active_device_list);
> diff --git a/security/Kconfig.policy b/security/Kconfig.policy
> index 9ea52e91da..8ddb67ac2d 100644
> --- a/security/Kconfig.policy
> +++ b/security/Kconfig.policy
> @@ -68,6 +68,14 @@ 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
> +	  Changing the security policy, will look for a pinctrl with the name
> +	  barebox,policy-<policyname>. If there is one, it will change the
> +	  pinctrl for this. This could be used to disable the RX (and TX)
> +	  Pin in lockdown mode for the console or disable the usage of SPI.

"for example".

> +
>  config SECURITY_POLICY_PATH
>  	string
>  	depends on SECURITY_POLICY
> diff --git a/security/policy.c b/security/policy.c
> index e2d1b10a78..4d51af63e7 100644
> --- a/security/policy.c
> +++ b/security/policy.c
> @@ -7,6 +7,7 @@
>  #include <linux/bitmap.h>
>  #include <param.h>
>  #include <device.h>
> +#include <pinctrl.h>
>  #include <stdio.h>
>  
>  #include <security/policy.h>
> @@ -90,12 +91,23 @@ bool is_allowed(const struct security_policy *policy, unsigned option)
>  int security_policy_activate(const struct security_policy *policy)
>  {
>  	const struct security_policy *old_policy = active_policy;
> +	struct device *dev;
> +	char *policy_pinctrl;
>  
>  	if (policy == old_policy)
>  		return 0;
>  
>  	active_policy = policy;
>  
> +	if (IS_ENABLED(CONFIG_SECURITY_POLICY_PINCTRL)) {
> +		policy_pinctrl = basprintf("barebox,policy-%s", active_policy->name);
> +		list_for_each_entry(dev, &active_device_list, active) {
> +			if (IS_ERR(pinctrl_get_select(dev, policy_pinctrl)))
> +				pinctrl_select_state_default(dev);
> +		}
> +		free(policy_pinctrl);
> +	}

This breaks HS200 on i.MX. Reverting the default state on error is not
a safe fallback.

I am thinking maybe, we should change the binding a bit and make it:

barebox,policy-lockdown-default for example and then a lookup
for "default" also does a lookup for "barebox,policy-${policy}-default".

That way, we will have something generically usable.

In any case, it's not acceptable to change pinctrl settings of devices
that did not have security policy specific pinctrl groups.

Thanks,
Ahmad

> +
>  	for (int i = 0; i < SCONFIG_NUM; i++) {
>  		if (__is_allowed(policy, i) == __is_allowed(old_policy, i))
>  			continue;
> 


-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2026-03-18 11:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-18  9:21 [PATCH v3 0/5] Add helper for security policies Fabian Pflug
2026-03-18  9:21 ` [PATCH v3 1/5] of: add of_property_write_string_array() Fabian Pflug
2026-03-18  9:22 ` [PATCH v3 2/5] common: bootm: add policy to commandline Fabian Pflug
2026-03-18 10:23   ` Sascha Hauer
2026-03-18  9:22 ` [PATCH v3 3/5] security: policy: set active policy on boot Fabian Pflug
2026-03-18 11:28   ` Ahmad Fatoum
2026-03-18 11:38     ` Fabian Pflug
2026-03-18 11:54       ` Ahmad Fatoum
2026-03-18 12:47         ` Fabian Pflug
2026-03-19 14:58           ` Ahmad Fatoum
2026-03-18  9:22 ` [PATCH v3 4/5] security: configure pinctrl based on policy name Fabian Pflug
2026-03-18 11:43   ` Ahmad Fatoum [this message]
2026-03-18  9:22 ` [PATCH v3 5/5] security: kernel_pinctrl: fixup pinctrl in kernel dts Fabian Pflug
2026-03-18 11:53   ` Ahmad Fatoum
2026-03-18  9:57 ` [PATCH v3 0/5] Add helper for security policies Sascha Hauer
2026-03-18 11:43   ` 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=810b68c0-35fe-479e-8b62-a517ee2a50cf@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=f.pflug@pengutronix.de \
    --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