Blame SOURCES/0005-Fix-live-debugging-with-lockdown-integrity.patch

f27a4c
From e90c0011d6e9476104c4c43aa76d2d0830a15946 Mon Sep 17 00:00:00 2001
f27a4c
From: Philipp Rudo <prudo@redhat.com>
f27a4c
Date: Tue, 9 Nov 2021 14:52:22 +0100
f27a4c
Subject: [PATCH] Fix live debugging with lockdown=integrity
f27a4c
f27a4c
With kernel lockdown the access to kernel interfaces that allow to
f27a4c
extract confidential information (lockdown=confidentiality) or modify a
f27a4c
running kernel (lockdown=integrity) can be restricted. Two of the
f27a4c
interfaces that can be restricted are /dev/mem (integrity &
f27a4c
confidentiality) and /proc/kcore (confidentiality). With
f27a4c
lockdown=integrity this leads to a situation where /dev/mem exists but
f27a4c
is not readable while /proc/kcore exists and is readable. This breaks
f27a4c
crash's live debugging when it is invoked without argument, i.e.
f27a4c
f27a4c
$ crash
f27a4c
[...]
f27a4c
crash: /dev/mem: Operation not permitted
f27a4c
f27a4c
while passing /proc/kcore as image succeeds. The reason for this is that
f27a4c
crash always picks /dev/mem as source when it exits but doesn't check if
f27a4c
it is readable. Fix this by only selecting /dev/mem when it is readable.
f27a4c
f27a4c
Signed-off-by: Philipp Rudo <prudo@redhat.com>
f27a4c
---
f27a4c
 filesys.c | 2 +-
f27a4c
 main.c    | 2 +-
f27a4c
 2 files changed, 2 insertions(+), 2 deletions(-)
f27a4c
f27a4c
diff --git a/filesys.c b/filesys.c
f27a4c
index 3361b6c12ed3..43cbe826fc79 100644
f27a4c
--- a/filesys.c
f27a4c
+++ b/filesys.c
f27a4c
@@ -3666,7 +3666,7 @@ get_live_memory_source(void)
f27a4c
 	if (pc->live_memsrc)
f27a4c
 		goto live_report;
f27a4c
 
f27a4c
-	if (file_exists("/dev/mem", NULL))
f27a4c
+	if (file_readable("/dev/mem"))
f27a4c
 		pc->live_memsrc = "/dev/mem";
f27a4c
 	else if (file_exists("/proc/kcore", NULL)) {
f27a4c
 		pc->flags &= ~DEVMEM;
f27a4c
diff --git a/main.c b/main.c
f27a4c
index 388ac46c3834..dfd343cd9dd4 100644
f27a4c
--- a/main.c
f27a4c
+++ b/main.c
f27a4c
@@ -1119,7 +1119,7 @@ setup_environment(int argc, char **argv)
f27a4c
 	pc->flags2 |= REDZONE;
f27a4c
 	pc->confd = -2;
f27a4c
 	pc->machine_type = MACHINE_TYPE;
f27a4c
-	if (file_exists("/dev/mem", NULL)) {     /* defaults until argv[] is parsed */
f27a4c
+	if (file_readable("/dev/mem")) {     /* defaults until argv[] is parsed */
f27a4c
 		pc->readmem = read_dev_mem;
f27a4c
 		pc->writemem = write_dev_mem;
f27a4c
 	} else if (file_exists("/proc/kcore", NULL)) {
f27a4c
-- 
f27a4c
2.30.2
f27a4c