public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Zhouyi Zhou <zhouzhouyi@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>,
	Peter Zijlstra <peterz@infradead.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	rcu <rcu@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"lance@osuosl.org" <lance@osuosl.org>,
	"Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: BUG : PowerPC RCU: torture test failed with __stack_chk_fail
Date: Wed, 26 Apr 2023 02:15:25 +0000	[thread overview]
Message-ID: <20230426021525.GA2171827@google.com> (raw)
In-Reply-To: <CAABZP2w8eDSRXCoLiWGjGtz6VifPfaaF=Mje7Y8aXjugy-vNkA@mail.gmail.com>

Hi Zhouyi,

On Wed, Apr 26, 2023 at 09:31:17AM +0800, Zhouyi Zhou wrote:
[..]
> Joel makes the learning process easier for me, indeed!

I know that feeling being a learner myself ;-)

> One question I have tried very hard to understand, but still confused.
> for now, I know
> r13 is fixed, but r1 is not, why "r9,40(r1)"'s 40(r1) can be assumed
> to be equal to 3192(r10).

First you have to I guess read up a bit about stack canaries. Google for
"gcc stack protector" and "gcc stack canaries", and the look for basics of
"buffer overflow attacks". That'll explain the concept of stack guards etc
(Sorry if this is too obvious but I did not know how much you knew about it
already).

40(r1) is where the canary was stored. In the beginning of the function, you
have this:

c000000000226d58:	78 0c 2d e9 	ld      r9,3192(r13)
c000000000226d5c:	28 00 21 f9 	std     r9,40(r1)

r1 is your stack pointer. 3192(r13) is the canary value.

40(r1) is where the canary is stored for later comparison.

r1 should not change through out the function I believe, because otherwise
you don't know where the stack frame is, right?

Later you have this stuff before the function returns which gcc presumably
did due to optimization. That mr means move register and is where the caching
of r13 to r10 happens that Boqun pointed.

c000000000226eb4:	78 6b aa 7d 	mr      r10,r13
[...]
and then the canary comparison happens:

c000000000226ed8:	28 00 21 e9 	ld      r9,40(r1)
c000000000226edc:	78 0c 4a e9 	ld      r10,3192(r10)
c000000000226ee0:	79 52 29 7d 	xor.    r9,r9,r10
c000000000226ee4:	00 00 40 39 	li      r10,0
c000000000226ee8:	b8 03 82 40 	bne     c0000000002272a0 <srcu_gp_start_if_needed+0x5a0>

So looks like for this to blow up, the preemption/migration has to happen
precisely between the mr doing the caching, and the xor doing the comparison,
since that's when the r10 will be stale.

thanks,

 - Joel


  reply	other threads:[~2023-04-26  2:15 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22 12:46 BUG : PowerPC RCU: torture test failed with __stack_chk_fail 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 [this message]
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
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=20230426021525.GA2171827@google.com \
    --to=joel@joelfernandes.org \
    --cc=boqun.feng@gmail.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=lance@osuosl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=segher@kernel.crashing.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