rxgk_get_key() and rxgk_rekey() compare the wire key number with the low 16 bits of current_key - 1 without checking that current_key is nonzero. On a new connection, cksum 0xffff therefore selects UINT_MAX as the key number. The missing key slot makes rxgk_rekey() derive a new context from keys[0] and overwrite that slot with crank false, losing the reference to the original context and leaving the connection with the wrong key state. We verified the path using a real AF_RXRPC client and a raw UDP server that sent a DATA packet with cksum 0xffff. The run reported five suspected leaks; two objects had an allocation backtrace through rxgk_generate_transport_key(), rxgk_get_key() and rxgk_verify_packet(). The slot overwrite and lost context reference are established by the source-level ownership analysis. Reject the previous-key match while current_key is zero. Fixes: 7a7513a3081c ("rxrpc: rxgk: Implement connection rekeying") Assisted-by: Codex:GPT-6 Signed-off-by: Lin Ma --- net/rxrpc/rxgk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/rxrpc/rxgk.c b/net/rxrpc/rxgk.c index f9f5a2dc62ed..0a62475691f7 100644 --- a/net/rxrpc/rxgk.c +++ b/net/rxrpc/rxgk.c @@ -100,7 +100,8 @@ static struct rxgk_context *rxgk_rekey(struct rxrpc_connection *conn, } else { if (*specific_key_number == (u16)current_key) key_number = current_key; - else if (*specific_key_number == (u16)(current_key - 1)) + else if (current_key > 0 && + *specific_key_number == (u16)(current_key - 1)) key_number = current_key - 1; else if (*specific_key_number == (u16)(current_key + 1)) goto crank_window; @@ -185,7 +186,8 @@ static struct rxgk_context *rxgk_get_key(struct rxrpc_connection *conn, */ if (*specific_key_number == (u16)current_key) key_number = current_key; - else if (*specific_key_number == (u16)(current_key - 1)) + else if (current_key > 0 && + *specific_key_number == (u16)(current_key - 1)) key_number = current_key - 1; else if (*specific_key_number == (u16)(current_key + 1)) goto rekey; -- 2.56.1