ipv4: icmp: validate reply type before using icmp_pointers
Subsystems (3)
PATCH v2 1/1 ipv4: icmp: validate reply type before using icmp_pointers
From: Ruide Cao <[email protected]>
Extended echo replies use ICMP_EXT_ECHOREPLY as the outbound reply type. That value is outside the range covered by icmp_pointers[], which only describes the traditional ICMP types up to NR_ICMP_TYPES.
Avoid consulting icmp_pointers[] for reply types outside that range, and use array_index_nospec() for the remaining in-range lookup. Normal ICMP replies keep their existing behavior unchanged.
---
changes in v2:
use array_index_nospec()
v1 link: https://lore.kernel.org/all/efb2c33f544ece7727704608fc577525b415ae26.1776563662.git.caoruide123@gmail.com/
net/ipv4/icmp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/icmp.c +4 -1
@@ -64,6 +64,7 @@#include <linux/jiffies.h> #include <linux/kernel.h> #include <linux/fcntl.h> +#include <linux/nospec.h> #include <linux/socket.h> #include <linux/in.h> #include <linux/inet.h>
@@ -373,7 +374,9 @@ static int icmp_glue_bits(void *from, char *to, int offset, int len, int odd, to, len); skb->csum =csum_block_add (skb->csum, csum, odd); -if (icmp_pointers[icmp_param->data.icmph.type].error) +if (icmp_param->data.icmph.type <=NR_ICMP_TYPES && + icmp_pointers[array_index_nospec (icmp_param->data.icmph.type, +NR_ICMP_TYPES +1 )].error)nf_ct_attach (skb, icmp_param->skb);return 0 ; }
Signature · 1 line
2.34.1
Quoted 18 lines · Ren Wei
From: Ruide Cao <[email protected]>
Extended echo replies use
ICMP_EXT_ECHOREPLYas the outbound reply type. That value is outside the range covered by icmp_pointers[], which only describes the traditional ICMP types up toNR_ICMP_TYPES.Avoid consulting icmp_pointers[] for reply types outside that range, and use
array_index_nospec()for the remaining in-range lookup. Normal ICMP replies keep their existing behavior unchanged.Fixes d329ea5bd884 ("icmp: add response to RFC 8335 PROBE messages")Reported-by Yuan Tan <[email protected]>Reported-by Yifan Wu <[email protected]>Reported-by Juefei Pu <[email protected]>Reported-by Xin Liu <[email protected]>Signed-off-by Ruide Cao <[email protected]>Signed-off-by Ren Wei <[email protected]>
Quoted 4 lines
---
changes in v2:
usearray_index_nospec()
v1 link: https://lore.kernel.org/all/efb2c33f544ece7727704608fc577525b415ae26.1776563662.git.caoruide123@gmail.com/
Sashiko has generated a review of this patch. I do not believe the problems flagged there need to be addressed as the array indexes used in those cases have are always valid. However, I would appreciate it if you could look over this.
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 Tue, 21 Apr 2026 12:16:31 +0800 you wrote:
From: Ruide Cao <[email protected]>
Extended echo replies use
ICMP_EXT_ECHOREPLYas the outbound reply type. That value is outside the range covered by icmp_pointers[], which only describes the traditional ICMP types up toNR_ICMP_TYPES.Avoid consulting icmp_pointers[] for reply types outside that range, and use
array_index_nospec()for the remaining in-range lookup. Normal ICMP replies keep their existing behavior unchanged.[...]
Here is the summary with links:
- [net,v2] ipv4: icmp: validate reply type before using icmp_pointers
https://git.kernel.org/netdev/net/c/67bf002a2d73
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html