linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stafford Horne <shorne@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	Andy Shevchenko <andriy.shevchenko@intel.com>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Andy Shevchenko <andy@kernel.org>,
	device-mapper development <dm-devel@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Mike Snitzer <msnitzer@redhat.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	Milan Broz <gmazyland@gmail.com>
Subject: Re: [PATCH v2] hex2bin: make the function hex_to_bin constant-time
Date: Sun, 8 May 2022 09:37:26 +0900	[thread overview]
Message-ID: <YncQxl1shpH5TpbK@antec> (raw)
In-Reply-To: <YnLkYjOF2vEOdjOo@antec>

On Thu, May 05, 2022 at 05:38:58AM +0900, Stafford Horne wrote:
> On Wed, May 04, 2022 at 01:10:03PM -0700, Linus Torvalds wrote:
> > On Wed, May 4, 2022 at 12:58 PM Stafford Horne <shorne@gmail.com> wrote:
> > >
> > > I have uploaded a diff I created here:
> > >   https://gist.github.com/54334556f2907104cd12374872a0597c
> > >
> > > It shows the same output.
> > 
> > In hex_to_bin itself it seems to only be a difference due to some
> > register allocation (r19 and r3 switched around).
> > 
> > But then it gets inlined into hex2bin and there changes there seem to
> > be about instruction and basic block scheduling, so it's a lot harder
> > to see what's going on.
> > 
> > And a lot of constant changes, which honestly look just like code code
> > moved around by 16 bytes and offsets changed due to that.
> > 
> > So I doubt it's hex_to_bin() that is causing problems, I think it's
> > purely code movement. Which explains why adding a nop or a fake printk
> > fixes things.
> > 
> > Some alignment assumption that got broken?
> 
> This is what it looks like to me too.  I will have to do a deep dive on what is
> going on with this particular build combination as I can't figure out what it is
> off the top of my head.
> 
> This test is using a gcc 11 compiler, I tried with my gcc 12 toolchain and the
> issue cannot be reproduced.
> 
>   - musl gcc 11 - https://musl.cc/or1k-linux-musl-cross.tgz
>   - openrisc gcc 12 - https://github.com/openrisc/or1k-gcc/releases/tag/or1k-12.0.1-20220210-20220304
> 
> But again the difference between the two compiler outputs is a lot of register
> allocation and offsets changes.  Its not easy to see anything that stands out.
> I checked the change log for the openrisc specific changes from gcc 11 to gcc
> 12.  Nothing seems to stand out, mcount profiler fix for PIC, a new large binary
> link flag.

Hello,

Just an update on this.  The issue so far has been traced to the alignment of
the crypto multiplication function fe_mul_impl in lib/crypto/curve25519-fiat32.c.

This patch e5be15767e7e ("hex2bin: make the function hex_to_bin constant-time")
allowed for the alignment to be just right to cause the failure.  Without
this patch and forcing the alignment we can reproduce the issue.  So though the
bisect is correct, this patch is not the root cause of the issue.

Using some l.nop sliding techniques and some strategically placed .align
statements I have been able to reproduce the issue on:

  - gcc 11 and gcc 12
  - preempt and non-preempt kernels

I have not been able to reproduce this on my FPGA, so far only QEMU.  My
hunch now is that since the fe_mul_impl function contains some rather long basic
blocks it appears that timer interrupts that interrupt qemu mid basic block
execution somehow is causing this.  The hypothesis is it may be basic block
resuming behavior in qemu that causes incosistent behavior.

It will take a bit more time to trace this.  Since I maintain OpenRISC QEMU the
issue is on me.

Again, It's safe to say that patch e5be15767e7e ("hex2bin: make the function
hex_to_bin constant-time") is not an issue.

-Stafford

  reply	other threads:[~2022-05-08  0:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-24 20:54 [PATCH] hex2bin: make the function hex_to_bin constant-time Mikulas Patocka
2022-04-24 21:30 ` Joe Perches
2022-04-24 21:37 ` Linus Torvalds
2022-04-24 21:42   ` Linus Torvalds
2022-04-25  9:37     ` David Laight
2022-04-25 11:04       ` Mikulas Patocka
2022-04-25 12:59         ` David Laight
2022-04-25 13:33           ` Mikulas Patocka
2022-04-25 12:07   ` [PATCH v2] " Mikulas Patocka
2022-04-25 17:53     ` Linus Torvalds
2022-05-04  8:38     ` Stafford Horne
2022-05-04  8:57       ` Mikulas Patocka
2022-05-04  9:20         ` Andy Shevchenko
2022-05-04  9:47           ` Milan Broz
2022-05-04  9:50             ` Jason A. Donenfeld
2022-05-04 11:54           ` Mikulas Patocka
2022-05-04  9:42       ` Jason A. Donenfeld
2022-05-04  9:44         ` Jason A. Donenfeld
2022-05-04  9:57         ` Jason A. Donenfeld
2022-05-04 10:07           ` Andy Shevchenko
2022-05-04 10:15             ` Jason A. Donenfeld
2022-05-04 18:00               ` Linus Torvalds
2022-05-04 19:42                 ` Jason A. Donenfeld
2022-05-04 19:51                   ` Linus Torvalds
2022-05-04 20:00                     ` Linus Torvalds
2022-05-04 20:12                       ` Stafford Horne
2022-05-04 20:26                         ` Linus Torvalds
2022-05-04 21:24                           ` Linus Torvalds
2022-05-04 19:57                   ` Stafford Horne
2022-05-04 20:10                     ` Linus Torvalds
2022-05-04 20:38                       ` Stafford Horne
2022-05-08  0:37                         ` Stafford Horne [this message]
2022-05-11 12:17                           ` Stafford Horne

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=YncQxl1shpH5TpbK@antec \
    --to=shorne@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dm-devel@redhat.com \
    --cc=gmazyland@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=msnitzer@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=zohar@linux.ibm.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).