From patchwork Fri Jul 12 05:28:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 11041559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8D5E14E3 for ; Fri, 12 Jul 2019 05:48:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9380428AD3 for ; Fri, 12 Jul 2019 05:48:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 820E228BAD; Fri, 12 Jul 2019 05:48: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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 2244328AD3 for ; Fri, 12 Jul 2019 05:48:25 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=QEyOhIh6jn1G4FFCKmRcBgUq3clX2HV7zBmBKtrFTTE=; b=JV8PlWBmyI22wz AaRy9WlNYXlUWTnebjSXOv+aekeYRAN8f/VLmlr0XGtkHDkIDioTcnphj38cu5A0VGwgNCBNWmwWR /Bn87w3z0w60tr7/+hxK+lz+v2ACzt7vujAA87KCxK4wSjU2lYl0CL/elp1syRVPkbi1jHfocCHFC tuki0SjeJOGGIgGiNOZr1G8/MDcrBiCB9/COQRjvUg2u1kakAz8hb/l/nz4fYuKDL2Qt3vR3naRFj doHh3XG6pnNfSJ4wUDv/j51BTGvwMil6LJ7R/liE14oXbqGmg/h31e6du199Y/Z9w9YsUlzITM36E IZ9LpsFQYbSTkpv9qqeQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hloPr-0008IK-Ee; Fri, 12 Jul 2019 05:48:19 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hlo93-0002uE-Lw for linux-arm-kernel@lists.infradead.org; Fri, 12 Jul 2019 05:31:00 +0000 Received: by mail-pf1-x441.google.com with SMTP id u14so3802529pfn.2 for ; Thu, 11 Jul 2019 22:30:57 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=PDeednBQHQCWJxR0NKh3z84Gd8kBTabHNB90hamsE18=; b=fg+1pG/65q1qXXBewk6qvQ3fXz3wzzkJ7zUevy8Y1aRCJChOX+8X7X3JDJPcYtWKI2 VO4DcEBZ9cyrhoulmGddYbjt5ggPKQHxtm8F3clPGhci3I1aXUQmLQJRB7Ezb8gl8fLi FhkAa/BV2XsSz+9MFltsJX4GzpC+8DMP6ODQsCzXh5nf80aw/2plK5nWH5JiYQ2ocbn1 BaKR8GDvosIPOqJOo7vrd6f/ByVec4o3rRBqiMJ/jO7ZzqAfXXTufXDJ1StpfdiAn6gi cnMvgYBDyPFw+RExwgQW9uLq9kLoB/Z/shDKW1HTqmD70MPowKwbZVLiMB0qfnwh/Hw6 +TPw== 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:mime-version:content-transfer-encoding; bh=PDeednBQHQCWJxR0NKh3z84Gd8kBTabHNB90hamsE18=; b=Oh5sUJLNBU/AbuJcuVbsqmqvGFQmlIqXB/LmO9iWbzxhABPSbyVE1UGDwfzVPGqzWO dTr/R5BsYshSouhE3bthKhLL9OhEfr4UgpUcW+1iCfc5VwFQGiazjk6u4dywnGOfiE9s o7fnwQ+Z/plA3SaxwhmiEIOTlcifFhXxBNZ67Qo9c/6OXaBQEyWBOA/WkiKjq42kjIgL XSXZNPBsBenmiiUFzCobtF0N/WjLseD58JpiBI4OyEXfh8fWoyeybETvwrzLUSr11nfR DfKrSAL5xF8gqq1VoQRHZm2SSODSBcoTOsZGOw+L50V+qOpOhgGqpMG/aLFjRkYSGcKp 3Pkw== X-Gm-Message-State: APjAAAU2FwVal4RuxViBVey0Fybv+gLkRsl/LeB4ziLume1U0a0rNFtj nmLyICLsc4GqJUjCTVnRzKvowA== X-Google-Smtp-Source: APXvYqzW2ZFdIDBVTYKNu8BFlnnBclltK1PVkRmVauZ0T/9ZSkmOtGZ5z0BYckQlNm2+hJU6Y866SQ== X-Received: by 2002:a17:90a:bf02:: with SMTP id c2mr9448970pjs.73.1562909456962; Thu, 11 Jul 2019 22:30:56 -0700 (PDT) Received: from localhost ([122.172.28.117]) by smtp.gmail.com with ESMTPSA id s67sm7989665pjb.8.2019.07.11.22.30.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jul 2019 22:30:56 -0700 (PDT) From: Viresh Kumar To: stable@vger.kernel.org, Julien Thierry Subject: [PATCH v4.4 V2 43/43] arm64: futex: Mask __user pointers prior to dereference Date: Fri, 12 Jul 2019 10:58:31 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190711_223057_816072_A442CC2F X-CRM114-Status: GOOD ( 11.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Marc Zyngier , Viresh Kumar , Will Deacon , mark.brown@arm.com, Catalin Marinas , Russell King , linux-arm-kernel@lists.infradead.org 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 91b2d3442f6a44dce875670d702af22737ad5eff 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: Viresh Kumar --- 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 34d4d2e2f561..8ab6e83cb629 100644 --- a/arch/arm64/include/asm/futex.h +++ b/arch/arm64/include/asm/futex.h @@ -53,9 +53,10 @@ : "memory") static inline int -arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr) +arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *_uaddr) { int oldval = 0, ret, tmp; + u32 __user *uaddr = __uaccess_mask_ptr(_uaddr); pagefault_disable(); @@ -93,15 +94,17 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, 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"