Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp17441imu; Thu, 8 Nov 2018 14:00:41 -0800 (PST) X-Google-Smtp-Source: AJdET5eYVe68O0tchoNJoZQVTd6NiY7zN/BbBokgHSB9f/nP29cRqEEujMEMOHkcZDQrS3GhvRry X-Received: by 2002:a17:902:4827:: with SMTP id s36-v6mr6060618pld.226.1541714441090; Thu, 08 Nov 2018 14:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541714441; cv=none; d=google.com; s=arc-20160816; b=xT+P8xxxgvNV7vshf3GHb308SMEmITzdv+7p/g110H3xKC9rr6/aFvm8r7ZEUqykbZ zLpp0fV2Y9ZXB2GJkpubwtzuxCV6AcFcWHBnrpXHyskGZqI17jHF6d41v48SfpK1ijoO QOG9gCv36LaOnspiTUi3b4j11TIbYsSGYbfSZv1+WyXsYlDyI9XFnx+k4sWdXIKOGIV7 pfuMbYcMqFx5/4qOpnfAVOFFcNWYmPzN4zeMk4mvSeLEXlBj9NUIRQ2jlI+IVRzwnZke yLcIIORYVqnS05VflC2I05IP2qf6k9xhlefNFQguXhSH9cUxZxyoSEO3FjaMlFDKqi8C hcaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IkuVJN7ehmVRoCulG3MAPL/pkBdRa240V6Mw9D2973E=; b=yaCFci6OgJEpICTHTCCp8iRKTDl5M7W8KsI7Ka6FRZEAEUEmih/AxxxFUuHrX0wz4p XvszrmLE9f/VlCcStug1O+PUiGRVUaKVWv3oidM9ZbSQYxIVClm+da6sX+dYmO3KJhsa Rx19L4PChgUuDaFxKK649aPBavBCGl5V7SRPRRDk2AxuNV4CU4Zz0r577DZEQAM9cHtC t4VhlojWaYP8+ks6FLH6Qa0SLUK2fnGtmt0ixwgDBpOxpzhrSYs9M0W2sjwdXMJJVy3E du35D3uu+2TkUk/ROuhETrRcr8khSNfq9PqmqSADs6TYIV5SDNB2Unash/CrMdJZND2T M6RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1JEhC4ax; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p2-v6si6207041pli.79.2018.11.08.14.00.25; Thu, 08 Nov 2018 14:00:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1JEhC4ax; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729925AbeKIHgn (ORCPT + 99 others); Fri, 9 Nov 2018 02:36:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:54254 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728284AbeKIHgm (ORCPT ); Fri, 9 Nov 2018 02:36:42 -0500 Received: from localhost (unknown [208.72.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 276DC20892; Thu, 8 Nov 2018 21:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714354; bh=r6TjTBKneVH4Di0AwvHYGxdwyFcS3VS5d4L5kNhbucg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1JEhC4axKKsq45MX17BDasqRKBO8af3luRcBbrebLNL8I9rcEL+0qB/U1qYt92ReN aWrW+Fiut8iIC94G5pC+omt+pCULqWLfzvUBNuRA8bd8bvvVyPz2bEC6fGeI8/BIMO BHZRuAIjWYUaylJHSpavvgGBmi09uz/tLyTmYCq4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mateusz Jurczyk , Julian Wiedmann , "David S. Miller" , Sasha Levin Subject: [PATCH 4.4 028/114] af_iucv: Move sockaddr length checks to before accessing sa_family in bind and connect handlers Date: Thu, 8 Nov 2018 13:50:43 -0800 Message-Id: <20181108215101.652628608@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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]; /* Verify the input sockaddr */ - if (!addr || addr->sa_family != AF_IUCV) - return -EINVAL; - - if (addr_len < sizeof(struct sockaddr_iucv)) + if (addr_len < sizeof(struct sockaddr_iucv) || + addr->sa_family != AF_IUCV) return -EINVAL; lock_sock(sk); @@ -852,7 +850,7 @@ static int iucv_sock_connect(struct socket *sock, struct sockaddr *addr, struct iucv_sock *iucv = iucv_sk(sk); int err; - if (addr->sa_family != AF_IUCV || alen < sizeof(struct sockaddr_iucv)) + if (alen < sizeof(struct sockaddr_iucv) || addr->sa_family != AF_IUCV) return -EINVAL; if (sk->sk_state != IUCV_OPEN && sk->sk_state != IUCV_BOUND) -- 2.17.1