diff mbox series

[1/3] MIPS: uaccess: Added __get/__put_kernel_nofault

Message ID 20210330172702.146909-2-tsbogend@alpha.franken.de (mailing list archive)
State Superseded
Headers show
Series MIPS: Remove get_fs/set_fs | expand

Commit Message

Thomas Bogendoerfer March 30, 2021, 5:26 p.m. UTC
Added __get/__put_kernel_nofault as preparation for removing
get/set_fs.

Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
---
 arch/mips/include/asm/uaccess.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Christoph Hellwig March 30, 2021, 5:48 p.m. UTC | #1
On Tue, Mar 30, 2021 at 07:26:58PM +0200, Thomas Bogendoerfer wrote:
> Added __get/__put_kernel_nofault as preparation for removing
> get/set_fs.

For !CONFIG_EVA __get_user_common is simply defined to
__get_kernel_common, which probably does the wrong thing here
as it would allow access to user space addresses, won't it?
Thomas Bogendoerfer March 30, 2021, 8:02 p.m. UTC | #2
On Tue, Mar 30, 2021 at 07:48:35PM +0200, Christoph Hellwig wrote:
> On Tue, Mar 30, 2021 at 07:26:58PM +0200, Thomas Bogendoerfer wrote:
> > Added __get/__put_kernel_nofault as preparation for removing
> > get/set_fs.
> 
> For !CONFIG_EVA __get_user_common is simply defined to
> __get_kernel_common, which probably does the wrong thing here
> as it would allow access to user space addresses, won't it?

it does, so I'm missing a copy_from_kernel_nofault_allowed() function,
which only allows kernel access, right ?

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index d273a3857809..c5cab0b8f902 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -355,6 +355,18 @@  do {									\
 	(val) = __gu_tmp.t;						\
 }
 
+#define HAVE_GET_KERNEL_NOFAULT
+
+#define __get_kernel_nofault(dst, src, type, err_label)			\
+do {									\
+	int __gu_err;							\
+									\
+	__get_kernel_common(*((type *)(dst)), sizeof(type),		\
+			    (__force type *)(src));			\
+	if (unlikely(__gu_err))						\
+		goto err_label;						\
+} while (0)
+
 #ifndef CONFIG_EVA
 #define __put_kernel_common(ptr, size) __put_user_common(ptr, size)
 #else
@@ -483,6 +495,18 @@  do {									\
 
 extern void __put_user_unknown(void);
 
+#define __put_kernel_nofault(dst, src, type, err_label)			\
+do {									\
+	type __pu_val;					\
+	int __pu_err = 0;						\
+									\
+	__pu_val = *(__force type *)(src);				\
+	__put_kernel_common(((type *)(dst)), sizeof(type));		\
+	if (unlikely(__pu_err))						\
+		goto err_label;						\
+} while (0)
+
+
 /*
  * We're generating jump to subroutines which will be outside the range of
  * jump instructions