[PATCH v6 2/7] security: policy: sanity check parameters

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Mar 24 07:35:53 PDT 2026


Hi,

On 3/24/26 10:52 AM, Fabian Pflug wrote:
> Do a sanity check for the the is_allowed, before using it as array
> index.
> 
> Signed-off-by: Fabian Pflug <f.pflug at pengutronix.de>
> ---
>  commands/sconfig.c | 7 ++++++-
>  security/policy.c  | 2 ++
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/commands/sconfig.c b/commands/sconfig.c
> index 02c3a6b1ed..3ca4478270 100644
> --- a/commands/sconfig.c
> +++ b/commands/sconfig.c
> @@ -37,7 +37,12 @@ static void sconfig_print(const struct security_policy *policy)
>  static int sconfig_command_notify(struct notifier_block *nb,
>  				  unsigned long opt, void *unused)
>  {
> -	bool allow = is_allowed(NULL, opt);
> +	bool allow;
> +
> +	if (opt >= SCONFIG_NUM)
> +		return 0;

Here you use >=

> +
> +	allow = is_allowed(NULL, opt);
>  
>  	printf("%s%s%s%s\n", allow ? green : red, allow ? "+" : "-", nc,
>  	       sconfig_names[opt]);
> diff --git a/security/policy.c b/security/policy.c
> index 85333d9e6f..95e7bf99a2 100644
> --- a/security/policy.c
> +++ b/security/policy.c
> @@ -52,6 +52,8 @@ static bool __is_allowed(const struct security_policy *policy, unsigned option)
>  {
>  	if (!policy)
>  		return true;
> +	if (WARN(option > SCONFIG_NUM))
> +		return false;

and here only >

I think you want both to be >= because option is an index?


Thanks,
Ahmad

>  
>  	return policy->policy[option];
>  }
> 

-- 
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 |




More information about the barebox mailing list