[PATCH net] rxrpc: Fix overread of short key descriptions

From: Lin Ma

Date: Sun Nov 22 2026 - 20:14:14 EST


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@xxxxxxxxxx>
---
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);