[PATCH v7 08/14] rxrpc: Release conn->key when init_connection_security() fails

Jarkko Sakkinen jarkko at kernel.org
Sun Nov 29 17:05:37 UTC 2026


Clear conn->key before calling key_put() when init_connection_security()
fails, publish conn->key with smp_store_release(), and read its serial
under rcu_read_lock() in rxrpc_connection_seq_show().

Fixes: 17926a79320a ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
Signed-off-by: Jarkko Sakkinen <jarkko at kernel.org>
---
 net/rxrpc/conn_event.c | 7 ++++++-
 net/rxrpc/key.c        | 3 ++-
 net/rxrpc/proc.c       | 6 +++++-
 net/rxrpc/rxgk.c       | 3 ++-
 4 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/net/rxrpc/conn_event.c b/net/rxrpc/conn_event.c
index 611c790bc6d0..096807f13354 100644
--- a/net/rxrpc/conn_event.c
+++ b/net/rxrpc/conn_event.c
@@ -298,8 +298,13 @@ static int rxrpc_process_event(struct rxrpc_connection *conn,
 
 		ret = conn->security->init_connection_security(
 			conn, conn->key->payload.data[0]);
-		if (ret < 0)
+		if (ret < 0) {
+			struct key *key = conn->key;
+
+			WRITE_ONCE(conn->key, NULL);
+			key_put(key);
 			return ret;
+		}
 
 		spin_lock_irq(&conn->state_lock);
 		if (conn->state == RXRPC_CONN_SERVICE_CHALLENGING) {
diff --git a/net/rxrpc/key.c b/net/rxrpc/key.c
index cbd26da44951..8fb30848011d 100644
--- a/net/rxrpc/key.c
+++ b/net/rxrpc/key.c
@@ -686,7 +686,8 @@ int rxrpc_get_server_data_key(struct rxrpc_connection *conn,
 	if (ret < 0)
 		goto error;
 
-	conn->key = key;
+	/* Pair with READ_ONCE() in rxrpc_connection_seq_show(). */
+	smp_store_release(&conn->key, key);
 	_leave(" = 0 [%d]", key_serial(key));
 	return 0;
 
diff --git a/net/rxrpc/proc.c b/net/rxrpc/proc.c
index e9a27fa7b25d..8c17514c0c57 100644
--- a/net/rxrpc/proc.c
+++ b/net/rxrpc/proc.c
@@ -146,6 +146,7 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
 	struct rxrpc_connection *conn;
 	struct rxrpc_net *rxnet = rxrpc_net(seq_file_net(seq));
 	const char *state;
+	key_serial_t kserial;
 	char lbuff[RXRPC_PROC_ADDRBUF_SIZE], rbuff[RXRPC_PROC_ADDRBUF_SIZE];
 
 	if (v == &rxnet->conn_proc_list) {
@@ -168,6 +169,9 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
 	scnprintf(lbuff, sizeof(lbuff), "%pISpc", &conn->local->srx.transport);
 	scnprintf(rbuff, sizeof(rbuff), "%pISpc", &conn->peer->srx.transport);
 print:
+	rcu_read_lock();
+	kserial = key_serial(READ_ONCE(conn->key));
+	rcu_read_unlock();
 	state = rxrpc_is_conn_aborted(conn) ?
 		rxrpc_call_completions[conn->completion] :
 		rxrpc_conn_states[conn->state];
@@ -182,7 +186,7 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
 		   refcount_read(&conn->ref),
 		   atomic_read(&conn->active),
 		   state,
-		   key_serial(conn->key),
+		   kserial,
 		   conn->tx_serial,
 		   conn->hi_serial,
 		   conn->channels[0].call_id,
diff --git a/net/rxrpc/rxgk.c b/net/rxrpc/rxgk.c
index 77a67ace1d24..ad0c883ab5d8 100644
--- a/net/rxrpc/rxgk.c
+++ b/net/rxrpc/rxgk.c
@@ -1255,7 +1255,8 @@ static int rxgk_verify_response(struct rxrpc_connection *conn,
 	if (ret < 0)
 		goto out_gk;
 
-	conn->key = key;
+	/* Pair with READ_ONCE() in rxrpc_connection_seq_show(). */
+	smp_store_release(&conn->key, key);
 	key = NULL;
 	ret = 0;
 out_gk:
-- 
2.47.3




More information about the Linux-security-module-archive mailing list