[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <155110351173.21156.682447092137241969.stgit@devbox>
Date: Mon, 25 Feb 2019 23:05:11 +0900
From: Masami Hiramatsu <mhiramat@...nel.org>
To: Steven Rostedt <rostedt@...dmis.org>,
Linus Torvalds <torvalds@...ux-foundation.org>
Cc: mhiramat@...nel.org, linux-kernel@...r.kernel.org,
Andy Lutomirski <luto@...capital.net>,
Ingo Molnar <mingo@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Changbin Du <changbin.du@...il.com>,
Jann Horn <jannh@...gle.com>,
Kees Cook <keescook@...omium.org>,
Andy Lutomirski <luto@...nel.org>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
Nadav Amit <namit@...are.com>,
Peter Zijlstra <peterz@...radead.org>
Subject: [RFC PATCH 1/4] uaccess: Make sure kernel_uaccess_faults_ok is updated before pagefault
Make sure the kernel_uaccess_faults_ok is updated before a
pagefault can hit and the last loads/stores issued before
resotring kernel_uaccess_faults_ok.
Signed-off-by: Masami Hiramatsu <mhiramat@...nel.org>
---
fs/namespace.c | 2 ++
mm/maccess.c | 12 ++++++------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index a677b59efd74..88a8e0eb6234 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2699,6 +2699,7 @@ static long exact_copy_from_user(void *to, const void __user * from,
return n;
current->kernel_uaccess_faults_ok++;
+ barrier();
while (n) {
if (__get_user(c, f)) {
memset(t, 0, n);
@@ -2708,6 +2709,7 @@ static long exact_copy_from_user(void *to, const void __user * from,
f++;
n--;
}
+ barrier();
current->kernel_uaccess_faults_ok--;
return n;
}
diff --git a/mm/maccess.c b/mm/maccess.c
index f3416632e5a4..7a9752d59587 100644
--- a/mm/maccess.c
+++ b/mm/maccess.c
@@ -29,12 +29,12 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
- pagefault_disable();
current->kernel_uaccess_faults_ok++;
+ pagefault_disable();
ret = __copy_from_user_inatomic(dst,
(__force const void __user *)src, size);
- current->kernel_uaccess_faults_ok--;
pagefault_enable();
+ current->kernel_uaccess_faults_ok--;
set_fs(old_fs);
return ret ? -EFAULT : 0;
@@ -59,11 +59,11 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
- pagefault_disable();
current->kernel_uaccess_faults_ok++;
+ pagefault_disable();
ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
- current->kernel_uaccess_faults_ok--;
pagefault_enable();
+ current->kernel_uaccess_faults_ok--;
set_fs(old_fs);
return ret ? -EFAULT : 0;
@@ -97,16 +97,16 @@ long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count)
return 0;
set_fs(KERNEL_DS);
- pagefault_disable();
current->kernel_uaccess_faults_ok++;
+ pagefault_disable();
do {
ret = __get_user(*dst++, (const char __user __force *)src++);
} while (dst[-1] && ret == 0 && src - unsafe_addr < count);
- current->kernel_uaccess_faults_ok--;
dst[-1] = '\0';
pagefault_enable();
+ current->kernel_uaccess_faults_ok--;
set_fs(old_fs);
return ret ? -EFAULT : src - unsafe_addr;
Powered by blists - more mailing lists