From patchwork Fri Mar 20 09:00:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Hu X-Patchwork-Id: 1258724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48kHnC12M2z9sRf; Fri, 20 Mar 2020 20:01:03 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jFDWH-0002Yd-QG; Fri, 20 Mar 2020 09:00:45 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jFDWG-0002YM-L7 for fwts-devel@lists.ubuntu.com; Fri, 20 Mar 2020 09:00:44 +0000 Received: from [106.104.73.87] (helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jFDWF-0004ne-T0; Fri, 20 Mar 2020 09:00:44 +0000 From: Ivan Hu To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] lib: add kernel lockdown check Date: Fri, 20 Mar 2020 17:00:37 +0800 Message-Id: <20200320090038.15263-1-ivan.hu@canonical.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" Kernel lockdown is added since 4.17 and more patches in 5.4 It blocks the access to the uefi runtime services. Add the function for checking kernel lockdown status. Signed-off-by: Ivan Hu Acked-by: Anthony Wong Acked-by: Colin Ian King --- src/lib/include/fwts_efi_module.h | 1 + src/lib/src/fwts_efi_module.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/lib/include/fwts_efi_module.h b/src/lib/include/fwts_efi_module.h index c086dc3e..c82e26d7 100644 --- a/src/lib/include/fwts_efi_module.h +++ b/src/lib/include/fwts_efi_module.h @@ -24,5 +24,6 @@ int fwts_lib_efi_runtime_load_module(fwts_framework *fw); int fwts_lib_efi_runtime_unload_module(fwts_framework *fw); int fwts_lib_efi_runtime_open(void); int fwts_lib_efi_runtime_close(int fd); +bool fwts_lib_efi_runtime_kernel_lockdown(void); #endif diff --git a/src/lib/src/fwts_efi_module.c b/src/lib/src/fwts_efi_module.c index d49f20b0..bc56acb7 100644 --- a/src/lib/src/fwts_efi_module.c +++ b/src/lib/src/fwts_efi_module.c @@ -183,3 +183,21 @@ int fwts_lib_efi_runtime_close(int fd) { return close(fd); } + +/* + * fwts_lib_efi_runtime_kernel_lockdown() + * check if the kernel has been lockdown + */ +bool fwts_lib_efi_runtime_kernel_lockdown(void) +{ + char *data; + + if ((data = fwts_get("/sys/kernel/security/lockdown")) != NULL) { + if (strstr(data, "[none]") == NULL) { + free(data); + return true; + } + } + free(data); + return false; +}