Return-Path: Received: from mail-sn1nam02on0113.outbound.protection.outlook.com ([104.47.36.113]:53303 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932682AbeDIAg4 (ORCPT ); Sun, 8 Apr 2018 20:36:56 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Mateusz Jurczyk , Julian Wiedmann , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 070/162] af_iucv: Move sockaddr length checks to before accessing sa_family in bind and connect handlers Date: Mon, 9 Apr 2018 00:28:33 +0000 Message-ID: <20180409002738.163941-70-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Mateusz Jurczyk [ Upstream commit e3c42b61ff813921ba58cfc0019e3fd63f651190 ] Verify that the caller-provided sockaddr structure is large enough to contain the sa_family field, before accessing it in bind() and connect() handlers of the AF_IUCV socket. Since neither syscall enforces a minimum size of the corresponding memory region, very short sockaddrs (zero or one byte long) result in operating on uninitialized memory while referencing .sa_family. Fixes: 52a82e23b9f2 ("af_iucv: Validate socket address length in iucv_sock_= bind()") Signed-off-by: Mateusz Jurczyk [jwi: removed unneeded null-check for addr] Signed-off-by: Julian Wiedmann Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/iucv/af_iucv.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c index aeffb65181f5..5984cc35d508 100644 --- a/net/iucv/af_iucv.c +++ b/net/iucv/af_iucv.c @@ -705,10 +705,8 @@ static int iucv_sock_bind(struct socket *sock, struct = sockaddr *addr, char uid[9]; =20 /* Verify the input sockaddr */ - if (!addr || addr->sa_family !=3D AF_IUCV) - return -EINVAL; - - if (addr_len < sizeof(struct sockaddr_iucv)) + if (addr_len < sizeof(struct sockaddr_iucv) || + addr->sa_family !=3D AF_IUCV) return -EINVAL; =20 lock_sock(sk); @@ -852,7 +850,7 @@ static int iucv_sock_connect(struct socket *sock, struc= t sockaddr *addr, struct iucv_sock *iucv =3D iucv_sk(sk); int err; =20 - if (addr->sa_family !=3D AF_IUCV || alen < sizeof(struct sockaddr_iucv)) + if (alen < sizeof(struct sockaddr_iucv) || addr->sa_family !=3D AF_IUCV) return -EINVAL; =20 if (sk->sk_state !=3D IUCV_OPEN && sk->sk_state !=3D IUCV_BOUND) --=20 2.15.1