ipv4: icmp: fix null-ptr-deref in icmp_build_probe()
Subsystems (4)
PATCH 1/1 ipv4: icmp: fix null-ptr-deref in icmp_build_probe()
ipv6_stub->ipv6_dev_find() may return ERR_PTR(-EAFNOSUPPORT) when the IPv6 stack is not active (CONFIG_IPV6=m and not loaded), and passing this error pointer to dev_hold() will cause a kernel crash with null-ptr-deref.
Instead, silently discard the request. RFC 8335 does not appear to define a specific response for the case where an IPv6 interface identifier is syntactically valid but the implementation cannot perform the lookup at runtime, and silently dropping the request may safer than misreporting "No Such Interface".
--- net/ipv4/icmp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/ipv4/icmp.c +9 -1
@@ -1270,7 +1270,8 @@ static enum skb_drop_reason icmp_echo(struct sk_buff *skb)* Searches for net_device that matches PROBE interface identifier * and builds PROBE reply message in icmphdr. * -* Returns false if PROBE responses are disabled via sysctl +* Returns false if PROBE responses are disabled via sysctl or +* the request should be silently discarded. */ bool icmp_build_probe (struct sk_buff *skb,struct icmphdr *icmphdr)
@@ -1346,6 +1347,13 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)if (iio->ident.addr.ctype3_hdr.addrlen !=sizeof (struct in6_addr )) goto send_mal_query; dev = ipv6_stub->ipv6_dev_find (net, &iio->ident.addr.ip_addr.ipv6_addr, dev); +/* +* If IPv6 identifier lookup is unavailable, silently +* discard the request instead of misreporting NO_IF. +*/ +if (IS_ERR (dev)) +return false; +dev_hold (dev);break ;#endif
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerQuoted 5 lines · On Thu, 2 Apr 2026 15:04:19 +0800 Yiqi Sun wrote:
Instead, silently discard the request. RFC 8335 does not appear to define a specific response for the case where an IPv6 interface identifier is syntactically valid but the implementation cannot perform the lookup at runtime, and silently dropping the request may safer than misreporting "No Such Interface".
Well, my intuition would be to fall thru and make the check after the switch handle error pointers. But I guess this version gives us the opportunity to delete the just-added check on net->net-next merge so ok.
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 5 lines · On Thu, 2 Apr 2026 15:04:19 +0800 you wrote:
ipv6_stub->ipv6_dev_find()may returnERR_PTR(-EAFNOSUPPORT)when the IPv6 stack is not active (CONFIG_IPV6=mand not loaded), and passing this error pointer todev_hold()will cause a kernel crash with null-ptr-deref.
Quoted 7 lines
Instead, silently discard the request. RFC 8335 does not appear to define a specific response for the case where an IPv6 interface identifier is syntactically valid but the implementation cannot perform the lookup at runtime, and silently dropping the request may safer than misreporting "No Such Interface".
[...]
Here is the summary with links:
- [net] ipv4: icmp: fix null-ptr-deref in icmp_build_probe()
https://git.kernel.org/netdev/net/c/fde29fd93493
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH net] ipv4: icmp: fix null-ptr-deref in icmp_build_probe(): manual merge
In reply to Yiqi SunHello,
+cc linux-next
Quoted 10 lines · Yiqi Sun
ipv6_stub->ipv6_dev_find()may returnERR_PTR(-EAFNOSUPPORT)when the IPv6 stack is not active (CONFIG_IPV6=mand not loaded), and passing this error pointer todev_hold()will cause a kernel crash with null-ptr-deref.Instead, silently discard the request. RFC 8335 does not appear to define a specific response for the case where an IPv6 interface identifier is syntactically valid but the implementation cannot perform the lookup at runtime, and silently dropping the request may safer than misreporting "No Such Interface".
FYI, we got a small conflict when merging 'net' in 'net-next' in the MPTCP tree due to this patch applied in 'net':
fde29fd93493 ("ipv4: icmp: fix null-ptr-deref in icmp_build_probe()")
and this one from 'net-next':
d98adfbdd5c0 ("ipv4: drop ipv6_stub usage and use direct function calls")
----- Generic Message -----
The best is to avoid conflicts between 'net' and 'net-next' trees but if they cannot be avoided when preparing patches, a note about how to fix them is much appreciated.
The conflict has been resolved on our side [1] and the resolution we suggest is attached to this email. Please report any issues linked to this conflict resolution as it might be used by others. If you worked on the mentioned patches, don't hesitate to ACK this conflict resolution.
---------------------------
Rerere cache is available in [2].
1: https://github.com/multipath-tcp/mptcp_net-next/commit/c14d8597c9a0
2: https://github.com/multipath-tcp/mptcp-upstream-rr-cache/commit/d4699ea
Quoted 4 lines
net/ipv4/icmp.c +0
-0
(...)
net/ipv4/icmp.c bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr) · line 1349
Quoted 5 lines
bool
icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)net/ipv4/icmp.c +0
-0@@ -1346,6 +1347,13 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)if (iio->ident.addr.ctype3_hdr.addrlen !=sizeof (struct in6_addr )) goto send_mal_query; dev = ipv6_stub->ipv6_dev_find (net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
The conflict was in the context: the commit in net-next modified this line above, while the one in net added this block below.
net/ipv4/icmp.c bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr) · line 1359
Quoted 10 lines
net/ipv4/icmp.c +7
-0+/* +* If IPv6 identifier lookup is unavailable, silently +* discard the request instead of misreporting NO_IF. +*/ +if (IS_ERR (dev)) +return false; +dev_hold (dev);break ;#endif
----------------------- 8< -----------------------
net/ipv4/icmp.c +0 -0
@@@ -1342,7 -1345,14 +1342,14 @@@ bool icmp_build_probe(struct sk_buff *scase ICMP_AFI_IP6 :if (iio->ident.addr.ctype3_hdr.addrlen !=sizeof (struct in6_addr )) goto send_mal_query; - dev = ipv6_stub->ipv6_dev_find (net, &iio->ident.addr.ip_addr.ipv6_addr, dev); + dev =ipv6_dev_find (net, &iio->ident.addr.ip_addr.ipv6_addr, dev); +/* +* If IPv6 identifier lookup is unavailable, silently +* discard the request instead of misreporting NO_IF. +*/ +if (IS_ERR (dev)) +return false; +dev_hold (dev);break ;#endif ----------------------- 8< -----------------------
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Jakub Kicinski
maintainerRe: [PATCH net] ipv4: icmp: fix null-ptr-deref in icmp_build_probe(): manual merge
Review
Quoted 11 lines · On Mon, 6 Apr 2026 12:48:28 +0200 Matthieu Baerts wrote:
- dev =
ipv6_stub->ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
+ dev =ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);(quoted diff) +7
-0+ /* + * If IPv6 identifier lookup is unavailable, silently + * discard the request instead of misreporting NO_IF. + */ + if (IS_ERR(dev)) + return false; + dev_hold(dev); break;
See my reply, AFAIU we can just delete this new check in net-next.
Re: [PATCH net] ipv4: icmp: fix null-ptr-deref in icmp_build_probe(): manual merge
Hi Jakub,
Thank you for your reply!
Quoted 13 lines · Jakub Kicinski
Review
Quoted 11 lines · On Mon, 6 Apr 2026 12:48:28 +0200 Matthieu Baerts wrote:
- dev =
ipv6_stub->ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
+ dev =ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);(quoted diff) +7
-0+ /* + * If IPv6 identifier lookup is unavailable, silently + * discard the request instead of misreporting NO_IF. + */ + if (IS_ERR(dev)) + return false; + dev_hold(dev); break;
Quoted 1 line
See my reply, AFAIU we can just delete this new check in net-next.
Good idea.
Should this not be done in an explicit patch, rather than "hidden" during the merge?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Jakub Kicinski
maintainerRe: [PATCH net] ipv4: icmp: fix null-ptr-deref in icmp_build_probe(): manual merge
Quoted 14 lines · On Mon, 6 Apr 2026 18:10:14 +0200 Matthieu Baerts wrote:
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Mon, 6 Apr 2026 12:48:28 +0200 Matthieu Baerts wrote:
- dev =
ipv6_stub->ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
+ dev =ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);(quoted diff) +7
-0+ /* + * If IPv6 identifier lookup is unavailable, silently + * discard the request instead of misreporting NO_IF. + */ + if (IS_ERR(dev)) + return false; + dev_hold(dev); break;
Quoted 6 lines
Quoted 1 line
See my reply, AFAIU we can just delete this new check in net-next.
Good idea.
Should this not be done in an explicit patch, rather than "hidden" during the merge?
Dunno, it's not a huge change, feels like a good fit for a merge.