]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rxrpc: Fix server keyring leak
authorDavid Howells <dhowells@redhat.com>
Fri, 2 Oct 2020 13:04:51 +0000 (14:04 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Oct 2020 07:46:23 +0000 (09:46 +0200)
[ Upstream commit 38b1dc47a35ba14c3f4472138ea56d014c2d609b ]

If someone calls setsockopt() twice to set a server key keyring, the first
keyring is leaked.

Fix it to return an error instead if the server key keyring is already set.

Fixes: 17926a79320a ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/rxrpc/ar-key.c

index 20549c13eb13d8b7b439b3948986640278692fa2..ea615e53eab2841255b6eba53a2927c29fc09f87 100644 (file)
@@ -897,7 +897,7 @@ int rxrpc_request_key(struct rxrpc_sock *rx, char __user *optval, int optlen)
 
        _enter("");
 
-       if (optlen <= 0 || optlen > PAGE_SIZE - 1)
+       if (optlen <= 0 || optlen > PAGE_SIZE - 1 || rx->securities)
                return -EINVAL;
 
        description = kmalloc(optlen + 1, GFP_KERNEL);