From: Sabrina Dubroca <sd@queasysnail.net>
To: Hangbin Liu <liuhangbin@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
David Ahern <dsahern@kernel.org>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Vasiliy Kovalev <kovalev@altlinux.org>,
Guillaume Nault <gnault@redhat.com>
Subject: Re: [PATCHv2 net] ipv6: sr: fix invalid unregister error path
Date: Wed, 8 May 2024 11:33:18 +0200 [thread overview]
Message-ID: <ZjtG3iQywq2xll6H@hog> (raw)
In-Reply-To: <20240508025502.3928296-1-liuhangbin@gmail.com>
2024-05-08, 10:55:02 +0800, Hangbin Liu wrote:
> The error path of seg6_init() is wrong in case CONFIG_IPV6_SEG6_LWTUNNEL
> is not defined. In that case if seg6_hmac_init() fails, the
> genl_unregister_family() isn't called.
>
> At the same time, add seg6_local_exit() and fix the genl unregister order
> in seg6_exit().
>
> Fixes: 5559cea2d5aa ("ipv6: sr: fix possible use-after-free and null-ptr-deref")
> Reported-by: Guillaume Nault <gnault@redhat.com>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> v2: define label out_unregister_genl in CONFIG_IPV6_SEG6_LWTUNNEL(Sabrina Dubroca)
> ---
> net/ipv6/seg6.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv6/seg6.c b/net/ipv6/seg6.c
> index 35508abd76f4..6a80d93399ce 100644
> --- a/net/ipv6/seg6.c
> +++ b/net/ipv6/seg6.c
> @@ -551,8 +551,8 @@ int __init seg6_init(void)
> #endif
> #ifdef CONFIG_IPV6_SEG6_LWTUNNEL
> out_unregister_genl:
> - genl_unregister_family(&seg6_genl_family);
> #endif
> + genl_unregister_family(&seg6_genl_family);
Sorry, I didn't notice when you answered my comment yesterday, but
this will create unreachable code after return when
CONFIG_IPV6_SEG6_LWTUNNEL=n and CONFIG_IPV6_SEG6_HMAC=n:
out:
return err;
genl_unregister_family(&seg6_genl_family);
out_unregister_pernet:
unregister_pernet_subsys(&ip6_segments_ops);
goto out;
(stragely, gcc doesn't complain about it, I thought it would)
The only solution I can think of if we want to avoid it is ugly:
#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
out_unregister_genl:
#endif
+#if IS_ENABLED(CONFIG_IPV6_SEG6_LWTUNNEL) || IS_ENABLED(CONFIG_IPV6_SEG6_HMAC)
genl_unregister_family(&seg6_genl_family);
+#endif
out_unregister_pernet:
unregister_pernet_subsys(&ip6_segments_ops);
goto out;
(on top of v2)
For all other cases your patch looks correct.
--
Sabrina
next prev parent reply other threads:[~2024-05-08 9:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 2:55 [PATCHv2 net] ipv6: sr: fix invalid unregister error path Hangbin Liu
2024-05-08 9:33 ` Sabrina Dubroca [this message]
2024-05-08 14:23 ` Hangbin Liu
2024-05-08 9:40 ` Simon Horman
2024-05-08 12:04 ` kovalev
2024-05-08 14:28 ` Hangbin Liu
2024-05-08 14:26 ` Hangbin Liu
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=ZjtG3iQywq2xll6H@hog \
--to=sd@queasysnail.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=gnault@redhat.com \
--cc=kovalev@altlinux.org \
--cc=kuba@kernel.org \
--cc=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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).