Skip to content

Commit 67bf002

Browse files
RyderCRDkuba-moo
authored andcommitted
ipv4: icmp: validate reply type before using icmp_pointers
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. Fixes: d329ea5 ("icmp: add response to RFC 8335 PROBE messages") Cc: stable@kernel.org Reported-by: Yuan Tan <yuantan098@gmail.com> Reported-by: Yifan Wu <yifanwucs@gmail.com> Reported-by: Juefei Pu <tomapufckgml@gmail.com> Reported-by: Xin Liu <bird@lzu.edu.cn> Signed-off-by: Ruide Cao <caoruide123@gmail.com> Signed-off-by: Ren Wei <n05ec@lzu.edu.cn> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/0dace90c01a5978e829ca741ef684dbd7304ce62.1776628519.git.caoruide123@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 7ebc650 commit 67bf002

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

net/ipv4/icmp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include <linux/jiffies.h>
6565
#include <linux/kernel.h>
6666
#include <linux/fcntl.h>
67+
#include <linux/nospec.h>
6768
#include <linux/socket.h>
6869
#include <linux/in.h>
6970
#include <linux/inet.h>
@@ -371,7 +372,9 @@ static int icmp_glue_bits(void *from, char *to, int offset, int len, int odd,
371372
to, len);
372373

373374
skb->csum = csum_block_add(skb->csum, csum, odd);
374-
if (icmp_pointers[icmp_param->data.icmph.type].error)
375+
if (icmp_param->data.icmph.type <= NR_ICMP_TYPES &&
376+
icmp_pointers[array_index_nospec(icmp_param->data.icmph.type,
377+
NR_ICMP_TYPES + 1)].error)
375378
nf_ct_attach(skb, icmp_param->skb);
376379
return 0;
377380
}

0 commit comments

Comments
 (0)