All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Cc: Jia Zhang <zhang.jia@linux.alibaba.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Sean Christopherson <seanjc@google.com>,
	Shuah Khan <shuah@kernel.org>, X86 ML <x86@kernel.org>,
	linux-sgx@vger.kernel.org,
	"open list:KERNEL SELFTEST FRAMEWORK" 
	<linux-kselftest@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] selftests/sgx: fix EINIT failure dueto SGX_INVALID_SIGNATURE
Date: Fri, 12 Mar 2021 18:53:06 +0200	[thread overview]
Message-ID: <YEuccsOIBlACqG6A@kernel.org> (raw)
In-Reply-To: <710b65d6-e492-ae24-f2af-6973e1df1b85@linux.alibaba.com>

On Thu, Mar 11, 2021 at 12:53:49PM +0800, Tianjia Zhang wrote:
> 
> 
> On 3/11/21 11:42 AM, Jarkko Sakkinen wrote:
> > On Thu, Mar 11, 2021 at 10:47:50AM +0800, Jia Zhang wrote:
> > > 
> > > 
> > > On 2021/3/11 上午5:39, Jarkko Sakkinen wrote:
> > > > On Wed, Mar 10, 2021 at 08:44:44PM +0800, Jia Zhang wrote:
> > > > > 
> > > > > 
> > > > > On 2021/3/2 下午9:47, Jarkko Sakkinen wrote:
> > > > > > On Mon, Mar 01, 2021 at 09:54:37PM -0800, Andy Lutomirski wrote:
> > > > > > > On Mon, Mar 1, 2021 at 9:06 PM Tianjia Zhang
> > > > > > > <tianjia.zhang@linux.alibaba.com> wrote:
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > On 3/1/21 5:54 PM, Jarkko Sakkinen wrote:
> > > > > > > > > On Mon, Mar 01, 2021 at 01:18:36PM +0800, Tianjia Zhang wrote:
> > > > > > > > > > q2 is not always 384-byte length. Sometimes it only has 383-byte.
> > > > > > > > > 
> > > > > > > > > What does determine this?
> > > > > > > > > 
> > > > > > > > > > In this case, the valid portion of q2 is reordered reversely for
> > > > > > > > > > little endian order, and the remaining portion is filled with zero.
> > > > > > > > > 
> > > > > > > > > I'm presuming that you want to say "In this case, q2 needs to be reversed because...".
> > > > > > > > > 
> > > > > > > > > I'm lacking these details:
> > > > > > > > > 
> > > > > > > > > 1. Why the length of Q2 can vary?
> > > > > > > > > 2. Why reversing the bytes is the correct measure to counter-measure
> > > > > > > > >      this variation?
> > > > > > > > > 
> > > > > > > > > /Jarkko
> > > > > > > > > 
> > > > > > > > 
> > > > > > > > When use openssl to generate a key instead of using the built-in
> > > > > > > > sign_key.pem, there is a probability that will encounter this problem.
> > > > > > > > 
> > > > > > > > Here is a problematic key I encountered. The calculated q1 and q2 of
> > > > > > > > this key are both 383 bytes, If the length is not processed, the
> > > > > > > > hardware signature will fail.
> > > > > > > 
> > > > > > > Presumably the issue is that some keys have parameters that have
> > > > > > > enough leading 0 bits to be effectively shorter.  The openssl API
> > > > > > > (and, sadly, a bunch  of the ASN.1 stuff) treats these parameters as
> > > > > > > variable-size integers.
> > > > > > 
> > > > > > But the test uses a static key. It used to generate a key on fly but
> > > > > 
> > > > > IMO even though the test code, it comes from the linux kernel, meaning
> > > > > that its quality has a certain guarantee and it is a good reference, so
> > > > > the test code still needs to ensure its correctness.
> > > > 
> > > > Hmm... what is working incorrectly then?
> > > 
> > > In current implementation, it is working well, after all the static key
> > > can derive the full 384-byte length of q1 and q2. As mentioned above, if
> > > someone refers to the design of signing tool from selftest code, it is
> > > quite possible that the actual implementation will use dynamical or
> > > external signing key deriving shorter q1 and/or q2 in length.
> > 
> > A self-test needs is not meant to be generic to be directly used in 3rd
> > party code. With the current key there is not issue => there is no issue.
> > 
> 
> For keys generated on fly, self-test does not work properly, this experience
> is really worse.

It does not generate keys on fly. There's a static key.

/Jarkko

  reply	other threads:[~2021-03-12 16:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01  5:18 [PATCH] selftests/sgx: fix EINIT failure dueto SGX_INVALID_SIGNATURE Tianjia Zhang
2021-03-01  9:54 ` Jarkko Sakkinen
2021-03-02  5:06   ` Tianjia Zhang
2021-03-02  5:54     ` Andy Lutomirski
2021-03-02 13:47       ` Jarkko Sakkinen
2021-03-10 12:44         ` Jia Zhang
2021-03-10 21:39           ` Jarkko Sakkinen
2021-03-11  2:47             ` Jia Zhang
2021-03-11  3:42               ` Jarkko Sakkinen
2021-03-11  4:53                 ` Tianjia Zhang
2021-03-12 16:53                   ` Jarkko Sakkinen [this message]
2021-03-11  5:55                 ` Jia Zhang
2021-03-03 12:03       ` Tianjia Zhang
2021-03-02 12:51     ` Jarkko Sakkinen
2021-03-03 12:12       ` Tianjia Zhang

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=YEuccsOIBlACqG6A@kernel.org \
    --to=jarkko@kernel.org \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@redhat.com \
    --cc=seanjc@google.com \
    --cc=shuah@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tianjia.zhang@linux.alibaba.com \
    --cc=x86@kernel.org \
    --cc=zhang.jia@linux.alibaba.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.