From: Simon Horman <horms@kernel.org>
To: Wang Liang <wangliang74@huawei.com>
Cc: Chuck Lever <cel@kernel.org>,
chuck.lever@oracle.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, brauner@kernel.org,
kernel-tls-handshake@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, yuehaibing@huawei.com,
zhangchangzhong@huawei.com
Subject: Re: [PATCH net] net/handshake: Fix null-ptr-deref in handshake_complete()
Date: Wed, 10 Dec 2025 10:08:48 +0000 [thread overview]
Message-ID: <aTlGsMozNBaLDpNW@horms.kernel.org> (raw)
In-Reply-To: <5d5a0cf3-e085-4921-b340-b84446526985@huawei.com>
On Wed, Dec 10, 2025 at 10:51:11AM +0800, Wang Liang wrote:
...
> > Hi,
> >
> > Clang 21.1.7 W=1 builds are rather unhappy about this:
> >
> > net/handshake/netlink.c:110:3: error: cannot jump from this goto statement to its label
> > 110 | goto out_status;
> > | ^
> > net/handshake/netlink.c:114:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
> > 114 | FD_PREPARE(fdf, O_CLOEXEC, sock->file);
> > | ^
> > net/handshake/netlink.c:104:3: error: cannot jump from this goto statement to its label
> > 104 | goto out_status;
> > | ^
> > net/handshake/netlink.c:114:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
> > 114 | FD_PREPARE(fdf, O_CLOEXEC, sock->file);
> > | ^
> > net/handshake/netlink.c:100:3: error: cannot jump from this goto statement to its label
> > 100 | goto out_status;
> > | ^
> > net/handshake/netlink.c:114:13: note: jump bypasses initialization of variable with __attribute__((cleanup))
> > 114 | FD_PREPARE(fdf, O_CLOEXEC, sock->file);
> > | ^
> >
> > My undersatnding of the problem is as follows:
> >
> > FD_PREPARE uses __cleanup to call class_fd_prepare_destructor when
> > resources when fdf goes out of scope.
> >
> > Prior to this patch this was when the if (req) block was existed.
> > Either via return or a goto due to an error.
> >
> > Now it is when handshake_nl_accept_doit() itself is exited.
> > Again via a return or a goto due to error.
> >
> > But, importantly, such a goto can now occur before fdf is initialised.
> > Boom!
>
>
> Thanks for your analysis, you are right!
>
> How about adding a null check before calling handshake_complete()?
I assumed the problem lies around the initialisation of fdf
and class_fd_prepare_destructor being called regardless of that
having occurred. But maybe I miss your point.
In any case, I would advocate an approach that left FD_PREPARE in a scope
where it is always called before the scope is exited.
>
> Like:
>
> diff --git a/net/handshake/netlink.c b/net/handshake/netlink.c
> index 1d33a4675a48..b989456fc4c5 100644
> --- a/net/handshake/netlink.c
> +++ b/net/handshake/netlink.c
> @@ -126,7 +126,8 @@ int handshake_nl_accept_doit(struct sk_buff *skb, struct
> genl_info *info)
> }
>
> out_complete:
> - handshake_complete(req, -EIO, NULL);
> + if (req)
> + handshake_complete(req, -EIO, NULL);
> out_status:
> trace_handshake_cmd_accept_err(net, req, NULL, err);
> return err;
>
> ------
> Best regards
> Wang Liang
>
next prev parent reply other threads:[~2025-12-10 10:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 11:58 [PATCH net] net/handshake: Fix null-ptr-deref in handshake_complete() Wang Liang
2025-12-09 14:39 ` Chuck Lever
2025-12-10 2:50 ` Wang Liang
2025-12-09 18:06 ` Simon Horman
2025-12-10 2:51 ` Wang Liang
2025-12-10 10:08 ` Simon Horman [this message]
2025-12-10 1:36 ` kernel test robot
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=aTlGsMozNBaLDpNW@horms.kernel.org \
--to=horms@kernel.org \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kernel-tls-handshake@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wangliang74@huawei.com \
--cc=yuehaibing@huawei.com \
--cc=zhangchangzhong@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).