net/rxrpc/key.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rxrpc_read() checks whether the key description starts with "afs@" by
calling memcmp() with a length of 4. The description is an arbitrary
NUL-terminated string supplied when the key is created and is only
required to be non-empty, so it can be as short as one character. In
that case memcmp() reads up to two bytes past the end of the
kmemdup()'d description (which is strlen(description) + 1 bytes long).
The result of the comparison is not affected because the NUL terminator
is reached within the first four bytes, and the overread is normally
confined to the slab object, but it is still an out-of-bounds read.
Use str_has_prefix(), which stops at the NUL terminator.
Fixes: ed6dd18b5aceb ("RxRPC: Allow RxRPC keys to be read")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
net/rxrpc/key.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
index cbd26da44951..019e512aeb1f 100644
--- a/net/rxrpc/key.c
+++ b/net/rxrpc/key.c
@@ -746,7 +746,7 @@ static long rxrpc_read(const struct key *key,
_enter("");
/* we don't know what form we should return non-AFS keys in */
- if (memcmp(key->description, "afs@", 4) != 0)
+ if (!str_has_prefix(key->description, "afs@"))
return -EOPNOTSUPP;
cnlen = strlen(key->description + 4);
Hi! This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information: - How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan. - Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages. Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. *IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages. -- The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Hi,
Found by code inspection/static analysis while auditing rxrpc key
handling. I did exercise the path at runtime: add_key("rxrpc", "a",
NULL, 0, ...) followed by keyctl_read() reaches the
memcmp(key->description, "afs@", 4) and returns -EOPNOTSUPP.
It is only a C-level overread: kmalloc rounds the 2-byte description up
to an 8-byte object, the inlined 4-byte load is not KASAN-instrumented,
and the extra bytes are slab padding. There is no crash, no KASAN
report and no user-visible effect, so this is a small correctness/UB
fix rather than a runtime-triggered bug.
Thanks,
Lin Ma
© 2016 - 2026 Red Hat, Inc.