mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	Clark Williams <williams@redhat.com>,
	Juri Lelli <juri.lelli@gmail.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: WARN_ON: userstacktrace on irq events
Date: Fri, 21 Jun 2019 23:12:32 +0900	[thread overview]
Message-ID: <20190621231232.259536faeea4b19cf39a7688@kernel.org> (raw)
In-Reply-To: <20190405093209.7a5c5133@gandalf.local.home>

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

> On Fri, 5 Apr 2019 10:12:27 +0200 (CEST)
> Thomas Gleixner <tglx@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 <mhiramat@kernel.org>

  reply	other threads:[~2019-06-21 14:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-03 16:16 Steven Rostedt
2019-04-05  8:12 ` Thomas Gleixner
2019-04-05 13:32   ` Steven Rostedt
2019-06-21 14:12     ` Masami Hiramatsu [this message]
2019-07-22  8:32       ` [PATCH 0/1] x86/stacktrace: Fix userstacktrace access_ok() WARNING in " Eiichi Tsukata
2019-07-22  8:32         ` [PATCH 1/1] " Eiichi Tsukata
2019-07-22  8:46           ` [tip:x86/urgent] x86/stacktrace: Prevent access_ok() warnings in arch_stack_walk_user() tip-bot for Eiichi Tsukata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190621231232.259536faeea4b19cf39a7688@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=juri.lelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome