public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.6 v3 0/3] Set the bpf_net_context before invoking BPF XDP in the TUN driver
@ 2025-02-26  9:39 Ricardo Cañuelo Navarro
  2025-02-26  9:39 ` [PATCH 6.6 v3 1/3] net: Reference bpf_redirect_info via task_struct on PREEMPT_RT Ricardo Cañuelo Navarro
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Ricardo Cañuelo Navarro @ 2025-02-26  9:39 UTC (permalink / raw)
  To: stable, Sebastian Andrzej Siewior
  Cc: revest, kernel-dev, Andrii Nakryiko, Eduard Zingerman, Hao Luo,
	Jiri Olsa, John Fastabend, KP Singh, Martin KaFai Lau, Song Liu,
	Stanislav Fomichev, Yonghong Song, Alexei Starovoitov,
	Jesper Dangaard Brouer, Toke Høiland-Jørgensen,
	Jakub Kicinski, syzbot+0b5c75599f1d872bea6f,
	syzbot+5ae46b237278e2369cac, syzbot+c1e04a422bbc0f0f2921,
	Jeongjun Park, syzbot+44623300f057a28baf1e, Jason Wang,
	Willem de Bruijn, syzbot+3c2b6d5d4bec3b904933,
	syzbot+707d98c8649695eaf329, syzbot+c226757eb784a9da3e8b,
	syzbot+61a1cfc2b6632363d319, syzbot+709e4c85c904bcd62735,
	David S. Miller

A private syzbot instance reported "KASAN: slab-use-after-free Read in
dev_map_enqueue" under some runtime environments.

Upstream patch fecef4cd42c6 ("tun: Assign missing bpf_net_context")
fixes the issue. In order to bring this patch to stable v6.6 it's also
necessary to bring upstream patch 401cb7dae813 ("net: Reference
bpf_redirect_info via task_struct on PREEMPT_RT.") as a dependency.

The dependency patch (401cb7dae813 ("net: Reference bpf_redirect_info
via task_struct on PREEMPT_RT.")) comes from a patch series [1], the
second patch addresses a missing change in the series. Only these two
patches were picked up because the purpose of this backport is to fix
the particular issue discovered by syzbot. However, maybe Sebastian may
consider it's a better idea to backport the whole series instead of only
these two patches. I'd also appreciate if you can share your opinion on
whether this backport should be applied to other stable branches as
well.

Both patches needed some manual work in order to be applied on stable,
mostly related to changes in the context lines:

In the case of 401cb7dae813 ("net: Reference bpf_redirect_info via
task_struct on PREEMPT_RT."), the backport addresses the differences in
net/core/dev.c:napi_threaded_poll(), busy_poll_stop(), napi_busy_loop()
and net_rx_action() between upstream and stable. This
allows the patch to be applied without bringing additional dependencies,
such as dad6b9770263 ("net: Allow to use SMP threads for backlog
NAPI."). The rest of the changes are made to adapt context lines and are
unrelated to the purpose of the patch.

For fecef4cd42c6 ("tun: Assign missing bpf_net_context"), the backport
addresses the changes in function parameters introduced by
7cd1107f48e2a ("bpf, xdp: constify some bpf_prog * function arguments")
and 4d2bb0bfe874 ("xdp: rely on skb pointer reference in do_xdp_generic
and netif_receive_generic_xdp").

Additionally, upstream commit 9da49aa80d68 ("tun: Add missing
bpf_net_ctx_clear() in do_xdp_generic()"), which fixes
fecef4cd42c6 ("tun: Assign missing bpf_net_context") is also backported
with trivial changes to adapt the differences in the patch context.

[1] https://lore.kernel.org/all/20240612170303.3896084-1-bigeasy@linutronix.de/

Signed-off-by: Ricardo Cañuelo Navarro <rcn@igalia.com>

---
Changes in v3:
- Additional patch backported:
  9da49aa80d68 ("tun: Add missing bpf_net_ctx_clear() in do_xdp_generic()")
  which fixes fecef4cd42c6 ("tun: Assign missing bpf_net_context.").
  Suggested by Sasha's helper bot.
- Link to v2: https://lore.kernel.org/r/20250225-20250204-kasan-slab-use-after-free-read-in-dev_map_enqueue__submit-v2-0-bc31173653b4@igalia.com

Changes in v2:
- Fix backport for patch 401cb7dae813 ("net: Reference bpf_redirect_info
  via task_struct on PREEMPT_RT.") in v1.
- Add context for the patches and SoB tags.
- Extend the recipient list.
- Link to v1: https://lore.kernel.org/r/20250224-20250204-kasan-slab-use-after-free-read-in-dev_map_enqueue__submit-v1-0-de5d47556d96@igalia.com

---
Jeongjun Park (1):
      tun: Add missing bpf_net_ctx_clear() in do_xdp_generic()

Sebastian Andrzej Siewior (2):
      net: Reference bpf_redirect_info via task_struct on PREEMPT_RT.
      tun: Assign missing bpf_net_context.

 drivers/net/tun.c      |  7 +++++++
 include/linux/filter.h | 56 +++++++++++++++++++++++++++++++++++++++++---------
 include/linux/sched.h  |  3 +++
 kernel/bpf/cpumap.c    |  3 +++
 kernel/bpf/devmap.c    |  9 +++++++-
 kernel/fork.c          |  1 +
 net/bpf/test_run.c     | 11 +++++++++-
 net/core/dev.c         | 34 +++++++++++++++++++++++++++++-
 net/core/filter.c      | 44 +++++++++++----------------------------
 net/core/lwt_bpf.c     |  3 +++
 10 files changed, 126 insertions(+), 45 deletions(-)
---
base-commit: c0249d3a0c3cf082d56f4285647ddba19ef604a7
change-id: 20250224-20250204-kasan-slab-use-after-free-read-in-dev_map_enqueue__submit-b907af839805

Cheers,
Ricardo


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-02-28  5:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26  9:39 [PATCH 6.6 v3 0/3] Set the bpf_net_context before invoking BPF XDP in the TUN driver Ricardo Cañuelo Navarro
2025-02-26  9:39 ` [PATCH 6.6 v3 1/3] net: Reference bpf_redirect_info via task_struct on PREEMPT_RT Ricardo Cañuelo Navarro
2025-02-27  5:08   ` Sasha Levin
2025-02-28  4:56   ` Sasha Levin
2025-02-26  9:39 ` [PATCH 6.6 v3 2/3] tun: Assign missing bpf_net_context Ricardo Cañuelo Navarro
2025-02-27  5:08   ` Sasha Levin
2025-02-28  4:56   ` Sasha Levin
2025-02-26  9:39 ` [PATCH 6.6 v3 3/3] tun: Add missing bpf_net_ctx_clear() in do_xdp_generic() Ricardo Cañuelo Navarro
2025-02-27  5:08   ` Sasha Levin
2025-02-28  4:56   ` Sasha Levin
2025-02-26 16:31 ` [PATCH 6.6 v3 0/3] Set the bpf_net_context before invoking BPF XDP in the TUN driver Sebastian Andrzej Siewior
2025-02-26 17:12   ` Ricardo Cañuelo Navarro
2025-02-27 16:31 ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox