mail archive of the barebox mailing list
 help / color / mirror / Atom feed
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 2/7] security: policy: sanity check parameters
Date: Fri, 20 Mar 2026 08:17:28 +0100	[thread overview]
Message-ID: <20260320-v2026-02-0-topic-sconfig_console-v5-2-2efcaa7cb03e@pengutronix.de> (raw)
In-Reply-To: <20260320-v2026-02-0-topic-sconfig_console-v5-0-2efcaa7cb03e@pengutronix.de>

Do a sanity check for the the is_allowed, before using it as array
index.

Signed-off-by: Fabian Pflug <f.pflug@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;
+
+	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;
 
 	return policy->policy[option];
 }

-- 
2.47.3




  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 ` Fabian Pflug [this message]
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 ` [PATCH v5 5/7] common: bootm: add policy to commandline Fabian Pflug
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-2-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