Skip to content

Commit

Permalink
Don't allow zero sized segments that will panic the stack.
Browse files Browse the repository at this point in the history
Reported-by: syzbot+5542516fa4afe7a101e6@syzkaller.appspotmail.com
  • Loading branch information
mlelstv authored and mlelstv committed Nov 17, 2019
1 parent bc98eb4 commit 1f03898
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions sys/netinet/tcp_output.c
@@ -1,4 +1,4 @@
/* $NetBSD: tcp_output.c,v 1.211 2019/02/25 10:49:16 maxv Exp $ */
/* $NetBSD: tcp_output.c,v 1.212 2019/11/17 08:21:25 mlelstv Exp $ */

/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
Expand Down Expand Up @@ -135,7 +135,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.211 2019/02/25 10:49:16 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.212 2019/11/17 08:21:25 mlelstv Exp $");

#ifdef _KERNEL_OPT
#include "opt_inet.h"
Expand Down Expand Up @@ -252,6 +252,7 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep,
break;
#endif
default:
hdrlen = 1; /* prevent zero sized segments */
goto out;
}

Expand Down Expand Up @@ -386,6 +387,13 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep,
*txsegsizep = uimin(so->so_snd.sb_hiwat >> 1, *txsegsizep);
}

/*
* A segment must at least store header + options
*/
if (*txsegsizep < hdrlen + optlen) {
return EMSGSIZE;
}

if (*txsegsizep != tp->t_segsz) {
/*
* If the new segment size is larger, we don't want to
Expand Down

0 comments on commit 1f03898

Please sign in to comment.