From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) by mx.groups.io with SMTP id smtpd.web10.207.1688080064165106901 for ; Thu, 29 Jun 2023 16:07:44 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=WBQ30P9r; spf=pass (domain: gmail.com, ip: 209.85.167.169, mailfrom: kuqin12@gmail.com) Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-39ca120c103so876366b6e.2 for ; Thu, 29 Jun 2023 16:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688080063; x=1690672063; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=6pfqoKHbodi/HIkEf4MV4030kf9Rvw7OjijhejLPewY=; b=WBQ30P9rlnVSpHBazW0r6rpTgrhQj0t348ODTbzxmaKfQgdNFzwmbOlSGH9z0uYe5P zD0dlkDT9J1N//rOW760+Alu130HMzks/6HChZdIKxMvYL6nVRS/GmaSf+l8AHppOEjI 55zRftP0OJjMLZLhUX9iUCHQnv5UxbrCdnYQBO2rTHJBuUJpSBJ1hpSru10nIR0n1WZG 4DaEn5PzhlKCQe0LCWymWEij+bK718GaedwYc9AkbQeXHe7g7uxxLAzXLdv+ReZsAmUJ NJURQ62Z9uczCLKDBmudkq9nxfg6TfGIcvkBPNjTIOaGOJs3tMPubX+Wianu8E10Qj43 S10w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688080063; x=1690672063; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6pfqoKHbodi/HIkEf4MV4030kf9Rvw7OjijhejLPewY=; b=kNmDxWJNfFEx0sW9FEe3oN2bFy2ybqhwuozfDaOqn5DA3dYqCCh6iTnqMGqRi7rnka es0VaIfBZ6DG6UFdM4aVBdEArtXQ7h1E+XgzyqFVbwX1s5JWhlm3jLo5QibevmxeO+3J 1hjtrsDJRw67HA8p7jlW7AUROHn6NEpPkfLik3PdusN/OGeBAGi64ogofv2binKX9NSP WCYraleBN66BzeuIsxL82B5TRSGn8ScgcidFhds/iXR/Ztwy69TFyikda/Kz3U6Kx2iG gG1aaDrS+Cy10hegL9Bn3WJ521doIpBv021VirMOl4DXj2lSXVzvCWbwumUFfsRFoKy7 WzJA== X-Gm-Message-State: AC+VfDx9UklpwRVfphJVEYZXz31Qrf3/QV9Yr8YsOZzffczIhm1WqFQp axJeGUxjlaqNkmbCXhufwxi+HnfDQAQ= X-Google-Smtp-Source: ACHHUZ5LzouKVAS/Uw7oHIGXcG8mur9h2g7FxVyCVm346v23Ui2y+MtQc8twXHIANBDQQRamuEX8EQ== X-Received: by 2002:aca:2808:0:b0:3a3:7a73:f1a8 with SMTP id 8-20020aca2808000000b003a37a73f1a8mr688233oix.41.1688080063003; Thu, 29 Jun 2023 16:07:43 -0700 (PDT) Return-Path: Received: from ?IPV6:2001:4898:d8:33:956:7e07:c1c3:d47a? ([2001:4898:80e8:2:8976:7e07:c1c3:d47a]) by smtp.gmail.com with ESMTPSA id j21-20020aa78dd5000000b0067f2413bf6dsm3760182pfr.106.2023.06.29.16.07.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jun 2023 16:07:42 -0700 (PDT) Message-ID: Date: Thu, 29 Jun 2023 16:07:42 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [edk2-devel] [PATCH v1 7/8] SecurityPkg/RngDxe: Select safe default Rng algorithm To: devel@edk2.groups.io, sami.mujawar@arm.com, pierre.gondois@arm.com Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Jose Marinho , Samer El-Haj-Mahmoud , "nd@arm.com" References: <20230509074042.1523428-1-pierre.gondois@arm.com> <20230509074042.1523428-8-pierre.gondois@arm.com> From: "Kun Qin" In-Reply-To: Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Sami, Your suggestion in https://edk2.groups.io/g/devel/message/106511 works properly during my test. But I think we still need to keep the `+      &RngGuid, ` change below as a bug fix? Thanks, Kun On 6/29/2023 3:28 AM, Sami Mujawar wrote: > Hi Pierre, > > I think this patch would not be required if my suggestions for patch > 6/8 are adopted. > > Regards, > > Sami Mujawar > > On 09/05/2023 08:40 am, pierre.gondois@arm.com wrote: >> From: Pierre Gondois >> >> The first element of mAvailableAlgoArray should be the default >> algorithm to avoid going through a selection process at each >> RngGetRNG() call. >> Once all the available Rng algorithms have been probed, place >> a safe Rng algorithm at the first position of mAvailableAlgoArray. >> >> Signed-off-by: Pierre Gondois >> --- >>   .../RngDxe/AArch64/AArch64Algo.c              | 48 ++++++++++++++++++- >>   1 file changed, 47 insertions(+), 1 deletion(-) >> >> diff --git >> a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c >> b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c >> index a1ff7bd58fda..ed236b2e8141 100644 >> --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c >> +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c >> @@ -17,6 +17,50 @@ >>   // Maximum number of Rng algorithms. >>   #define RNG_AVAILABLE_ALGO_MAX  2 >>   +/** mAvailableAlgoArray[0] should contain the default Rng algorithm. >> +    The Rng algorithm at the first index might be unsafe. >> +    If a safe algorithm is available, choose it as the default one. >> +**/ >> +VOID >> +EFIAPI >> +RngFindDefaultAlgo ( >> +  VOID >> +  ) >> +{ >> +  EFI_RNG_ALGORITHM  *CurAlgo; >> +  EFI_RNG_ALGORITHM  TmpGuid; >> +  UINTN              Index; >> + >> +  CurAlgo = &mAvailableAlgoArray[0]; >> + >> +  if (IsZeroGuid (CurAlgo) || >> +      !CompareGuid (CurAlgo, &gEfiRngAlgorithmUnSafe)) >> +  { >> +    // mAvailableAlgoArray[0] is a valid Rng algorithm. >> +    return; >> +  } >> + >> +  for (Index = 1; Index < mAvailableAlgoArrayCount; Index++) { >> +    CurAlgo = &mAvailableAlgoArray[Index]; >> +    if (!IsZeroGuid (CurAlgo) || >> +        CompareGuid (CurAlgo, &gEfiRngAlgorithmUnSafe)) >> +    { >> +      break; >> +    } >> +  } >> + >> +  if (Index == mAvailableAlgoArrayCount) { >> +    // No valid Rng algorithm available. >> +    return; >> +  } >> + >> +  CopyMem (&TmpGuid, CurAlgo, sizeof (EFI_RNG_ALGORITHM)); >> +  CopyMem (CurAlgo, &mAvailableAlgoArray[0], sizeof >> (EFI_RNG_ALGORITHM)); >> +  CopyMem (&mAvailableAlgoArray[0], &TmpGuid, sizeof >> (EFI_RNG_ALGORITHM)); >> + >> +  return; >> +} >> + >>   /** Allocate and initialize mAvailableAlgoArray with the available >>       Rng algorithms. Also update mAvailableAlgoArrayCount. >>   @@ -45,7 +89,7 @@ GetAvailableAlgorithms ( >>     if (!EFI_ERROR (Status)) { >>       CopyMem ( >>         &mAvailableAlgoArray[mAvailableAlgoArrayCount], >> -      RngGuid, >> +      &RngGuid, >>         sizeof (RngGuid) >>         ); >>       mAvailableAlgoArrayCount++; >> @@ -68,5 +112,7 @@ GetAvailableAlgorithms ( >>       mAvailableAlgoArrayCount++; >>     } >>   +  RngFindDefaultAlgo (); >> + >>     return EFI_SUCCESS; >>   } > > > > >