From patchwork Mon Dec 9 06:00:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1205926 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pY57rmHj"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47WXcp23ygz9sNH for ; Mon, 9 Dec 2019 17:01:14 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E0369816C1; Mon, 9 Dec 2019 07:00:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pY57rmHj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D3EC2816C5; Mon, 9 Dec 2019 07:00:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 57BE9816B5 for ; Mon, 9 Dec 2019 07:00:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pj1-x1044.google.com with SMTP id n96so5387592pjc.3 for ; Sun, 08 Dec 2019 22:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TEAEDj9erVipp4yLLE2gQ4KtxKQihSj29/GQcgpNpqU=; b=pY57rmHjC/iOpYY1nbXdx6VS+DR5p33o/wSmuYKm6P3xuPynIsGq4nkYYQU1Fr39Hz prmFR791bdBFBaePvD1w4PBClantdHLL8LxTPSDUzbToR7DgKANCRxDo9rapH1PDaVE5 m5sAsoO2qiLJ+qyzKIiSUJguHwE/IZgquarsBroFQrwXAhEpHgRqyN5LInO8EM3hfabL TbaPtIo17QMeND2Glq71hF4vH96vojnc4VNESQp4s4xY5w90/7zfdOfFAJwQbGMEZfxs qFPeeQvaHgijzw11KRQ++NoVPy6HXHW6RwN6+heHaeZ0++I7gYhSSD/ws9PSQ6MmLRpj uvFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TEAEDj9erVipp4yLLE2gQ4KtxKQihSj29/GQcgpNpqU=; b=DmAYWPpQXod5jpsZ5PG1Uhss3pb75OcuuaMZoph+8+zu5WesEw7oNBtXW/H9lSANnt dBFHHWCZA/L/3+6/0A9gl+73FDhedhb+mfTN5/Qv4Lvqgso9Xvy7uKPrkF8NhajrePLZ Oovxp2H0SThxwY4r5lufyL7Okf8MHAlliID6amntrZYE12LC0PBtAABSvWBxGPzv+V0+ ud+vi0bmhYEbs5E8aRYvXeth70Lf+3f3dkE5LAQhT1XLFC6gActsDYBc6aw7pEWbWqwI FF3ijk9wogFI49nhdi9cHDTsxe5AqLpL+UPuY+x5vAkKYmyHdypHXdc5lvY3hk65yeT4 8r0g== X-Gm-Message-State: APjAAAVccH3zDwJXyMpKNYe98tCmoSZo8FUlTyPcKvRoryUDGH7i1sF+ H0rqtGtBpgswDgwjougDp4TEng== X-Google-Smtp-Source: APXvYqxri3h6LzChn+ofitA3T1qfDDFTHqqTyGTACHrXyhfemrQKDF4kGY8nQCdNNs8xPqa0j4CJSQ== X-Received: by 2002:a17:90b:8d6:: with SMTP id ds22mr29756557pjb.100.1575871198963; Sun, 08 Dec 2019 21:59:58 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z30sm25218930pff.131.2019.12.08.21.59.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Dec 2019 21:59:58 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, trini@konsulko.com Subject: [PATCH v3 09/16] efi_loader: set up secure boot Date: Mon, 9 Dec 2019 15:00:49 +0900 Message-Id: <20191209060056.32426-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191209060056.32426-1-takahiro.akashi@linaro.org> References: <20191209060056.32426-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: u-boot@lists.denx.de, mail@patrick-wildt.de Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean The following variable is exported as UEFI specification defines: SignatureSupport: array of GUIDs representing the type of signatures supported by the platform firmware Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_setup.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index de7b616c6daa..50cef1b4dfde 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -82,6 +82,39 @@ out: return ret; } +#ifdef CONFIG_EFI_SECURE_BOOT +/** + * efi_init_secure_boot - initialize secure boot state + * + * Return: EFI_SUCCESS on success, status code (negative) on error + */ +static efi_status_t efi_init_secure_boot(void) +{ + efi_guid_t signature_types[] = { + EFI_CERT_SHA256_GUID, + EFI_CERT_X509_GUID, + }; + efi_status_t ret; + + /* TODO: read-only */ + ret = EFI_CALL(efi_set_variable(L"SignatureSupport", + &efi_global_variable_guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS + | EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(signature_types), + &signature_types)); + if (ret != EFI_SUCCESS) + printf("EFI: cannot initialize SignatureSupport variable\n"); + + return ret; +} +#else +static efi_status_t efi_init_secure_boot(void) +{ + return EFI_SUCCESS; +} +#endif /* CONFIG_EFI_SECURE_BOOT */ + /** * efi_init_obj_list() - Initialize and populate EFI object list * @@ -122,6 +155,11 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + /* Secure boot */ + ret = efi_init_secure_boot(); + if (ret != EFI_SUCCESS) + goto out; + /* Indicate supported runtime services */ ret = efi_init_runtime_supported(); if (ret != EFI_SUCCESS)