Received: by 10.213.65.68 with SMTP id h4csp3597241imn; Tue, 3 Apr 2018 07:41:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx49mf9h8u1f97uw2OmFT5eSNOxUOpg/JaDK1rUj/foVtPdDmlQjSikITgplaCwdqdoAQR2dJ X-Received: by 2002:a17:902:5902:: with SMTP id o2-v6mr13295527pli.81.1522766480710; Tue, 03 Apr 2018 07:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522766480; cv=none; d=google.com; s=arc-20160816; b=S+jH6X08EYnkr7xgnM4dqqqfS5dfs2LIvgQ3af9iQ2lAc9yr86AKf3hWGqJeHSZjXQ c9BvRkdngfCNRaOx+06kVfIAgxFCZphU3cvfNz5EWHkZ9nW0UfS310xbR11ppuxyPV8I Zw3dnkBdGRZ0AgWT7KjEzfIHrnI2v/ewu35Ydr2Sdnu/zAVnEReB7Swq1yye9dgkbw9m CRaKkBXqyrWUa5/mDueWs7wchLtv31CnwRmoSSJWm267yC/W602MkqhRVKh0zKU1dFoh NiDMVHMhID2HR1oFX3UuBgcdWe3uMfpSs88TTDbMNgLl8WCYPnfAGxqd7J7Lv2mhshGU BbsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=WpetBnm1lhZnn3dOaQgV44L6P35wukWnVDJhwn/0nyA=; b=dEGCv8DhMxeh8TzdW7y55U9wRowqj1w1O6S2pMTSuviuHTB8o4MkUl+GuDpxI+xBhu 09Yz3YQRiGP3efUg1iDWdytRVb2oHLuEcOpuTEYzU6Pg+XZZVU2H1saPq5ONewsqjiJ8 JcoR3ei3/O0R0x89nkC2Rhk8ONkY7CYy6v+ijf3+Wb+CFYrQd11+SqRbPK1kwwFgBz9h DaV3vmeCy5pS6YlclCJuA5ZXimJ7/oGKsqrtiECFq+tJUrMHxA9vmH5566XXdBfABDo4 PSNwNUHhXXyxIqKzZP5ICzgRYuqOAW/+UriaIsDpcPKLH9jYOnZyAfl85DLXfiJB/Ng6 NUyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=h7Hf+6Ph; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c76si2054450pga.156.2018.04.03.07.41.06; Tue, 03 Apr 2018 07:41:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=h7Hf+6Ph; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751696AbeDCOjn (ORCPT + 99 others); Tue, 3 Apr 2018 10:39:43 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:45696 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751353AbeDCOjl (ORCPT ); Tue, 3 Apr 2018 10:39:41 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w33EOW6B056050; Tue, 3 Apr 2018 14:39:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2017-10-26; bh=WpetBnm1lhZnn3dOaQgV44L6P35wukWnVDJhwn/0nyA=; b=h7Hf+6PhambbAZZOH2zEQoOfGNe2PtHVTpI7wQM9aRob7+HwDEI5EEhfET63HVRY6+wg T/Zf4LjFKhf/5N4M59SPDdb513GUU3VoJLM99sQ9o4+VE5qcuwVnig0keWPaCG/nlFqd 1nKc3xZWhCjsmGES/7mvpGVBAL2/BohNcE/u0jshOZnHvY/c9pPMj/KuOnh6fPTPRVPb w0RzacPp+KQHQwd+BRtwZhHQxjOyr1upc70t20qwnOhVMNBZ/s0BfcQSVH3OCKMfomwe NAzIUTi7Desn3VX7qA8VWhrVjsNQswkx+2olVvaZ9Szp3wLTWnIM63TcsXmDSDslcskN Qg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2h4bbfr3dd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 03 Apr 2018 14:39:22 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w33EdMXq016506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Apr 2018 14:39:22 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w33EdLbb012793; Tue, 3 Apr 2018 14:39:21 GMT Received: from olila.local.net-space.pl (/10.175.189.238) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 03 Apr 2018 07:39:20 -0700 From: Daniel Kiper To: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, xen-devel@lists.xenproject.org Cc: ard.biesheuvel@linaro.org, boris.ostrovsky@oracle.com, eric.snowberg@oracle.com, hpa@zytor.com, jgross@suse.com, konrad.wilk@oracle.com, mingo@redhat.com, tglx@linutronix.de Subject: [PATCH v2] x86/xen/efi: Initialize UEFI secure boot state during dom0 boot Date: Tue, 3 Apr 2018 16:39:05 +0200 Message-Id: <1522766345-4169-1-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8851 signatures=668697 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804030148 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initialize UEFI secure boot state during dom0 boot. Otherwise the kernel may not even know that it runs on secure boot enabled platform. Signed-off-by: Daniel Kiper --- arch/x86/xen/efi.c | 57 +++++++++++++++++++++++++++++ drivers/firmware/efi/libstub/secureboot.c | 3 ++ 2 files changed, 60 insertions(+) diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c index a18703b..1804b27 100644 --- a/arch/x86/xen/efi.c +++ b/arch/x86/xen/efi.c @@ -115,6 +115,61 @@ static efi_system_table_t __init *xen_efi_probe(void) return &efi_systab_xen; } +/* + * Determine whether we're in secure boot mode. + * + * Please keep the logic in sync with + * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot(). + */ +static enum efi_secureboot_mode xen_efi_get_secureboot(void) +{ + static efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID; + static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID; + efi_status_t status; + u8 moksbstate, secboot, setupmode; + unsigned long size; + + size = sizeof(secboot); + status = efi.get_variable(L"SecureBoot", &efi_variable_guid, + NULL, &size, &secboot); + + if (status == EFI_NOT_FOUND) + return efi_secureboot_mode_disabled; + + if (status != EFI_SUCCESS) + goto out_efi_err; + + size = sizeof(setupmode); + status = efi.get_variable(L"SetupMode", &efi_variable_guid, + NULL, &size, &setupmode); + + if (status != EFI_SUCCESS) + goto out_efi_err; + + if (secboot == 0 || setupmode == 1) + return efi_secureboot_mode_disabled; + + /* See if a user has put the shim into insecure mode. */ + size = sizeof(moksbstate); + status = efi.get_variable(L"MokSBStateRT", &shim_guid, + NULL, &size, &moksbstate); + + /* If it fails, we don't care why. Default to secure. */ + if (status != EFI_SUCCESS) + goto secure_boot_enabled; + + if (moksbstate == 1) + return efi_secureboot_mode_disabled; + + secure_boot_enabled: + pr_info("UEFI Secure Boot is enabled.\n"); + return efi_secureboot_mode_enabled; + + out_efi_err: + pr_err("Could not determine UEFI Secure Boot status.\n"); + return efi_secureboot_mode_unknown; +} + void __init xen_efi_init(void) { efi_system_table_t *efi_systab_xen; @@ -129,6 +184,8 @@ void __init xen_efi_init(void) boot_params.efi_info.efi_systab = (__u32)__pa(efi_systab_xen); boot_params.efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32); + boot_params.secure_boot = xen_efi_get_secureboot(); + set_bit(EFI_BOOT, &efi.flags); set_bit(EFI_PARAVIRT, &efi.flags); set_bit(EFI_64BIT, &efi.flags); diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c index 8f07eb4..72d9dfb 100644 --- a/drivers/firmware/efi/libstub/secureboot.c +++ b/drivers/firmware/efi/libstub/secureboot.c @@ -30,6 +30,9 @@ /* * Determine whether we're in secure boot mode. + * + * Please keep the logic in sync with + * arch/x86/xen/efi.c:xen_efi_get_secureboot(). */ enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg) { -- 1.7.10.4