lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211008124052.GA976@C02TD0UTHF1T.local>
Date:   Fri, 8 Oct 2021 13:40:52 +0100
From:   Mark Rutland <mark.rutland@....com>
To:     Peter Zijlstra <peterz@...radead.org>
Cc:     keescook@...omium.org, jannh@...gle.com,
        linux-kernel@...r.kernel.org, vcaputo@...garu.com,
        mingo@...hat.com, juri.lelli@...hat.com,
        vincent.guittot@...aro.org, dietmar.eggemann@....com,
        rostedt@...dmis.org, bsegall@...gle.com, mgorman@...e.de,
        bristot@...hat.com, akpm@...ux-foundation.org,
        christian.brauner@...ntu.com, amistry@...gle.com,
        Kenta.Tada@...y.com, legion@...nel.org,
        michael.weiss@...ec.fraunhofer.de, mhocko@...e.com, deller@....de,
        zhengqi.arch@...edance.com, me@...in.cc, tycho@...ho.pizza,
        tglx@...utronix.de, bp@...en8.de, hpa@...or.com, axboe@...nel.dk,
        metze@...ba.org, laijs@...ux.alibaba.com, luto@...nel.org,
        dave.hansen@...ux.intel.com, ebiederm@...ssion.com,
        ohoono.kwon@...sung.com, kaleshsingh@...gle.com,
        yifeifz2@...inois.edu, jpoimboe@...hat.com,
        linux-hardening@...r.kernel.org, linux-arch@...r.kernel.org,
        vgupta@...nel.org, linux@...linux.org.uk, will@...nel.org,
        guoren@...nel.org, bcain@...eaurora.org, monstr@...str.eu,
        tsbogend@...ha.franken.de, nickhu@...estech.com,
        jonas@...thpole.se, mpe@...erman.id.au, paul.walmsley@...ive.com,
        hca@...ux.ibm.com, ysato@...rs.sourceforge.jp, davem@...emloft.net,
        chris@...kel.net
Subject: Re: [PATCH 6/7] arch: __get_wchan || STACKTRACE_SUPPORT

[Adding Josh, since there might be a concern here from a livepatch pov]

On Fri, Oct 08, 2021 at 01:15:33PM +0200, Peter Zijlstra wrote:
> It's trivial to implement __get_wchan() with CONFIG_STACKTRACE

Possibly, but I don't think this is quite right -- semantic issue below.
 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
> ---

> --- a/arch/arm64/include/asm/processor.h
> +++ b/arch/arm64/include/asm/processor.h
> @@ -257,8 +257,6 @@ struct task_struct;
>  /* Free all resources held by a thread. */
>  extern void release_thread(struct task_struct *);
>  
> -unsigned long __get_wchan(struct task_struct *p);
> -
>  void update_sctlr_el1(u64 sctlr);
>  
>  /* Thread switching */
> --- a/arch/arm64/kernel/process.c
> +++ b/arch/arm64/kernel/process.c
> @@ -528,32 +528,6 @@ __notrace_funcgraph struct task_struct *
>  	return last;
>  }
>  
> -unsigned long __get_wchan(struct task_struct *p)
> -{
> -	struct stackframe frame;
> -	unsigned long stack_page, ret = 0;
> -	int count = 0;
> -
> -	stack_page = (unsigned long)try_get_task_stack(p);
> -	if (!stack_page)
> -		return 0;
> -
> -	start_backtrace(&frame, thread_saved_fp(p), thread_saved_pc(p));
> -
> -	do {
> -		if (unwind_frame(p, &frame))
> -			goto out;
> -		if (!in_sched_functions(frame.pc)) {
> -			ret = frame.pc;
> -			goto out;
> -		}
> -	} while (count++ < 16);
> -
> -out:
> -	put_task_stack(p);
> -	return ret;
> -}
> -

> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -1966,6 +1966,21 @@ bool sched_task_on_rq(struct task_struct
>  	return task_on_rq_queued(p);
>  }
>  
> +#ifdef CONFIG_STACKTRACE
> +static unsigned long __get_wchan(struct task_struct *p)
> +{
> +	unsigned long entry = 0;
> +
> +	stack_trace_save_tsk(p, &entry, 1, 0);

This assumes stack_trace_save_tsk() will skip sched functions, but I
don't think that's ever been a requirement? It's certinaly not
documented anywhere that I could find, and arm64 doesn't do so today,
and this patch causes wchan to just log `__switch_to` for everything.

I realise you "fix" that for some arches in the next patch, but it's not
clear to me that's the right thing to do -- I would expect that
stack_trace_save_tsk() *shouldn't* skip anything unless we've explicitly
told it to via skipnr, because I'd expect that
stack_trace_save_tsk_reliable() mustn't, in case we ever need to patch
anything in the scheduler (or arch ctxsw code) with a livepatch, or if
you ever *want* to have the sched functions in a trace.

So I have two big questions:

1) Where precisely should stack_trace_save_tsk() and
   stack_trace_save_tsk_reliable() start from?

1) What should you do when you *do* want sched functions in a trace?

We could side-step the issue here by using arch_stack_walk(), which'd
make it easy to skip sched functions in the core code.

Thanks,
Mark.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ