The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org, Herbert Xu <herbert@gondor.apana.org.au>
Cc: Richard Weinberger <richard@nod.at>,
	linux-kernel@vger.kernel.org, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 3/3] crypto: af_alg - Stop after finding name in allowlist
Date: Sun,  2 Aug 2026 16:00:55 -0700	[thread overview]
Message-ID: <20260802230055.100746-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20260802230055.100746-1-ebiggers@kernel.org>

If the algorithm name is found in the allowlist and the privilege check
doesn't pass, there's no need to consider remaining entries since the
list contains (and is intended to contain) at most one entry per name.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 crypto/af_alg.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 1e5da61b315c..ab84c4488a15 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -145,10 +145,13 @@ int af_alg_check_restriction(const char *name,
 	if (level == 1) {
 		for (const struct af_alg_allowlist_entry *ent = allowlist;
 		     ent->name; ent++) {
-			if (strcmp(name, ent->name) == 0 &&
-			    ((ent->flags & AF_ALG_UNPRIVILEGED) ||
-			     af_alg_capable()))
-				return 0;
+			if (strcmp(name, ent->name) == 0) {
+				if ((ent->flags & AF_ALG_UNPRIVILEGED) ||
+				    af_alg_capable())
+					return 0;
+				/* List contains at most one entry per name. */
+				break;
+			}
 		}
 	}
 	/*
-- 
2.55.0


      parent reply	other threads:[~2026-08-02 23:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 23:00 [PATCH 0/3] crypto: af_alg_restrict cleanups Eric Biggers
2026-08-02 23:00 ` [PATCH 1/3] crypto: af_alg - Make cbc(paes) privileged-only Eric Biggers
2026-08-04  6:39   ` Richard Weinberger
2026-08-02 23:00 ` [PATCH 2/3] crypto: af_alg - Replace 'bool privileged' with flags Eric Biggers
2026-08-02 23:00 ` Eric Biggers [this message]

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=20260802230055.100746-4-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    /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