]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
arm64: Add support for user sub-page fault probing
authorCatalin Marinas <catalin.marinas@arm.com>
Sat, 23 Apr 2022 10:07:50 +0000 (11:07 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Mon, 25 Apr 2022 09:25:43 +0000 (10:25 +0100)
With MTE, even if the pte allows an access, a mismatched tag somewhere
within a page can still cause a fault. Select ARCH_HAS_SUBPAGE_FAULTS if
MTE is enabled and implement the probe_subpage_writeable() function.
Note that get_user() is sufficient for the writeable MTE check since the
same tag mismatch fault would be triggered by a read. The caller of
probe_subpage_writeable() will need to check the pte permissions
(put_user, GUP).

Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20220423100751.1870771-3-catalin.marinas@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/Kconfig
arch/arm64/include/asm/mte.h
arch/arm64/include/asm/uaccess.h
arch/arm64/kernel/mte.c

index 57c4c995965f8291bf3c89303bc8c00dc0276dd4..290b88238103b0599e8876dbdb4b7513822d783d 100644 (file)
@@ -1871,6 +1871,7 @@ config ARM64_MTE
        depends on AS_HAS_LSE_ATOMICS
        # Required for tag checking in the uaccess routines
        depends on ARM64_PAN
+       select ARCH_HAS_SUBPAGE_FAULTS
        select ARCH_USES_HIGH_VMA_FLAGS
        help
          Memory Tagging (part of the ARMv8.5 Extensions) provides
index adcb937342f14d2d431eab7bff46e90a19f9a026..aa523591a44e5635ee1d2ed2fd4f22e418513fa6 100644 (file)
@@ -47,6 +47,7 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg);
 long get_mte_ctrl(struct task_struct *task);
 int mte_ptrace_copy_tags(struct task_struct *child, long request,
                         unsigned long addr, unsigned long data);
+size_t mte_probe_user_range(const char __user *uaddr, size_t size);
 
 #else /* CONFIG_ARM64_MTE */
 
index e8dce0cc5eaae7f50d03fed5146ba9004e1039b8..63f9c828f1a7103a39aa43d7db0b0c08cf940a52 100644 (file)
@@ -460,4 +460,19 @@ static inline int __copy_from_user_flushcache(void *dst, const void __user *src,
 }
 #endif
 
+#ifdef CONFIG_ARCH_HAS_SUBPAGE_FAULTS
+
+/*
+ * Return 0 on success, the number of bytes not probed otherwise.
+ */
+static inline size_t probe_subpage_writeable(const char __user *uaddr,
+                                            size_t size)
+{
+       if (!system_supports_mte())
+               return 0;
+       return mte_probe_user_range(uaddr, size);
+}
+
+#endif /* CONFIG_ARCH_HAS_SUBPAGE_FAULTS */
+
 #endif /* __ASM_UACCESS_H */
index 78b3e0f8e997cab99b70bffe181949d8d29610dc..35697a09926ffe9d87f39cfc05af63a879d78daa 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/swapops.h>
 #include <linux/thread_info.h>
 #include <linux/types.h>
+#include <linux/uaccess.h>
 #include <linux/uio.h>
 
 #include <asm/barrier.h>
@@ -543,3 +544,32 @@ static int register_mte_tcf_preferred_sysctl(void)
        return 0;
 }
 subsys_initcall(register_mte_tcf_preferred_sysctl);
+
+/*
+ * Return 0 on success, the number of bytes not probed otherwise.
+ */
+size_t mte_probe_user_range(const char __user *uaddr, size_t size)
+{
+       const char __user *end = uaddr + size;
+       int err = 0;
+       char val;
+
+       __raw_get_user(val, uaddr, err);
+       if (err)
+               return size;
+
+       uaddr = PTR_ALIGN(uaddr, MTE_GRANULE_SIZE);
+       while (uaddr < end) {
+               /*
+                * A read is sufficient for mte, the caller should have probed
+                * for the pte write permission if required.
+                */
+               __raw_get_user(val, uaddr, err);
+               if (err)
+                       return end - uaddr;
+               uaddr += MTE_GRANULE_SIZE;
+       }
+       (void)val;
+
+       return 0;
+}