Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1413025pxf; Fri, 12 Mar 2021 08:57:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxP/xlt1zmgskHQZQtLLLrx4hR5aC8xHXFVcWYoLpiJ+FEManr+rnGM1qTQhYbMM3lWTipn X-Received: by 2002:a17:907:3f26:: with SMTP id hq38mr9681707ejc.374.1615568242863; Fri, 12 Mar 2021 08:57:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615568242; cv=none; d=google.com; s=arc-20160816; b=Od3LgsBszZdsVLFDg0qt/geRFnZHLcCAI/aAmtIgc5sBEaNc83e1FhOalVozoqvZmg pNMd4dne0FqBoUFbjMCs7AMe/7zbfwcla5gJiebogpKVNqXkoiURKBo0whYia/Sopfl+ p7QiePi3Su3fawGrGOL4axb/310qjEmj9lKn8qXO/jBxMs9uORfXXUv3Yd5L0RfZbCNu 0pmXFpiHaTnCzz6MtZwfvaX16qQq/0hmXvSbIF14wY+BJEanzWZtexJlbxrNkO/VJ5N1 hh4VaVNFLhM/rL6bNMlU2tDXfaIg+542FtHu/F20O4Gt0xNkcWdOrZ9JkEARoeLxLROF YqFA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8U+wg/THg4cLVZhB0JcGrcLWEPVUpwQpI3iHuFIWReo=; b=dE2TlN0HyXx7C2wHtywPE5VEoJe9i2EHs3JPe+E3olW2Q1nUKu20Zb6ZREBg/gC6TB ddmVduYbnmCe+VIp0mDYzoU5ag/5LN09A/DZ0HCXsILlVitU0Yb/43Q2q2tEICc+wnB0 1al9Uxp4GThDd1ZfZ/fhnvOdiAZH2PFVLXj0pFgBfTkKCOKwZLYIcYM63IVuzehVEpUp L9WA1JV8r0N9vpb+DngqHYfGd2HBDtC2V0gwklAMvs9VosV1YKiyBqCLzPvr5Gb6T7RV 5aRu9J5qKk4u/DYywtunsUQC8cuWOw/Pyl8+8qvAJqPaCYeprQafth27r+OlhFjw04Cq +SUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q3JXi+S0; 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 p25si4426334edm.297.2021.03.12.08.57.00; Fri, 12 Mar 2021 08:57:22 -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=Q3JXi+S0; 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 S231346AbhCLQx7 (ORCPT + 99 others); Fri, 12 Mar 2021 11:53:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:49506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbhCLQxb (ORCPT ); Fri, 12 Mar 2021 11:53:31 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C58E764FD9; Fri, 12 Mar 2021 16:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615568011; bh=aF/mMRBTJBBXplInmQ4Ie8yBGvNGzPk48GM4ArjgNIE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q3JXi+S0hFtM7MxJAZcxykl+OYDBOkih6O6UNKQGYBMLG+PAiy2VR2W9zXtkpEYKk V8fftnIRLe65q1nHXjfuYR77hVjdPJ5LEMzH6nYNY0szn8mWyK+Yc4LeGJEkY1Igla nDw0M+TJSTqdj76HRi4mcpWJsutWWz6BMlVLvx47h2E3yOH41kKXa/XtQOYhX4r3V0 tdwR02tvj109O1T6FwoJE7EZLIFlegiMwY9PC0xI13FDMWyAdZaUugZNFStpVQ1xa9 nqXM5QuRmRuNqjDLqMs87v4NQcw0untqVeetygnm6pwYoyVmbxQ9KR920fw+EkmzZ5 2FJC+04lDPyzw== Date: Fri, 12 Mar 2021 18:53:06 +0200 From: Jarkko Sakkinen To: Tianjia Zhang Cc: Jia Zhang , 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 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> <1f5c2375-39e2-65a8-3ad3-8dc43422f568@linux.alibaba.com> <20ef1254-007d-04ce-8df5-5122ffd4d8d3@linux.alibaba.com> <710b65d6-e492-ae24-f2af-6973e1df1b85@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <710b65d6-e492-ae24-f2af-6973e1df1b85@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > > > > > 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