From: Jakub Kicinski <kuba@kernel.org>
To: Chuck Lever <cel@kernel.org>
Cc: kernel-tls-handshake@lists.linux.dev, netdev@vger.kernel.org,
dan.carpenter@linaro.org
Subject: Re: [PATCH 2/5] net/handshake: Fix handshake_dup() ref counting
Date: Fri, 5 May 2023 13:58:08 -0700 [thread overview]
Message-ID: <20230505135808.6992113b@kernel.org> (raw)
In-Reply-To: <168321389545.16695.14828237648251844351.stgit@oracle-102.nfsv4bat.org>
On Thu, 04 May 2023 11:25:05 -0400 Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> If get_unused_fd_flags() fails, we ended up calling fput(sock->file)
> twice.
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: 3b3009ea8abb ("net/handshake: Create a NETLINK service for handling handshake requests")
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> diff --git a/net/handshake/netlink.c b/net/handshake/netlink.c
> index 7ec8a76c3c8a..3508bc3e661d 100644
> --- a/net/handshake/netlink.c
> +++ b/net/handshake/netlink.c
> @@ -96,17 +96,13 @@ EXPORT_SYMBOL(handshake_genl_put);
> */
> static int handshake_dup(struct socket *sock)
> {
> - struct file *file;
> int newfd;
>
> - file = get_file(sock->file);
> newfd = get_unused_fd_flags(O_CLOEXEC);
> - if (newfd < 0) {
> - fput(file);
> + if (newfd < 0)
> return newfd;
> - }
>
> - fd_install(newfd, file);
> + fd_install(newfd, sock->file);
I'm not vfs expert but doesn't this mean that we will now have the file
installed in the fd table, under newfd, before we incremented the
refcount? Can't another thread close(newfd) and make sock->file
get freed?
> return newfd;
> }
>
> @@ -143,11 +139,11 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct genl_info *info)
> goto out_complete;
>
> trace_handshake_cmd_accept(net, req, req->hr_sk, fd);
> + get_file(sock->file); /* released by DONE */
What if DONE does not get called?
> return 0;
>
> out_complete:
> handshake_complete(req, -EIO, NULL);
We don't want to release the fd here?
> - fput(sock->file);
> out_status:
> trace_handshake_cmd_accept_err(net, req, NULL, err);
> return err;
--
pw-bot: cr
next prev parent reply other threads:[~2023-05-05 20:58 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-04 15:24 [PATCH 0/5] Bug fixes for net/handshake Chuck Lever
2023-05-04 15:24 ` [PATCH 1/5] net/handshake: Remove unneeded check from handshake_dup() Chuck Lever
2023-05-05 13:15 ` Simon Horman
2023-05-04 15:25 ` [PATCH 2/5] net/handshake: Fix handshake_dup() ref counting Chuck Lever
2023-05-05 13:15 ` Simon Horman
2023-05-05 20:58 ` Jakub Kicinski [this message]
2023-05-05 23:28 ` Chuck Lever
2023-05-04 15:25 ` [PATCH 3/5] net/handshake: Fix uninitialized local variable Chuck Lever
2023-05-05 13:15 ` Simon Horman
2023-05-04 15:25 ` [PATCH 4/5] net/handshake: handshake_genl_notify() shouldn't ignore @flags Chuck Lever
2023-05-05 13:15 ` Simon Horman
2023-05-04 15:26 ` [PATCH 5/5] net/handshake: Enable the SNI extension to work properly Chuck Lever
2023-05-05 13:16 ` Simon Horman
2023-05-05 20:39 ` [PATCH 0/5] Bug fixes for net/handshake Jakub Kicinski
2023-05-05 23:16 ` Chuck Lever
2023-05-05 23:47 ` Jakub Kicinski
2023-05-05 23:58 ` Chuck Lever
2023-05-08 5:51 ` Paolo Abeni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230505135808.6992113b@kernel.org \
--to=kuba@kernel.org \
--cc=cel@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=kernel-tls-handshake@lists.linux.dev \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox