On Fri, 5 Apr 2019 09:32:09 -0400
Steven Rostedt <rost...@goodmis.org> wrote:

> On Fri, 5 Apr 2019 10:12:27 +0200 (CEST)
> Thomas Gleixner <t...@linutronix.de> wrote:
> 
> > > BOOM! Warn on.
> > > 
> > > Can we make that access_ok() call in the copy_stack_frame not trigger
> > > the warning just if we are in an interrupt?  
> > 
> > You really want to have access_ok_atomic() or such which does not have the
> > WARN and use that in copy_stack_frame(). That's fine here because the
> > actual copy is inside a pagefault disabled region.
> 
> I was thinking the same.
> 
> Masami, did you post patches to do something like this?
> "access_ok_inatomic()" or something?

Yeah, last month I sent 
"x86/uaccess: Allow access_ok() in irq context if pagefault_disabled"

If you correctly disables the pagefault, access_ok() shouldn't warn it.
Ah, I see.

copy_stack_frame(const void __user *fp, struct stack_frame_user *frame)
{
        int ret;

        if (!access_ok(fp, sizeof(*frame))) <== this is out of 
pagefault_disable()!
                return 0;

        ret = 1;
        pagefault_disable();
        if (__copy_from_user_inatomic(frame, fp, sizeof(*frame)))
                ret = 0;
        pagefault_enable();

        return ret;
}

How is below patch?

---
diff --git a/arch/x86/kernel/stacktrace.c b/arch/x86/kernel/stacktrace.c
index 2abf27d7df6b..36ff77c801f7 100644
--- a/arch/x86/kernel/stacktrace.c
+++ b/arch/x86/kernel/stacktrace.c
@@ -98,14 +98,11 @@ struct stack_frame_user {
 static int
 copy_stack_frame(const void __user *fp, struct stack_frame_user *frame)
 {
-       int ret;
+       int ret = 1;
 
-       if (!access_ok(fp, sizeof(*frame)))
-               return 0;
-
-       ret = 1;
        pagefault_disable();
-       if (__copy_from_user_inatomic(frame, fp, sizeof(*frame)))
+       if (!access_ok(fp, sizeof(*frame)) ||
+           __copy_from_user_inatomic(frame, fp, sizeof(*frame)))
                ret = 0;
        pagefault_enable();
 

-- 
Masami Hiramatsu <mhira...@kernel.org>

Reply via email to