Received: by 10.213.65.68 with SMTP id h4csp2117752imn; Sun, 8 Apr 2018 20:08:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ghZeZhrHDiIOc7jAhviV7plvwhSWJAzbwvinZCaJhvjVmte+x7z/izp3Xxa2698uJyZzU X-Received: by 2002:a17:902:b60c:: with SMTP id b12-v6mr37125434pls.203.1523243332451; Sun, 08 Apr 2018 20:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243332; cv=none; d=google.com; s=arc-20160816; b=XmEQXaRyfxH66rMM+KhrhHnwrKLioKxUdHZC9YplRVL8TzV//OpZE/SJZccxAS5hn3 AATFEFaVSTlZkoL8bEwQoWlF/ht65YIa9I064yS3agAMwXyjzoqvDdzy5ij7iaXK4gni GmocP3WaHWVdX2Ir+9p3PmtsuCerPJ9IdCdCUkhxK5ZpuyuKASfE5ZKeLSh+Vtp8dKbz DryrL9eohu9VYCGn8btNDL2bW7zLj6kqXH1Sg5piJa+WkHEYg97z5U+obE8i8S71zur+ t6G6eds3fpldPNHwzVaXKaqHfk6dGPGGMzNZdmFL+u2JSaLlH0YXKXBrdyqqF73fJwQQ hX2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=qIbc/BZ7sPtc7m/ZlgB6XlhM3+gExiQkZtplwRjz4VY=; b=pUtCpuFZnVMtGzp++CekW5Gm4OWVvUID5lKYsrCEcDalWyMbl7WuHBEHp8kk6rXGRf eRx32neMtRumTkGTxT21Gic/r6gJatz9AngZbaKbO1J7ZulEXhiE5EcP96HeJprDJHV9 V//4rFC+yHyd0tvMCyxy78te4kynJbcofV7ZlQkplYKCyjRrjsf7huco07jBwI3M4yTt 7EFe4FzS1pGgOIaPrNPAl5fK0kid5z/Mb+ykfFZjoKjq8OMWoeGlCLxoMAOdgZZOFsZj 54BDJPe8iODW78m0d2hK7mEpFH994W96PXzkjFj2Ymhy1o1aWSwZGFTq/AGI+XzUuMs9 hN+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Ppz8GjDI; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11-v6si14416524plq.544.2018.04.08.20.08.16; Sun, 08 Apr 2018 20:08:52 -0700 (PDT) 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=@microsoft.com header.s=selector1 header.b=Ppz8GjDI; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932358AbeDICPQ (ORCPT + 99 others); Sun, 8 Apr 2018 22:15:16 -0400 Received: from mail-dm3nam03on0093.outbound.protection.outlook.com ([104.47.41.93]:60032 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756107AbeDIAaf (ORCPT ); Sun, 8 Apr 2018 20:30:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=qIbc/BZ7sPtc7m/ZlgB6XlhM3+gExiQkZtplwRjz4VY=; b=Ppz8GjDIJU7D4cav+Vf6yLmXiHxk5rvT2py2TwKQk7NtJG6wWSDsnn6dwsTWg12MPLi1BLTJpm7Qy4KmPwN9xqO0SeiBk1+w1Q+Y2nQD+SGLE3EeThAv3z4QOp3HhDhwja5+2rQXnZPXJF2SFtJHOqkt4BivT11rI0Wk2VNH+XA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0807.namprd21.prod.outlook.com (10.167.110.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:30:30 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:30:30 +0000 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.9 143/293] af_iucv: Move sockaddr length checks to before accessing sa_family in bind and connect handlers Thread-Topic: [PATCH AUTOSEL for 4.9 143/293] af_iucv: Move sockaddr length checks to before accessing sa_family in bind and connect handlers Thread-Index: AQHTz5kotnHqDknhCEixYxwFMqGesQ== Date: Mon, 9 Apr 2018 00:24:44 +0000 Message-ID: <20180409002239.163177-143-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0807;7:uTnPIqsSyc2235+Ikq+1kqTAR7oM21VAfrh9WvUSJGL72mQPs60uzW1Br0E3oCtVwwcDpKXc/AjY4RGrsT++SwtZX9LXXQcbmtvQDRmM2MqfN3TYxcGfp2XLab2W6i070rAISIB1p6yEp0H4YQxNn+zegvgrNY5QuI3TAeXbAoQVoKO+0Oke9iti0Y5fJBjqOdJNKZzaZgDAsxV7qBrTvEwK9uGM2erm/5i/dAHogfLzcJT9Rc6TWDTw6IPhUAjP;20:w/dKLY6EUAgh0sn2zwQIpZYsb7m8EipuToVq9ZypnELD7ghjC3bidZG503IVlt/MRynchB5pAwvemW4h4uqO3NYTKXH795L3Zak2A+l1WwrRWkhJGXcq6xBTTNhnadwq/+weJizN9T6IByGWGGl9BROvlWYnj4/Hk1zeRnE56JQ= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 6d5d6eed-bd46-4a98-a368-08d59db11946 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0807; x-ms-traffictypediagnostic: DM5PR2101MB0807: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(211936372134217)(153496737603132)(104084551191319)(21532816269658); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3231221)(944501327)(52105095)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0807;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0807; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(39860400002)(396003)(366004)(376002)(346002)(199004)(189003)(14454004)(4326008)(54906003)(25786009)(53936002)(2900100001)(1076002)(3280700002)(6486002)(186003)(2616005)(68736007)(110136005)(11346002)(10090500001)(6116002)(107886003)(3846002)(36756003)(8676002)(72206003)(22452003)(66066001)(26005)(6512007)(478600001)(3660700001)(81156014)(86362001)(81166006)(86612001)(7736002)(305945005)(8936002)(10290500003)(6436002)(105586002)(6666003)(316002)(59450400001)(76176011)(5660300001)(476003)(106356001)(2906002)(6506007)(446003)(2501003)(99286004)(5250100002)(486006)(102836004)(97736004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0807;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: buG363QraJXpqMVgQvEUh1TjeS4rFLVdA5AKreMjEYzqAEjhdvv1euCOFGOvDbuHSn8lOZE5sZ2Uon3cnxbCD4QSn/USEkwgn7heCxs78wn5YHx/lt/qVeWnlc2Q/8EmIuZxUtfuZnTKwurh3Ed8+DqjGz6vAGTOCKMqXcn8etFsnGwaFVDO10xi27SK+0ATBuYQJ6JQrGmdnw3LG4t7kFvfZZX/fKNwEM4KJ4v6tReE5QtY27JElWK9ZDPaPGCRnhGpsXTp7hSHx55oJi7F8+88Yot0ewC91eKBHTHtYS0smKtrNaY7dcMKOZcRHpj5jyXgCtGXkXnZ87LaMQm+sX50lJtXTM6qMZbZEaZnlD3NaWmALTOM/UmBqA9Cm9DBMIszF7njEnCliZt4t0/GrBHYQQBuNKwlK6Ds9IS2g04= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d5d6eed-bd46-4a98-a368-08d59db11946 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:24:44.7532 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0807 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 c2dfc32eb9f2..a69003fbf5b9 100644 --- a/net/iucv/af_iucv.c +++ b/net/iucv/af_iucv.c @@ -708,10 +708,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); @@ -855,7 +853,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