linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Kees Cook <keescook@chromium.org>
Cc: "Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Daniel Bristot de Oliveira" <bristot@redhat.com>,
	"kernel test robot" <oliver.sang@intel.com>,
	"Vito Caputo" <vcaputo@pengaru.com>,
	"Jann Horn" <jannh@google.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Christian Brauner" <christian.brauner@ubuntu.com>,
	"Anand K Mistry" <amistry@google.com>,
	"Kenta.Tada@sony.com" <Kenta.Tada@sony.com>,
	"Alexey Gladkov" <legion@kernel.org>,
	"Michael Weiß" <michael.weiss@aisec.fraunhofer.de>,
	"Michal Hocko" <mhocko@suse.com>, "Helge Deller" <deller@gmx.de>,
	"Qi Zheng" <zhengqi.arch@bytedance.com>,
	"Tobin C. Harding" <me@tobin.cc>,
	"Tycho Andersen" <tycho@tycho.pizza>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Borislav Petkov" <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Jens Axboe" <axboe@kernel.dk>,
	"Stefan Metzmacher" <metze@samba.org>,
	"Lai Jiangshan" <laijs@linux.alibaba.com>,
	"Andy Lutomirski" <luto@kernel.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	"Ohhoon Kwon" <ohoono.kwon@samsung.com>,
	"Kalesh Singh" <kaleshsingh@google.com>,
	"YiFei Zhu" <yifeifz2@illinois.edu>,
	"Josh Poimboeuf" <jpoimboe@redhat.com>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-hardening@vger.kernel.org, x86@kernel.org
Subject: Re: [PATCH v2 2/6] sched: Add wrapper for get_wchan() to keep task blocked
Date: Thu, 30 Sep 2021 10:29:33 +0200	[thread overview]
Message-ID: <YVV1bR9TTUVjXI7G@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <YVV1NZ68kLRYBo10@hirez.programming.kicks-ass.net>

On Thu, Sep 30, 2021 at 10:28:37AM +0200, Peter Zijlstra wrote:
> On Thu, Sep 30, 2021 at 10:27:07AM +0200, Peter Zijlstra wrote:
> > On Wed, Sep 29, 2021 at 03:02:14PM -0700, Kees Cook wrote:
> > > Having a stable wchan means the process must be blocked and for it to
> > > stay that way while performing stack unwinding.
> > 
> > How's this instead?
> > 
> On top of which we can do..

But that then leads to..

---
Subject: arch: Fix STACKTRACE_SUPPORT
From: Peter Zijlstra <peterz@infradead.org>
Date: Thu Sep 30 10:21:15 CEST 2021

A few archs got save_stack_trace_tsk() vs in_sched_functions() wrong.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/csky/kernel/stacktrace.c  |    7 ++++++-
 arch/mips/kernel/stacktrace.c  |   27 ++++++++++++++++-----------
 arch/nds32/kernel/stacktrace.c |   20 +++++++++++---------
 3 files changed, 33 insertions(+), 21 deletions(-)

--- a/arch/csky/kernel/stacktrace.c
+++ b/arch/csky/kernel/stacktrace.c
@@ -132,12 +132,17 @@ static bool save_trace(unsigned long pc,
 	return __save_trace(pc, arg, false);
 }
 
+static bool save_trace_nosched(unsigned long pc, void *arg)
+{
+	return __save_trace(pc, arg, true);
+}
+
 /*
  * Save stack-backtrace addresses into a stack_trace buffer.
  */
 void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
 {
-	walk_stackframe(tsk, NULL, save_trace, trace);
+	walk_stackframe(tsk, NULL, save_trace_nosched, trace);
 }
 EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
 
--- a/arch/mips/kernel/stacktrace.c
+++ b/arch/mips/kernel/stacktrace.c
@@ -66,16 +66,7 @@ static void save_context_stack(struct st
 #endif
 }
 
-/*
- * Save stack-backtrace addresses into a stack_trace buffer.
- */
-void save_stack_trace(struct stack_trace *trace)
-{
-	save_stack_trace_tsk(current, trace);
-}
-EXPORT_SYMBOL_GPL(save_stack_trace);
-
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+void __save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace, bool savesched)
 {
 	struct pt_regs dummyregs;
 	struct pt_regs *regs = &dummyregs;
@@ -88,6 +79,20 @@ void save_stack_trace_tsk(struct task_st
 		regs->cp0_epc = tsk->thread.reg31;
 	} else
 		prepare_frametrace(regs);
-	save_context_stack(trace, tsk, regs, tsk == current);
+	save_context_stack(trace, tsk, regs, savesched);
+}
+
+/*
+ * Save stack-backtrace addresses into a stack_trace buffer.
+ */
+void save_stack_trace(struct stack_trace *trace)
+{
+	__save_stack_trace_tsk(current, trace, true);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace);
+
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+{
+	__save_stack_trace_tsk(tsk, trace, false);
 }
 EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
--- a/arch/nds32/kernel/stacktrace.c
+++ b/arch/nds32/kernel/stacktrace.c
@@ -6,13 +6,7 @@
 #include <linux/stacktrace.h>
 #include <linux/ftrace.h>
 
-void save_stack_trace(struct stack_trace *trace)
-{
-	save_stack_trace_tsk(current, trace);
-}
-EXPORT_SYMBOL_GPL(save_stack_trace);
-
-void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+static void __save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace, bool savesched)
 {
 	unsigned long *fpn;
 	int skip = trace->skip;
@@ -21,10 +15,8 @@ void save_stack_trace_tsk(struct task_st
 
 	if (tsk == current) {
 		__asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(fpn));
-		savesched = 1;
 	} else {
 		fpn = (unsigned long *)thread_saved_fp(tsk);
-		savesched = 0;
 	}
 
 	while (!kstack_end(fpn) && !((unsigned long)fpn & 0x3)
@@ -50,4 +42,14 @@ void save_stack_trace_tsk(struct task_st
 		fpn = (unsigned long *)fpp;
 	}
 }
+void save_stack_trace(struct stack_trace *trace)
+{
+	__save_stack_trace_tsk(current, trace, true);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace);
+
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+{
+	__save_stack_trace_tsk(tsk, trace, false);
+}
 EXPORT_SYMBOL_GPL(save_stack_trace_tsk);

  reply	other threads:[~2021-09-30  8:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 22:02 [PATCH v2 0/6] wchan: Fix ORC support and leaky fallback Kees Cook
2021-09-29 22:02 ` [PATCH v2 1/6] Revert "proc/wchan: use printk format instead of lookup_symbol_name()" Kees Cook
2021-09-29 22:02 ` [PATCH v2 2/6] sched: Add wrapper for get_wchan() to keep task blocked Kees Cook
2021-09-30  8:27   ` Peter Zijlstra
2021-09-30  8:28     ` Peter Zijlstra
2021-09-30  8:29       ` Peter Zijlstra [this message]
2021-09-29 22:02 ` [PATCH v2 3/6] proc: Use task_is_running() for wchan in /proc/$pid/stat Kees Cook
2021-09-29 22:02 ` [PATCH v2 4/6] proc: Only report /proc/$pid/wchan when process is blocked Kees Cook
2021-09-29 22:02 ` [PATCH v2 5/6] x86: Fix get_wchan() to support the ORC unwinder Kees Cook
2021-09-29 22:02 ` [PATCH v2 6/6] leaking_addresses: Always print a trailing newline Kees Cook
2021-09-30 14:37   ` Tycho Andersen
2021-09-30  1:01 ` [PATCH v2 0/6] wchan: Fix ORC support and leaky fallback Josh Poimboeuf
2021-09-30  8:40   ` Peter Zijlstra
2021-09-30 15:18     ` Kees Cook
2021-09-30 18:39       ` Peter Zijlstra

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=YVV1bR9TTUVjXI7G@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=Kenta.Tada@sony.com \
    --cc=akpm@linux-foundation.org \
    --cc=amistry@google.com \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=deller@gmx.de \
    --cc=dietmar.eggemann@arm.com \
    --cc=ebiederm@xmission.com \
    --cc=hpa@zytor.com \
    --cc=jannh@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=juri.lelli@redhat.com \
    --cc=kaleshsingh@google.com \
    --cc=keescook@chromium.org \
    --cc=laijs@linux.alibaba.com \
    --cc=legion@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=me@tobin.cc \
    --cc=metze@samba.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=michael.weiss@aisec.fraunhofer.de \
    --cc=mingo@redhat.com \
    --cc=ohoono.kwon@samsung.com \
    --cc=oliver.sang@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=tycho@tycho.pizza \
    --cc=vcaputo@pengaru.com \
    --cc=vincent.guittot@linaro.org \
    --cc=x86@kernel.org \
    --cc=yifeifz2@illinois.edu \
    --cc=zhengqi.arch@bytedance.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;
as well as URLs for NNTP newsgroup(s).