ipv6: ioam: fix type confusion of dst_entry
Subsystems (3)
PATCH 1/1 ipv6: ioam: fix type confusion of dst_entry
IOAM uses a dummy dst_entry(null_dst) to mark that the destination should not be changed after the transformation. This dst is stored in the IOAM lwt state and may be passed to dst_cache_set_ip6().
However, the IPv6 dst cache path eventually calls rt6_get_cookie(), which treats the dst_entry as part of a struct rt6_info. Since the null_dst was embedded directly as a struct dst_entry in struct ioam6_lwt, this resulted in an invalid cast and rt6_get_cookie() reading fields from the wrong object.
In practice, the wrong cookie is not used while dst->obsolete is zero, but rt6_get_cookie() may also access per-cpu value when rt->sernum is zero. In this case, rt->sernum aliases ioam6_lwt::cache::reset_ts, which can become zero, making this a potential invalid pointer access.
Fix this by embedding a full struct rt6_info for the dummy IPv6 route and passing its dst member to the dst APIs.
--- net/ipv6/ioam6_iptunnel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/ipv6/ioam6_iptunnel.c +4 -4
@@ -35,7 +35,7 @@ struct ioam6_lwt_freq { };struct ioam6_lwt { -struct dst_entry null_dst; +struct rt6_info null_rt;struct dst_cache cache;struct ioam6_lwt_freq freq;atomic_t pkt_cnt;
@@ -176,7 +176,7 @@ static int ioam6_build_state(struct net *net, struct nlattr *nla,* it is stored in the cache. Then, +1/-1 each time we read the cache * and release it. Long story short, we're fine. */ -dst_init (&ilwt->null_dst,NULL ,NULL ,DST_OBSOLETE_NONE ,DST_NOCOUNT ); +dst_init (&ilwt->null_rt.dst,NULL ,NULL ,DST_OBSOLETE_NONE ,DST_NOCOUNT );atomic_set (&ilwt->pkt_cnt,0 ); ilwt->freq.k = freq_k;
@@ -360,7 +360,7 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)/* This is how we notify that the destination does not change after * transformation and that we need to use orig_dst instead of the cache */ -if (dst == &ilwt->null_dst) { +if (dst == &ilwt->null_rt.dst) {dst_release (dst); dst = orig_dst;
@@ -429,7 +429,7 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)local_bh_disable ();if (orig_dst->lwtstate == dst->lwtstate)dst_cache_set_ip6 (&ilwt->cache, - &ilwt->null_dst, &fl6.saddr); + &ilwt->null_rt.dst, &fl6.saddr);else dst_cache_set_ip6 (&ilwt->cache, dst, &fl6.saddr);local_bh_enable ();
Signature · 1 line
2.43.0
Quoted 10 lines · Jiayuan Chen
IOAM uses a dummy
dst_entry(null_dst)to mark that the destination should not be changed after the transformation. This dst is stored in the IOAM lwt state and may be passed todst_cache_set_ip6().However, the IPv6 dst cache path eventually calls
rt6_get_cookie(), which treats thedst_entryas part of a structrt6_info. Since thenull_dstwas embedded directly as a structdst_entryin structioam6_lwt, this resulted in an invalid cast andrt6_get_cookie()reading fields from the wrong object.
Quoted 7 lines
In practice, the wrong cookie is not used while
dst->obsoleteis zero, butrt6_get_cookie()may also access per-cpu value whenrt->sernumis zero. In this case,rt->sernumaliasesioam6_lwt::cache::reset_ts, which can become zero, making this a potential invalid pointer access.Fix this by embedding a full struct
rt6_infofor the dummy IPv6 route and passing its dst member to the dst APIs.
Good catch, thanks!
Quoted 2 lines
Fixes 47ce7c854563 ("net: ipv6: ioam6: fix double reallocation")Signed-off-by Jiayuan Chen <[email protected]>
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 Thu, 18 Jun 2026 18:43:35 +0800 you wrote:
IOAM uses a dummy
dst_entry(null_dst)to mark that the destination should not be changed after the transformation. This dst is stored in the IOAM lwt state and may be passed todst_cache_set_ip6().However, the IPv6 dst cache path eventually calls
rt6_get_cookie(), which treats thedst_entryas part of a structrt6_info. Since thenull_dstwas embedded directly as a structdst_entryin structioam6_lwt, this resulted in an invalid cast andrt6_get_cookie()reading fields from the wrong object.[...]
Here is the summary with links:
- [net] ipv6: ioam: fix type confusion of dst_entry
https://git.kernel.org/netdev/net/c/9ed19e11d214
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html