From: Leon Romanovsky <leon@kernel.org>
To: Chen Zhongjin <chenzhongjin@huawei.com>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
mkubecek@suse.cz
Subject: Re: [PATCH net] xfrm: Fix ignored return value in xfrm6_init()
Date: Sun, 6 Nov 2022 21:08:18 +0200 [thread overview]
Message-ID: <Y2gGIuwY368X8Won@unreal> (raw)
In-Reply-To: <20221103090713.188740-1-chenzhongjin@huawei.com>
On Thu, Nov 03, 2022 at 05:07:13PM +0800, Chen Zhongjin wrote:
> When IPv6 module initializing in xfrm6_init(), register_pernet_subsys()
> is possible to fail but its return value is ignored.
>
> If IPv6 initialization fails later and xfrm6_fini() is called,
> removing uninitialized list in xfrm6_net_ops will cause null-ptr-deref:
>
> KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f]
> CPU: 1 PID: 330 Comm: insmod
> RIP: 0010:unregister_pernet_operations+0xc9/0x450
> Call Trace:
> <TASK>
> unregister_pernet_subsys+0x31/0x3e
> xfrm6_fini+0x16/0x30 [ipv6]
> ip6_route_init+0xcd/0x128 [ipv6]
> inet6_init+0x29c/0x602 [ipv6]
> ...
>
> Fix it by catching the error return value of register_pernet_subsys().
>
> Fixes: 8d068875caca ("xfrm: make gc_thresh configurable in all namespaces")
> Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
> ---
> net/ipv6/xfrm6_policy.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
I see same error in net/ipv4/xfrm4_policy.c which introduced by same
commit mentioned in Fixes line.
Thanks
>
> diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
> index 4a4b0e49ec92..ea435eba3053 100644
> --- a/net/ipv6/xfrm6_policy.c
> +++ b/net/ipv6/xfrm6_policy.c
> @@ -287,9 +287,13 @@ int __init xfrm6_init(void)
> if (ret)
> goto out_state;
>
> - register_pernet_subsys(&xfrm6_net_ops);
> + ret = register_pernet_subsys(&xfrm6_net_ops);
> + if (ret)
> + goto out_protocol;
> out:
> return ret;
> +out_protocol:
> + xfrm6_protocol_fini();
> out_state:
> xfrm6_state_fini();
> out_policy:
> --
> 2.17.1
>
next prev parent reply other threads:[~2022-11-06 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 9:07 [PATCH net] xfrm: Fix ignored return value in xfrm6_init() Chen Zhongjin
2022-11-06 19:08 ` Leon Romanovsky [this message]
2022-11-07 3:22 ` Chen Zhongjin
2022-11-07 8:06 ` Leon Romanovsky
2022-11-17 6:33 ` Steffen Klassert
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=Y2gGIuwY368X8Won@unreal \
--to=leon@kernel.org \
--cc=chenzhongjin@huawei.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
--cc=yoshfuji@linux-ipv6.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;
as well as URLs for NNTP newsgroup(s).