net: pull gso packet headers in core stack
Subsystems (2)
cover net: pull gso packet headers in core stack
Most ndo_start_xmit() methods expects headers of gso packets to be already in skb->head.
net/core/tso.c users are particularly at risk, because tso_build_hdr() does a memcpy(hdr, skb->data, hdr_len);
qdisc_pkt_len_segs_init() already does a dissection of gso packets.
Use pskb_may_pull() instead of skb_header_pointer() to make sure drivers do not have to reimplement this.
First patch is a small cleanup to ease second patch review.
Eric Dumazet (2):
net: qdisc_pkt_len_segs_init() cleanup
net: pull headers in qdisc_pkt_len_segs_init()
include/net/dropreason-core.h | 3 ++ net/core/dev.c | 81 ++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 35 deletions(-)
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
PATCH 1/2 net: qdisc_pkt_len_segs_init() cleanup
Reduce indentation level by returning early if the transport header was not set.
Add an unlikely() clause as this is not the common case.
No functional change.
--- net/core/dev.c | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
net/core/dev.c +31 -31
@@ -4104,6 +4104,7 @@ EXPORT_SYMBOL_GPL(validate_xmit_skb_list);static void qdisc_pkt_len_segs_init (struct sk_buff *skb) {struct skb_shared_info *shinfo =skb_shinfo (skb); +unsigned int hdr_len;u16 gso_segs;qdisc_skb_cb (skb)->pkt_len = skb->len;
@@ -4117,44 +4118,43 @@ static void qdisc_pkt_len_segs_init(struct sk_buff *skb)/* To get more precise estimation of bytes sent on wire, * we add to pkt_len the headers size of all segments */ -if (skb_transport_header_was_set (skb)) { -unsigned int hdr_len; +if (unlikely (!skb_transport_header_was_set (skb))) +return ; -/* mac layer + network layer */ -if (!skb->encapsulation) - hdr_len =skb_transport_offset (skb); -else - hdr_len =skb_inner_transport_offset (skb); +/* mac layer + network layer */ +if (!skb->encapsulation) + hdr_len =skb_transport_offset (skb); +else + hdr_len =skb_inner_transport_offset (skb); -/* + transport layer */ -if (likely (shinfo->gso_type & (SKB_GSO_TCPV4 |SKB_GSO_TCPV6 ))) { -const struct tcphdr *th; -struct tcphdr _tcphdr; +/* + transport layer */ +if (likely (shinfo->gso_type & (SKB_GSO_TCPV4 |SKB_GSO_TCPV6 ))) { +const struct tcphdr *th; +struct tcphdr _tcphdr; - th =skb_header_pointer (skb, hdr_len, -sizeof (_tcphdr), &_tcphdr); -if (likely (th)) - hdr_len +=__tcp_hdrlen (th); - }else if (shinfo->gso_type &SKB_GSO_UDP_L4 ) { -struct udphdr _udphdr; + th =skb_header_pointer (skb, hdr_len, +sizeof (_tcphdr), &_tcphdr); +if (likely (th)) + hdr_len +=__tcp_hdrlen (th); + }else if (shinfo->gso_type &SKB_GSO_UDP_L4 ) { +struct udphdr _udphdr; -if (skb_header_pointer (skb, hdr_len, -sizeof (_udphdr), &_udphdr)) - hdr_len +=sizeof (struct udphdr ); - } +if (skb_header_pointer (skb, hdr_len, +sizeof (_udphdr), &_udphdr)) + hdr_len +=sizeof (struct udphdr ); + } -if (unlikely (shinfo->gso_type &SKB_GSO_DODGY )) { -int payload = skb->len - hdr_len; +if (unlikely (shinfo->gso_type &SKB_GSO_DODGY )) { +int payload = skb->len - hdr_len; -/* Malicious packet. */ -if (payload <=0 ) -return ; - gso_segs =DIV_ROUND_UP (payload, shinfo->gso_size); - shinfo->gso_segs = gso_segs; -qdisc_skb_cb (skb)->pkt_segs = gso_segs; - } -qdisc_skb_cb (skb)->pkt_len += (gso_segs -1 ) * hdr_len; +/* Malicious packet. */ +if (payload <=0 ) +return ; + gso_segs =DIV_ROUND_UP (payload, shinfo->gso_size); + shinfo->gso_segs = gso_segs; +qdisc_skb_cb (skb)->pkt_segs = gso_segs; } +qdisc_skb_cb (skb)->pkt_len += (gso_segs -1 ) * hdr_len; } static int dev_qdisc_enqueue(struct sk_buff *skb, struct Qdisc *q,
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Re: [PATCH net-next 1/2] net: qdisc_pkt_len_segs_init() cleanup
Quoted 11 lines · Eric Dumazet
Reduce indentation level by returning early if the transport header was not set.
Add an
unlikely()clause as this is not the common case.No functional change.
Signed-off-by Eric Dumazet <[email protected]>--- net/core/dev.c | 62 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
PATCH 2/2 net: pull headers in qdisc_pkt_len_segs_init()
In reply to Eric DumazetMost ndo_start_xmit() methods expects headers of gso packets to be already in skb->head.
net/core/tso.c users are particularly at risk, because tso_build_hdr() does a memcpy(hdr, skb->data, hdr_len);
qdisc_pkt_len_segs_init() already does a dissection of gso packets.
Use pskb_may_pull() instead of skb_header_pointer() to make sure drivers do not have to reimplement this.
Some malicious packets could be fed, detect them so that we can drop them sooner with a new SKB_DROP_REASON_SKB_BAD_GSO drop_reason.
--- include/net/dropreason-core.h | 3 +++ net/core/dev.c | 51 +++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 20 deletions(-)
include/net/dropreason-core.h +3 -0
@@ -74,6 +74,7 @@ FN(UNHANDLED_PROTO) \ FN(SKB_CSUM) \ FN(SKB_GSO_SEG) \ + FN(SKB_BAD_GSO) \ FN(SKB_UCOPY_FAULT) \ FN(DEV_HDR) \ FN(DEV_READY) \
@@ -392,6 +393,8 @@ enum skb_drop_reason {SKB_DROP_REASON_SKB_CSUM ,/** @SKB_DROP_REASON_SKB_GSO_SEG: gso segmentation error */ SKB_DROP_REASON_SKB_GSO_SEG , +/** @SKB_DROP_REASON_SKB_BAD_GSO: malicious gso packet. */ + SKB_DROP_REASON_SKB_BAD_GSO,/** * @SKB_DROP_REASON_SKB_UCOPY_FAULT: failed to copy data from user space, * e.g., via zerocopy_sg_from_iter() or skb_orphan_frags_rx()
net/core/dev.c +31 -20
103 lines not on this page · raw message
Signature · 1 line
2.53.0.1213.gd9a14994de-goog
Re: [PATCH net-next 2/2] net: pull headers in qdisc_pkt_len_segs_init()
Quoted 14 lines · Eric Dumazet
Most
ndo_start_xmit()methods expects headers of gso packets to be already inskb->head.
net/core/tso.cusers are particularly at risk, becausetso_build_hdr()does amemcpy(hdr, skb->data, hdr_len);
qdisc_pkt_len_segs_init()already does a dissection of gso packets.Use
pskb_may_pull()instead ofskb_header_pointer()to make sure drivers do not have to reimplement this.Some malicious packets could be fed, detect them so that we can drop them sooner with a new
SKB_DROP_REASON_SKB_BAD_GSOdrop_reason.
Quoted 7 lines
Fixes e876f208af18 ("net: Add a software TSO helper API")Signed-off-by Eric Dumazet <[email protected]>--- include/net/dropreason-core.h | 3 +++ net/core/dev.c | 51 +++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 20 deletions(-)
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Fri, 3 Apr 2026 22:15:38 +0000 you wrote:
Most
ndo_start_xmit()methods expects headers of gso packets to be already inskb->head.
net/core/tso.cusers are particularly at risk, becausetso_build_hdr()does amemcpy(hdr, skb->data, hdr_len);
qdisc_pkt_len_segs_init()already does a dissection of gso packets.[...]
Here is the summary with links:
- [net-next,1/2] net: qdisc_pkt_len_segs_init() cleanup
https://git.kernel.org/netdev/net-next/c/30e02ec3b4b6 - [net-next,2/2] net: pull headers in qdisc_pkt_len_segs_init() https://git.kernel.org/netdev/net-next/c/7fb4c1967011
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html