Skip to contentSkip to conversation

ipv4: icmp: validate reply type before using icmp_pointers

PATCH Superseded Ren Wei 3 participants 4 messages Apr 19 – Apr 23 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

PATCH 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 keep the existing behavior for normal ICMP replies unchanged.

Fixes d329ea5bd884 ("icmp: add response to RFC 8335 PROBE messages")
---
 net/ipv4/icmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/icmp.c +2 -1
index 4e2a6c70dcd8..d8036663f035 100644
@@ -373,7 +373,8 @@ 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[icmp_param->data.icmph.type].error)
 		nf_ct_attach(skb, icmp_param->skb);
 	return 0;
 }
Signature · 1 line
2.34.1
#2 lore raw
Quoted 27 lines · Ren Wei

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 keep the existing behavior for normal ICMP replies unchanged.

Fixes d329ea5bd884 ("icmp: add response to RFC 8335 PROBE messages")
---
 net/ipv4/icmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/icmp.c +0 -0
index 4e2a6c70dcd8..d8036663f035 100644

net/ipv4/icmp.c static int icmp_glue_bits(void *from, char *to, int offset, int len, int odd, · line 379

Quoted 8 lines
net/ipv4/icmp.c +2 -1
@@ -373,7 +373,8 @@ 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[icmp_param->data.icmph.type].error)
                nf_ct_attach(skb, icmp_param->skb);
        return 0;

Pedantic mode: Perhaps also use array_index_nospec()

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Ren Wei
Quoted 9 lines · Ren Wei

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 keep the existing behavior for normal ICMP replies unchanged.

Quoted 8 lines
Fixes d329ea5bd884 ("icmp: add response to RFC 8335 PROBE messages")

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.

reviewer
#4 lore raw
Quoted 19 lines · Simon Horman
Quoted 9 lines · Ren Wei

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 keep the existing behavior for normal ICMP replies unchanged.

Quoted 8 lines
Fixes d329ea5bd884 ("icmp: add response to RFC 8335 PROBE messages")
Quoted 6 lines

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.

Sorry, I meant that to be a reply to v2.
I will respond there too.