From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nhV3P-0006c9-0U for mharc-grub-devel@gnu.org; Thu, 21 Apr 2022 07:32:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhV3K-0006Yx-HK for grub-devel@gnu.org; Thu, 21 Apr 2022 07:32:50 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:45028) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhV3I-00063z-7I for grub-devel@gnu.org; Thu, 21 Apr 2022 07:32:50 -0400 Received: by mail-pj1-x102e.google.com with SMTP id m14-20020a17090a34ce00b001d5fe250e23so1610360pjf.3 for ; Thu, 21 Apr 2022 04:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=PptqosMwrfUxMpBpWAWxDBlBouz6wkYHhMy1IBaZJXQ=; b=KwiVXw4Qz/mtvfUB3W8MH0YjKz2GNLUNrZm5Olfb/IGVM7i52c2GRtT68W8NkrFFKP LsmHGDoR+oQYEqkARWpNWINvVH3enM6EtsSlx56ov7JL6cdy7yAPpzezBNKM70tXSMWS p6mGIDTwanB9BctyDwdTajJz6T7AsKpmHDq9Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=PptqosMwrfUxMpBpWAWxDBlBouz6wkYHhMy1IBaZJXQ=; b=g+KWbEnUVMmJVjZgnKHcVVDfO3X8UtQifpzg30o9qaJ0Us6qgDPm0PQcPa3HwE6H17 SSV+2ZVs2sBedcd2GNoRs4ny2mIzEPkA7FSOPVAMLcnkgE2e/iayV3cmn7yCnINHU+fq ++5mnfLa2XJu7ocecYqvPvnqqMFj6v1yPAyVZV9Jsa6qlwM1HlCh6Bq3LPaMn4/av0lZ orKO2SMIdnWrT+Mjn2/OuIH/1UIpGZzsiTt2Y/cgcYVVDB5sv5BcRfQnuERNXn6808nf nyhajomcju9lPTRu9nW6LUNQe4uHojka2NyPR61DNyEU98n6fyVifCsajdh0/mJl3i63 CC8w== X-Gm-Message-State: AOAM532i3Dv+c2OTFha1iSpgjyKDQ0Er5cdPgUx2l1vyu8loBLVQakmW JS30kwsUeK8TmYvaqoK8uYq29w== X-Google-Smtp-Source: ABdhPJzuBR4D3fVaO5IhAAHf7x6Gfb/O8+Txm2hRSjyD2088izL7E9jywuNTimsSRxbJ//Si98jPeA== X-Received: by 2002:a17:90b:3503:b0:1d1:c700:e484 with SMTP id ls3-20020a17090b350300b001d1c700e484mr9929742pjb.245.1650540765616; Thu, 21 Apr 2022 04:32:45 -0700 (PDT) Received: from localhost ([2001:4479:e000:e400:4260:be14:52a8:8c94]) by smtp.gmail.com with ESMTPSA id c19-20020aa78c13000000b0050ad022a651sm4314760pfd.110.2022.04.21.04.32.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 04:32:45 -0700 (PDT) From: Daniel Axtens To: Michal =?utf-8?Q?Such=C3=A1nek?= Cc: grub-devel@gnu.org, 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 In-Reply-To: <20220421075750.GV163591@kunlun.suse.cz> References: <20220421074714.1561049-1-dja@axtens.net> <20220421074714.1561049-16-dja@axtens.net> <20220421075750.GV163591@kunlun.suse.cz> Date: Thu, 21 Apr 2022 21:32:41 +1000 Message-ID: <875yn2eko6.fsf@dja-thinkpad.axtens.net> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=dja@axtens.net; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: Thu, 21 Apr 2022 11:32:51 -0000 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 report was to support additional regular, non-extended key usages. Here's the change broken out: 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