From patchwork Mon Mar 19 16:07:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 132063 Delivered-To: patch@linaro.org Received: by 10.80.152.129 with SMTP id j1csp3059648edb; Mon, 19 Mar 2018 10:15:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELuxg3exHo/y2kwRQILhSia7IFHP4ycNI2AltnNHO1sNjhs11vpOUQ6mMfweWO0pJIn60znC X-Received: by 2002:a17:902:68c2:: with SMTP id x2-v6mr4163917plm.129.1521479715415; Mon, 19 Mar 2018 10:15:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521479715; cv=none; d=google.com; s=arc-20160816; b=y2igB7nfYA1iUKUz/NW6julM9jL1cM08OwMGmvNfUEC8TUE96QLUySudwqyYSVCvF+ Ftu2HEOOv6HKhYNmI/2Q24ZHAanNV86g6XRHNs8PoDOoH72fDJba/VNuKgPGW5aDnYfn xl1BI5Ysz7hrtabF0inH1Yij+QfGhLp/HeGkJ8aURf5qxhCZSQOKjdjXTTTx9C1rpgGk bF6YY188m3TEHQ13klqr7QlNMTGGs3rgvvDebyYeEGgm+vJqe+JBeZ557gZ7ahVmPtcK OTBjIGnllG4qqj2BDYGJNwWat6OvViYLUuBArwhRyk/VxioRuVrN11N83/TD+T7ROEGZ GmHQ== 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=KP4AuA5ayVyW6WZ7m+OcJWJwc1gBJvA9I68+utMc+X4=; b=xAnU0u0++xlo7vJmg4JUA+Ti6mc5/R7jSudg6t/JK10JMKoTpSGBN0f6liXnJ7i6lj DDuem2dNWoeutzSt375FswMON4wmhN+VnKPO1rookfdLFLvCYii83vdun7qFIA/tEeCK MWyOUm8bAku6BS8oqAUzVTzzDG5we1ZQbc2YIk7iyU0/Ea6tSNZ0iSWep9PXvNKCSlZC gK5JkrkuGbxWiDBfkO59j9oIhyg5pntxSK/Mw/IyKpjjJmkVhjcrNV3wa3ZCTSvcwDY3 mNB3wqJwHezgRGyRavjND7kEZtlxbaFipWiVH5XShI8duV6EfJMdbbJ7bQJPPeqxt7wX w53g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=G+c5fQoJ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 b34-v6si340537pld.249.2018.03.19.10.15.15; Mon, 19 Mar 2018 10:15:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=G+c5fQoJ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 S967924AbeCSRPN (ORCPT + 10 others); Mon, 19 Mar 2018 13:15:13 -0400 Received: from mail-bn3nam01on0110.outbound.protection.outlook.com ([104.47.33.110]:35072 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966550AbeCSQKC (ORCPT ); Mon, 19 Mar 2018 12:10:02 -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=KP4AuA5ayVyW6WZ7m+OcJWJwc1gBJvA9I68+utMc+X4=; b=G+c5fQoJZfe8gTuO34Xgdof0e2xaFGxe31BxKPbhvzF1cnA4AftH7NGa0W5DxytLdxriXUac0IPM3pSiJV3EqhXwMTmWLRBjFleAzglp8f4rVHJA5OHl5WlCoBA/G9lCCuj2i7VlwSNt3P+Du+lKus4mc+g3T5y2LcWG5YlfWpA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1095.namprd21.prod.outlook.com (52.132.130.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.631.0; Mon, 19 Mar 2018 16:09:53 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 16:09:53 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL for 4.4 102/167] arm64: futex: Fix undefined behaviour with FUTEX_OP_OPARG_SHIFT usage Thread-Topic: [PATCH AUTOSEL for 4.4 102/167] arm64: futex: Fix undefined behaviour with FUTEX_OP_OPARG_SHIFT usage Thread-Index: AQHTv5xhCbJ5RYWUFkCvPOJYN+eEpQ== Date: Mon, 19 Mar 2018 16:07:29 +0000 Message-ID: <20180319160513.16384-102-alexander.levin@microsoft.com> References: <20180319160513.16384-1-alexander.levin@microsoft.com> In-Reply-To: <20180319160513.16384-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; DM5PR2101MB1095; 7:cMa6w6x60n0SEJt3J1TDEjQBgbPr4ZGeTv89I1VvL51p8OJ6o07i7IX9INAQ2eIdeJyUFeWHQljgfjzA0flxQQsqWApZA1YkF94c5UavNo654Tl7MjC8iH7QDwETg2j+EIjfFgIZUl2kV73SZCKee2Qwb0/mVBcToeF6fiqtAGAFOgIVug7CfobByS1hHb1is2Z/wUytoR9qViK1LLiQhRW+tR4/oOdausLKCpBqPjbkwu6rRGMk5ZvqHrcH1nga; 20:Q7f2B+tc5qXbFYNKr3q+Vb1O77hur8mw0v/RWr8Y242+krK6n+aOVyawbJFU4qYsxfEMwb3UniHwin7k5JfC2/EJ+iMaPZPRtwOSwo50oYjW7XKOUXNbmr+8NisUkiX5HhiM6oKCaOtPjsQbunhITSShiBmT82Q8FGU652rTnkQ= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b257ca6b-6e2b-4427-8c50-08d58db3da08 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR2101MB1095; x-ms-traffictypediagnostic: DM5PR2101MB1095: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501300)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:DM5PR2101MB1095; BCL:0; PCL:0; RULEID:; SRVR:DM5PR2101MB1095; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(346002)(366004)(39860400002)(396003)(39380400002)(189003)(199004)(305945005)(316002)(1076002)(7736002)(14454004)(86612001)(25786009)(8936002)(2950100002)(110136005)(66066001)(186003)(10090500001)(6666003)(5250100002)(2501003)(99286004)(76176011)(86362001)(4326008)(68736007)(3660700001)(105586002)(8676002)(81166006)(81156014)(106356001)(3280700002)(72206003)(10290500003)(478600001)(2900100001)(59450400001)(97736004)(54906003)(6512007)(53936002)(6506007)(102836004)(6436002)(5660300001)(6486002)(107886003)(26005)(2906002)(22452003)(6116002)(3846002)(36756003)(22906009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR2101MB1095; H:DM5PR2101MB1032.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: h3nsgaTAgAtlOaVAamdvRCKwjyg1qGT6PwJI/bS0F8+D9xSuFPbMchq9xporlZAlKMRnZyxp2OyRsXRm8kx8VDotXfg7pnAObvFJfG+CLqnENJMyztPWpe6UDQvqNms29ACDjdwd+FSdRzcl+wA3cttbyVD6sZJ9CA4Ntx78MBsJcwtndjcdABou0Y8+Lx8//WtG+DnoE3oJOw7Kx/lmAAyi/ZMIz1s2yK1cm1qcw0+phL9jL+8vnu03H+a/T8OrNaJuuHzCTQ2PHpkkHJww7xzgBh+Z9PAFyF7TJYEBdv8FlE21G0dIhIu0P/NJZ5g77yv+hsl7qkmJnYgI9c+CbQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b257ca6b-6e2b-4427-8c50-08d58db3da08 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 16:07:29.6806 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1095 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Will Deacon [ Upstream commit 5f16a046f8e144c294ef98cd29d9458b5f8273e5 ] FUTEX_OP_OPARG_SHIFT instructs the futex code to treat the 12-bit oparg field as a shift value, potentially leading to a left shift value that is negative or with an absolute value that is significantly larger then the size of the type. UBSAN chokes with: -- 2.14.1 ================================================================================ UBSAN: Undefined behaviour in ./arch/arm64/include/asm/futex.h:60:13 shift exponent -1 is negative CPU: 1 PID: 1449 Comm: syz-executor0 Not tainted 4.11.0-rc4-00005-g977eb52-dirty #11 Hardware name: linux,dummy-virt (DT) Call trace: [] dump_backtrace+0x0/0x538 arch/arm64/kernel/traps.c:73 [] show_stack+0x20/0x30 arch/arm64/kernel/traps.c:228 [] __dump_stack lib/dump_stack.c:16 [inline] [] dump_stack+0x120/0x188 lib/dump_stack.c:52 [] ubsan_epilogue+0x18/0x98 lib/ubsan.c:164 [] __ubsan_handle_shift_out_of_bounds+0x250/0x294 lib/ubsan.c:421 [] futex_atomic_op_inuser arch/arm64/include/asm/futex.h:60 [inline] [] futex_wake_op kernel/futex.c:1489 [inline] [] do_futex+0x137c/0x1740 kernel/futex.c:3231 [] SYSC_futex kernel/futex.c:3281 [inline] [] SyS_futex+0x114/0x268 kernel/futex.c:3249 [] el0_svc_naked+0x24/0x28 ================================================================================ syz-executor1 uses obsolete (PF_INET,SOCK_PACKET) sock: process `syz-executor0' is using obsolete setsockopt SO_BSDCOMPAT This patch attempts to fix some of this by: * Making encoded_op an unsigned type, so we can shift it left even if the top bit is set. * Casting to signed prior to shifting right when extracting oparg and cmparg * Consider only the bottom 5 bits of oparg when using it as a left-shift value. Whilst I think this catches all of the issues, I'd much prefer to remove this stuff, as I think it's unused and the bugs are copy-pasted between a bunch of architectures. Reviewed-by: Robin Murphy Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/include/asm/futex.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h index 5f3ab8c1db55..f50753573989 100644 --- a/arch/arm64/include/asm/futex.h +++ b/arch/arm64/include/asm/futex.h @@ -53,16 +53,16 @@ : "memory") static inline int -futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) +futex_atomic_op_inuser(unsigned int encoded_op, u32 __user *uaddr) { int op = (encoded_op >> 28) & 7; int cmp = (encoded_op >> 24) & 15; - int oparg = (encoded_op << 8) >> 20; - int cmparg = (encoded_op << 20) >> 20; + int oparg = (int)(encoded_op << 8) >> 20; + int cmparg = (int)(encoded_op << 20) >> 20; int oldval = 0, ret, tmp; if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) - oparg = 1 << oparg; + oparg = 1U << (oparg & 0x1f); if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32))) return -EFAULT;