From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v6 2/3] Add tst_secureboot_enabled() helper function
Date: Tue, 12 Jan 2021 10:57:58 +0100 [thread overview]
Message-ID: <20210112095759.11910-2-mdoucha@suse.cz> (raw)
In-Reply-To: <20210112095759.11910-1-mdoucha@suse.cz>
Also check for SecureBoot status in tst_lockdown_enabled() if the lockdown
sysfile is not available/readable and the kernel is configured to enable
lockdown automatically under SecureBoot.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
Changes since v1:
- check whether machine is in EFI mode first
Changes since v2:
- move tst_secureboot_enabled() code to a separate header file
- move EFIVAR_CFLAGS and EFIVAR_LIBS out of global CFLAGS and LDLIBS
Changes since v3:
- rewritten using direct read from /sys/ (without libefivar)
Changes since v5:
- fixed #includes
include/tst_lockdown.h | 1 +
lib/tst_lockdown.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/include/tst_lockdown.h b/include/tst_lockdown.h
index 78eaeccea..172a7daf5 100644
--- a/include/tst_lockdown.h
+++ b/include/tst_lockdown.h
@@ -5,6 +5,7 @@
#define PATH_LOCKDOWN "/sys/kernel/security/lockdown"
+int tst_secureboot_enabled(void);
int tst_lockdown_enabled(void);
#endif /* TST_LOCKDOWN_H */
diff --git a/lib/tst_lockdown.c b/lib/tst_lockdown.c
index e7c19813c..cda7d7abd 100644
--- a/lib/tst_lockdown.c
+++ b/lib/tst_lockdown.c
@@ -10,6 +10,36 @@
#include "tst_safe_macros.h"
#include "tst_safe_stdio.h"
#include "tst_lockdown.h"
+#include "tst_private.h"
+
+#define EFIVAR_SECUREBOOT "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c"
+
+int tst_secureboot_enabled(void)
+{
+ int fd;
+ char data[5];
+
+ if (access(EFIVAR_SECUREBOOT, F_OK)) {
+ tst_res(TINFO, "Efivar FS not available");
+ return -1;
+ }
+
+ fd = open(EFIVAR_SECUREBOOT, O_RDONLY);
+
+ if (fd == -1) {
+ tst_res(TINFO | TERRNO,
+ "Cannot open SecureBoot Efivar sysfile");
+ return -1;
+ } else if (fd < 0) {
+ tst_brk(TBROK | TERRNO, "Invalid open() return value %d", fd);
+ return -1;
+ }
+
+ SAFE_READ(1, fd, data, 5);
+ SAFE_CLOSE(fd);
+ tst_res(TINFO, "SecureBoot: %s", data[4] ? "on" : "off");
+ return data[4];
+}
int tst_lockdown_enabled(void)
{
@@ -17,6 +47,14 @@ int tst_lockdown_enabled(void)
FILE *file;
if (access(PATH_LOCKDOWN, F_OK) != 0) {
+ char flag;
+
+ flag = tst_kconfig_get("CONFIG_EFI_SECURE_BOOT_LOCK_DOWN");
+
+ /* SecureBoot enabled could mean integrity lockdown */
+ if (flag == 'y' && tst_secureboot_enabled() > 0)
+ return 1;
+
tst_res(TINFO, "Unable to determine system lockdown state");
return 0;
}
--
2.29.2
next prev parent reply other threads:[~2021-01-12 9:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-12 9:57 [LTP] [PATCH v6 1/3] Add tst_kconfig_get() helper function Martin Doucha
2021-01-12 9:57 ` Martin Doucha [this message]
2021-01-14 13:38 ` [LTP] [PATCH v6 2/3] Add tst_secureboot_enabled() " Cyril Hrubis
2021-01-14 13:46 ` Martin Doucha
2021-01-14 14:09 ` Cyril Hrubis
2021-01-12 9:57 ` [LTP] [PATCH v6 3/3] syscalls/iopl02, ioperm02: Skip when kernel is locked down Martin Doucha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210112095759.11910-2-mdoucha@suse.cz \
--to=mdoucha@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.