From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.82]) by mx.groups.io with SMTP id smtpd.web11.28989.1674424454082826715 for ; Sun, 22 Jan 2023 13:54:14 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=aFj4eycn; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.94.82, mailfrom: jbobek@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BI0876vnga3qlZc6ssQcMsYuMUrecMeHI3uGcHABlo6akhAcviemdtv7drw7E4tpb7jX0x3fBNMXo2eGFReQUPdn3I18Vaiopvf+06SPNlREsK58NMLHaJJKA0qT9Qw31AR4YTamgrbWtorLOTByRW5mGSCfO9jZrjEenac80JFHvPOJkw6SHTJyk80F8dCafNcAmEGTJJUiHoDLCq7k2wHZFDh9KNk1nMmc+x+veD0Q0u0SIoFFVMStFZNjW4gtS4uzO1BwjjvzW0eVomGTylmz3zwLy0+PNjnamB34gpvXSG2rkBbR76C9X050xbWznCSvkJAXXX3PTXsn6YWjMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4hfhweOkaqNBTRYVXS0GHzRCishSfASkD4R4rM9v3WE=; b=jP1R1/SjwIRaPLMg0cZyZYpj8AIRA2nrOxm1eQpac8+0xZOBNIzFfoXm2ckDBE9XnjvY+PKW2wMVFjn5BYUKsT89e2VoZ38YIrQHtiZCVof/83NbrLJSO5wgm9vKorzPGbuu7ywdQlcNI7mg0Y7qHywePXoDHFd/724vX9od6bujpO8Yg37sECfgcc64xT+dkeQyoW+odtyKPvlx99xNwHPlp4Y7VvHaq1XLaW8ZHCT/tzV8TFBToERLX8pRm7kEWXhLEku/ZZBONsb1BpW9c55ugKv0fSXt3G9b9eSVrnA9Xj1J84NU70NRnSCr7ekq34WtYn7p7GoEEN+KGt51sA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4hfhweOkaqNBTRYVXS0GHzRCishSfASkD4R4rM9v3WE=; b=aFj4eycnJ0v2dHPvrTBjnT5ZV0gDyFK1RD73WA/sHT93/IDeu3Vqoi8fjY5a6cGjiPDg4DeJmoH1XRUbWjOQWcCK1j/pgBtda2iz5l7bb6Sq6wxrHbwCFctYpM8P7euXI+KtHWFS1qtNgVTFylAoCp6WBHAawwsIkZTOjvcXqCDX7G/cziVOtpdSZaxp5QqSvb4JEhmpy1oPz1GbKJY69qYmuxnS6pUyN4brITK6YXgVn73Ao8c4rAMLRhuP0S+1WlmEkjIIkT+26FrsdDXejnLFV9WyJyE2wZ3MQ7vZB3XKGg8WrIrIIQkxOeJIgUeGl6MyQCDWEQYkcu7BQkD11A== Received: from CY5PR03CA0024.namprd03.prod.outlook.com (2603:10b6:930:8::35) by BY5PR12MB5509.namprd12.prod.outlook.com (2603:10b6:a03:1d7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33; Sun, 22 Jan 2023 21:54:11 +0000 Received: from CY4PEPF0000C985.namprd02.prod.outlook.com (2603:10b6:930:8:cafe::d3) by CY5PR03CA0024.outlook.office365.com (2603:10b6:930:8::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.33 via Frontend Transport; Sun, 22 Jan 2023 21:54:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CY4PEPF0000C985.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6043.13 via Frontend Transport; Sun, 22 Jan 2023 21:54:10 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Sun, 22 Jan 2023 13:54:10 -0800 Received: from jbobek-titan.nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Sun, 22 Jan 2023 13:54:09 -0800 From: "Jan Bobek" To: CC: Jan Bobek , Jiewen Yao , "Jian J Wang" , Min Xu Subject: [PATCH v2 1/1] SecurityPkg/AuthVariableLib: Check SHA-256 OID with ContentInfo present Date: Sun, 22 Jan 2023 14:53:48 -0700 Message-ID: <20230122215348.47191-1-jbobek@nvidia.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Return-Path: jbobek@nvidia.com X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000C985:EE_|BY5PR12MB5509:EE_ X-MS-Office365-Filtering-Correlation-Id: 4fd9a289-fa10-4ec9-7a42-08dafcc33197 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 01c8k8lPrA/kA5hF4MGDpqUUgBEyt7Bb0PfIJkzCx9mMLXyMzyXnVknCMPsS0CQBW2Q+a58CSMgjg7s4EW5OfQjTQ5dvir1/U7VKk6QYKz5H2JXYEcG9SHo0sFunWlcYnDS2bOnfRVM3zA1Q9Xr40egfhwtRF2geHyLpEPht4y81EkIVIU7B1ykHqsX6TtYUItWCTEQEepODGBtF2Jes9a+ufK70AcTermt9C0PBJSU9m6khk8iY8IexbPcUeo/3qhKKTlhpvHZMwIYQxpF+pKESC5hJlNRGTNVWNXbZjWYbm93vZo4oUr/AstxmN+b+WTaii14cRoPkwipbYWN4ZUjVqDnVCoft7c1sT/rTjpjZcRBdlZs5aBrKz458JpuvQbOvSYW919hEBlaFPPvH3zpo28G/bhoI+JD1hP/bd85CTasu/kW2rgP3ID60S6VPikFafQKiNbw4z0QuCHNJC368dqDsnulUHazmWzmej9w2NrBYGJticiLxw1Nlt/Uy3YRfaTcS9neNbzt5xgWaAnIgeTAQNWxtm8rgnr/E9fzHvWakW58VbFJ36oSiT0w78LunRAe8MWIAGbJqZ8DWymCuSiF+0lO7kkjYC/X6yO9G48/XoiF9xPURgFvknAxE2biRkksmz/aEhARyQWHrM1nc+kF+toBu5hlTRJ0mPImqjrf/lDmslQZs0WDEIyDspzCoWHTWZEfv+IgzAxBY0rJqzWa3zfJ4E/+VpG8GCAwg8QepzbwwPuzAIDa/r0B4LQmMG0x3kYqZyPsy+abhJ9TGR5JPN7ulTU1y/+6G+wk= X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230022)(4636009)(396003)(39850400004)(376002)(346002)(136003)(451199015)(46966006)(36840700001)(83380400001)(36860700001)(356005)(82740400003)(7636003)(86362001)(15650500001)(2906002)(41300700001)(4326008)(5660300002)(8936002)(82310400005)(40480700001)(6916009)(8676002)(16526019)(186003)(26005)(6666004)(336012)(47076005)(426003)(1076003)(2616005)(19627235002)(316002)(54906003)(70586007)(70206006)(966005)(478600001)(7696005)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jan 2023 21:54:10.5772 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4fd9a289-fa10-4ec9-7a42-08dafcc33197 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000C985.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB5509 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4305 Based on whether the DER-encoded ContentInfo structure is present in authenticated SetVariable payload or not, the SHA-256 OID can be located at different places. UEFI specification explicitly states the driver shall support both cases, but the old code assumed ContentInfo was not present and incorrectly rejected authenticated variable updates when it were present. Cc: Jiewen Yao Cc: Jian J Wang Cc: Min Xu Signed-off-by: Jan Bobek --- .../Library/AuthVariableLib/AuthService.c | 50 ++++++++++++++++--- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/SecurityPkg/Library/AuthVariableLib/AuthService.c b/SecurityPk= g/Library/AuthVariableLib/AuthService.c index 054ee4d1d988..9beeca09aeba 100644 --- a/SecurityPkg/Library/AuthVariableLib/AuthService.c +++ b/SecurityPkg/Library/AuthVariableLib/AuthService.c @@ -1925,7 +1925,7 @@ VerifyTimeBasedPayload ( // SignedData.digestAlgorithms shall contain the digest algorithm used w= hen preparing the // signature. Only a digest algorithm of SHA-256 is accepted. // - // According to PKCS#7 Definition: + // According to PKCS#7 Definition (https://www.rfc-editor.org/rfc/rfc= 2315): // SignedData ::=3D SEQUENCE { // version Version, // digestAlgorithms DigestAlgorithmIdentifiers, @@ -1933,15 +1933,49 @@ VerifyTimeBasedPayload ( // .... } // The DigestAlgorithmIdentifiers can be used to determine the hash a= lgorithm // in VARIABLE_AUTHENTICATION_2 descriptor. - // This field has the fixed offset (+13) and be calculated based on t= wo bytes of length encoding. + // This field has the fixed offset (+13) or (+32) based on whether th= e DER-encoded + // ContentInfo structure is present or not, and can be calculated bas= ed on two + // bytes of length encoding. + // + // Both condition can be handled in WrapPkcs7Data() in CryptPkcs7Veri= fyCommon.c. + // + // See below examples: + // + // 1. Without ContentInfo + // 30 82 0c da // SEQUENCE (5 element) (3294 BYTES) -- SignedData + // 02 01 01 // INTEGER 1 -- Version + // 31 0f // SET (1 element) (15 BYTES) -- DigestAlgorithmIdentifie= rs + // 30 0d // SEQUENCE (2 element) (13 BYTES) -- AlgorithmIdentif= ier + // 06 09 // OBJECT-IDENTIFIER (9 BYTES) -- algorithm + // 60 86 48 01 65 03 04 02 01 // sha256 [2.16.840.1.101.3= .4.2.1] + // 05 00 // NULL (0 BYTES) -- parameters + // + // Example from: https://uefi.org/revocationlistfile + // + // 2. With ContentInfo + // 30 82 05 90 // SEQUENCE (1424 BYTES) -- ContentInfo + // 06 09 // OBJECT-IDENTIFIER (9 BYTES) -- ContentType + // 2a 86 48 86 f7 0d 01 07 02 // signedData [1.2.840.113549.1.7= .2] + // a0 82 05 81 // CONTEXT-SPECIFIC CONSTRUCTED TAG 0 (1409 BYTES) = -- content + // 30 82 05 7d // SEQUENCE (1405 BYTES) -- SignedData + // 02 01 01 // INTEGER 1 -- Version + // 31 0f // SET (1 element) (15 BYTES) -- DigestAlgorithmIde= ntifiers + // 30 0d // SEQUENCE (13 BYTES) -- AlgorithmIdentifier + // 06 09 // OBJECT-IDENTIFIER (9 BYTES) -- algorithm + // 60 86 48 01 65 03 04 02 01 // sha256 [2.16.840.1= .101.3.4.2.1] + // 05 00 // NULL (0 BYTES) -- parameters + // + // Example generated with: https://wiki.archlinux.org/title/Unified_Exte= nsible_Firmware_Interface/Secure_Boot#Manual_process // if ((Attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) != =3D 0) { - if (SigDataSize >=3D (13 + sizeof (mSha256OidValue))) { - if (((*(SigData + 1) & TWO_BYTE_ENCODE) !=3D TWO_BYTE_ENCODE) || - (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha256OidV= alue)) !=3D 0)) - { - return EFI_SECURITY_VIOLATION; - } + if ( ( (SigDataSize >=3D (13 + sizeof (mSha256OidValue))) + && ( ((*(SigData + 1) & TWO_BYTE_ENCODE) !=3D TWO_BYTE_ENCODE) + || (CompareMem (SigData + 13, &mSha256OidValue, sizeof (mSha2= 56OidValue)) !=3D 0))) + && ( (SigDataSize >=3D (32 + sizeof (mSha256OidValue))) + && ( ((*(SigData + 20) & TWO_BYTE_ENCODE) !=3D TWO_BYTE_ENCODE) + || (CompareMem (SigData + 32, &mSha256OidValue, sizeof (mSha2= 56OidValue)) !=3D 0)))) + { + return EFI_SECURITY_VIOLATION; } } =20 --=20 2.30.2