* [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead()
@ 2026-09-21 20:49 Yuya Kusakabe
2026-09-21 21:59 ` Justin Iurman
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Yuya Kusakabe @ 2026-09-21 20:49 UTC (permalink / raw)
To: Andrea Mayer, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Justin Iurman
Cc: netdev, linux-kernel, Yuya Kusakabe
The seg6, ioam6 and rpl lwtunnels size their skb_cow_head() request as
the length they are about to push plus dst_dev_overhead(), then push the
new headers and rebuild the mac header below them with
skb_mac_header_rebuild(). That rebuild needs skb->mac_len of headroom,
but dst_dev_overhead() leaves LL_RESERVED_SPACE() of the egress device,
16 bytes for plain Ethernet.
Where the mac header is longer than that, as it is on ingress through a
VLAN device with reorder_hdr off, the rebuild runs out of room:
skb_set_mac_header(skb, -skb->mac_len) computes a negative offset,
stores it unchecked in the u16 skb->mac_header, and the memmove that
follows writes skb->mac_len bytes about 64 KB past skb->head.
Forwarding plain ping6 traffic through such a device reproduces it on
all five seg6 encapsulation modes and on the rpl and ioam6 inline paths;
skb->mac_header comes back as 65534 on a 704-byte head.
Return the larger of the two. The helper already returns skb->mac_len
when it has no dst, so this only makes the other branch agree, and it
covers every caller rather than each call site in turn.
Fixes: 40475b63761a ("net: ipv6: seg6_iptunnel: mitigate 2-realloc issue")
Fixes: dce525185bc9 ("net: ipv6: ioam6_iptunnel: mitigate 2-realloc issue")
Fixes: 985ec6f5e623 ("net: ipv6: rpl_iptunnel: mitigate 2-realloc issue")
Suggested-by: Andrea Mayer <andrea.mayer@uniroma2.it>
Assisted-by: LLM
Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>
---
Changes in v3:
- Fix dst_dev_overhead() itself rather than each of its callers [Andrea]
- Drop Justin's Reviewed-by from v2, which was given for the per-caller
version; the patch no longer touches the files he reviewed
- Link to v2: https://lore.kernel.org/r/20260918-seg6-maclen-headroom-v2-1-4d370af55b2e@gmail.com
Changes in v2:
- Use max_t(unsigned int, ...) rather than max() [Justin]
- Make the same change in ioam6_iptunnel and rpl_iptunnel [Justin]
- Reproduce and verify the fix on those two as well: unpatched, rpl
underflows in 12 of 16 probed configurations and ioam6 in 3 of 13,
both reaching about 64 KB past a 320-byte head; patched, neither
underflows in 18
- Rewrap the requests so they no longer exceed 80 columns
- Retitle for net: ipv6, now that the change spans three files
- Link to v1: https://lore.kernel.org/r/20260917-seg6-maclen-headroom-v1-1-02ccec50f096@gmail.com
---
include/net/dst.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/net/dst.h b/include/net/dst.h
index 307073eae7f8..dbedfe72e1fd 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -455,7 +455,8 @@ static inline unsigned int dst_dev_overhead(struct dst_entry *dst,
struct sk_buff *skb)
{
if (likely(dst))
- return LL_RESERVED_SPACE(dst->dev);
+ return max_t(unsigned int, skb->mac_len,
+ LL_RESERVED_SPACE(dst->dev));
return skb->mac_len;
}
---
base-commit: 9a1599eeb8d18a2113e4cabcbd3bec5a8377dbed
change-id: 20260917-seg6-maclen-headroom-53a339c17dac
Best regards,
--
Yuya Kusakabe <yuya.kusakabe@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead()
2026-09-21 20:49 [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead() Yuya Kusakabe
@ 2026-09-21 21:59 ` Justin Iurman
2026-09-22 11:24 ` Gabriel Goller
2026-09-22 15:13 ` Andrea Mayer
2 siblings, 0 replies; 5+ messages in thread
From: Justin Iurman @ 2026-09-21 21:59 UTC (permalink / raw)
To: Yuya Kusakabe, Andrea Mayer, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman
Cc: netdev, linux-kernel
On 9/21/26 22:49, Yuya Kusakabe wrote:
> The seg6, ioam6 and rpl lwtunnels size their skb_cow_head() request
> as the length they are about to push plus dst_dev_overhead(), then
> push the new headers and rebuild the mac header below them with
> skb_mac_header_rebuild(). That rebuild needs skb->mac_len of
> headroom, but dst_dev_overhead() leaves LL_RESERVED_SPACE() of the
> egress device, 16 bytes for plain Ethernet.
>
> Where the mac header is longer than that, as it is on ingress
> through a VLAN device with reorder_hdr off, the rebuild runs out of
> room: skb_set_mac_header(skb, -skb->mac_len) computes a negative
> offset, stores it unchecked in the u16 skb->mac_header, and the
> memmove that follows writes skb->mac_len bytes about 64 KB past skb-
> >head. Forwarding plain ping6 traffic through such a device
> reproduces it on all five seg6 encapsulation modes and on the rpl
> and ioam6 inline paths; skb->mac_header comes back as 65534 on a 704-
> byte head.
>
> Return the larger of the two. The helper already returns skb-
> >mac_len when it has no dst, so this only makes the other branch
> agree, and it covers every caller rather than each call site in
> turn.
>
> Fixes: 40475b63761a ("net: ipv6: seg6_iptunnel: mitigate 2-realloc
> issue") Fixes: dce525185bc9 ("net: ipv6: ioam6_iptunnel: mitigate 2-
> realloc issue") Fixes: 985ec6f5e623 ("net: ipv6: rpl_iptunnel:
> mitigate 2-realloc issue") Suggested-by: Andrea Mayer
> <andrea.mayer@uniroma2.it> Assisted-by: LLM Signed-off-by: Yuya
> Kusakabe <yuya.kusakabe@gmail.com> --- Changes in v3: - Fix
> dst_dev_overhead() itself rather than each of its callers [Andrea] -
> Drop Justin's Reviewed-by from v2, which was given for the per-
> caller version; the patch no longer touches the files he reviewed -
> Link to v2: https://lore.kernel.org/r/20260918-seg6-maclen-headroom-
> v2-1-4d370af55b2e@gmail.com
>
> Changes in v2: - Use max_t(unsigned int, ...) rather than max()
> [Justin] - Make the same change in ioam6_iptunnel and rpl_iptunnel
> [Justin] - Reproduce and verify the fix on those two as well:
> unpatched, rpl underflows in 12 of 16 probed configurations and
> ioam6 in 3 of 13, both reaching about 64 KB past a 320-byte head;
> patched, neither underflows in 18 - Rewrap the requests so they no
> longer exceed 80 columns - Retitle for net: ipv6, now that the
> change spans three files - Link to v1: https://lore.kernel.org/
> r/20260917-seg6-maclen-headroom-v1-1-02ccec50f096@gmail.com ---
> include/net/dst.h | 3 ++- 1 file changed, 2 insertions(+), 1
> deletion(-)
>
> diff --git a/include/net/dst.h b/include/net/dst.h index
> 307073eae7f8..dbedfe72e1fd 100644 --- a/include/net/dst.h +++ b/
> include/net/dst.h @@ -455,7 +455,8 @@ static inline unsigned int
> dst_dev_overhead(struct dst_entry *dst, struct sk_buff *skb) { if
> (likely(dst)) - return LL_RESERVED_SPACE(dst->dev); + return
> max_t(unsigned int, skb->mac_len, + LL_RESERVED_SPACE(dst-
> >dev));
>
> return skb->mac_len; }
>
Reviewed-by: Justin Iurman <justin.iurman@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead()
2026-09-21 20:49 [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead() Yuya Kusakabe
2026-09-21 21:59 ` Justin Iurman
@ 2026-09-22 11:24 ` Gabriel Goller
2026-09-22 14:49 ` Eric Dumazet
2026-09-22 15:13 ` Andrea Mayer
2 siblings, 1 reply; 5+ messages in thread
From: Gabriel Goller @ 2026-09-22 11:24 UTC (permalink / raw)
To: Yuya Kusakabe
Cc: Andrea Mayer, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, Justin Iurman, netdev, linux-kernel
On 22.09.2026 05:49, Yuya Kusakabe wrote:
> The seg6, ioam6 and rpl lwtunnels size their skb_cow_head() request as
> the length they are about to push plus dst_dev_overhead(), then push the
> new headers and rebuild the mac header below them with
> skb_mac_header_rebuild(). That rebuild needs skb->mac_len of headroom,
> but dst_dev_overhead() leaves LL_RESERVED_SPACE() of the egress device,
> 16 bytes for plain Ethernet.
>
> Where the mac header is longer than that, as it is on ingress through a
> VLAN device with reorder_hdr off, the rebuild runs out of room:
> skb_set_mac_header(skb, -skb->mac_len) computes a negative offset,
> stores it unchecked in the u16 skb->mac_header, and the memmove that
> follows writes skb->mac_len bytes about 64 KB past skb->head.
> Forwarding plain ping6 traffic through such a device reproduces it on
> all five seg6 encapsulation modes and on the rpl and ioam6 inline paths;
> skb->mac_header comes back as 65534 on a 704-byte head.
>
> Return the larger of the two. The helper already returns skb->mac_len
> when it has no dst, so this only makes the other branch agree, and it
> covers every caller rather than each call site in turn.
>
> Fixes: 40475b63761a ("net: ipv6: seg6_iptunnel: mitigate 2-realloc issue")
> Fixes: dce525185bc9 ("net: ipv6: ioam6_iptunnel: mitigate 2-realloc issue")
> Fixes: 985ec6f5e623 ("net: ipv6: rpl_iptunnel: mitigate 2-realloc issue")
> Suggested-by: Andrea Mayer <andrea.mayer@uniroma2.it>
> Assisted-by: LLM
> Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>
LGTM
Did a quick test and could reproduce the issue:
FAIL seg6 inline nsegs=4
[ 3.557169] BUG: KASAN: slab-use-after-free in __seg6_do_srh_inline+0x34b/0x620
Couldn't reproduce it after applying this patch.
Consider:
Reviewed-by: Gabriel Goller <g.goller@proxmox.com>
Tested-by: Gabriel Goller <g.goller@proxmox.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead()
2026-09-22 11:24 ` Gabriel Goller
@ 2026-09-22 14:49 ` Eric Dumazet
0 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2026-09-22 14:49 UTC (permalink / raw)
To: Gabriel Goller
Cc: Yuya Kusakabe, Andrea Mayer, David S. Miller, Jakub Kicinski,
Paolo Abeni, Simon Horman, Justin Iurman, netdev, linux-kernel
On Tue, Sep 22, 2026 at 1:24 PM Gabriel Goller <g.goller@proxmox.com> wrote:
>
> On 22.09.2026 05:49, Yuya Kusakabe wrote:
> > The seg6, ioam6 and rpl lwtunnels size their skb_cow_head() request as
> > the length they are about to push plus dst_dev_overhead(), then push the
> > new headers and rebuild the mac header below them with
> > skb_mac_header_rebuild(). That rebuild needs skb->mac_len of headroom,
> > but dst_dev_overhead() leaves LL_RESERVED_SPACE() of the egress device,
> > 16 bytes for plain Ethernet.
> >
> > Where the mac header is longer than that, as it is on ingress through a
> > VLAN device with reorder_hdr off, the rebuild runs out of room:
> > skb_set_mac_header(skb, -skb->mac_len) computes a negative offset,
> > stores it unchecked in the u16 skb->mac_header, and the memmove that
> > follows writes skb->mac_len bytes about 64 KB past skb->head.
> > Forwarding plain ping6 traffic through such a device reproduces it on
> > all five seg6 encapsulation modes and on the rpl and ioam6 inline paths;
> > skb->mac_header comes back as 65534 on a 704-byte head.
> >
> > Return the larger of the two. The helper already returns skb->mac_len
> > when it has no dst, so this only makes the other branch agree, and it
> > covers every caller rather than each call site in turn.
> >
> > Fixes: 40475b63761a ("net: ipv6: seg6_iptunnel: mitigate 2-realloc issue")
> > Fixes: dce525185bc9 ("net: ipv6: ioam6_iptunnel: mitigate 2-realloc issue")
> > Fixes: 985ec6f5e623 ("net: ipv6: rpl_iptunnel: mitigate 2-realloc issue")
> > Suggested-by: Andrea Mayer <andrea.mayer@uniroma2.it>
> > Assisted-by: LLM
> > Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead()
2026-09-21 20:49 [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead() Yuya Kusakabe
2026-09-21 21:59 ` Justin Iurman
2026-09-22 11:24 ` Gabriel Goller
@ 2026-09-22 15:13 ` Andrea Mayer
2 siblings, 0 replies; 5+ messages in thread
From: Andrea Mayer @ 2026-09-22 15:13 UTC (permalink / raw)
To: Yuya Kusakabe
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Justin Iurman, netdev, linux-kernel, Andrea Mayer
On Tue, 22 Sep 2026 05:49:56 +0900
Yuya Kusakabe <yuya.kusakabe@gmail.com> wrote:
> The seg6, ioam6 and rpl lwtunnels size their skb_cow_head() request as
> the length they are about to push plus dst_dev_overhead(), then push the
> new headers and rebuild the mac header below them with
> skb_mac_header_rebuild(). That rebuild needs skb->mac_len of headroom,
> but dst_dev_overhead() leaves LL_RESERVED_SPACE() of the egress device,
> 16 bytes for plain Ethernet.
>
> Where the mac header is longer than that, as it is on ingress through a
> VLAN device with reorder_hdr off, the rebuild runs out of room:
> skb_set_mac_header(skb, -skb->mac_len) computes a negative offset,
> stores it unchecked in the u16 skb->mac_header, and the memmove that
> follows writes skb->mac_len bytes about 64 KB past skb->head.
> Forwarding plain ping6 traffic through such a device reproduces it on
> all five seg6 encapsulation modes and on the rpl and ioam6 inline paths;
> skb->mac_header comes back as 65534 on a 704-byte head.
>
> Return the larger of the two. The helper already returns skb->mac_len
> when it has no dst, so this only makes the other branch agree, and it
> covers every caller rather than each call site in turn.
>
> Fixes: 40475b63761a ("net: ipv6: seg6_iptunnel: mitigate 2-realloc issue")
> Fixes: dce525185bc9 ("net: ipv6: ioam6_iptunnel: mitigate 2-realloc issue")
> Fixes: 985ec6f5e623 ("net: ipv6: rpl_iptunnel: mitigate 2-realloc issue")
> Suggested-by: Andrea Mayer <andrea.mayer@uniroma2.it>
> Assisted-by: LLM
> Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>
> ---
> Changes in v3:
> - Fix dst_dev_overhead() itself rather than each of its callers [Andrea]
> - Drop Justin's Reviewed-by from v2, which was given for the per-caller
> version; the patch no longer touches the files he reviewed
> - Link to v2: https://lore.kernel.org/r/20260918-seg6-maclen-headroom-v2-1-4d370af55b2e@gmail.com
>
> Changes in v2:
> - Use max_t(unsigned int, ...) rather than max() [Justin]
> - Make the same change in ioam6_iptunnel and rpl_iptunnel [Justin]
> - Reproduce and verify the fix on those two as well: unpatched, rpl
> underflows in 12 of 16 probed configurations and ioam6 in 3 of 13,
> both reaching about 64 KB past a 320-byte head; patched, neither
> underflows in 18
> - Rewrap the requests so they no longer exceed 80 columns
> - Retitle for net: ipv6, now that the change spans three files
> - Link to v1: https://lore.kernel.org/r/20260917-seg6-maclen-headroom-v1-1-02ccec50f096@gmail.com
> ---
> include/net/dst.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Thanks for the rework,
Andrea
Reviewed-by: Andrea Mayer <andrea.mayer@uniroma2.it>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-22 15:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21 20:49 [PATCH net v3] net: ipv6: keep room for the mac header in dst_dev_overhead() Yuya Kusakabe
2026-09-21 21:59 ` Justin Iurman
2026-09-22 11:24 ` Gabriel Goller
2026-09-22 14:49 ` Eric Dumazet
2026-09-22 15:13 ` Andrea Mayer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®