Skip to contentSkip to conversation

net: warn if transport header was not set

PATCH In review Eric Dumazet 3 participants 3 messages May 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: warn if transport header was not set

From: Eric Dumazet <[email protected]>

Make sure skb_transport_header() and skb_transport_offset() uses are not fooled if the transport header has not been set.

This change will likely expose existing bugs in linux networking stacks.

---
 include/linux/skbuff.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/skbuff.h +1 -0
index d58669d6cb91aa30edc70d59a0a7e9d4e2298842..043c59fa0bd6d921f2d2e211348929681bfce186 100644
@@ -2804,6 +2804,7 @@ static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
 
 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
 {
+	WARN_ON_ONCE(!skb_transport_header_was_set(skb));
 	return skb->head + skb->transport_header;
 }
 
Signature · 1 line
2.36.0.512.ge40c2bad7a-goog
maintainer
#1 lore raw
Quoted 17 lines · On Mon, 9 May 2022 09:57:16 -0700 Eric Dumazet wrote:

From: Eric Dumazet <[email protected]>

Make sure skb_transport_header() and skb_transport_offset() uses are not fooled if the transport header has not been set.

This change will likely expose existing bugs in linux networking stacks.

---
 include/linux/skbuff.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/skbuff.h +0 -0
index d58669d6cb91aa30edc70d59a0a7e9d4e2298842..043c59fa0bd6d921f2d2e211348929681bfce186 100644

include/linux/skbuff.h static inline bool skb_transport_header_was_set(const struct sk_buff *skb) · line 2810

Quoted 7 lines
include/linux/skbuff.h +1 -0
@@ -2804,6 +2804,7 @@ static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
 
 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
 {
+	WARN_ON_ONCE(!skb_transport_header_was_set(skb));
 	return skb->head + skb->transport_header;
 }
 

This is for prod or for syzbot?

What are your feelings on putting this under a kconfig?

We already have a #ifdef DEBUG in skb_checksum_none_assert() we could generalize that into some form of kconfig-gated SKB_CHECK(). Kconfig-gated so that people don't feel self-conscious about using it. I wrote such a patch a few times already but never sent it.

#2 lore raw
Quoted 29 lines · Jakub Kicinski
Quoted 17 lines · On Mon, 9 May 2022 09:57:16 -0700 Eric Dumazet wrote:

From: Eric Dumazet <[email protected]>

Make sure skb_transport_header() and skb_transport_offset() uses are not fooled if the transport header has not been set.

This change will likely expose existing bugs in linux networking stacks.

---
 include/linux/skbuff.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/skbuff.h +0 -0
index d58669d6cb91aa30edc70d59a0a7e9d4e2298842..043c59fa0bd6d921f2d2e211348929681bfce186 100644

include/linux/skbuff.h static inline bool skb_transport_header_was_set(const struct sk_buff *skb) · line 2810

Quoted 7 lines
include/linux/skbuff.h +1 -0
@@ -2804,6 +2804,7 @@ static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
 
 static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
 {
+     WARN_ON_ONCE(!skb_transport_header_was_set(skb));
      return skb->head + skb->transport_header;
 }
 

This is for prod or for syzbot?

Quoted 7 lines

What are your feelings on putting this under a kconfig?

We already have a #ifdef DEBUG in skb_checksum_none_assert() we could generalize that into some form of kconfig-gated SKB_CHECK(). Kconfig-gated so that people don't feel self-conscious about using it. I wrote such a patch a few times already but never sent it.

Sure, we can add a CONFIG_DEBUG_NET, I think it has been suggested in the past. Then we can ask syzbot teams to turn on this option.

I will send a series with this.