From patchwork Fri Mar 9 09:06:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10270393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6062560594 for ; Fri, 9 Mar 2018 10:24:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47B3229D71 for ; Fri, 9 Mar 2018 10:24:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B4CE29D75; Fri, 9 Mar 2018 10:24:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C7AE529D71 for ; Fri, 9 Mar 2018 10:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=cn5mE1S0ODP3Lyzisubz10GEDf4+Fapsz1nQyJoXVrc=; b=swrOTDJF6HFq0Q/aBCLgztvEUC gh1bWO1jnhZIpzcI/n54XfAgra5i/yhqycb8cRORinxNX8KKb5/PkyPbYudUi4YjTez2h0n1JKN2u gNrxRm6vRa7+CbUzOvfwsTS05rDj2yvqh4Q/vdhfcju6rvJFIcWskcXJcPKW6tui5zAD9a/5b4luD 66+fHNOsVX/habpcYSv0ItOLKRovKA8YmasUXg1mD//pbCinSxNhrIt7br+AUEe2DzuCR0pc0/z7k 12SAN2mtxR93mOpZ8GDeht6voJd3t3aesWPrqQb6L7Zk5BELO9UwUWgrY+CpVDjUWwPeCFr5enUUD dDJ/Wk8w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1euFCb-0007CG-0M; Fri, 09 Mar 2018 10:24:41 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euF7j-0002qN-Ip for linux-arm-kernel@bombadil.infradead.org; Fri, 09 Mar 2018 10:19:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SyI3U36shF5F9LaIc+liAk6e/lcIQNYXEEYj4a+4ihc=; b=E8Z0iPVYcMJ/fk3DDFG+FCuyR ekrzFbjHG+AKpK5ogycBmIZrK+ciSzxVNYHkU5fXEtkAhR+kSuyA2BsmJvVLaXM724whkuoyQCMWg Ox6dN+BkQ7mSK7QrmqHfVLFOjh5f8E9NKKb9eN3eacZbNJdSkGX59SzJewTF0PxS6eAfy0N/kviRF e8ZZLImuqZ60usrjhmHtSpvGVoLo38lXhLgD69Bqt55imEStlntsgz1R/aEEFmZsuMHwDCz/t040v wSY4U1o/jtEB3tzoxq2+YzdGvyuaUldp3eNuZx6dNu2bVEWa5g1mtD+GRcv+B/MBGYcdxsFPp6o1x J/hEq4O3Q==; Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1euE1n-0002dN-V8 for linux-arm-kernel@lists.infradead.org; Fri, 09 Mar 2018 09:09:29 +0000 Received: by mail-pf0-x244.google.com with SMTP id f80so1051164pfa.8 for ; Fri, 09 Mar 2018 01:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SyI3U36shF5F9LaIc+liAk6e/lcIQNYXEEYj4a+4ihc=; b=LYzArlXq/3UMPk6266o/crAZATK2k3rEP1AILKBnLEo/ZLcVEmFWSox+QX8IJMdhd3 nIiYMQ3Y8ln8+zSyvszp73AXNv6CjzVMfb4BI7ch6fkPRMfvLUdCo40aZSR/yz6VZumL 4JzeBo9BZIJxq2AlO6mLnXopjh9g8yjFSm+8c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SyI3U36shF5F9LaIc+liAk6e/lcIQNYXEEYj4a+4ihc=; b=ZpLpIsnSPULoLrKMR5qMQBaepv8G3sUXfGtijc+kUIyZ1fc9IuWgYEIdXFz/kVfe4N DqZ7S5acrQ0PJJZiPZOp/pHD/UNkit3ETA7nPZ3wvrP8hc+tgWkwt1okfa0v5N0VQrTm frdEKBAavpFdDlMpVbQo7EFCV7YvQ4sLF4ijAkZ9BCgPQPA9Qmq9Y1cDLYUjo6Fhq8LL 7trhrfCMdek+TbYx9skOEd3v6vmv181Mj+61oGDxyH+sWbwHypcytCKtqhVwtocixx5k bAqpfaPb6iYNBgFD51iEqbNfrPV+fiFgjZlW1Hpm8SvjDOhJm7u83FO9CZ5okv9ZS65U yEEg== X-Gm-Message-State: APf1xPB1zT8CBHJVGVZ8hbEtKR3Lgvup6RuC+dTyQNK9QNr9xtyWiK32 LxSj1m9ghUt8cIWpNm0siKGi6Q== X-Google-Smtp-Source: AG47ELtxtHCyR39/++Q2vVvh5en3j9YJDnj0ANQQy31sCKUzfLsEXUcHxyqh7Rnj1IaYvhUhSxRaXw== X-Received: by 10.101.97.139 with SMTP id c11mr23159558pgv.439.1520586552954; Fri, 09 Mar 2018 01:09:12 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id c7sm1961752pfg.36.2018.03.09.01.09.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Mar 2018 01:09:12 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , broonie@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 10/39] arm64: futex: Mask __user pointers prior to dereference Date: Fri, 9 Mar 2018 17:06:53 +0800 Message-Id: <20180309090722.26279-11-alex.shi@linaro.org> X-Mailer: git-send-email 2.16.2.440.gc6284da In-Reply-To: <20180309090722.26279-1-alex.shi@linaro.org> References: <20180309090722.26279-1-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180309_040928_246340_5F1AA5B3 X-CRM114-Status: GOOD ( 13.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alex Shi MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 5f3ab8c1db55..27eebc6f6976 100644 --- a/arch/arm64/include/asm/futex.h +++ b/arch/arm64/include/asm/futex.h @@ -53,13 +53,14 @@ : "memory") 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; @@ -111,15 +112,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); asm volatile("// futex_atomic_cmpxchg_inatomic\n" ALTERNATIVE("nop", SET_PSTATE_PAN(0), ARM64_HAS_PAN, CONFIG_ARM64_PAN) " prfm pstl1strm, %2\n"