mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [wrecked] x86-add-failure-injection-to-get-put-clear_user.patch removed from -mm tree
@ 2020-10-13 18:20 akpm
       [not found] ` <CAG_fn=U+zDi-Z7FmkhUWsMjVALvG-jkOgvmjiz6_HfjzLcF4UQ@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: akpm @ 2020-10-13 18:20 UTC (permalink / raw)
  To: akinobu.mita, alinde, andreyknvl, arnd, bp, corbet, dvyukov,
	elver, glider, hch, hpa, mingo, mm-commits, peterz, tglx, viro


The patch titled
     Subject: x86: add failure injection to get/put/clear_user
has been removed from the -mm tree.  Its filename was
     x86-add-failure-injection-to-get-put-clear_user.patch

This patch was dropped because other changes were merged, which wrecked this patch

------------------------------------------------------
From: Albert van der Linde <alinde@google.com>
Subject: x86: add failure injection to get/put/clear_user

To test fault-tolerance of user memory acceses in x86, add support for
fault injection.

Make both put_user() and get_user() fail with -EFAULT, and clear_user()
fail by not clearing any bytes.

Link: http://lkml.kernel.org/r/20200831171733.955393-4-alinde@google.com
Signed-off-by: Albert van der Linde <alinde@google.com>
Reviewed-by: Akinobu Mita <akinobu.mita@gmail.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Marco Elver <elver@google.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 arch/x86/include/asm/uaccess.h |   68 +++++++++++++++++--------------
 arch/x86/lib/usercopy_64.c     |    3 +
 2 files changed, 42 insertions(+), 29 deletions(-)

--- a/arch/x86/include/asm/uaccess.h~x86-add-failure-injection-to-get-put-clear_user
+++ a/arch/x86/include/asm/uaccess.h
@@ -5,6 +5,7 @@
  * User space memory access functions
  */
 #include <linux/compiler.h>
+#include <linux/fault-inject-usercopy.h>
 #include <linux/kasan-checks.h>
 #include <linux/string.h>
 #include <asm/asm.h>
@@ -175,11 +176,16 @@ extern int __get_user_bad(void);
 	register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX);		\
 	__chk_user_ptr(ptr);						\
 	might_fault();							\
-	asm volatile("call __get_user_%P4"				\
-		     : "=a" (__ret_gu), "=r" (__val_gu),		\
+	if (should_fail_usercopy()) {					\
+		(x) = 0;						\
+		__ret_gu = -EFAULT;					\
+	} else {							\
+		asm volatile("call __get_user_%P4"			\
+			: "=a" (__ret_gu), "=r" (__val_gu),		\
 			ASM_CALL_CONSTRAINT				\
-		     : "0" (ptr), "i" (sizeof(*(ptr))));		\
-	(x) = (__force __typeof__(*(ptr))) __val_gu;			\
+			: "0" (ptr), "i" (sizeof(*(ptr))));		\
+		(x) = (__force __typeof__(*(ptr))) __val_gu;		\
+	}								\
 	__builtin_expect(__ret_gu, 0);					\
 })
 
@@ -236,31 +242,35 @@ extern void __put_user_8(void);
  *
  * Return: zero on success, or -EFAULT on error.
  */
-#define put_user(x, ptr)					\
-({								\
-	int __ret_pu;						\
-	__typeof__(*(ptr)) __pu_val;				\
-	__chk_user_ptr(ptr);					\
-	might_fault();						\
-	__pu_val = x;						\
-	switch (sizeof(*(ptr))) {				\
-	case 1:							\
-		__put_user_x(1, __pu_val, ptr, __ret_pu);	\
-		break;						\
-	case 2:							\
-		__put_user_x(2, __pu_val, ptr, __ret_pu);	\
-		break;						\
-	case 4:							\
-		__put_user_x(4, __pu_val, ptr, __ret_pu);	\
-		break;						\
-	case 8:							\
-		__put_user_x8(__pu_val, ptr, __ret_pu);		\
-		break;						\
-	default:						\
-		__put_user_x(X, __pu_val, ptr, __ret_pu);	\
-		break;						\
-	}							\
-	__builtin_expect(__ret_pu, 0);				\
+#define put_user(x, ptr)						\
+({									\
+	int __ret_pu;							\
+	__typeof__(*(ptr)) __pu_val;					\
+	__chk_user_ptr(ptr);						\
+	might_fault();							\
+	__pu_val = x;							\
+	if (should_fail_usercopy()) {					\
+		__ret_pu = -EFAULT;					\
+	} else {							\
+		switch (sizeof(*(ptr))) {				\
+		case 1:							\
+			__put_user_x(1, __pu_val, ptr, __ret_pu);	\
+			break;						\
+		case 2:							\
+			__put_user_x(2, __pu_val, ptr, __ret_pu);	\
+			break;						\
+		case 4:							\
+			__put_user_x(4, __pu_val, ptr, __ret_pu);	\
+			break;						\
+		case 8:							\
+			__put_user_x8(__pu_val, ptr, __ret_pu);		\
+			break;						\
+		default:						\
+			__put_user_x(X, __pu_val, ptr, __ret_pu);	\
+			break;						\
+		}							\
+	}								\
+	__builtin_expect(__ret_pu, 0);					\
 })
 
 #define __put_user_size(x, ptr, size, label)				\
--- a/arch/x86/lib/usercopy_64.c~x86-add-failure-injection-to-get-put-clear_user
+++ a/arch/x86/lib/usercopy_64.c
@@ -7,6 +7,7 @@
  * Copyright 2002 Andi Kleen <ak@suse.de>
  */
 #include <linux/export.h>
+#include <linux/fault-inject-usercopy.h>
 #include <linux/uaccess.h>
 #include <linux/highmem.h>
 
@@ -50,6 +51,8 @@ EXPORT_SYMBOL(__clear_user);
 
 unsigned long clear_user(void __user *to, unsigned long n)
 {
+	if (should_fail_usercopy())
+		return n;
 	if (access_ok(to, n))
 		return __clear_user(to, n);
 	return n;
_

Patches currently in -mm which might be from alinde@google.com are

lib-include-linux-add-usercopy-failure-capability.patch
lib-uaccess-add-failure-injection-to-usercopy-functions.patch


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [wrecked] x86-add-failure-injection-to-get-put-clear_user.patch removed from -mm tree
       [not found] ` <CAG_fn=U+zDi-Z7FmkhUWsMjVALvG-jkOgvmjiz6_HfjzLcF4UQ@mail.gmail.com>
@ 2020-10-14 21:00   ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2020-10-14 21:00 UTC (permalink / raw)
  To: Alexander Potapenko
  Cc: Akinobu Mita, Albert van der Linde, Andrey Konovalov,
	Arnd Bergmann, Borislav Petkov, Jonathan Corbet, Dmitriy Vyukov,
	Marco Elver, Christoph Hellwig, H. Peter Anvin, Ingo Molnar,
	mm-commits, Peter Zijlstra, Thomas Gleixner, Al Viro

On Wed, 14 Oct 2020 16:00:56 +0200 Alexander Potapenko <glider@google.com> wrote:

> Hi Andrew,
> 
> On Tue, Oct 13, 2020 at 8:20 PM <akpm@linux-foundation.org> wrote:
> >
> >
> > The patch titled
> >      Subject: x86: add failure injection to get/put/clear_user
> > has been removed from the -mm tree.  Its filename was
> >      x86-add-failure-injection-to-get-put-clear_user.patch
> >
> > This patch was dropped because other changes were merged, which wrecked this patch
> 
> On top of which tree should we rebase the patches to see/resolve these
> conflicts?
> linux-next/akpm and linux-mm/master seem to still contain all three
> patches in question.

The problem is ec6347bb43395 ("x86, powerpc: Rename memcpy_mcsafe() to
copy_mc_to_{user, kernel}()"), which is in Linus's tree.  It seems to
have got slammed in at the last minute (with a cc:stable so I guess
it's important).  Please rebase and retest against current -linus and
resend?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-14 21:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-13 18:20 [wrecked] x86-add-failure-injection-to-get-put-clear_user.patch removed from -mm tree akpm
     [not found] ` <CAG_fn=U+zDi-Z7FmkhUWsMjVALvG-jkOgvmjiz6_HfjzLcF4UQ@mail.gmail.com>
2020-10-14 21:00   ` Andrew Morton

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).