[PATCH net] rxrpc: Fix RxGK rekey on a DATA packet that fails verification

From: Andrew Stellman

Date: Sat Nov 28 2026 - 14:17:39 EST


From: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>

rxgk_verify_packet() passes the key number from the DATA header to
rxgk_get_key() before the packet is verified. If it's the next key
number, rxgk_get_key() advances the connection's key window, and the
window stays advanced if AUTH verification or ENCRYPT decryption then
fails.

For AUTH and ENCRYPT, verify a packet with the next key number using a
transport key that isn't installed yet, and advance the window only
after the packet verifies. PLAIN keeps the existing lookup.

Tested with KASAN in an arm64 QEMU guest on mainline at
commit 7cd8495c0f16 ("Merge tag 'io_uring-7.4-20261127' of
git://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux").
After a forged AUTH DATA packet with the next key number, the call
failed with EPROTO and the next outgoing DATA packet used key 1 without
this patch and key 0 with it. Valid 3,000-byte AUTH and ENCRYPT calls
with a token bytelife of 11 completed with and without it.

The issue was found by Claude Opus 5.5 running Quality Playbook, an
LLM-driven code review tool:
https://github.com/andrewstellman/quality-playbook
The fix was drafted with OpenAI GPT-6 (Codex) and this changelog with
Claude Opus 5.5, and both were reviewed by me.

Fixes: 7a7513a3081c ("rxrpc: rxgk: Implement connection rekeying")
Signed-off-by: Andrew Stellman <astellman@xxxxxxxxxxxxxxxxxxx>
---
A reproducer is available on request.

Separately, with two concurrent 3,000-byte calls on one connection and
a token bytelife of 11, both calls completed (each got its 36-byte
reply) in 424/1460 AUTH and 518/1460 ENCRYPT runs without this patch
and 390/1460 and 528/1460 with it, over five boots of each kernel.
Most failed runs aborted with RXGK_BADKEYNO. The counts varied widely
between boots and don't establish a regression or an improvement. In
temporary trace logging on both kernels, every RXGK_BADKEYNO reject
was a DATA packet with key 0 after the connection's key number had
reached 2.

net/rxrpc/rxgk.c | 44 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 40 insertions(+), 4 deletions(-)

diff --git a/net/rxrpc/rxgk.c b/net/rxrpc/rxgk.c
index 77a67ace1d2481..9be3ff54f7c75a 100644
--- a/net/rxrpc/rxgk.c
+++ b/net/rxrpc/rxgk.c
@@ -587,13 +587,39 @@ error:
static int rxgk_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
{
struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
- struct rxgk_context *gk;
+ struct rxrpc_connection *conn = call->conn;
+ struct rxgk_context *gk, *cur = NULL;
u16 key_number = sp->hdr.cksum;
+ unsigned int current_key;
+ bool commit = false;
+ int ret;

_enter("{%d{%x}},{#%u}",
call->debug_id, key_serial(call->conn->key), sp->hdr.seq);

- gk = rxgk_get_key(call->conn, &key_number);
+ /* Verify a next-key packet before advancing the key window. */
+ if (conn->security_level == RXRPC_SECURITY_AUTH ||
+ conn->security_level == RXRPC_SECURITY_ENCRYPT) {
+ read_lock(&conn->security_use_lock);
+ current_key = conn->rxgk.key_number;
+ cur = conn->rxgk.keys[current_key &
+ (ARRAY_SIZE(conn->rxgk.keys) - 1)];
+ if (cur && current_key < UINT_MAX &&
+ key_number == (u16)(current_key + 1))
+ refcount_inc(&cur->usage);
+ else
+ cur = NULL;
+ read_unlock(&conn->security_use_lock);
+ }
+
+ if (cur) {
+ gk = rxgk_generate_transport_key(conn, cur->key,
+ current_key + 1, GFP_NOFS);
+ rxgk_put(cur);
+ commit = true;
+ } else {
+ gk = rxgk_get_key(call->conn, &key_number);
+ }
if (IS_ERR(gk)) {
switch (PTR_ERR(gk)) {
case -ESTALE:
@@ -610,13 +636,23 @@ static int rxgk_verify_packet(struct rxrpc_call *call, struct sk_buff *skb)
rxgk_put(gk);
return 0;
case RXRPC_SECURITY_AUTH:
- return rxgk_verify_packet_integrity(call, gk, skb);
+ ret = rxgk_verify_packet_integrity(call, gk, skb);
+ break;
case RXRPC_SECURITY_ENCRYPT:
- return rxgk_verify_packet_encrypted(call, gk, skb);
+ ret = rxgk_verify_packet_encrypted(call, gk, skb);
+ break;
default:
rxgk_put(gk);
return -ENOANO;
}
+
+ if (ret == 0 && commit) {
+ /* A later packet with this key can retry a failed advance. */
+ gk = rxgk_get_key(conn, &key_number);
+ if (!IS_ERR(gk))
+ rxgk_put(gk);
+ }
+ return ret;
}

/*
--
2.53.0