Received: by 10.223.185.116 with SMTP id b49csp3488752wrg; Mon, 26 Feb 2018 00:24:56 -0800 (PST) X-Google-Smtp-Source: AH8x227GCyLJWVqV+4xnBu0FlolbNG9DmGF2RfL9sGZoMjGS/+bVDZay0N/P0rVG5VN3cgQrFg6e X-Received: by 10.98.34.75 with SMTP id i72mr9693425pfi.165.1519633495978; Mon, 26 Feb 2018 00:24:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633495; cv=none; d=google.com; s=arc-20160816; b=rZ27oyhAU3ckP7f55cLiVkVA/g9/5ErT/36iIldsQ1Vre/UotYr2ZI59dFKDTKkhKq 4m4PXKRSFLZvlHbwOOfTGRRQkN+G1PbKwSzeehXOQcXdgf6RTKj/wAX6b0YJm4tXIPZC 5xi39VZtWK/9QQZ3mPrRH461jbSntFbaq4CzMCatLJnfLo1A0n/jisTkzmX5DfgDD9f5 Pugw6+FmX6fSiltmQhAH24yu6Lvc83pmb4oM3K3ClXOBSOJYKb64WqMD92eO+Scwg6NA h0qJrOxBA4+ZUQg4Fp0tJiRr5vfx6J/WdjXHPrg46FRJxs5fe/QhmmzRWFBEGPJtToyN 4rSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=ieEfJQsM4sBvXx7mXsGG38weJFE2pHNKljsnVCbD9xI=; b=w5MKtWwE9ZsUP5WUbM3PwvnE6F4NdrQdX0aZ7ik9umDOe7HkpqNyOnTU987sdTTrMn MK/aF157UiJVUa78h5g3ZzWF7uOO46XoiJ16dtncZC8ve7ZHYLFpi+CK1itTJRyw1epq 7fiiX5MhZF/t+C8UwVcx73XNdFD8tvvgPsFkSmn7su1mn0T70EgWnHa+AqCsiBn79KoM cSisdq7IAgLRhBqlVLRogBPLWaE/qJ59j/aN7VmkMi5sUXO7TZVwcyM+p4hXW9Wsp1AD RBnb7mqB59OhKqnHqp9gETNKSVZAgc10vQx0CjCEQFope+dcA86EI5lhwhDPmLWbJKkX 4GyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WUx5z9M5; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u187si5248597pgc.451.2018.02.26.00.24.41; Mon, 26 Feb 2018 00:24:55 -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=@linaro.org header.s=google header.b=WUx5z9M5; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752491AbeBZIXI (ORCPT + 99 others); Mon, 26 Feb 2018 03:23:08 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:46508 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751793AbeBZIXE (ORCPT ); Mon, 26 Feb 2018 03:23:04 -0500 Received: by mail-pl0-f68.google.com with SMTP id x19so8861026plr.13 for ; Mon, 26 Feb 2018 00:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=ieEfJQsM4sBvXx7mXsGG38weJFE2pHNKljsnVCbD9xI=; b=WUx5z9M505qUpiQcj+a/NlT1Q+F8mp4sYpex56WGyCXo9DiKptlyp5wcidmum6Bkmj 0pZbywgZ5YLWwvwSldmlgPIOoMiiGkxhtTgmbZA50OCdh7dNi+GzGYhartB4YHluLHIF avK4g4hb97ldKynm0DOh7IqBQH/FRDLcSmaF0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ieEfJQsM4sBvXx7mXsGG38weJFE2pHNKljsnVCbD9xI=; b=aRPsXDmuO7/hK8PLcOXhzc8A8ytnlVxAPmqmV/TF5LWGdNFsDLmbyiBuzM+9G7ucK/ yAwFWZ5laK01BboNtJhblPYATk0z6p/9FcPK2f//Gif2UaQq0Km3Ac34ywt5j76y8GiN Lg2ABMv/KOziQqxT9RptX7YhB9MyX38WOr2zumnjH3hLJjw2jGZSCPV1El3X7OknUpeg 0kihRrwb36c/W7pDMcwCFDmfAf6NdQPRckGDE7BXKxdOfZZNCneCXrjFhp+xnNtbwg2U 8r7mpFxS6ewTKwCLeCahpunB5TiBSaXHTIeyMP16p/I7+MU+vERSGrxWx7daQvnzgcaE r+3A== X-Gm-Message-State: APf1xPDQAx9Qe9YJbxRMR3f/y5OXgsuODlBLWx5bVB1HA8mntIbonlPv Qa9ajmwTiU8+oyUbPXlLy4rPkeEDfw8= X-Received: by 2002:a17:902:b904:: with SMTP id bf4-v6mr9693178plb.195.1519633383679; Mon, 26 Feb 2018 00:23:03 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.22.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:23:03 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org (moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 16/52] arm64: futex: Mask __user pointers prior to dereference Date: Mon, 26 Feb 2018 16:19:50 +0800 Message-Id: <1519633227-29832-17-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon commit 91b2d3442f6a upstream. The arm64 futex code has some explicit dereferencing of user pointers where performing atomic operations in response to a futex command. This patch uses masking to limit any speculative futex operations to within the user address space. Signed-off-by: Will Deacon Signed-off-by: Catalin Marinas Signed-off-by: Alex Shi Conflicts: change on old futex_atomic_op_inuser function instead of arch_futex_atomic_op_inuser in arch/arm64/include/asm/futex.h --- arch/arm64/include/asm/futex.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/futex.h b/arch/arm64/include/asm/futex.h index 85c4a89..1943cf6 100644 --- a/arch/arm64/include/asm/futex.h +++ b/arch/arm64/include/asm/futex.h @@ -48,13 +48,14 @@ do { \ } while (0) static inline int -futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) +futex_atomic_op_inuser (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 oldval = 0, ret, tmp; + u32 __user *uaddr = __uaccess_mask_ptr(_uaddr); if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) oparg = 1 << oparg; @@ -106,15 +107,17 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) } static inline int -futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, +futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *_uaddr, u32 oldval, u32 newval) { int ret = 0; u32 val, tmp; + u32 __user *uaddr; - if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32))) + if (!access_ok(VERIFY_WRITE, _uaddr, sizeof(u32))) return -EFAULT; + uaddr = __uaccess_mask_ptr(_uaddr); uaccess_enable(); asm volatile("// futex_atomic_cmpxchg_inatomic\n" " prfm pstl1strm, %2\n" -- 2.7.4