lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Tue, 1 Nov 2022 19:03:06 +0800
From:   Chen Zhongjin <chenzhongjin@...wei.com>
To:     <linux-kernel@...r.kernel.org>, <netfilter-devel@...r.kernel.org>,
        <coreteam@...filter.org>, <netdev@...r.kernel.org>,
        <bpf@...r.kernel.org>
CC:     <pablo@...filter.org>, <kadlec@...filter.org>, <fw@...len.de>,
        <davem@...emloft.net>, <edumazet@...gle.com>, <kuba@...nel.org>,
        <pabeni@...hat.com>, <john.fastabend@...il.com>,
        <lorenzo@...nel.org>, <ast@...nel.org>
Subject: Re: [PATCH] netfilter: nf_nat: Fix possible memory leak in
 nf_nat_init()

On 2022/11/1 17:34, Chen Zhongjin wrote:
> In nf_nat_init(), register_nf_nat_bpf() can fail and return directly
> without any error handling.
> Then nf_nat_bysource will leak and registering of &nat_net_ops won't
> be reverted. This leaves wild ops in subsystem linkedlist and when
> another module tries to call register_pernet_operations() it triggers
> page fault:
>
>   BUG: unable to handle page fault for address: fffffbfff81b964c
>   RIP: 0010:register_pernet_operations+0x1b9/0x5f0
>   Call Trace:
>   <TASK>
>    register_pernet_subsys+0x29/0x40
>    ebtables_init+0x58/0x1000 [ebtables]
>    ...
>
> Fixes: 820dc0523e05 ("net: netfilter: move bpf_ct_set_nat_info kfunc in nf_nat_bpf.c")
> Signed-off-by: Chen Zhongjin <chenzhongjin@...wei.com>
> ---
>   net/netfilter/nf_nat_core.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
> index 18319a6e6806..b24b4dfc1ca4 100644
> --- a/net/netfilter/nf_nat_core.c
> +++ b/net/netfilter/nf_nat_core.c
> @@ -1152,7 +1152,12 @@ static int __init nf_nat_init(void)
>   	WARN_ON(nf_nat_hook != NULL);
>   	RCU_INIT_POINTER(nf_nat_hook, &nat_hook);
>   
> -	return register_nf_nat_bpf();
> +	ret = register_nf_nat_bpf();
> +	if (ret < 0) {
> +		kvfree(nf_nat_bysource);
> +		unregister_pernet_subsys(&nat_net_ops);
> +	}
> +	return ret;
>   }

I noticed that follow_master_nat should also be unregistered.

Going to send v2, discard this one.


Best,

Chen

>   
>   static void __exit nf_nat_cleanup(void)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ