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] [thread-next>] [day] [month] [year] [list]
Message-ID: <bf23f26-6cf0-b6e-f720-adcd8658a29b@netfilter.org>
Date: Mon, 2 Oct 2023 21:06:23 +0200 (CEST)
From: Jozsef Kadlecsik <kadlec@...filter.org>
To: Simon Horman <horms@...nel.org>
cc: xiaolinkui <xiaolinkui@....com>, Pablo Neira Ayuso <pablo@...filter.org>, 
    Florian Westphal <fw@...len.de>, David Miller <davem@...emloft.net>, 
    edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com, 
    justinstitt@...gle.com, kuniyu@...zon.com, netfilter-devel@...r.kernel.org, 
    coreteam@...filter.org, netdev@...r.kernel.org, 
    linux-kernel@...r.kernel.org, Linkui Xiao <xiaolinkui@...inos.cn>
Subject: Re: [PATCH] netfilter: ipset: add ip_set lock to ip_set_test

Hi,

On Mon, 2 Oct 2023, Simon Horman wrote:

> On Wed, Sep 27, 2023 at 09:03:09PM +0800, xiaolinkui wrote:
> > From: Linkui Xiao <xiaolinkui@...inos.cn>
> > 
> > If the ip_set is not locked during ip_set_test, the following situations
> > may occur:
> > 
> > 	CPU0				CPU1
> > 	ip_rcv->
> > 	ip_rcv_finish->
> > 	ip_local_deliver->
> > 	nf_hook_slow->
> > 	iptable_filter_hook->
> > 	ipt_do_table->
> > 	set_match_v4->
> > 	ip_set_test->			list_set_destroy->
> > 	hash_net4_kadt->		set->data = NULL
> 
> I'm having a bit of trouble analysing this.
> In particular, I'm concerned that in such a scenario set
> itself will be also freed, which seems likely to lead to problems.
> 
> Can you provide a more complete call stack for CPU1 ?

ip_set_test() runs intentionally without holding a spinlock, it uses RCU.

But I don't understand the scenario at all:

	CPU0:				CPU1:
	hash_net4_kadt			list_set_destroy

	so it's a hash:net type		which works on a list
	of set				type of sets only

The list type of set can freely be destroyed (when not referenced), the 
destroy operation has no effect whatsoever on its possible hash:net type 
of member set.

Moreover, kernel side add/del/test can only be performed when the set in 
question is referenced. Referenced sets cannot be deleted.

So what is the scenario really in this case?

Best regards,
Jozsef

> > 	h = set->data
> > 	.cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK)
> > 
> > The set->data is empty, continuing to access set->data will result in a
> > kernel NULL pointer. The call trace is as follows:
> > 
> > [2350616.024418] Call trace:
> > [2350616.024670]  hash_net4_kadt+0x38/0x148 [ip_set_hash_net]
> > [2350616.025147]  ip_set_test+0xbc/0x230 [ip_set]
> > [2350616.025549]  set_match_v4+0xac/0xd0 [xt_set]
> > [2350616.025951]  ipt_do_table+0x32c/0x678 [ip_tables]
> > [2350616.026391]  iptable_filter_hook+0x30/0x40 [iptable_filter]
> > [2350616.026905]  nf_hook_slow+0x50/0x100
> > [2350616.027256]  ip_local_deliver+0xd4/0xe8
> > [2350616.027616]  ip_rcv_finish+0x90/0xb0
> > [2350616.027961]  ip_rcv+0x50/0xb0
> > [2350616.028261]  __netif_receive_skb_one_core+0x58/0x68
> > [2350616.028716]  __netif_receive_skb+0x28/0x80
> > [2350616.029098]  netif_receive_skb_internal+0x3c/0xa8
> > [2350616.029533]  napi_gro_receive+0xf8/0x170
> > [2350616.029898]  receive_buf+0xec/0xa08 [virtio_net]
> > [2350616.030323]  virtnet_poll+0x144/0x310 [virtio_net]
> > [2350616.030761]  net_rx_action+0x158/0x3a0
> > [2350616.031124]  __do_softirq+0x11c/0x33c
> > [2350616.031470]  irq_exit+0x11c/0x128
> > [2350616.031793]  __handle_domain_irq+0x6c/0xc0
> > [2350616.032172]  gic_handle_irq+0x6c/0x170
> > [2350616.032528]  el1_irq+0xb8/0x140
> > [2350616.032835]  arch_cpu_idle+0x38/0x1c0
> > [2350616.033183]  default_idle_call+0x24/0x58
> > [2350616.033549]  do_idle+0x1a4/0x268
> > [2350616.033859]  cpu_startup_entry+0x28/0x78
> > [2350616.034234]  secondary_start_kernel+0x17c/0x1c8
> > 
> > Signed-off-by: Linkui Xiao <xiaolinkui@...inos.cn>
> > ---
> >  net/netfilter/ipset/ip_set_core.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
> > index 35d2f9c9ada0..46f4f47e29e4 100644
> > --- a/net/netfilter/ipset/ip_set_core.c
> > +++ b/net/netfilter/ipset/ip_set_core.c
> > @@ -747,7 +747,9 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb,
> >  	    !(opt->family == set->family || set->family == NFPROTO_UNSPEC))
> >  		return 0;
> >  
> > +	ip_set_lock(set);
> >  	ret = set->variant->kadt(set, skb, par, IPSET_TEST, opt);
> > +	ip_set_unlock(set);
> >  
> >  	if (ret == -EAGAIN) {
> >  		/* Type requests element to be completed */
> > -- 
> > 2.17.1
> > 
> > 
> 

-
E-mail  : kadlec@...ckhole.kfki.hu, kadlecsik.jozsef@...ner.hu
PGP key : https://wigner.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics
          H-1525 Budapest 114, POB. 49, Hungary

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ