Skip to content

Commit 9609dad

Browse files
YangY-Xiaodavem330
authored andcommitted
ipv4: tcp_input: fix stack out of bounds when parsing TCP options.
The TCP option parsing routines in tcp_parse_options function could read one byte out of the buffer of the TCP options. 1 while (length > 0) { 2 int opcode = *ptr++; 3 int opsize; 4 5 switch (opcode) { 6 case TCPOPT_EOL: 7 return; 8 case TCPOPT_NOP: /* Ref: RFC 793 section 3.1 */ 9 length--; 10 continue; 11 default: 12 opsize = *ptr++; //out of bound access If length = 1, then there is an access in line2. And another access is occurred in line 12. This would lead to out-of-bound access. Therefore, in the patch we check that the available data length is larger enough to pase both TCP option code and size. Signed-off-by: Young Xiao <92siuyang@gmail.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 62851d7 commit 9609dad

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎net/ipv4/tcp_input.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,6 +3791,8 @@ void tcp_parse_options(const struct net *net,
37913791
length--;
37923792
continue;
37933793
default:
3794+
if (length < 2)
3795+
return;
37943796
opsize = *ptr++;
37953797
if (opsize < 2) /* "silly options" */
37963798
return;

0 commit comments

Comments
 (0)