net/handshake: fix file ref count in handshake_nl_accept_doit()
authorMoritz Wanzenböck <moritz.wanzenboeck@linbit.com>
Thu, 19 Oct 2023 12:58:47 +0000 (14:58 +0200)
committerJakub Kicinski <kuba@kernel.org>
Mon, 23 Oct 2023 17:19:33 +0000 (10:19 -0700)
commit7798b59409c345d4a6034a4326bceb9f7e2e8b58
tree6274e5c929824616d2f6d062cf89b0a5ee385a2b
parent13454e6e0df2ff37853596d546438ac84ca6a413
net/handshake: fix file ref count in handshake_nl_accept_doit()

If req->hr_proto->hp_accept() fail, we call fput() twice:
Once in the error path, but also a second time because sock->file
is at that point already associated with the file descriptor. Once
the task exits, as it would probably do after receiving an error
reading from netlink, the fd is closed, calling fput() a second time.

To fix, we move installing the file after the error path for the
hp_accept() call. In the case of errors we simply put the unused fd.
In case of success we can use fd_install() to link the sock->file
to the reserved fd.

Fixes: 7ea9c1ec66bc ("net/handshake: Fix handshake_dup() ref counting")
Signed-off-by: Moritz Wanzenböck <moritz.wanzenboeck@linbit.com>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Link: https://lore.kernel.org/r/20231019125847.276443-1-moritz.wanzenboeck@linbit.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/handshake/netlink.c