crypto: af_alg - Stop after finding name in allowlist

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>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Eric Biggers 2026-08-02 16:00:55 -07:00 committed by Herbert Xu
parent 185c67edbb
commit 68554337b4

View File

@ -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;
}
}
}
/*