Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp956682pxb; Wed, 3 Mar 2021 22:28:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCn3l2nkcEhG/yFGgBEy8Zki8OvpemkiuP68h3V7NOr3lBEXC2beoW7ek9l8uC7JJzh1vi X-Received: by 2002:a17:906:5918:: with SMTP id h24mr2548879ejq.501.1614839279992; Wed, 03 Mar 2021 22:27:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614839279; cv=none; d=google.com; s=arc-20160816; b=SbRwy3hXlZsyq9ElBBHmI4Fe15hLEEJPgWhzwQWMVLt4Hzc4M7htJjY42w1gutKuIV ZbbmnJA4jwIlL4n2p75KyYn9s3UBxcELzPlyowZ9+nflP7QuTrEqvWPjMSMqBzz2MYL5 9wOgcXYlG2Y8d8bMxbhuA1J8mRNlqyRXAY4tcEe7AHtXrqDejbZ5yvcAGCaAs2p4YuqL OulHsk8HrS4iZhBVt3jbpA8gVEn6LYX9okX5Dzp065ag5EdEWqfd+t5jIwKDfPotXYgz fJevOdQRJH99SFKVPu5/7QzCVTX1/FlHfysjYJ9yumGSnhyoVluBDuJBUnexdoSmh7On FBvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=obahe07rEA1V5RSNuYXtCvsz+eD4B9t2+ZgM++L+N70=; b=btjB24eP63fusxsokGvgTFXnKl/1EbLRyCVpCaE1B1pef4LyIcB1n+EvFoefRQ5ZQX /Wu/fQ92PRM1Q2XATkqX9okY+U+x6qkxP0f11fZYnBNTvhJsVy9cOhIX1NYpKxYIwLov jY6tkA28aVWsudMj8rBUpGGRPXLIjsB82sCsj2izV+gLkxFcqB4TgZnuL688AMYqHX0e J+HvgGaEYoJMJpvPz3ZwcRZjvJ0EqpyGvHEpMm6NtZQH6brcrd13IuBKtvp81HWoDAzh kkD1PL+PXch3SY1/PfPHhR+6liUzjqVeIBtx5x6lq3FeIVRdIKD0d7613fDV2S23Gh5p aQ+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hSh8R9um; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si17011648edw.196.2021.03.03.22.27.37; Wed, 03 Mar 2021 22:27:59 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hSh8R9um; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1839394AbhCBQRk (ORCPT + 99 others); Tue, 2 Mar 2021 11:17:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:38500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351217AbhCBNtZ (ORCPT ); Tue, 2 Mar 2021 08:49:25 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id F3B7D60C41; Tue, 2 Mar 2021 13:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614692863; bh=1QT9Jo+ZtFYdSbb6Zn/Pha/R/xZ7LYXPosLrCrzMQcU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hSh8R9umiFJRz+GUvZwTd2thTzX9ClmlXqz8aglezu0NoxCyoRi87nCzNRsFAz5h5 xHpje6dLGhNJ/bzyC+yvU0Reo+7x3tm2NBVX0n6ytmmyL4US6+irCTb3wkPT9yy9io ZLGwKsrL9Lkklekkd7u9FdxyC4WvXS7NsaATpNMns1vzXOI/prFyywA0mN4nCPiR8s Wa8KXA5q4FOOiHiPNsQcTFijayStjXeGLv55MeypRFbLFMSZOTz3OT2gcHGdrYdGgl spb554fomGDxD5ibG9F7ByYgXNRMdHLaDmUYrIa51EpL0Z5WuY+CXePaJYC6eQPDwO RXg2g1yztMugA== Date: Tue, 2 Mar 2021 15:47:24 +0200 From: Jarkko Sakkinen To: Andy Lutomirski Cc: Tianjia Zhang , 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 , Jia Zhang Subject: Re: [PATCH] selftests/sgx: fix EINIT failure dueto SGX_INVALID_SIGNATURE Message-ID: References: <20210301051836.30738-1-tianjia.zhang@linux.alibaba.com> <3bcdcf04-4bed-ed95-84b6-790675f18240@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 in some of the last versions I replaced key generation with a static key: static RSA *gen_sign_key(void) { unsigned long sign_key_length; BIO *bio; RSA *key; sign_key_length = (unsigned long)&sign_key_end - (unsigned long)&sign_key; bio = BIO_new_mem_buf(&sign_key, sign_key_length); if (!bio) return NULL; key = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL); BIO_free(bio); return key; } /Jarkko