net/handshake: Unpin sock->file if a handshake is cancelled
authorChuck Lever <chuck.lever@oracle.com>
Thu, 11 May 2023 15:49:17 +0000 (11:49 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 12 May 2023 08:24:08 +0000 (09:24 +0100)
If user space never calls DONE, sock->file's reference count remains
elevated. Enable sock->file to be freed eventually in this case.

Reported-by: Jakub Kacinski <kuba@kernel.org>
Fixes: 3b3009ea8abb ("net/handshake: Create a NETLINK service for handling handshake requests")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/handshake/handshake.h
net/handshake/request.c

index 4dac965c99df0b65c92bf83a830d55c78e85ba9b..8aeaadca844fdc0de6fd1683d493907f5e6506b7 100644 (file)
@@ -31,6 +31,7 @@ struct handshake_req {
        struct list_head                hr_list;
        struct rhash_head               hr_rhash;
        unsigned long                   hr_flags;
+       struct file                     *hr_file;
        const struct handshake_proto    *hr_proto;
        struct sock                     *hr_sk;
        void                            (*hr_odestruct)(struct sock *sk);
index 94d5cef3e048b7fec001c6bd32c917e778834e96..d78d41abb3d993b31f9a7e64e6efa17263ea132b 100644 (file)
@@ -239,6 +239,7 @@ int handshake_req_submit(struct socket *sock, struct handshake_req *req,
        }
        req->hr_odestruct = req->hr_sk->sk_destruct;
        req->hr_sk->sk_destruct = handshake_sk_destruct;
+       req->hr_file = sock->file;
 
        ret = -EOPNOTSUPP;
        net = sock_net(req->hr_sk);
@@ -334,6 +335,9 @@ bool handshake_req_cancel(struct sock *sk)
                return false;
        }
 
+       /* Request accepted and waiting for DONE */
+       fput(req->hr_file);
+
 out_true:
        trace_handshake_cancel(net, req, sk);