From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nhjry-0002ul-Ug for mharc-grub-devel@gnu.org; Thu, 21 Apr 2022 23:22:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhjrx-0002tf-FZ for grub-devel@gnu.org; Thu, 21 Apr 2022 23:22:05 -0400 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:34786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhjrv-0002y0-9M for grub-devel@gnu.org; Thu, 21 Apr 2022 23:22:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1650597719; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=fXmTTeJ40DqQJtEcgUK58f8Rkcz0cq+7vTzb6NCKZVg=; b=SXNX6tiBlVxyCoivEnOTyYzRyZ0Y3taQMyJ1hx/SUo9BgnuJ5VZwCx22sSmiycO0RceXeH 0fO2v7OPWrRxUXLtsUkP02tSbMgnm4Tlzqa6bSn/iQQ/ek7erAVPHDEAqYBNqhznMN+EGP AW1yN8YYBLSVL2BkqUMV0NpnirGZH/g= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2171.outbound.protection.outlook.com [104.47.17.171]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-35-aDAMS00AP5WfdYOHo1gdHw-1; Fri, 22 Apr 2022 05:21:58 +0200 X-MC-Unique: aDAMS00AP5WfdYOHo1gdHw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ny141KJoy6qxgujqurkGUaLhXdlF+cmP2g1CG5dA9t3NWzppkEvp3u4e7XNVb+GGc3XADNOH/+RuJtaua0+mWF7DxYy2P8Ef4ikcMczaKDPiXfjQLG7ZKIBgydllQH/eIyyvk/e+2GO4l+FBfreVIX2V2/eRplZEGThuzwWqRHj6eOveEEQtk/xmXUE18/mwOcWfHV86hBHcyEijulA2+G6JIUVCcy9KlVKxT3RH2OQ+S8CJtEONzDfmpX7tSlZwJPpOEiZUua6UOGG3uZFt2738HUw72vG/MfUrCHnOwFRdOAY+3dYDlsVQxPFi+3QpQvyJdhv+y/7Re4awbU52jQ== 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=fXmTTeJ40DqQJtEcgUK58f8Rkcz0cq+7vTzb6NCKZVg=; b=JoA/Ni9xld+gfgParroLfGiC+DqKzRF+RGd7jbFLfYE2En8EcSTMlmplxx6aVu7xfsCRRl2jQfHowbvmFRaX+zkpplMRyBSOE1ctEw9eFzHm6ePEWt2u3EAiVuryR+kY2qfdrhm8/B8ekoDTfKVZyLrWexOY4K5sf9lHfRbVDIGGOpqH1y7bBQExX35Vftge7IGdpnridNvVQqJUQi3C+C5x/EUQrYJMoL1WSTo3j+tYJIyKcBuVC6PBoC7qootcMbwx/XCqhBCF2A3TOnkGZ5nUOe+fiWhbLviuEzlcDflQ812bVYfQldtOLGnqFlNfrxTTLRalW8qHWftPOMltjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DU2PR04MB9081.eurprd04.prod.outlook.com (2603:10a6:10:2f0::13) by DB6PR04MB3142.eurprd04.prod.outlook.com (2603:10a6:6:7::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Fri, 22 Apr 2022 03:21:55 +0000 Received: from DU2PR04MB9081.eurprd04.prod.outlook.com ([fe80::ac7d:127a:3e85:494]) by DU2PR04MB9081.eurprd04.prod.outlook.com ([fe80::ac7d:127a:3e85:494%6]) with mapi id 15.20.5186.014; Fri, 22 Apr 2022 03:21:55 +0000 Date: Fri, 22 Apr 2022 11:21:48 +0800 From: Michael Chang To: The development of GNU GRUB Cc: Michal =?iso-8859-1?Q?Such=E1nek?= , rashmica.g@gmail.com, alastair@d-silva.org, nayna@linux.ibm.com, sudhakar@linux.ibm.com, Javier Martinez Canillas Subject: Re: [PATCH v3 15/19] appended signatures: parse PKCS#7 signedData and X.509 certificates Message-ID: <20220422032148.GA4794@mazu> References: <20220421074714.1561049-1-dja@axtens.net> <20220421074714.1561049-16-dja@axtens.net> <20220421075750.GV163591@kunlun.suse.cz> <875yn2eko6.fsf@dja-thinkpad.axtens.net> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <875yn2eko6.fsf@dja-thinkpad.axtens.net> User-Agent: Mutt/1.10.1 (2018-07-13) X-ClientProxiedBy: HK2PR02CA0200.apcprd02.prod.outlook.com (2603:1096:201:20::12) To DU2PR04MB9081.eurprd04.prod.outlook.com (2603:10a6:10:2f0::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 20dc3995-d002-4c53-f58a-08da240f4054 X-MS-TrafficTypeDiagnostic: DB6PR04MB3142:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +XsQThF/TkJgb5KtFLdaUH4CX+opbvoNIZdczQS8oG49dgarVdVYyW0Rp9+KQHcICRDmOJl3Mn0puRIvJFPVh7zRA1ZxKp0ykdNZqp1UVsbLOiTNX41+VMsTzqNA7Zifod5g/190ccOv3/16agBU3ghdXt6vkts3+QYCm7LScEykX0V3v3/FS7MYJVSS2NcyxurPaEshPOS/qg1/QKLyQasQl3U69K7IzOBMmeD3qrYK5f0KbNPg1FWzLodMAyXqVXMtdVLux2S2XrQ2rRp9Q1E2/q1fajZ3F2HY8QahPdw6NRMFZ1vEZxfm2QLkkr/wSzwY/cnTVts/Qeqa9mdrhEuVcvALxMElOAFaCHbtCujDv3rzFS2xj6Gce+QUsTusL/dcA0LbeN4iNmnm1YD/7wI7UiTuAwdT5hX9H8HT2Wur6uBVftdnXqwn2bnJrSDOH5d19fPSiE7H5zBu2cc29wAP081lX+hNuB2dEsG5BB0Biij67VR7i2mE5iMlpY6167/AmWve3AmUStPtCYCIt3tEmMZpgnYW1ArspTc7UmpGuOYuD91fjsPGq1+psYUadwgR2OHnZWtWN2mP8jjCu3hMOO9Fk3lLGq0opSirf6hsMaA8W9nEi2u9qQ7vg7UK7DTZ/FI+mbztDCGWUgrhWI55kf25TNaOlkT8ZALT8nA2OQ45tBQ2aGnmaHD+p9M0fcSkJSLWxXRF4izfF4rVnGJLfxJ2nmUiY/CUN1S+avQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB9081.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(7916004)(366004)(186003)(1076003)(508600001)(86362001)(66476007)(6916009)(66556008)(4326008)(8676002)(54906003)(66946007)(316002)(5660300002)(38100700002)(6486002)(966005)(8936002)(6512007)(9686003)(6506007)(83380400001)(33716001)(6666004)(33656002)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 2 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wg6kvTYAishTggX9zw0edUrq7xfTparJA4XcOyLM8+1LUM23sqcXRJthSUKY?= =?us-ascii?Q?bTPMAFZRF3Dnvsql9VObJC+VyTyLSasNFgM5NpadbE0OITcjWRIKZSlr+d/w?= =?us-ascii?Q?7l0V46Cd5rJJblWD/iD3e1vl4/F6wll2rwhTyJkklAmDgrUacx3J8QGWzgJU?= =?us-ascii?Q?Z03VnFIIaP0NImsQmThMBuHXeRRN1RY8knMghwFZ333g5MFQskc08swb/356?= =?us-ascii?Q?ndmm8YeWDTStgl+6SS8kn6Fg1lwlP/088H+y6sQXLWcAxn2LlpyDVCPIwTko?= =?us-ascii?Q?y2VaUfYePAzxeLSx3UP3Q729FR4X13KU6tnQyl9q1+IuJvCIG25IJ3tGYEJE?= =?us-ascii?Q?hgNl31KCtM2OrRu4mjlJS2jd48PguSXe/echqDrNFOZsQ+S6BLFd+VBpbKrN?= =?us-ascii?Q?kLCouac525OPYeggPn7Sr3iXXgxtXlasCVbnr8XJgdCRnVaVD8db5qZ2G2eS?= =?us-ascii?Q?JD3iXGY4R0Ek5X672towsvrRYY6peAt762R+pXQhPCRE4sbxJeyBkD4ZPXAw?= =?us-ascii?Q?0Y7R+Y03v+LOksqlxDgSRWp+d/AeesOlDHoKOTjcXkYTrGIDENCGPsEbXSOM?= =?us-ascii?Q?emBkYUQ5qdywjrv59OrOl7yk/X0OhD95JY+9fuoRQDQxiAGtXQ+bywNmbHfS?= =?us-ascii?Q?WhqoyQoGBKboI1VSsQiAmMJvbcFCeae6z4/qElLy3c57S6gkF4BaJDoS/wMZ?= =?us-ascii?Q?vkWiFJWgiZZodtND452459GLGDiSISDtESrD0G3wInkbiUGATP3dacr3MjDk?= =?us-ascii?Q?CQBbIXXQvI1j57vk3ltLZY63agSSCWSflibOpeoCNqhz6qSKnUKiVcYzpj8P?= =?us-ascii?Q?WkBlbEC30nFnhVpg4Y0RTjF18FAGsFFSVlUnjprxwOc4T56mVu8TFSN8O1LC?= =?us-ascii?Q?pI2BVWZczyJWG2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3qYAv?= X-MS-Exchange-AntiSpam-MessageData-1: nbJRC/pACBNdUg== X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20dc3995-d002-4c53-f58a-08da240f4054 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB9081.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2022 03:21:55.0640 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Xc6cTg8UFOc8eux/sqSZLh/yzM6/vgfc7SnSjO6PppQXVWmzE6M2s+6jK6026DxI X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR04MB3142 Received-SPF: pass client-ip=194.104.109.102; envelope-from=mchang@suse.com; helo=de-smtp-delivery-102.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 03:22:05 -0000 On Thu, Apr 21, 2022 at 09:32:41PM +1000, Daniel Axtens wrote: > Hi, > > >> This code allows us to parse: > >> > >> - PKCS#7 signedData messages. Only a single signerInfo is supported, > >> which is all that the Linux sign-file utility supports creating > >> out-of-the-box. Only RSA, SHA-256 and SHA-512 are supported. > >> Any certificate embedded in the PKCS#7 message will be ignored. > >> > >> - X.509 certificates: at least enough to verify the signatures on the > >> PKCS#7 messages. We expect that the certificates embedded in grub will > >> be leaf certificates, not CA certificates. The parser enforces this. > > > > Doesn't grub support CA certificates for EFI? > > > For EFI, the verification isn't done by grub, it's done by either the > shim or by firmware. They do - per the spec - support certificate > chaining. So you could validly put a CA cert into db or MokList and have > a signature on an Authenticode signature chain back to that. > > > Why limit to leaf certificates here? > > Conventionally, appended signatures don't include embedded certificates > whereas Authenticode signatures do. There's nothing stopping you putting > one into the PKCS#7 message for an appended signature - it's just not > the way they are used on kernel modules or kernel binaries. So if > there's not an embedded certificate that can chain back to a CA > certificate, grub has to have access to the leaf certificate. > > > If this is technical limitation of the code in question could you fail > > the build when CA certificate is used rather than crashing the > > bootloader when it boots? > > I guess. I think IBM has been reasonably open in saying that static key > secure boot is not the end of the road for Power, so we expect that > ultimately keys could be loaded from somewhere other than the binary > like firmware storage. So even if we added this check in grub-mkimage, > we'd still need to keep it at runtime as well. > > >> - X.509 certificates support the Extended Key Usage extension and handle > >> it by verifying that the certificate has a single purpose, that is code > > ^^^^^^^^^^^^^^ > > This should be updated I suppose. > > So this is - surprisingly - still accurate! We still only support 1 > _Extended_ Key Usage. The change that we made as a result of SUSE's bug It is unclear to me OpenFirmware enforces such restriction as well ? My understanding is that the (single purpose) restriction is lifed in firmware becuase it happily accepts our cert and boots SUSE signed grub in secure boot without complaining Key Usage. If so I wonder why it is necessary for having the stricter check in grub ? > report was to support additional regular, non-extended key > usages. Here's the change broken out: Would this change be used next version ? Thanks, Michael > > commit 6056d5fc59907c486309c401135757f00ebf7760 > Author: Daniel Axtens > Date: Tue Nov 30 15:00:57 2021 +1100 > > x509: allow Digitial Signature plus other Key Usages > > Currently the x509 certificate parser for appended signature > verification requires that the certificate have the Digitial Signature > key usage and _only_ the Digitial Signature use. This is overly strict > and becomes policy enforcement rather than a security property. > > Require that the Digitial Signature usage is present, but do not > require that it is the only usage present. > > Reported-by: Michal Suchanek > Signed-off-by: Daniel Axtens > > diff --git a/grub-core/commands/appendedsig/x509.c b/grub-core/commands/appendedsig/x509.c > index 70480aa73c9d..6ae985b30ff8 100644 > --- a/grub-core/commands/appendedsig/x509.c > +++ b/grub-core/commands/appendedsig/x509.c > @@ -547,7 +547,7 @@ cleanup: > > /* > * Verify the Key Usage extension. > - * We only permit the Digital signature usage. > + * We require the Digital signature usage. > */ > static grub_err_t > verify_key_usage (grub_uint8_t *value, int value_size) > @@ -586,10 +586,10 @@ verify_key_usage (grub_uint8_t *value, int value_size) > goto cleanup; > } > > - if (usage != digitalSignatureUsage) > + if (!(usage & digitalSignatureUsage)) > { > err = > - grub_error (GRUB_ERR_BAD_FILE_TYPE, "Unexpected Key Usage value: %x", > + grub_error (GRUB_ERR_BAD_FILE_TYPE, "Key Usage (0x%x) missing Digital Signature usage", > usage); > goto cleanup; > } > > Kind regards, > Daniel > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel