Received: from list by lists.gnu.org with archive (Exim 4.71) id 1g9uUu-0004MC-Ff for mharc-grub-devel@gnu.org; Tue, 09 Oct 2018 12:04:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9uUt-0004Ks-1h for grub-devel@gnu.org; Tue, 09 Oct 2018 12:04:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9uUo-00011z-UG for grub-devel@gnu.org; Tue, 09 Oct 2018 12:04:34 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:40473) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g9uUg-0000uO-7z for grub-devel@gnu.org; Tue, 09 Oct 2018 12:04:24 -0400 Received: by mail-wm1-x344.google.com with SMTP id z204-v6so2601578wmc.5 for ; Tue, 09 Oct 2018 09:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id; bh=IKUjru33m2z2FoEPIo7wxHaW6iIPpm3kR6foMa/4lL4=; b=Sf3q2kI8G8XNooOPtIt5RJmDzln5kH+8HQP33eZqNmAGOEjHiqluqR71tLEkpWBeSx 75nPu/8Xv3ldIyAyBHtdjFz7fJFXnxs/KFgKvTaswiMy/Y+ZPTLQZBPn8md/UEQXrYMH FCT/bKu6Rf671rTxxyoDwvnFIV1uJTzjIaLGg= 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; bh=IKUjru33m2z2FoEPIo7wxHaW6iIPpm3kR6foMa/4lL4=; b=GlA75sQJ6buSOTVPOWdIMdsRLdP9mBkmuqOkAIx8TE7UWv3Pul/ZiOUhqbO/RohRlV L93yHjq4sEeGI6j40K1Uo1fkM9qZO6JMvRCREqbHCy2275KVue2weROOJa/C8/uB5a1h zn9fud6IShyTOwMkDIss8veukGBWr50CDPQRbPzrFjmKkf2w8vEYXWHwx73n1pKFoixN x5+6j4qmznVUl1vwujOHqKk6uRA7esvfGWvVg0vefn5f9BrYsYislgvm6+vbxUO3D7hV Zfg/c6u9/gnPnHVUs7BFLjMgzpeCyCXkZuu1OEfJUXqRSz51A17masXIYn+G6F/31uqJ /hcg== X-Gm-Message-State: ABuFfohMuggXLEgxcY9sGYsyJJlCxaJ3rwdHxG0bIvRBQF2/5hmJA8bj cVp81SWR0SkqMDvhOthBRV9TRaG2PiHNBg== X-Google-Smtp-Source: ACcGV61fyL7d9Mqu1CqmXWiM2CvDpvIL7NWBEIdyhGlBk8+sDjwy2Lg/Z6G8yg1E85wLVMIv6skiUg== X-Received: by 2002:a1c:4406:: with SMTP id r6-v6mr2595741wma.4.1539101053405; Tue, 09 Oct 2018 09:04:13 -0700 (PDT) Received: from localhost.localdomain ([185.122.0.240]) by smtp.gmail.com with ESMTPSA id o63-v6sm18797262wmd.3.2018.10.09.09.04.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 09:04:12 -0700 (PDT) From: Ignat Korchagin To: grub-devel@gnu.org Cc: Ignat Korchagin Subject: [PATCH] loader/i386/linux: report UEFI secure boot status to the Linux kernel Date: Tue, 9 Oct 2018 16:04:03 +0000 Message-Id: <20181009160403.19124-1-ignat@cloudflare.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 16:04:36 -0000 Linux kernel from 4.11 has secure_boot member as part of linux_kernel_params. Currently, GRUB does not populate it, so the kernel reports "Secure boot could not be determined" on boot. We can populate it in EFI mode, so the kernel "knows" the status. Signed-off-by: Ignat Korchagin --- grub-core/loader/i386/linux.c | 34 +++++++++++++++++++++++++++++++++- include/grub/i386/linux.h | 12 ++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 4eab55a2d..7fc188603 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -396,6 +396,37 @@ grub_linux_boot_mmap_fill (grub_uint64_t addr, grub_uint64_t size, return 0; } +#ifdef GRUB_MACHINE_EFI +static grub_uint8_t +grub_efi_secureboot_mode (void) +{ + grub_efi_guid_t efi_var_guid = GRUB_EFI_GLOBAL_VARIABLE_GUID; + grub_size_t efi_var_size = 0; + grub_uint8_t *secure_boot; + grub_uint8_t *setup_mode; + grub_uint8_t secureboot_mode = LINUX_EFI_SECUREBOOT_MODE_UNSET; + + secure_boot = grub_efi_get_variable ("SecureBoot", &efi_var_guid, &efi_var_size); + setup_mode = grub_efi_get_variable ("SetupMode", &efi_var_guid, &efi_var_size); + + if (!secure_boot || !setup_mode) + goto fail; + + if ((*secure_boot == 0) || (*setup_mode == 1)) + secureboot_mode = LINUX_EFI_SECUREBOOT_MODE_DISABLED; + else + secureboot_mode = LINUX_EFI_SECUREBOOT_MODE_ENABLED; + +fail: + if (setup_mode) + grub_free (setup_mode); + if (secure_boot) + grub_free (secure_boot); + + return secureboot_mode; +} +#endif + static grub_err_t grub_linux_boot (void) { @@ -574,6 +605,7 @@ grub_linux_boot (void) grub_efi_uintn_t efi_desc_size; grub_size_t efi_mmap_target; grub_efi_uint32_t efi_desc_version; + ctx.params->secure_boot = grub_efi_secureboot_mode (); err = grub_efi_finish_boot_services (&efi_mmap_size, efi_mmap_buf, NULL, &efi_desc_size, &efi_desc_version); if (err) @@ -760,7 +792,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_params.code32_start = prot_mode_target + lh.code32_start - GRUB_LINUX_BZIMAGE_ADDR; linux_params.kernel_alignment = (1 << align); - linux_params.ps_mouse = linux_params.padding10 = 0; + linux_params.ps_mouse = linux_params.padding11 = 0; len = sizeof (linux_params) - sizeof (lh); if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len) diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index 60c7c3b5e..4493a3fdb 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -270,7 +270,15 @@ struct linux_kernel_params grub_uint8_t mmap_size; /* 1e8 */ - grub_uint8_t padding9[0x1f1 - 0x1e9]; + grub_uint8_t padding9[0x1ec - 0x1e9]; + + grub_uint8_t secure_boot; /* 1ec */ +#define LINUX_EFI_SECUREBOOT_MODE_UNSET 0 +#define LINUX_EFI_SECUREBOOT_MODE_UNKNOWN 1 +#define LINUX_EFI_SECUREBOOT_MODE_DISABLED 2 +#define LINUX_EFI_SECUREBOOT_MODE_ENABLED 3 + + grub_uint8_t padding10[0x1f1 - 0x1ed]; grub_uint8_t setup_sects; /* The size of the setup in sectors */ grub_uint16_t root_flags; /* If the root is mounted readonly */ @@ -280,7 +288,7 @@ struct linux_kernel_params grub_uint16_t vid_mode; /* Video mode control */ grub_uint16_t root_dev; /* Default root device number */ - grub_uint8_t padding10; /* 1fe */ + grub_uint8_t padding11; /* 1fe */ grub_uint8_t ps_mouse; /* 1ff */ grub_uint16_t jump; /* Jump instruction */ -- 2.11.0