Skip to contentSkip to conversation

ipv6: exthdrs: refresh nh after handling HAO option

PATCH Applied Ren Wei 4 participants 5 messages May 22 – May 27 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Ren Wei

author
#1 lore raw

PATCH 1/1 ipv6: exthdrs: refresh nh after handling HAO option

In reply to a message not in the archive

From: Zhengchuan Liang <[email protected]>

ip6_parse_tlv() caches skb_network_header(skb) in nh while walking IPv6 TLVs.

ipv6_dest_hao() may call pskb_expand_head() for a cloned skb, which can move the skb head and invalidate the cached network header pointer. Refresh nh after ipv6_dest_hao() returns so any trailing padding or TLVs are parsed from the current skb head.

This matches the existing pattern used in ip6_parse_tlv() after helpers that can modify skb header storage.

Fixes a831f5bbc89a ("[IPV6] MIP6: Add inbound interface of home address option.")
Assisted-by Codex:gpt-5.4
---
 net/ipv6/exthdrs.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv6/exthdrs.c +2 -0
index 47c5502a34a2..751e07392aae 100644
@@ -201,6 +201,8 @@ static bool ip6_parse_tlv(bool hopbyhop,
 				case IPV6_TLV_HAO:
 					if (!ipv6_dest_hao(skb, off))
 						return false;
+
+					nh = skb_network_header(skb);
 					break;
 #endif
 				default:
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#2 lore raw
Quoted 31 lines · Ren Wei

From: Zhengchuan Liang <[email protected]>

ip6_parse_tlv() caches skb_network_header(skb) in nh while walking IPv6 TLVs.

ipv6_dest_hao() may call pskb_expand_head() for a cloned skb, which can move the skb head and invalidate the cached network header pointer. Refresh nh after ipv6_dest_hao() returns so any trailing padding or TLVs are parsed from the current skb head.

This matches the existing pattern used in ip6_parse_tlv() after helpers that can modify skb header storage.

Fixes a831f5bbc89a ("[IPV6] MIP6: Add inbound interface of home address option.")
Assisted-by Codex:gpt-5.4
---
  net/ipv6/exthdrs.c | 2 ++
  1 file changed, 2 insertions(+)
net/ipv6/exthdrs.c +0 -0
index 47c5502a34a2..751e07392aae 100644

net/ipv6/exthdrs.c static bool ip6_parse_tlv(bool hopbyhop, · line 208

Quoted 8 lines
net/ipv6/exthdrs.c +2 -0
@@ -201,6 +201,8 @@ static bool ip6_parse_tlv(bool hopbyhop,
  				case IPV6_TLV_HAO:
  					if (!ipv6_dest_hao(skb, off))
  						return false;
+
+					nh = skb_network_header(skb);
  					break;
  #endif
  				default:

Note that the same issue applies to IPV6_TLV_JUMBO (hopopts), I've sent a patch to fix it as well (see [1]). Which makes me wonder... at some point, we may refresh the nh pointer once by default, regardless of the option. The impact wouldn't be that huge, and it would avoid missing the above for similar (new) cases.

[1]
https://lore.kernel.org/netdev/[email protected]/

maintainer Reviewed-by
#3 lore raw
Quoted 14 lines · Justin Iurman
Quoted 13 lines · Ren Wei

From: Zhengchuan Liang <[email protected]>

ip6_parse_tlv() caches skb_network_header(skb) in nh while walking IPv6 TLVs.

ipv6_dest_hao() may call pskb_expand_head() for a cloned skb, which can move the skb head and invalidate the cached network header pointer. Refresh nh after ipv6_dest_hao() returns so any trailing padding or TLVs are parsed from the current skb head.

This matches the existing pattern used in ip6_parse_tlv() after helpers that can modify skb header storage.

Quoted 9 lines
Quoted 9 lines
Fixes a831f5bbc89a ("[IPV6] MIP6: Add inbound interface of home address option.")
Assisted-by Codex:gpt-5.4
Quoted 20 lines
Quoted 9 lines
---
  net/ipv6/exthdrs.c | 2 ++
  1 file changed, 2 insertions(+)
net/ipv6/exthdrs.c +0 -0
index 47c5502a34a2..751e07392aae 100644

net/ipv6/exthdrs.c static bool ip6_parse_tlv(bool hopbyhop, · line 208

Quoted 8 lines
net/ipv6/exthdrs.c +2 -0
@@ -201,6 +201,8 @@ static bool ip6_parse_tlv(bool hopbyhop,
  				case IPV6_TLV_HAO:
  					if (!ipv6_dest_hao(skb, off))
  						return false;
+
+					nh = skb_network_header(skb);
  					break;
  #endif
  				default:
Quoted 5 lines

Note that the same issue applies to IPV6_TLV_JUMBO (hopopts), I've sent a patch to fix it as well (see [1]). Which makes me wonder... at some point, we may refresh the nh pointer once by default, regardless of the option. The impact wouldn't be that huge, and it would avoid missing the above for similar (new) cases.

+1

Do you want to send such a patch to net-next once both patches are present there?

#5 lore raw
In reply to Ren Wei
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Fri, 22 May 2026 17:42:26 +0800 you wrote:

From: Zhengchuan Liang <[email protected]>

ip6_parse_tlv() caches skb_network_header(skb) in nh while walking IPv6 TLVs.

ipv6_dest_hao() may call pskb_expand_head() for a cloned skb, which can move the skb head and invalidate the cached network header pointer. Refresh nh after ipv6_dest_hao() returns so any trailing padding or TLVs are parsed from the current skb head.

[...]

Here is the summary with links:
- [net,1/1] ipv6: exthdrs: refresh nh after handling HAO option

    https://git.kernel.org/netdev/net/c/f7b52afe3592

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#4 lore raw
In reply to Ido Schimmel
Quoted 53 lines · Ido Schimmel
Quoted 14 lines · Justin Iurman
Quoted 13 lines · Ren Wei

From: Zhengchuan Liang <[email protected]>

ip6_parse_tlv() caches skb_network_header(skb) in nh while walking IPv6 TLVs.

ipv6_dest_hao() may call pskb_expand_head() for a cloned skb, which can move the skb head and invalidate the cached network header pointer. Refresh nh after ipv6_dest_hao() returns so any trailing padding or TLVs are parsed from the current skb head.

This matches the existing pattern used in ip6_parse_tlv() after helpers that can modify skb header storage.

Quoted 9 lines
Quoted 9 lines
Fixes a831f5bbc89a ("[IPV6] MIP6: Add inbound interface of home address option.")
Assisted-by Codex:gpt-5.4
Quoted 20 lines
Quoted 9 lines
---
   net/ipv6/exthdrs.c | 2 ++
   1 file changed, 2 insertions(+)
net/ipv6/exthdrs.c +0 -0
index 47c5502a34a2..751e07392aae 100644

net/ipv6/exthdrs.c static bool ip6_parse_tlv(bool hopbyhop, · line 208

Quoted 8 lines
net/ipv6/exthdrs.c +2 -0
@@ -201,6 +201,8 @@ static bool ip6_parse_tlv(bool hopbyhop,
   				case IPV6_TLV_HAO:
   					if (!ipv6_dest_hao(skb, off))
   						return false;
+
+					nh = skb_network_header(skb);
   					break;
   #endif
   				default:
Quoted 5 lines

Note that the same issue applies to IPV6_TLV_JUMBO (hopopts), I've sent a patch to fix it as well (see [1]). Which makes me wonder... at some point, we may refresh the nh pointer once by default, regardless of the option. The impact wouldn't be that huge, and it would avoid missing the above for similar (new) cases.

Quoted 4 lines

+1

Do you want to send such a patch to net-next once both patches are present there?

Sure, will do. In case I forget, don't hesitate to remind me offline.