mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-16 17:57:38 -04:00
tun: Assign missing bpf_net_context.
During the introduction of struct bpf_net_context handling for
XDP-redirect, the tun driver has been missed.
Jakub also pointed out that there is another call chain to
do_xdp_generic() originating from netif_receive_skb() and drivers may
use it outside from the NAPI context.
Set the bpf_net_context before invoking BPF XDP program within the TUN
driver. Set the bpf_net_context also in do_xdp_generic() if a xdp
program is available.
Reported-by: syzbot+0b5c75599f1d872bea6f@syzkaller.appspotmail.com
Reported-by: syzbot+5ae46b237278e2369cac@syzkaller.appspotmail.com
Reported-by: syzbot+c1e04a422bbc0f0f2921@syzkaller.appspotmail.com
Fixes: 401cb7dae8 ("net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://patch.msgid.link/20240704144815.j8xQda5r@linutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
3b2aef9922
commit
fecef4cd42
@@ -5126,11 +5126,14 @@ static DEFINE_STATIC_KEY_FALSE(generic_xdp_needed_key);
|
||||
|
||||
int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff **pskb)
|
||||
{
|
||||
struct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;
|
||||
|
||||
if (xdp_prog) {
|
||||
struct xdp_buff xdp;
|
||||
u32 act;
|
||||
int err;
|
||||
|
||||
bpf_net_ctx = bpf_net_ctx_set(&__bpf_net_ctx);
|
||||
act = netif_receive_generic_xdp(pskb, &xdp, xdp_prog);
|
||||
if (act != XDP_PASS) {
|
||||
switch (act) {
|
||||
@@ -5144,11 +5147,13 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff **pskb)
|
||||
generic_xdp_tx(*pskb, xdp_prog);
|
||||
break;
|
||||
}
|
||||
bpf_net_ctx_clear(bpf_net_ctx);
|
||||
return XDP_DROP;
|
||||
}
|
||||
}
|
||||
return XDP_PASS;
|
||||
out_redir:
|
||||
bpf_net_ctx_clear(bpf_net_ctx);
|
||||
kfree_skb_reason(*pskb, SKB_DROP_REASON_XDP);
|
||||
return XDP_DROP;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user