Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 6 May 2020 21:59:58 +0000 (UTC)
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r360705 - stable/11/sys/kern
Message-ID:  <202005062159.046LxwxL023189@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tuexen
Date: Wed May  6 21:59:58 2020
New Revision: 360705
URL: https://svnweb.freebsd.org/changeset/base/360705

Log:
  MFC r349989: Improve input validation for l_linger
  
  When using the SOL_SOCKET level socket option SO_LINGER, the structure
  struct linger is used as the option value. The component l_linger is of
  type int, but internally copied to the field so_linger of the structure
  struct socket. The type of so_linger is short, but it is assumed to be
  non-negative and the value is used to compute ticks to be stored in a
  variable of type int.
  
  Therefore, perform input validation on l_linger similar to the one
  performed by NetBSD and OpenBSD.
  
  Thanks to syzkaller for making me aware of this issue.
  
  Thanks to markj@ for pointing out that a similar check should be added
  to so_linger_set().
  
  Reviewed by:		markj
  Differential Revision:	https://reviews.freebsd.org/D20948

Modified:
  stable/11/sys/kern/uipc_socket.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/kern/uipc_socket.c
==============================================================================
--- stable/11/sys/kern/uipc_socket.c	Wed May  6 19:58:37 2020	(r360704)
+++ stable/11/sys/kern/uipc_socket.c	Wed May  6 21:59:58 2020	(r360705)
@@ -2535,7 +2535,12 @@ sosetopt(struct socket *so, struct sockopt *sopt)
 			error = sooptcopyin(sopt, &l, sizeof l, sizeof l);
 			if (error)
 				goto bad;
-
+			if (l.l_linger < 0 ||
+			    l.l_linger > USHRT_MAX ||
+			    l.l_linger > (INT_MAX / hz)) {
+				error = EDOM;
+				goto bad;
+			}
 			SOCK_LOCK(so);
 			so->so_linger = l.l_linger;
 			if (l.l_onoff)
@@ -3701,6 +3706,9 @@ so_linger_get(const struct socket *so)
 void
 so_linger_set(struct socket *so, int val)
 {
+
+	KASSERT(val >= 0 && val <= USHRT_MAX && val <= (INT_MAX / hz),
+	    ("%s: val %d out of range", __func__, val));
 
 	so->so_linger = val;
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005062159.046LxwxL023189>