[PATCH] arm: mm: Implement copy_from_kernel_nofault_allowed()
From: Daniel Thompson
Date: Thu Jan 13 2022 - 04:34:45 EST
Currently copy_from_kernel_nofault() can actually fault (due to software
PAN) if we attempt userspace access. In any case, the documented
behaviour for this function is to return -ERANGE if we attempt an access
outside of kernel space.
Implementing copy_from_kernel_nofault_allowed() solves both these
problems.
Signed-off-by: Daniel Thompson <daniel.thompson@xxxxxxxxxx>
---
arch/arm/mm/Makefile | 2 +-
arch/arm/mm/maccess.c | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 arch/arm/mm/maccess.c
diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile
index 3510503bc5e6..d1c5f4f256de 100644
--- a/arch/arm/mm/Makefile
+++ b/arch/arm/mm/Makefile
@@ -3,7 +3,7 @@
# Makefile for the linux arm-specific parts of the memory manager.
#
-obj-y := extable.o fault.o init.o iomap.o
+obj-y := extable.o fault.o init.o iomap.o maccess.o
obj-y += dma-mapping$(MMUEXT).o
obj-$(CONFIG_MMU) += fault-armv.o flush.o idmap.o ioremap.o \
mmap.o pgd.o mmu.o pageattr.o
diff --git a/arch/arm/mm/maccess.c b/arch/arm/mm/maccess.c
new file mode 100644
index 000000000000..0251062cb40d
--- /dev/null
+++ b/arch/arm/mm/maccess.c
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/uaccess.h>
+#include <linux/kernel.h>
+
+bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)
+{
+ return (unsigned long)unsafe_src >= TASK_SIZE;
+}
--
2.33.1