From: Simon Horman <horms@kernel.org>
To: xiaolinkui <xiaolinkui@126.com>
Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, justinstitt@google.com, kuniyu@amazon.com,
netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Linkui Xiao <xiaolinkui@kylinos.cn>
Subject: Re: [PATCH] netfilter: ipset: add ip_set lock to ip_set_test
Date: Mon, 2 Oct 2023 18:06:51 +0200 [thread overview]
Message-ID: <20231002160651.GX92317@kernel.org> (raw)
In-Reply-To: <20230927130309.30891-1-xiaolinkui@126.com>
On Wed, Sep 27, 2023 at 09:03:09PM +0800, xiaolinkui wrote:
> From: Linkui Xiao <xiaolinkui@kylinos.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
Hi,
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 ?
> 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@kylinos.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
>
>
next prev parent reply other threads:[~2023-10-02 16:07 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 13:03 [PATCH] netfilter: ipset: add ip_set lock to ip_set_test xiaolinkui
2023-10-02 16:06 ` Simon Horman [this message]
2023-10-02 19:06 ` Jozsef Kadlecsik
2023-10-03 3:02 ` xiaolinkui
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=20231002160651.GX92317@kernel.org \
--to=horms@kernel.org \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=justinstitt@google.com \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=kuniyu@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=xiaolinkui@126.com \
--cc=xiaolinkui@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.