diff mbox series

netfilter: nf_tables: Use get_cpu_ptr in nft_inner_eval

Message ID 804e05fe4615cfd51f0cc72307f578ea34a701b4.1732281838.git.xiaopei01@kylinos.cn (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series netfilter: nf_tables: Use get_cpu_ptr in nft_inner_eval | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: edumazet@google.com coreteam@netfilter.org
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-11-25--00-00 (tests: 791)

Commit Message

Pei Xiao Nov. 22, 2024, 1:32 p.m. UTC
syzbot complain about using smp_processor_id in preemptible.
use get_cpu_ptr to preempt_disable.

BUG: using smp_processor_id() in preemptible [00000000] code: syz.3.1627/12102
caller is nft_inner_eval+0xda/0x18e0 net/netfilter/nft_inner.c:251
CPU: 1 UID: 0 PID: 12102 Comm: syz.3.1627 Not tainted 6.12.0-syzkaller-03657-g43fb83c17ba2 #0
Hardware name: Google Compute Engine/Google Compute Engine, BIOS Google 10/30/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 check_preemption_disabled+0x10e/0x120 lib/smp_processor_id.c:49
 nft_inner_eval+0xda/0x18e0 net/netfilter/nft_inner.c:251
 expr_call_ops_eval net/netfilter/nf_tables_core.c:240 [inline]
 nft_do_chain+0x4ad/0x1da0 net/netfilter/nf_tables_core.c:288
 nft_do_chain_ipv4+0x202/0x320 net/netfilter/nft_chain_filter.c:23
 nf_hook_entry_hookfn include/linux/netfilter.h:154 [inline]
 nf_hook_slow+0xc3/0x220 net/netfilter/core.c:626
 nf_hook+0x2c4/0x450 include/linux/netfilter.h:269
 NF_HOOK_COND include/linux/netfilter.h:302 [inline]
 ip_output+0x185/0x230 net/ipv4/ip_output.c:434
 ip_local_out net/ipv4/ip_output.c:130 [inline]
 ip_send_skb+0x74/0x100 net/ipv4/ip_output.c:1496
 udp_send_skb+0xab6/0x1630 net/ipv4/udp.c:984
 udp_sendmsg+0x1c21/0x2a60 net/ipv4/udp.c:1272
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x1a6/0x270 net/socket.c:726
 ____sys_sendmsg+0x52a/0x7e0 net/socket.c:2581
 ___sys_sendmsg net/socket.c:2635 [inline]
 __sys_sendmmsg+0x36a/0x720 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xa0/0xb0 net/socket.c:2748
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported-by: syzbot+84d0441b9860f0d63285@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=84d0441b9860f0d63285
Fixes: 0e795b37ba04 ("netfilter: nft_inner: add percpu inner context")
Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
---
 net/netfilter/nft_inner.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Florian Westphal Nov. 22, 2024, 1:45 p.m. UTC | #1
Pei Xiao <xiaopei01@kylinos.cn> wrote:
> syzbot complain about using smp_processor_id in preemptible.
> use get_cpu_ptr to preempt_disable.

> Reported-by: syzbot+84d0441b9860f0d63285@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=84d0441b9860f0d63285
> Fixes: 0e795b37ba04 ("netfilter: nft_inner: add percpu inner context")
> Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> ---
>  net/netfilter/nft_inner.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nft_inner.c b/net/netfilter/nft_inner.c
> index 928312d01eb1..ae85851bab77 100644
> --- a/net/netfilter/nft_inner.c
> +++ b/net/netfilter/nft_inner.c
> @@ -248,7 +248,7 @@ static bool nft_inner_parse_needed(const struct nft_inner *priv,
>  static void nft_inner_eval(const struct nft_expr *expr, struct nft_regs *regs,
>  			   const struct nft_pktinfo *pkt)
>  {
> -	struct nft_inner_tun_ctx *tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx);
> +	struct nft_inner_tun_ctx *tun_ctx = get_cpu_ptr(&nft_pcpu_tun_ctx);
>  	const struct nft_inner *priv = nft_expr_priv(expr);

This can't be right, where is it re-enabled?

Not related to your patch:
Why is this percpu?  How is this softirq safe?
Pablo Neira Ayuso Nov. 22, 2024, 1:51 p.m. UTC | #2
On Fri, Nov 22, 2024 at 02:45:29PM +0100, Florian Westphal wrote:
> Pei Xiao <xiaopei01@kylinos.cn> wrote:
> > syzbot complain about using smp_processor_id in preemptible.
> > use get_cpu_ptr to preempt_disable.
> 
> > Reported-by: syzbot+84d0441b9860f0d63285@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=84d0441b9860f0d63285
> > Fixes: 0e795b37ba04 ("netfilter: nft_inner: add percpu inner context")
> > Signed-off-by: Pei Xiao <xiaopei01@kylinos.cn>
> > ---
> >  net/netfilter/nft_inner.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/net/netfilter/nft_inner.c b/net/netfilter/nft_inner.c
> > index 928312d01eb1..ae85851bab77 100644
> > --- a/net/netfilter/nft_inner.c
> > +++ b/net/netfilter/nft_inner.c
> > @@ -248,7 +248,7 @@ static bool nft_inner_parse_needed(const struct nft_inner *priv,
> >  static void nft_inner_eval(const struct nft_expr *expr, struct nft_regs *regs,
> >  			   const struct nft_pktinfo *pkt)
> >  {
> > -	struct nft_inner_tun_ctx *tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx);
> > +	struct nft_inner_tun_ctx *tun_ctx = get_cpu_ptr(&nft_pcpu_tun_ctx);
> >  	const struct nft_inner *priv = nft_expr_priv(expr);
> 
> This can't be right, where is it re-enabled?
> 
> Not related to your patch:
> Why is this percpu?  How is this softirq safe?

I can add an owner skbuff to nft_inner_tun_ctx area, so this
information can be canceled in case of softirq interference, then
trigger a reparsing of the header.
diff mbox series

Patch

diff --git a/net/netfilter/nft_inner.c b/net/netfilter/nft_inner.c
index 928312d01eb1..ae85851bab77 100644
--- a/net/netfilter/nft_inner.c
+++ b/net/netfilter/nft_inner.c
@@ -248,7 +248,7 @@  static bool nft_inner_parse_needed(const struct nft_inner *priv,
 static void nft_inner_eval(const struct nft_expr *expr, struct nft_regs *regs,
 			   const struct nft_pktinfo *pkt)
 {
-	struct nft_inner_tun_ctx *tun_ctx = this_cpu_ptr(&nft_pcpu_tun_ctx);
+	struct nft_inner_tun_ctx *tun_ctx = get_cpu_ptr(&nft_pcpu_tun_ctx);
 	const struct nft_inner *priv = nft_expr_priv(expr);
 
 	if (nft_payload_inner_offset(pkt) < 0)