Skip to content

Commit 57cf762

Browse files
dhowellsgregkh
authored andcommitted
rxrpc: Fix key/keyring checks in setsockopt(RXRPC_SECURITY_KEY/KEYRING)
commit 2afd86c upstream. An AF_RXRPC socket can be both client and server at the same time. When sending new calls (ie. it's acting as a client), it uses rx->key to set the security, and when accepting incoming calls (ie. it's acting as a server), it uses rx->securities. setsockopt(RXRPC_SECURITY_KEY) sets rx->key to point to an rxrpc-type key and setsockopt(RXRPC_SECURITY_KEYRING) sets rx->securities to point to a keyring of rxrpc_s-type keys. Now, it should be possible to use both rx->key and rx->securities on the same socket - but for userspace AF_RXRPC sockets rxrpc_setsockopt() prevents that. Fix this by: (1) Remove the incorrect check rxrpc_setsockopt(RXRPC_SECURITY_KEYRING) makes on rx->key. (2) Move the check that rxrpc_setsockopt(RXRPC_SECURITY_KEY) makes on rx->key down into rxrpc_request_key(). (3) Remove rxrpc_request_key()'s check on rx->securities. This (in combination with a previous patch) pushes the checks down into the functions that set those pointers and removes the cross-checks that prevent both key and keyring being set. Fixes: 17926a7 ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both") Closes: https://sashiko.dev/#/patchset/20260401105614.1696001-10-dhowells@redhat.com Signed-off-by: David Howells <dhowells@redhat.com> cc: Marc Dionne <marc.dionne@auristor.com> cc: Anderson Nascimento <anderson@allelesecurity.com> cc: Luxiao Xu <rakukuip@gmail.com> cc: Yuan Tan <yuantan098@gmail.com> cc: Simon Horman <horms@kernel.org> cc: linux-afs@lists.infradead.org cc: stable@kernel.org Link: https://patch.msgid.link/20260408121252.2249051-16-dhowells@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 12de9e0 commit 57cf762

2 files changed

Lines changed: 1 addition & 7 deletions

File tree

net/rxrpc/af_rxrpc.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -681,19 +681,13 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
681681
goto success;
682682

683683
case RXRPC_SECURITY_KEY:
684-
ret = -EINVAL;
685-
if (rx->key)
686-
goto error;
687684
ret = -EISCONN;
688685
if (rx->sk.sk_state != RXRPC_UNBOUND)
689686
goto error;
690687
ret = rxrpc_request_key(rx, optval, optlen);
691688
goto error;
692689

693690
case RXRPC_SECURITY_KEYRING:
694-
ret = -EINVAL;
695-
if (rx->key)
696-
goto error;
697691
ret = -EISCONN;
698692
if (rx->sk.sk_state != RXRPC_UNBOUND)
699693
goto error;

net/rxrpc/key.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ int rxrpc_request_key(struct rxrpc_sock *rx, sockptr_t optval, int optlen)
452452

453453
_enter("");
454454

455-
if (optlen <= 0 || optlen > PAGE_SIZE - 1 || rx->securities)
455+
if (optlen <= 0 || optlen > PAGE_SIZE - 1 || rx->key)
456456
return -EINVAL;
457457

458458
description = memdup_sockptr_nul(optval, optlen);

0 commit comments

Comments
 (0)