From patchwork Tue Dec 21 13:42:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12696980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 56D47C433EF for ; Tue, 21 Dec 2021 13:44:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=776hTe5JT+Wechlvh9sI7ajHgFQQITbhlii5cyJRpI8=; b=S/whQ/SOTs88rL 9xrX9h9ECrS9aF9Rjgamv5oqEAKvEXj1/8Y37CbP5VE8cNCsE+lWzH8ClBs7uUrvDl0H5TXjJ77Yu dcLTtdcgor4uk+zQNUdN9NfekkKcr/+A4e4/wq5EfBvnoSbZG2O5Pn8SuxWvvtIbHBFqHmafoO0iB RfJUjAmPa4o4wFr0KkmftjkhNKWhXrlE+bcpoFTqRHtw690JtLCahfYvsqU6UVeKNFqZ/WO0Ak89p GOhGG91VBsVCMg4IhcQZxc/B9o5LyyC0ImeXaDEAPXvAqhTtN+MWcJGvTmLun05OgVnEVGCffQQyQ i6956xr8qL+eSDaFm/+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzfQA-0070SU-Vn; Tue, 21 Dec 2021 13:43:15 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzfQ0-0070Qd-B3 for linux-arm-kernel@lists.infradead.org; Tue, 21 Dec 2021 13:43:05 +0000 Received: by mail-pl1-x629.google.com with SMTP id u16so4726481plg.9 for ; Tue, 21 Dec 2021 05:43:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cXE5nz2Dh2XMLOux2ADL8rWM/k/7Rz6q0XCLb0tocUs=; b=q1UOmn7yHWeUoMiofIk4LZM+5++enkj7NRuKRkE2DB0l96cvv9xOw1bXNg0i//9SkR BmTHlusS4Ja96HJpbVoVC9YYyOltLeqULZ5J0VZvrg/JFUiiL9Ovknijqvbls0LX2TKW LU02kq/hXXMViDG9gEIAmJcKWnog6IrUK8AeJMMAOSGKwZPXwlHC36b2bWwVi7K413Rj QKqdDuOYDqqHsAmd+VFanfka33aKBaJlwgGB7MLHmymj0SfFnDXISQ+8GQ7IMCI12tFq 77jpFOwaEo6zlAEfJPrR4dIdelzXv7+lF5MK2TF7YBpt0NM1o/9Qor+XcgpZouCLd/Lc MWSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cXE5nz2Dh2XMLOux2ADL8rWM/k/7Rz6q0XCLb0tocUs=; b=t6J3x1NPs60I6jTA8rJCKBppLnkJj5w57UUVWbItr3v1NGPvdUpMAOFMF9WDypWDmy UcOzp2QSoM36UP0ws1a4DHA9WcppH4NBptuBiGuJ/iFnYO+y6uxAX3XA8hmjj4OHooks LO2cq7y4t5OJIye9mLrixOOmwgUVzSSm6g1mbgl3BOw95WY7AOq2hF74H/At6U7baJwi yqw9EMAkkH4JLq3yCeKxPQ5/EIqbwmWseAbRGwA+Okrb+43M56bnGfnSm7Z5oKpXgaGf AdmhmAPXSP6hdR9sJJS6L15AcUDDbe1DMZ4WAR6QJ1++6cFGOxsYGQPv5g5WUn9PJ8R2 wQrw== X-Gm-Message-State: AOAM530Rj+Mw3/Vjf/Gk/SpG9SQ0Dl71sVgy29wxDjH869+Fj//g2Oej aK0fH4LmOXHXn/nEC0yrDQwFrCrnIg== X-Google-Smtp-Source: ABdhPJxkZUVO886mZzVK5FUKR/3TQMJpIbaJYd3M6u2BzXo5GysZC9EFDLV6Y3g3Z3LF1v1qVLATRw== X-Received: by 2002:a17:902:a618:b0:148:f7f6:ee8b with SMTP id u24-20020a170902a61800b00148f7f6ee8bmr3416832plq.93.1640094182715; Tue, 21 Dec 2021 05:43:02 -0800 (PST) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id e16sm4699143pfd.38.2021.12.21.05.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:43:02 -0800 (PST) From: Pingfan Liu To: linux-arm-kernel@lists.infradead.org Cc: Pingfan Liu , Catalin Marinas , Will Deacon , Mark Rutland , Vincenzo Frascino , Andrey Konovalov , Arnd Bergmann Subject: [PATCH 2/2] arm64: uaccess: disable preempt during uaccess PSTATE.{PAN, TCO} Date: Tue, 21 Dec 2021 21:42:42 +0800 Message-Id: <20211221134242.98877-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211221134242.98877-1-kernelfans@gmail.com> References: <20211221134242.98877-1-kernelfans@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211221_054304_401689_F76DA16C X-CRM114-Status: GOOD ( 13.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For the pair of uaccess_enable_privileged()/uaccess_disable_privileged(), if preemption happens, the exposure of the access to user space by another code piece is unexpected. For the pair of __uaccess_enable_tco_async()/__uaccess_disable_tco_async(), the change of PSTATE.TCO is exposed unexpectedly. For the two cases, simply disable preemption to fix the issue. Signed-off-by: Pingfan Liu Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Vincenzo Frascino Cc: Andrey Konovalov Cc: Arnd Bergmann To: linux-arm-kernel@lists.infradead.org --- arch/arm64/include/asm/uaccess.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 406888877bbd..37d5531f210d 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -193,14 +193,18 @@ static inline void __uaccess_enable_tco(void) */ static inline void __uaccess_disable_tco_async(void) { - if (system_uses_mte_async_or_asymm_mode()) - __uaccess_disable_tco(); + if (system_uses_mte_async_or_asymm_mode()) { + __uaccess_disable_tco(); + preempt_enable(); + } } static inline void __uaccess_enable_tco_async(void) { - if (system_uses_mte_async_or_asymm_mode()) + if (system_uses_mte_async_or_asymm_mode()) { + preempt_disable(); __uaccess_enable_tco(); + } } static inline void uaccess_disable_privileged(void) @@ -208,13 +212,16 @@ static inline void uaccess_disable_privileged(void) __uaccess_disable_tco(); if (uaccess_ttbr0_disable()) - return; + goto out; __uaccess_enable_hw_pan(); +out: + preempt_enable(); } static inline void uaccess_enable_privileged(void) { + preempt_disable(); __uaccess_enable_tco(); if (uaccess_ttbr0_enable())