rxgk_init_connection_security() currently stores a generated transport-key context before validating the token security level. A rejected level can therefore leave a context in conn->rxgk.keys[]; a retry overwrites it and leaks the context and its crypto transforms. Validate the level before setting conn->security_ix/conn->security_level or allocating a context. Found by LLM-assisted manual code inspection; not runtime-triggered. Related upstream fixes include commit 7e1876caa836 ("rxrpc: Fix leak of rxgk context in rxgk_verify_response()") and commit b555912b9b210 ("rxrpc: Fix key parsing memleak"). These analogous fixes support the allocation-lifetime analysis, but neither covers this path. Fixes: 9d1d2b59341f ("rxrpc: rxgk: Implement the yfs-rxgk security class (GSSAPI)") Assisted-by: Codex:GPT-6 Reviewed-by: Simon Horman Signed-off-by: Lin Ma --- v2: Move the security-level check before conn->security_ix and conn->security_level are set, so the error path doesn't modify the connection state, as suggested by Simon Horman. Link: https://lore.kernel.org/all/20261119030622.1017012-1-linma@zju.edu.cn/ net/rxrpc/rxgk.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/rxrpc/rxgk.c b/net/rxrpc/rxgk.c index 77a67ace1d24..a1165ac39566 100644 --- a/net/rxrpc/rxgk.c +++ b/net/rxrpc/rxgk.c @@ -239,6 +239,16 @@ static int rxgk_init_connection_security(struct rxrpc_connection *conn, _enter("{%d,%u},{%x}", conn->debug_id, conn->rxgk.key_number, key_serial(conn->key)); + switch (token->rxgk->level) { + case RXRPC_SECURITY_PLAIN: + case RXRPC_SECURITY_AUTH: + case RXRPC_SECURITY_ENCRYPT: + break; + default: + ret = -EKEYREJECTED; + goto error; + } + conn->security_ix = token->security_index; conn->security_level = token->rxgk->level; @@ -254,16 +264,6 @@ static int rxgk_init_connection_security(struct rxrpc_connection *conn, conn->rxgk.enctype = gk->krb5->etype; conn->rxgk.keys[gk->key_number & 3] = gk; - switch (conn->security_level) { - case RXRPC_SECURITY_PLAIN: - case RXRPC_SECURITY_AUTH: - case RXRPC_SECURITY_ENCRYPT: - break; - default: - ret = -EKEYREJECTED; - goto error; - } - ret = 0; error: _leave(" = %d", ret);