Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp629017pxf; Wed, 10 Mar 2021 13:41:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJyHD9HDw2P+wzOlAXk9JrYJEtYYYH/aWKh2qYf4XCfPa90c/WIKeR3zWTlIeltpjXr684Wx X-Received: by 2002:a17:907:76b6:: with SMTP id jw22mr438393ejc.11.1615412494334; Wed, 10 Mar 2021 13:41:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615412494; cv=none; d=google.com; s=arc-20160816; b=RGgiaahl5qpS8xnIhRWHWSRNn2kOBClgeOyvfp1AwvbSsP+mApWCnbXKD5fnsHdfBh h3mcOYfFCohIjoeVB/ntUtZ0tmJ9XdqqGClyKHz1ek2RS0AhpdbETxAzfzKAwEZ2JvD9 aMSAxOLSOExU1osxJC70qkPN8VWcYePLe6vTPi40fpUpCTUMscAsyIQOccLiaPHtRzKf WqX8P9Efy3kaI1bTlHc7jRwsuYibgJfK8dBNlfEoamhd0SpT7kJOpTK+4dliJtWaLo0h PqWCfH3iYKa/1AQ7LOxM5TjzekF7WMrXja1pzzd1Ssu7iQLzmxOG2hpStuAdtw9aclu9 Ei+w== 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=i8Y2hunIRfrqPQHQ2HPk/MzHFZ6JYdYNc79sbb7xJJ0=; b=dxmQeagJsmElfAOtjmzogOV1tZykLFKvXBSrbRegJ1JOe8k4cF37TSk//JuW7sLMNm APND0Fnafyw0zO3263wbWJQbO8hPehlySRhpUYIsMk5oEhtniGLWBi2PG7gowCUzb/WQ 63rrTyIHZLj0XFc6Qv03lOxXIrdcZILx1ve11IZA5iAbzPKbwSZb4Jw12K9tUmbBjoj8 USWlM6SC6xHebX/sTR3SXyZO/K81e6eMbRUbR4vFJturW+7L5949E5x0OkaxM8B+izdI ukwVB0ZuUsUQYLwhXoElM/hFW0jfLyXuh6TOX5Rv0wA9jhoHMQzG1mToWcEy00mJI95B JGwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=El7iw81e; 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 i8si394579edy.129.2021.03.10.13.41.08; Wed, 10 Mar 2021 13:41:34 -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=El7iw81e; 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 S230527AbhCJVkE (ORCPT + 99 others); Wed, 10 Mar 2021 16:40:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:42384 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbhCJVjg (ORCPT ); Wed, 10 Mar 2021 16:39:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D14864FC4; Wed, 10 Mar 2021 21:39:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615412375; bh=UdFxVt64TzjKasA+NMSYVTgOVpISnwKFURrW8ppuVck=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=El7iw81ezSJi4ARA7ejwk5ECH5c2j22Aay12Zi77N7B5T7/Fdw7c3wOJk35JlyBBW H8WtGS3rFYrYVYZcXQBFzQXDoeYjMeQ0/ElxndxpDnp1HpkvBz4CVjJ5952mcg7tgn LFZ9hXoZuTr4QdTJU7dhoKWkgOR2hOpRdFhAu/XGuywTu87XwgQhE7/37TEDLe92/Y +W762Xh/CO/ZL4zcdqk7e6VMUgL2uy4RpzpNeeVfTVLHhuh5UcUUNTSH1RGuoyMweZ sDCpsIkSFxOruGMEWq92/6GdUo/G748CQ/UqHa06QogWLJ/SqVhsm3M93XDkKmBOMJ vODf01DZHbIog== Date: Wed, 10 Mar 2021 23:39:11 +0200 From: Jarkko Sakkinen To: Jia Zhang Cc: Andy Lutomirski , 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 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1f5c2375-39e2-65a8-3ad3-8dc43422f568@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? /Jarkko