From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1DFAD740032 for ; Mon, 19 Feb 2024 20:18:06 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=fVhwWXbGMmKs1x9XdJ+A6WlkIJWdrueTYRvy/iUK+WI=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1708373885; v=1; b=mtD8OFEfbFDkYpRQzT0UG8TtyDJoPdJGo1SoJ4vrnNsV6TPkknJIjUbrbKLW/s3eGrle7rPy zq6mqr6xX/DFAesD0sAtkFti6WDWZkGocjadAOdn/ecs5Yo7qpRY1Tg+2lANhxGDSriZYrK44EL EpM6DV9XMs10lJEQ34mg43CQ= X-Received: by 127.0.0.2 with SMTP id J4sGYY7687511xMWDtf1igSx; Mon, 19 Feb 2024 12:18:05 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web10.4315.1708373884855600698 for ; Mon, 19 Feb 2024 12:18:05 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-UF1U4W7pN9qrBu_lfCaEVA-1; Mon, 19 Feb 2024 15:18:02 -0500 X-MC-Unique: UF1U4W7pN9qrBu_lfCaEVA-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FB6038212C3; Mon, 19 Feb 2024 20:18:02 +0000 (UTC) X-Received: from [10.39.194.20] (unknown [10.39.194.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9C9214F0; Mon, 19 Feb 2024 20:18:01 +0000 (UTC) Message-ID: <0d8b566a-ff75-16c2-ddf3-3ce754a66cff@redhat.com> Date: Mon, 19 Feb 2024 21:18:00 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] The API in BaseCryptLib can't seed the pseudorandom number generator properly To: eddie wang Cc: devel@edk2.groups.io References: <08efe7f7-b7d2-a806-39da-b3ebadd45ec4@redhat.com> <9db8ea7f-1d7d-3558-19e5-dbda730872ac@redhat.com> From: "Laszlo Ersek" In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ffiqxeNNym5zk9PSblRVXDKPx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=mtD8OFEf; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 2/17/24 10:17, eddie wang wrote: > Hi Laszlo, > After digging dipper,  we found that the *EVP_RAND_fetch *in > "rand_new_seed" and "rand_new_drbg" both got NULL in our case. It's > meant the DRBG implementation could  > not be fetched. We also compared it to the case on Linux, and they could > both fetched DRBG implementation correctly. Is it possible that the > opensslLib 3.0.9 caused any compatibility issues with edk2?  Or has > anyone else encountered the same problem with these openssl services? Sorry, I can't say. If you have a small reproducer UEFI application that works fine when built with edk2-stable202305, but does not work when built against either edk2-stable202308 or current master, then filing a TianoCore BZ (regression) seems justified. (AFAICT it was edk2-stable202308 that incorporated the OpenSSL 3.0.9 upgrade, from 1.1.1u.) Attaching the source code of the small repro application to the ticket would likely be helpful. Laszlo > Laszlo Ersek > 於 2024年2月 > 15日 週四 下午7:48寫道: > > On 2/15/24 12:09, eddie wang wrote: > > Hi Laszlo, > > Thanks for your reply. How can I enable the DEBUGs at RandomSeed() > ? Or > > any suggesting information that I can provide? > > Sorry, upon a closer look, I see you had already narrowed it down to > RAND_seed() and RAND_status(), which are direct OpenSSL APIs. So my > suggestion would amount to adding DEBUGs to OpenSSL, such as to > RAND_seed() in > "CryptoPkg/Library/OpensslLib/openssl/crypto/rand/rand_lib.c". > > But, I think you may be able to do just that. > "CryptoPkg/Library/Include/CrtLibSupport.h" already includes > , and DebugLib is listed under [LibraryClasses] in each > instance of OpensslLib. So if you modify your > "CryptoPkg/Library/OpensslLib/openssl" submodule directory tree locally, > with the following patch: > > | diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c > | index 0fcf4fe3bc1e..e5f105268f52 100644 > | --- a/crypto/rand/rand_lib.c > | +++ b/crypto/rand/rand_lib.c > | @@ -257,6 +257,8 @@ void RAND_seed(const void *buf, int num) > |      drbg = RAND_get0_primary(NULL); > |      if (drbg != NULL && num > 0) > |          EVP_RAND_reseed(drbg, 0, NULL, 0, buf, num); > | + > | +    DEBUG ((DEBUG_INFO, "%a: hello\n", __func__)); > |  } > | > |  void RAND_add(const void *buf, int num, double randomness) > > then you should get usable debug messages -- at least it builds for me. > > Inserting DEBUGs like this (over multiple rounds of testing / narrowing) > should lead you to the exact location that is responsible for the > initialization failure. > > You mention you have encountered the problem with a UEFI application. > That is relevant for choosing your DebugLib instance. If you already > have a function DebugLib instance for your platform (logging to the > serial port, for example), then just use that. > > Otherwise, consider building your UEFI application with a module scope > override in the DSC file, one that resolves DebugLib to > >   MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf > > or > >   MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf > > These will send DEBUG messages to the UEFI console or standard error > devices, respectively. > > hth > Laszlo > > > Laszlo Ersek > >> 於 2024年2月 > > 8日 週四 上午5:03寫道: > > > >     On 2/6/24 08:00, eddie wang wrote: > >     > Hi all, > >     > We had an UEFI application that used the EDK2(2023/12/05), > and  we > >     would > >     > like to take advantage of the services in BaseCryptLib .However, > >     the API > >     > in CryptPkg "*RandomSeed()*"(X64, in CryptRandTsc.c) always > returned > >     > false because of  the pseudorandom number generator set up > failed. > >     I am > >     > not sure this issue is from the *openssl configuration in > >     OpensslLib(we > >     > use the default configuration)* or is from the *openssl 3.0.9*. > >     > > >     > Is there any comments about this issue? > > > >     Can you narrow it down by inserting DEBUGs starting at > RandomSeed() > >     [CryptoPkg/Library/BaseCryptLib/Rand/CryptRandTsc.c], and then > digging > >     down as necessary? > > > >     Laszlo > > > > > > > >      > > > > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115599): https://edk2.groups.io/g/devel/message/115599 Mute This Topic: https://groups.io/mt/104198931/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-