Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp64095pxf; Wed, 10 Mar 2021 20:56:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJD2BHKK0td8Ywk8w9/8Xfhud4jISFzFv4TZx4xqz3GjgFnvQOdfOoimIx52gwOQpkHy96 X-Received: by 2002:a05:6402:1c86:: with SMTP id cy6mr6535926edb.276.1615438611343; Wed, 10 Mar 2021 20:56:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615438611; cv=none; d=google.com; s=arc-20160816; b=qLdjanITxVsv5YXUksYoL9Zo1X6i4F+/EhSYdCFSdq9BtUddaUB5RbUFvfwRqQITzq sTdtOwsuT+l4TfIRSPXy/IvrIqRGGDVJ9TLEDuA+Rf84Xg42f1+Hb4lf8abwTyr2MewX ZoppsEksfZq/Go7M63kYXTIwzuh7x9e2NOfdMt4edE+qZI9R9fEnU+guzbw4Q3BfQdB2 pMs2AxdHqMv3FEqIEfD7MxYd3d8lw3L68pWwYPEZ3RLyLk0PTpo2oWe/s+YdZrBYyy/J RII5c3h0igP2bLi6blCpjYsIqMhmrMaMIpuUz0m1rp1QsVwMBQYOKKBa7ZYoFbcbPYC7 wRzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=j3Z0MsTVWh7quJPO1wSAb6cx/QORDJcVs0Dj+M19F8k=; b=F43b/WMqPMIRg/ISZA/yehymJPaErtAKDvVvSmVvtsQPtmNolbhu3pTemoTb+w1DWP doaHZNDb/Sd/Pbio26aGPuzJLTz2qeqpLiETXOtFYuCbCK/ODx2ReaF1f2Y6Rmy3LbY5 +3m9OWi3Y/HFFvBrFCeynZ0KibwUPkpD2Fet0cFT15lnEAYb9qvQvL7p532HCENtoLJS Ko9sx69EoXfRsNFIhkPmw8o+UhWJQUry50qr/2BT7wY5D+Jl/OY7tSlIJikGn/y3GDhs wx+PH5Bi9izLThC/E0THdAhbl5RNhozMuBvCJWoMlPQDUHShbivAi5seDLny/aUOsCFI mdww== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp18si968343ejc.432.2021.03.10.20.56.25; Wed, 10 Mar 2021 20:56:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231279AbhCKEyY (ORCPT + 99 others); Wed, 10 Mar 2021 23:54:24 -0500 Received: from out30-57.freemail.mail.aliyun.com ([115.124.30.57]:47832 "EHLO out30-57.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230231AbhCKExy (ORCPT ); Wed, 10 Mar 2021 23:53:54 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=alimailimapcm10staff010182156082;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0URNwJ8P_1615438430; Received: from B-455UMD6M-2027.local(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0URNwJ8P_1615438430) by smtp.aliyun-inc.com(127.0.0.1); Thu, 11 Mar 2021 12:53:50 +0800 Subject: Re: [PATCH] selftests/sgx: fix EINIT failure dueto SGX_INVALID_SIGNATURE To: Jarkko Sakkinen , Jia Zhang Cc: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Sean Christopherson , Shuah Khan , X86 ML , linux-sgx@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , LKML References: <20210301051836.30738-1-tianjia.zhang@linux.alibaba.com> <3bcdcf04-4bed-ed95-84b6-790675f18240@linux.alibaba.com> <1f5c2375-39e2-65a8-3ad3-8dc43422f568@linux.alibaba.com> <20ef1254-007d-04ce-8df5-5122ffd4d8d3@linux.alibaba.com> From: Tianjia Zhang Message-ID: <710b65d6-e492-ae24-f2af-6973e1df1b85@linux.alibaba.com> Date: Thu, 11 Mar 2021 12:53:49 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 >>>>>> 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. Best regards, Tianjia