[PATCH 3/3] crypto: af_alg - Stop after finding name in allowlist
Eric Biggers <[email protected]> Sun, 2 Aug 2026 16:00:55 -0700
| Newsgroups | org.kernel.vger.linux-crypto,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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