Skip to content

Commit ba91c49

Browse files
nvmmaxdavem330
authored andcommitted
sch_cake: Fix out of bounds when parsing TCP options and header
The TCP option parser in cake qdisc (cake_get_tcpopt and cake_tcph_may_drop) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1. This fix is inspired by commit 9609dad ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options."). v2 changes: Added doff validation in cake_get_tcphdr to avoid parsing garbage as TCP header. Although it wasn't strictly an out-of-bounds access (memory was allocated), garbage values could be read where CAKE expected the TCP header if doff was smaller than 5. Cc: Young Xiao <92siuyang@gmail.com> Fixes: 8b71388 ("sch_cake: Add optional ACK filter") Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com> Acked-by: Toke Høiland-Jørgensen <toke@toke.dk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 07718be commit ba91c49

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎net/sched/sch_cake.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ static struct tcphdr *cake_get_tcphdr(const struct sk_buff *skb,
943943
}
944944

945945
tcph = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
946-
if (!tcph)
946+
if (!tcph || tcph->doff < 5)
947947
return NULL;
948948

949949
return skb_header_pointer(skb, offset,
@@ -967,6 +967,8 @@ static const void *cake_get_tcpopt(const struct tcphdr *tcph,
967967
length--;
968968
continue;
969969
}
970+
if (length < 2)
971+
break;
970972
opsize = *ptr++;
971973
if (opsize < 2 || opsize > length)
972974
break;
@@ -1104,6 +1106,8 @@ static bool cake_tcph_may_drop(const struct tcphdr *tcph,
11041106
length--;
11051107
continue;
11061108
}
1109+
if (length < 2)
1110+
break;
11071111
opsize = *ptr++;
11081112
if (opsize < 2 || opsize > length)
11091113
break;

0 commit comments

Comments
 (0)