Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1lRF3W-0002fR-Bj for mharc-grub-devel@gnu.org; Tue, 30 Mar 2021 10:09:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRF3V-0002e4-KR for grub-devel@gnu.org; Tue, 30 Mar 2021 10:09:17 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:35813) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lRF3R-0004rb-8T for grub-devel@gnu.org; Tue, 30 Mar 2021 10:09:17 -0400 Received: by mail-pf1-x432.google.com with SMTP id j25so12251007pfe.2 for ; Tue, 30 Mar 2021 07:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rkBtJy3SkipvdXFmR4zwwuBYcOtAqUJxBmDtVliiXlo=; b=bF8Q9Rs5a36EpRp3JIR6dDmU29Lj4u5CFZc77EK3DnMexVVFfy4zeapdEgLHYYUVTG bgVENPVo6YmDlvzESBqpwzAyfpeqKz508j2Ax6gw5eelVVEoCipU1vUIXne03VXBlrl6 Chfh9LUrTwUP92XsARSxDqjpMsAw41eZt7Zis= 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=rkBtJy3SkipvdXFmR4zwwuBYcOtAqUJxBmDtVliiXlo=; b=TDJaIEuL4xVvG5/+NN8MhmZa17qko6rjA20t1X+3OgjG4CPMGKrZg6NlS27idhHqVM DDee4mzcnUFMueKaSlztYajOU4yoqEv97lvjjzQir2GGVVIzButh78vjJpE7hHz8LUDc rekEFfyXjtJi5qrsNw7tf+zfffxWtTPP5SK5Dp3bV9Oi0sPA3LUXzUgvB8iwRAV0BZcx RUYWLmfr8x1yHzKj9eOd+e2NsvfVgaW/g+nM/66bw8MlGKo+W0F8VVyOHFp15/Z5Pn6y pH0LWd4Bxg3TidfzUm52OMr2joibZx90xBsQqZ1r7bjp9L41RgqLjntogpxWbaYnfyfq aMKw== X-Gm-Message-State: AOAM5332Gps4vY9PMETPSjw3d8tD6Fb7FoyQvOmNqKEgb9wCyLQd9mJV gWsMqO1oVBl/qkCu58Mv+eA/e6e9o3cpQg== X-Google-Smtp-Source: ABdhPJwO5uYA9OJPgdPYZAvFpOrhc40KqaMYWn0o/hqi1w45sE4HJY7AN+q1Ty+ZE2MT2fho1UqG7Q== X-Received: by 2002:a63:504f:: with SMTP id q15mr29488071pgl.290.1617113351741; Tue, 30 Mar 2021 07:09:11 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-cc4e-3d4e-f51c-bb52.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:cc4e:3d4e:f51c:bb52]) by smtp.gmail.com with ESMTPSA id w188sm20837297pfb.4.2021.03.30.07.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 07:09:11 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: rashmica.g@gmail.com, alastair@d-silva.org, Daniel Axtens Subject: [PATCH 19/19] ieee1275: enter lockdown based on /ibm,secure-boot Date: Wed, 31 Mar 2021 01:07:44 +1100 Message-Id: <20210330140744.176698-20-dja@axtens.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210330140744.176698-1-dja@axtens.net> References: <20210330140744.176698-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=dja@axtens.net; helo=mail-pf1-x432.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 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Mar 2021 14:09:17 -0000 If the 'ibm,secure-boot' property of the root node is 2 or greater, enter lockdown. Signed-off-by: Daniel Axtens --- docs/grub.texi | 4 ++-- grub-core/Makefile.core.def | 1 + grub-core/kern/ieee1275/init.c | 27 +++++++++++++++++++++++++++ include/grub/lockdown.h | 3 ++- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/grub.texi b/docs/grub.texi index 9a737683e64f..7cd45f5c5255 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -6184,8 +6184,8 @@ Measured boot is currently only supported on EFI platforms. @section Lockdown when booting on a secure setup The GRUB can be locked down when booted on a secure boot environment, for example -if the UEFI secure boot is enabled. On a locked down configuration, the GRUB will -be restricted and some operations/commands cannot be executed. +if UEFI or Power secure boot is enabled. On a locked down configuration, the +GRUB will be restricted and some operations/commands cannot be executed. The @samp{lockdown} variable is set to @samp{y} when the GRUB is locked down. Otherwise it does not exit. diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 4bef6dd0b99e..3f8194fcd43d 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -317,6 +317,7 @@ kernel = { powerpc_ieee1275 = kern/powerpc/cache.S; powerpc_ieee1275 = kern/powerpc/dl.c; powerpc_ieee1275 = kern/powerpc/compiler-rt.S; + powerpc_ieee1275 = kern/lockdown.c; sparc64_ieee1275 = kern/sparc64/cache.S; sparc64_ieee1275 = kern/sparc64/dl.c; diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c index d483e35eed2b..7a1ebdf94e06 100644 --- a/grub-core/kern/ieee1275/init.c +++ b/grub-core/kern/ieee1275/init.c @@ -44,6 +44,7 @@ #ifdef __sparc__ #include #endif +#include /* The minimal heap size we can live with. */ #define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024) @@ -270,6 +271,30 @@ grub_parse_cmdline (void) } } +static void +grub_get_ieee1275_secure_boot (void) +{ + grub_ieee1275_phandle_t root; + int rc; + grub_uint32_t is_sb; + + grub_ieee1275_finddevice ("/", &root); + + rc = grub_ieee1275_get_integer_property (root, "ibm,secure-boot", &is_sb, + sizeof (is_sb), 0); + + /* ibm,secure-boot: + * 0 - disabled + * 1 - audit + * 2 - enforce + * 3 - enforce + OS-specific behaviour + * + * We only support enforce. + */ + if (rc >= 0 && is_sb >= 2) + grub_lockdown (); +} + grub_addr_t grub_modbase; void @@ -295,6 +320,8 @@ grub_machine_init (void) #else grub_install_get_time_ms (grub_rtc_get_time_ms); #endif + + grub_get_ieee1275_secure_boot (); } void diff --git a/include/grub/lockdown.h b/include/grub/lockdown.h index 40531fa823bf..ebfee4bf06e7 100644 --- a/include/grub/lockdown.h +++ b/include/grub/lockdown.h @@ -24,7 +24,8 @@ #define GRUB_LOCKDOWN_DISABLED 0 #define GRUB_LOCKDOWN_ENABLED 1 -#ifdef GRUB_MACHINE_EFI +#if defined(GRUB_MACHINE_EFI) || \ + (defined(__powerpc__) && defined(GRUB_MACHINE_IEEE1275)) extern void EXPORT_FUNC (grub_lockdown) (void); extern int -- 2.27.0