From patchwork Tue Dec 21 13:42:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pingfan Liu X-Patchwork-Id: 12696979 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 15762C433F5 for ; Tue, 21 Dec 2021 13:44:36 +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: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:In-Reply-To:References: List-Owner; bh=mc/HrNAOuIGdW/VHvHlOcHM2+5N75zrppUTF1atkWMI=; b=v7PbPH6TU/IZ3w gbRLU9izsei9OQL61ZnR9SEw2J6/zefG2PgGiZw+ckC/wJ58BVCxwji3cC0u5Uj4PL1SsBVmSQ8AG ABvps8hj0PGWoGm6R/UXokMauNgaasuOcNcL35IHDyP/1y6CEKBP/0Rit+mRPPJGQftI9JE3znol0 M365CbzuhHOFi3Nm32K9eDPfHkcRqOVwW9GyIhA9kyfDCzfzczlzl8xETRIbzzqxudgp/IIytlmkS ddoJ0X9OLmk1PUR6HAWgOmGJgLp1P5RmAjOaX9nLLVVF8U3XSLWNkc1EZ36OcpAjGZ5OGb8aEkD/s z9aEv8X0buWBBLLpiCHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzfQ1-0070Qy-Ll; Tue, 21 Dec 2021 13:43:05 +0000 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mzfPy-0070Q0-Kf for linux-arm-kernel@lists.infradead.org; Tue, 21 Dec 2021 13:43:03 +0000 Received: by mail-pj1-x1036.google.com with SMTP id k6-20020a17090a7f0600b001ad9d73b20bso3249463pjl.3 for ; Tue, 21 Dec 2021 05:42:58 -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:mime-version :content-transfer-encoding; bh=gRxAYTk6EoY+ZnlT2h2yFEnUdiK3IqlpulC9UoGiUp8=; b=hBbLXujgDN1DpeGbKSrCuQAJSMkc7ejQ7LJWCdEgw/8EFRFw4CQP4aOWTRf5sCEbr/ FqzKKMpDnhvbCTetc96OqZvC7y05rSZNcWHehXa4djqv9CCPowwC3dBre7JQYB1UemkV s6nnemOOpSnZgbthBUXBwSDmDzIl5QPpHwG4LrRFgY8bj+jjheWCVIkK+Q0uMVYWQnQ0 L+Ap+xtzPY5ZJ17HU5Uu3AJJG3kl7W2D5hu05IprrPFqHziJBaFkx2G0RWBdkEygDhyA +EUy/eItxpkZhNWkEuFYAGpexk6DgO1vbzbfAWPy0WcFpeh9nK+UYxbyiWqj/VQB/tFo en2w== 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:mime-version :content-transfer-encoding; bh=gRxAYTk6EoY+ZnlT2h2yFEnUdiK3IqlpulC9UoGiUp8=; b=q8RzWkEMPBC8QugMlvv8yHSwQP9qB98hCe+5ggB3C4Eby0DntX1Vk+xH6JAvrsnSI0 TIr7qfSsjWLlTxJ07KiQ2bqZZ2yCdg/KTIm56rB5EzaoUpDyK5AXrN22KI+3SayreJA9 xQT2pDztLrE8hPXL5eB6nPtB04YWsemFsuSuLh8OBzGYAmyFCWGtfqWVtTOuU2hTk12T XrSMqJJuh0FUqBxmUHx0iIxThAKZjITvZcEkZbm1TekDZwirBGp3PAYZP8WFfRpaLEgD 6bwxgs9iwtEujInZMXHQ4m5h34rG469mX2PEinadtiAEwSNKukoZlvEcse8pGd/Six3d KukA== X-Gm-Message-State: AOAM531i2SbGutjnlGJl5dVFmhR2PkQkBLuVw0mBds5JlBje8ghdzA6F w+wFjxvRX4cbOlIqhGrSIk9xw5iFuQ== X-Google-Smtp-Source: ABdhPJxvPt6wU7dU7jRSm8sPQ0shB7owQLzgpOLPRM5Ya2AaaOnA/+OjFzDYMAMJbg51LJQ7a6FquA== X-Received: by 2002:a17:90a:ba95:: with SMTP id t21mr4025598pjr.113.1640094178210; Tue, 21 Dec 2021 05:42:58 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 05:42:57 -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 1/2] arm64: uaccess: disable preempt during uaccess through ttbr0 Date: Tue, 21 Dec 2021 21:42:41 +0800 Message-Id: <20211221134242.98877-1-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211221_054302_716441_5377EBFD X-CRM114-Status: GOOD ( 10.71 ) 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 If using software PAN, the ttbr0 should keep unchanged, otherwise, considering the following scenario: task1 __uaccess_ttbr0_enable() switch_mm(this,next,tsk), which resets ttbr0 to __pa_symbol(reserved_pg_dir) switch_mm(prev,this,tsk), which can not re-install the user page table automatically Tackle this issue by disabling preemption. 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 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 3a5ff5e20586..406888877bbd 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -121,6 +121,7 @@ static inline bool uaccess_ttbr0_disable(void) if (!system_uses_ttbr0_pan()) return false; __uaccess_ttbr0_disable(); + preempt_enable(); return true; } @@ -128,6 +129,7 @@ static inline bool uaccess_ttbr0_enable(void) { if (!system_uses_ttbr0_pan()) return false; + preempt_disable(); __uaccess_ttbr0_enable(); return true; } 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())