linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Pingfan Liu <kernelfans@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Pingfan Liu <kernelfans@gmail.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH 2/2] arm64: uaccess: disable preempt during uaccess PSTATE.{PAN, TCO}
Date: Tue, 21 Dec 2021 21:42:42 +0800	[thread overview]
Message-ID: <20211221134242.98877-2-kernelfans@gmail.com> (raw)
In-Reply-To: <20211221134242.98877-1-kernelfans@gmail.com>

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 <kernelfans@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
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())
-- 
2.31.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-12-21 13:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21 13:42 [PATCH 1/2] arm64: uaccess: disable preempt during uaccess through ttbr0 Pingfan Liu
2021-12-21 13:42 ` Pingfan Liu [this message]
2021-12-22 13:02   ` [PATCH 2/2] arm64: uaccess: disable preempt during uaccess PSTATE.{PAN,TCO} Catalin Marinas
2021-12-23  9:39     ` Pingfan Liu
2021-12-22 12:59 ` [PATCH 1/2] arm64: uaccess: disable preempt during uaccess through ttbr0 Catalin Marinas
2021-12-23  9:36   ` Pingfan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211221134242.98877-2-kernelfans@gmail.com \
    --to=kernelfans@gmail.com \
    --cc=andreyknvl@gmail.com \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).