mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Peter Zijlstra <peterz@infradead.org>,
	Joel Fernandes <joel@joelfernandes.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	rcu <rcu@vger.kernel.org>, "lance@osuosl.org" <lance@osuosl.org>,
	Zhouyi Zhou <zhouzhouyi@gmail.com>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>
Subject: Re: BUG : PowerPC RCU: torture test failed with __stack_chk_fail
Date: Tue, 25 Apr 2023 13:36:31 +0000	[thread overview]
Message-ID: <7b76b5c6-e86e-0894-5745-b6ea8faa850c@csgroup.eu> (raw)
In-Reply-To: <20230425115313.GD1335080@hirez.programming.kicks-ass.net>



Le 25/04/2023 à 13:53, Peter Zijlstra a écrit :
> On Tue, Apr 25, 2023 at 06:59:29AM -0400, Joel Fernandes wrote:
>>> I'm a little confused; the way I understand the whole stack protector
>>> thing to work is that we push a canary on the stack at call and on
>>> return check it is still valid. Since in general tasks randomly migrate,
>>> the per-cpu validation canary should be the same on all CPUs.
> 
>> AFAICS, the canary is randomly chosen both in the kernel [1]. This
> 
> Yes, at boot, once. But thereafter it should be the same for all CPUs.

Each task has its own canary, stored in task struct :

kernel/fork.c:1012:     tsk->stack_canary = get_random_canary();

On PPC32 we have register 'r2' that points to task struct at all time, 
so GCC is instructed to find canary at an offset from r2.

But on PPC64 we have no such register. Instead we have r13 that points 
to the PACA struct which is a per-cpu structure, and we have a pointer 
to 'current' task struct in the PACA struct. So in order to be able to 
have the canary as an offset of a fixed register as expected by GCC, we 
copy the task canary into the cpu's PACA struct during _switch():

	addi	r6,r4,-THREAD	/* Convert THREAD to 'current' */
	std	r6,PACACURRENT(r13)	/* Set new 'current' */
#if defined(CONFIG_STACKPROTECTOR)
	ld	r6, TASK_CANARY(r6)
	std	r6, PACA_CANARY(r13)
#endif

The problem is that r13 will change if a task is switched to another 
CPU. But if GCC is using a copy of an older value of r13, then it will 
take the canary from another CPU's PACA struct hence it'll get the 
canary of the task running on that CPU instead of getting the canary of 
the current task running on the current CPU.

Christophe

  reply	other threads:[~2023-04-25 13:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22 12:46 Zhouyi Zhou
2023-04-22 19:19 ` Joel Fernandes
2023-04-23  1:37   ` Zhouyi Zhou
2023-04-23  5:45     ` Zhouyi Zhou
2023-04-22 19:28 ` Joel Fernandes
2023-04-24  0:32   ` Boqun Feng
2023-04-24  4:00     ` Zhouyi Zhou
2023-04-24 13:14     ` Michael Ellerman
2023-04-24 15:13       ` Segher Boessenkool
2023-04-24 15:28         ` Boqun Feng
2023-04-24 17:29           ` Segher Boessenkool
2023-04-24 19:25             ` Boqun Feng
2023-04-24 18:55           ` Joel Fernandes
2023-04-25 10:13             ` Peter Zijlstra
2023-04-25 10:58               ` Zhouyi Zhou
2023-04-25 11:06                 ` Joel Fernandes
2023-04-25  3:12                   ` Zhouyi Zhou
2023-04-25 13:40                   ` Christophe Leroy
2023-04-25 13:49                     ` Zhouyi Zhou
2023-04-26  0:32                       ` Joel Fernandes
2023-04-26  1:31                         ` Zhouyi Zhou
2023-04-26  2:15                           ` Joel Fernandes
2023-04-26  2:37                             ` Zhouyi Zhou
2023-04-26  0:42                     ` Joel Fernandes
2023-04-26 12:29                   ` Michael Ellerman
2023-04-26 13:44                     ` Joel Fernandes
2023-04-26 14:20                       ` Peter Zijlstra
2023-04-26 14:45                         ` Michael Ellerman
2023-04-28 10:35                     ` Christophe Leroy
2023-04-25 10:59               ` Joel Fernandes
2023-04-25 11:53                 ` Peter Zijlstra
2023-04-25 13:36                   ` Christophe Leroy [this message]
2023-04-24 22:07 ` Michael Ellerman
2023-04-24 22:13   ` Zhouyi Zhou
2023-04-25  6:01   ` Zhouyi Zhou
2023-04-25  9:27     ` Zhouyi Zhou
2023-04-27  3:09       ` Michael Ellerman
2023-04-27  3:32         ` Zhouyi Zhou
2023-04-27  9:21         ` Zhouyi Zhou
2023-04-27 14:13           ` Michael Ellerman
2023-04-27 14:29             ` Zhouyi Zhou

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=7b76b5c6-e86e-0894-5745-b6ea8faa850c@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=boqun.feng@gmail.com \
    --cc=joel@joelfernandes.org \
    --cc=lance@osuosl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=zhouzhouyi@gmail.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

all inboxes | Powered by JetHome®