tcp: fix TCP_REPAIR_QUEUE bound checking
Subsystems (3)
PATCH 1/1 tcp: fix TCP_REPAIR_QUEUE bound checking
syzbot is able to produce a nasty WARN_ON() in tcp_verify_left_out() with following C-repro :
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3setsockopt(3, SOL_TCP, TCP_REPAIR, [1], 4) = 0setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4) = 0bind(3, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("0.0.0.0")}, 16) = 0 sendto(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
1242, MSG_FASTOPEN, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("127.0.0.1")}, 16) = 1242setsockopt(3, SOL_TCP, TCP_REPAIR_WINDOW, "\4\0\0@+\205\0\0\377\377\0\0\377\377\377\177\0\0\0\0", 20) = 0writev(3, [{"\270", 1}], 1) = 1
setsockopt(3, SOL_TCP, TCP_REPAIR_OPTIONS, "\10\0\0\0\0\0\0\0\0\0\0\0|\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 386) = 0 writev(3, [{"\210v\r[\226\320t\231qwQ\204\264l\254\t\1\20\245\214p\350H\223\254;\\\37\345\307p$"..., 3144}], 1) = 3144
The 3rd system call looks odd :setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4) = 0
This patch makes sure bound checking is using an unsigned compare.
--- net/ipv4/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/tcp.c +1 -1
@@ -2674,7 +2674,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,case TCP_REPAIR_QUEUE :if (!tp->repair) err = -EPERM ; -else if (val <TCP_QUEUES_NR ) +else if ((unsigned int )val <TCP_QUEUES_NR ) tp->repair_queue = val;else err = -EINVAL ;
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Sun, 29 Apr 2018 18:55:20 -0700
Quoted 14 lines
syzbot is able to produce a nasty
WARN_ON()intcp_verify_left_out()with following C-repro :
socket(PF_INET, SOCK_STREAM, IPPROTO_IP)= 3setsockopt(3, SOL_TCP, TCP_REPAIR, [1], 4)= 0setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4)= 0bind(3, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("0.0.0.0")}, 16)= 0 sendto(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,1242, MSG_FASTOPEN, {sa_family=AF_INET, sin_port=htons(20002), sin_addr=inet_addr("127.0.0.1")}, 16) = 1242
setsockopt(3, SOL_TCP, TCP_REPAIR_WINDOW, "\4\0\0@+\205\0\0\377\377\0\0\377\377\377\177\0\0\0\0", 20)= 0writev(3, [{"\270", 1}], 1)= 1
setsockopt(3,SOL_TCP,TCP_REPAIR_OPTIONS, "\10\0\0\0\0\0\0\0\0\0\0\0|\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 386) = 0 writev(3, [{"\210v\r[\226\320t\231qwQ\204\264l\254\t\1\20\245\214p\350H\223\254;\\\37\345\307p$"..., 3144}], 1) = 3144
Quoted 8 lines
The 3rd system call looks odd :
setsockopt(3, SOL_TCP, TCP_REPAIR_QUEUE, [-1], 4)= 0This patch makes sure bound checking is using an unsigned compare.
Fixes ee9952831cfd ("tcp: Initial repair mode")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>
Ouch.
Applied and queued up for -stable, thanks Eric.