netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] Drop packets with invalid headers to prevent KMSAN infoleak
@ 2024-10-19  7:11 Daniel Yang
  2024-10-21 22:25 ` Martin KaFai Lau
  2024-10-29 16:40 ` Alexander Lobakin
  0 siblings, 2 replies; 12+ messages in thread
From: Daniel Yang @ 2024-10-19  7:11 UTC (permalink / raw)
  To: Martin KaFai Lau, Daniel Borkmann, John Fastabend,
	Alexei Starovoitov, Andrii Nakryiko, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	open list:BPF [NETWORKING] (tcx & tc BPF, sock_addr),
	open list:BPF [NETWORKING] (tcx & tc BPF, sock_addr),
	open list
  Cc: Daniel Yang, syzbot+346474e3bf0b26bd3090

KMSAN detects uninitialized memory stored to memory by
bpf_clone_redirect(). Adding a check to the transmission path to find
malformed headers prevents this issue. Specifically, we check if the length
of the data stored in skb is less than the minimum device header length.
If so, drop the packet since the skb cannot contain a valid device header.
Also check if mac_header_len(skb) is outside the range provided of valid
device header lengths.

Testing this patch with syzbot removes the bug.

Fixes: 88264981f208 ("Merge tag 'sched_ext-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext")
Reported-by: syzbot+346474e3bf0b26bd3090@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=346474e3bf0b26bd3090
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
 net/core/filter.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index cd3524cb3..92d8f2098 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2191,6 +2191,13 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
 		return -ERANGE;
 	}
 
+	if (unlikely(skb->len < dev->min_header_len ||
+		     skb_mac_header_len(skb) < dev->min_header_len ||
+		     skb_mac_header_len(skb) > dev->hard_header_len)) {
+		kfree_skb(skb);
+		return -ERANGE;
+	}
+
 	bpf_push_mac_rcsum(skb);
 	return flags & BPF_F_INGRESS ?
 	       __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH net] Drop packets with invalid headers to prevent KMSAN infoleak
@ 2024-11-04  4:02 Daniel Yang
  2024-11-04 10:03 ` Eric Dumazet
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Yang @ 2024-11-04  4:02 UTC (permalink / raw)
  To: Martin KaFai Lau, Daniel Borkmann, John Fastabend,
	Alexei Starovoitov, Andrii Nakryiko, Eduard Zingerman, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman,
	open list:BPF [NETWORKING] (tcx & tc BPF, sock_addr),
	open list:BPF [NETWORKING] (tcx & tc BPF, sock_addr),
	open list
  Cc: Daniel Yang, syzbot+346474e3bf0b26bd3090

KMSAN detects uninitialized memory stored to memory by
bpf_clone_redirect(). Adding a check to the transmission path to find
malformed headers prevents this issue. Specifically, we check if the length
of the data stored in skb is less than the minimum device header length. If
so, drop the packet since the skb cannot contain a valid device header.
Also check if mac_header_len(skb) is outside the range provided of valid
device header lengths.

Testing this patch with syzbot removes the bug.

Macro added to not affect normal builds.

Fixes: 88264981f208 ("Merge tag 'sched_ext-for-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/sched_ext")
Reported-by: syzbot+346474e3bf0b26bd3090@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=346474e3bf0b26bd3090
Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
v1: Enclosed in macro to not affect normal builds

 net/core/filter.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index cd3524cb3..9c5786f9c 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2191,6 +2191,14 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
 		return -ERANGE;
 	}
 
+#if IS_ENABLED(CONFIG_KMSAN)
+	if (unlikely(skb->len < dev->min_header_len ||
+		     skb_mac_header_len(skb) < dev->min_header_len ||
+		     skb_mac_header_len(skb) > dev->hard_header_len)) {
+		kfree_skb(skb);
+		return -ERANGE;
+	}
+#endif
 	bpf_push_mac_rcsum(skb);
 	return flags & BPF_F_INGRESS ?
 	       __bpf_rx_skb(dev, skb) : __bpf_tx_skb(dev, skb);
-- 
2.39.2


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

end of thread, other threads:[~2024-11-04 10:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-19  7:11 [PATCH net] Drop packets with invalid headers to prevent KMSAN infoleak Daniel Yang
2024-10-21 22:25 ` Martin KaFai Lau
2024-10-22  1:37   ` Daniel Yang
2024-10-22 15:30     ` Paolo Abeni
2024-10-22 18:14     ` Martin KaFai Lau
2024-10-27  8:49       ` Daniel Yang
2024-10-28  5:42         ` Yonghong Song
2024-10-29 21:23           ` Daniel Yang
2024-10-29 16:40 ` Alexander Lobakin
2024-10-29 21:34   ` Daniel Yang
  -- strict thread matches above, loose matches on Subject: below --
2024-11-04  4:02 Daniel Yang
2024-11-04 10:03 ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).