netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: prevent pulling SKB_GSO_FRAGLIST skb
@ 2024-04-28 14:29 shiming.cheng
  2024-04-29 13:28 ` Willem de Bruijn
  2024-04-29 13:42 ` Jakub Kicinski
  0 siblings, 2 replies; 10+ messages in thread
From: shiming.cheng @ 2024-04-28 14:29 UTC (permalink / raw)
  To: willemdebruijn.kernel, edumazet, davem, kuba, pabeni,
	matthias.bgg
  Cc: linux-kernel, netdev, shiming.cheng, Lena Wang

From: Shiming Cheng <shiming.cheng@mediatek.com>

BPF or TC callers may pull in a length longer than skb_headlen()
for a SKB_GSO_FRAGLIST skb. The data in fraglist will be pulled
into the linear space. However it destroys the skb's structure
and may result in an invalid segmentation or kernel exception.

So we should add protection to stop the operation and return
error to remind callers.

Fixes: 3a1296a38d0c ("net: Support GRO/GSO fraglist chaining.")
Signed-off-by: Shiming Cheng <shiming.cheng@mediatek.com>
Signed-off-by: Lena Wang <lena.wang@mediatek.com>
---
 net/core/skbuff.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index f68f2679b086..2d35e009e814 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -6100,6 +6100,12 @@ EXPORT_SYMBOL(skb_vlan_untag);
 
 int skb_ensure_writable(struct sk_buff *skb, unsigned int write_len)
 {
+	if (skb_is_gso(skb) &&
+	    (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST) &&
+	     write_len > skb_headlen(skb)) {
+		return -ENOMEM;
+	}
+
 	if (!pskb_may_pull(skb, write_len))
 		return -ENOMEM;
 
-- 
2.18.0


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

end of thread, other threads:[~2024-05-29 14:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-28 14:29 [PATCH net] net: prevent pulling SKB_GSO_FRAGLIST skb shiming.cheng
2024-04-29 13:28 ` Willem de Bruijn
2024-04-29 13:42 ` Jakub Kicinski
2024-05-15  9:02   ` Lena Wang (王娜)
2024-05-16 15:11     ` Jakub Kicinski
2024-05-23 10:03       ` Lena Wang (王娜)
2024-05-23 12:46         ` Willem de Bruijn
2024-05-23 14:59           ` Willem de Bruijn
2024-05-29 11:35             ` Lena Wang (王娜)
2024-05-29 14:04               ` Willem de Bruijn

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).