From patchwork Mon Feb 26 08:19:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10241669 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 95E6360208 for ; Mon, 26 Feb 2018 08:47:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8ACCD29D27 for ; Mon, 26 Feb 2018 08:47:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F5D229D2C; Mon, 26 Feb 2018 08:47:25 +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 DB86029D27 for ; Mon, 26 Feb 2018 08:47:24 +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:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3RhebAIouF4rkkTM32SgMz4H1pD9KAITKDvKFT/QDsM=; b=uGrJAYWEqcZLul 1V4VB2KWgCxH5rhBs0IT9PiqWp739+/e7YHGc+Ob2hUp5ScB08a9FZ0pJtZVh4stH4eT6B1B/N8Zx L6LpKKU3xG3Tl9TJx2fnOXCyPyzt3uzpkVMOh7KB+CTuZ3aSRXfvKwuo/3IAIoLgGvwNhfs1hzvbv OV2gnTgwIUYYzoTJSaAv+kqJPj7DZtB7LR+nvG1BNUzgGs+5t+vzeYCpBUaYuHFIm+b5a92xMGXsw bHnyBAJEvmcN2MYYaLExskOTBzWUu3Zb+UdsKWL6K4rLbfMa5LkzwM9WrvwoHU1HHG7Yw/FYxEHjA 9ttvSUB/F55s0tZXKy/A==; 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 1eqERF-0004ea-OD; Mon, 26 Feb 2018 08:47:13 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqEK8-0005la-Uu for linux-arm-kernel@bombadil.infradead.org; Mon, 26 Feb 2018 08:39:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:To:From:Sender:Reply-To:Cc: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=ieEfJQsM4sBvXx7mXsGG38weJFE2pHNKljsnVCbD9xI=; b=aQ7M2JK0cKir43n8QSV8WF/4m /cxD3M1GsqsEkiti+CBcpD2a5kKzEETd8aN/u1BHpAnkYYtu5zIkY/6suz0AEhqGBAyIR19xCBtzA qcpbLZXe2+3zeLsQZneRAXIRqhKc/c6hnE29L4uJr9kqBjgqwjP+PNpeVtsN/VGTPFSJ6WO7wjmOM SiQ/LwZ9aS8UuCPrbDkgwx7yImLgEuf3PIJk5Co7AwjWj48/RyCkegBlfd09b7DR5cmAdzUfvj/Zf GRjqMDkzfTl+OEfS9t08Oeud0Phzt+5n9liAssNP20zt9XV8yzZ0TOsfOkrqxAsCbMVeep26CD9M4 5y3AS9IEQ==; Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE43-00069c-Qf for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:23:18 +0000 Received: by mail-pl0-x244.google.com with SMTP id 31so8855422ple.9 for ; Mon, 26 Feb 2018 00:23:05 -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=Phh8jQF/bP6ae3Uup+evTzaD9o/NPHGSKBF82Yj8qt4LNK9RUBTe9RGcEhwmg57fb5 9SZAUMPCstM67ua5ghwNww+nSG6AQzU1pEpsbB24lc+vvAXE5SduI8ZldBgJ8uvH31Wo ntO7+68fre7YoLMTEbL8u68WslVo/CUixW3qJBNNryHTUVnz3iU943Jt1RUceXxBU8Wm kYnAPCl76UQ73vvi8XsVkvir6/U2i9Lx9x3cnRtCzDicg+2otRRkXMr+aphqc6y7FVU2 64LEJtG/MUcZcckA7d7dj2K14c0KzUsm7y+GBG3q8GAdfTkquAKORqqvP3UCqCD1i0ti AjIQ== X-Gm-Message-State: APf1xPAjRR3WYKbXXgDAhr7STrCoWYsiZJuiAwSja39z3iuCvhq7Nrvf Y8NYhV5WOBF6yiWGgtTODHWTaw== X-Google-Smtp-Source: AH8x225wa5C82sbdPuxDIVVKyXcz6iybpRY48g9XczgbMWcpOWOXvjM1gT2x8Ztw41KwxZR+HxG+oQ== 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_082315_855673_6B452F4A X-CRM114-Status: GOOD ( 13.53 ) 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: , 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 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"