Received: by 10.223.176.5 with SMTP id f5csp800524wra; Sat, 3 Feb 2018 10:34:12 -0800 (PST) X-Google-Smtp-Source: AH8x225/LP9QGzLXAg+MCgZ3vfKuR84A5f3xB7jfR5O/4VgD3TDKBXK9gv2ivh0Ob8FHkzpl8yji X-Received: by 10.99.53.203 with SMTP id c194mr27571089pga.12.1517682852498; Sat, 03 Feb 2018 10:34:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517682852; cv=none; d=google.com; s=arc-20160816; b=lyaUQxnyf39t+5LPixR4NSVSo3mi5oXToXn4VmaA2mIk2o8fXdB9Tuf7iHFWFMN6xU ijvXD9IPgCIlqqdwAxWcFR2onVzvq07Ryx9uH3IK4Ri1Phykfu5z2Fl1qQ7OHFz4TtS3 YGG4Qt29eceNy/n4Ps7sHFWBTtk7tnLsGy8V+xkIfeBgdlQGPhEdvCRnPExahLyjF3Wn dn5wT5Tzf8cNYvxOlTIBz5leX/4WO1euAu5P4yQSiundzkZ7reJyqxN+84AXqm+J6Kks IjG3z54sXz/Zpp2bcNk+9Wiz7MiPgJhhm561lAZ0jA+wDRWfWgiijwfgOAWyRGO1lqRN VpWw== 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=vc1q+5RPDAul2ZBJZWg/boVLcRjiFYZSSb923mXxmbo=; b=Nem1/Gm/LYj5/x9p0gUILD16Pi4DkPsq28lwA2vGDLSxoJ7cvRF9fjv9bneAWtu40a qsO/Q6ow9rqZ9xwWIgHcYQwlEX1ncfaMGDVTGR0UVdd4z7uXGgM2WH94E7SAsuTWSsBf in0WBi7vW7gYecje/PokDvmMEXLbQqkQbkbzQuY4+lY26AulgAWDKvzQjndquiLVel8C xwGA5CNFLAnnz4X1wpUdsywSN5wLOsILgYwG41+S7aQhEU/NNcORQhEhq8St8x/tgcGK dO8uN75akG99Bkh4K4I7+67KXFEBeJZ8KLWncscAAlmtR/r1FmaGP1WVd611ZXq7hZDE wGIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=HyzfeU7R; 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 x9si3251161pgt.196.2018.02.03.10.33.57; Sat, 03 Feb 2018 10:34:12 -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=@microsoft.com header.s=selector1 header.b=HyzfeU7R; 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 S1753952AbeBCSdH (ORCPT + 99 others); Sat, 3 Feb 2018 13:33:07 -0500 Received: from mail-bl2nam02on0139.outbound.protection.outlook.com ([104.47.38.139]:10688 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753035AbeBCSE0 (ORCPT ); Sat, 3 Feb 2018 13:04:26 -0500 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=vc1q+5RPDAul2ZBJZWg/boVLcRjiFYZSSb923mXxmbo=; b=HyzfeU7RZc5knyoSurJEUDKUnHoCgqe8Mh4q4wZfChTQEggc3pYhTHQdW/iaXOsHQf6kCfujKc+gZgGmsSmF/O+wzDwB3OBhD9suhs1/qYgXEV52RoJZQTppoxmM+M7QjoDu5/JCi2QrvcXE8HV+jaCXIMm+jgHLl8v6GV7975w= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB0993.namprd21.prod.outlook.com (52.132.23.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.5; Sat, 3 Feb 2018 18:02:54 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:02:54 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Marcelo Ricardo Leitner , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 106/110] sctp: make use of pre-calculated len Thread-Topic: [PATCH AUTOSEL for 4.14 106/110] sctp: make use of pre-calculated len Thread-Index: AQHTnRkHPJIjJuHpsUCsjJ1wl9v6/Q== Date: Sat, 3 Feb 2018 18:01:34 +0000 Message-ID: <20180203180015.29073-106-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-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;BL0PR2101MB0993;7:r022H7osyfH8PVaHklZf/hai+zHqx0sb3MqOaaPl95bNlXsekglkPzV/IsQuNkKxwOdt3esxD2A44FV2oDHeZytyoezre5dYj25knVmdQshtjYvnC94cIZ9Io4O+6qTf0L5XIPJyHonPlljdFA+Bt/BL1HkZgaaDPhwYBMtlgKaki61d1UO7OoMqwCz9vOF0LFos726HCDwTQcrqi1DOexkT3/x/LphI2BkstKdbaoN0asMBRIJ9N/cRR64YV/vT x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: cb64639a-fc57-48fd-11f3-08d56b30591b x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB0993; x-ms-traffictypediagnostic: BL0PR2101MB0993: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158)(788757137089); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011);SRVR:BL0PR2101MB0993;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB0993; x-forefront-prvs: 05724A8921 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39380400002)(39860400002)(376002)(366004)(396003)(189003)(199004)(6436002)(186003)(3660700001)(8936002)(105586002)(2906002)(6346003)(6116002)(3280700002)(3846002)(97736004)(6486002)(1076002)(2950100002)(6666003)(81156014)(86362001)(575784001)(76176011)(102836004)(2501003)(5250100002)(26005)(68736007)(10090500001)(81166006)(8676002)(53936002)(5660300001)(22452003)(305945005)(107886003)(7736002)(4326008)(86612001)(36756003)(99286004)(316002)(6512007)(10290500003)(72206003)(6506007)(14454004)(478600001)(25786009)(106356001)(2900100001)(39060400002)(54906003)(110136005)(66066001)(22906009)(21314002)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB0993;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: 5QyCyFe0guWl03auGSDowv1Psp0g8D1QnHnfk+Y/QI7t5+ceKxV8Ai6mtPR29Ih+K/JusP7AyxJiIw/KhixVdQ== 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: cb64639a-fc57-48fd-11f3-08d56b30591b X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:01:34.2377 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB0993 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcelo Ricardo Leitner [ Upstream commit c76f97c99ae6d26d14c7f0e50e074382bfbc9f98 ] Some sockopt handling functions were calculating the length of the buffer to be written to userspace and then calculating it again when actually writing the buffer, which could lead to some write not using an up-to-date length. This patch updates such places to just make use of the len variable. Also, replace some sizeof(type) to sizeof(var). Signed-off-by: Marcelo Ricardo Leitner Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/sctp/socket.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 978fc7d1cf53..53e3634afea0 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c @@ -4948,7 +4948,7 @@ static int sctp_getsockopt_autoclose(struct sock *sk,= int len, char __user *optv len =3D sizeof(int); if (put_user(len, optlen)) return -EFAULT; - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int))) + if (copy_to_user(optval, &sctp_sk(sk)->autoclose, len)) return -EFAULT; return 0; } @@ -5579,6 +5579,9 @@ copy_getaddrs: err =3D -EFAULT; goto out; } + /* XXX: We should have accounted for sizeof(struct sctp_getaddrs) too, + * but we can't change it anymore. + */ if (put_user(bytes_copied, optlen)) err =3D -EFAULT; out: @@ -6015,7 +6018,7 @@ static int sctp_getsockopt_maxseg(struct sock *sk, in= t len, params.assoc_id =3D 0; } else if (len >=3D sizeof(struct sctp_assoc_value)) { len =3D sizeof(struct sctp_assoc_value); - if (copy_from_user(¶ms, optval, sizeof(params))) + if (copy_from_user(¶ms, optval, len)) return -EFAULT; } else return -EINVAL; @@ -6185,7 +6188,9 @@ static int sctp_getsockopt_active_key(struct sock *sk= , int len, =20 if (len < sizeof(struct sctp_authkeyid)) return -EINVAL; - if (copy_from_user(&val, optval, sizeof(struct sctp_authkeyid))) + + len =3D sizeof(struct sctp_authkeyid); + if (copy_from_user(&val, optval, len)) return -EFAULT; =20 asoc =3D sctp_id2assoc(sk, val.scact_assoc_id); @@ -6197,7 +6202,6 @@ static int sctp_getsockopt_active_key(struct sock *sk= , int len, else val.scact_keynumber =3D ep->active_key_id; =20 - len =3D sizeof(struct sctp_authkeyid); if (put_user(len, optlen)) return -EFAULT; if (copy_to_user(optval, &val, len)) @@ -6223,7 +6227,7 @@ static int sctp_getsockopt_peer_auth_chunks(struct so= ck *sk, int len, if (len < sizeof(struct sctp_authchunks)) return -EINVAL; =20 - if (copy_from_user(&val, optval, sizeof(struct sctp_authchunks))) + if (copy_from_user(&val, optval, sizeof(val))) return -EFAULT; =20 to =3D p->gauth_chunks; @@ -6268,7 +6272,7 @@ static int sctp_getsockopt_local_auth_chunks(struct s= ock *sk, int len, if (len < sizeof(struct sctp_authchunks)) return -EINVAL; =20 - if (copy_from_user(&val, optval, sizeof(struct sctp_authchunks))) + if (copy_from_user(&val, optval, sizeof(val))) return -EFAULT; =20 to =3D p->gauth_chunks; --=20 2.11.0