Skip to contentSkip to conversation

Restrict xmon when kernel is locked down

PATCH Superseded Christopher M. Riedl 2 participants 7 messages Aug 28, 2019 – Aug 29, 2019

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover Restrict xmon when kernel is locked down

Xmon should be either fully or partially disabled depending on the kernel lockdown state.

Put xmon into read-only mode for lockdown=integrity and completely disable xmon when lockdown=confidentiality. Since this can occur dynamically, there may be pre-existing, active breakpoints in xmon when transitioning into read-only mode. These breakpoints will still trigger, so allow them to be listed, but not cleared or altered, using xmon.

Changes since v4:
- Move lockdown state checks into xmon_core
- Allow clearing of breakpoints in xmon read-only mode
- Test simple scenarios (combinations of xmon and lockdown cmdline options, setting breakpoints and changing lockdown state, etc) in QEMU and on an actual POWER8 VM
- Rebase onto security/next-lockdown b602614a81078bf29c82b2671bb96a63488f68d6

Changes since v3:
- Allow active breakpoints to be shown/listed in read-only mode

Changes since v2:
- Rebased onto v36 of https://patchwork.kernel.org/cover/11049461/
(based on: f632a8170a6b667ee4e3f552087588f0fe13c4bb)
- Do not clear existing breakpoints when transitioning from lockdown=none to lockdown=integrity
- Remove line continuation and dangling quote (confuses checkpatch.pl) from the xmon command help/usage string

Christopher M. Riedl (2):
powerpc/xmon: Allow listing active breakpoints in read-only mode powerpc/xmon: Restrict when kernel is locked down

 arch/powerpc/xmon/xmon.c     | 104 +++++++++++++++++++++++++++--------
 include/linux/security.h     |   2 +
 security/lockdown/lockdown.c |   2 +
 3 files changed, 86 insertions(+), 22 deletions(-)
Signature · 1 line
2.23.0
#1 lore raw

PATCH v5 1/2 powerpc/xmon: Allow listing and clearing breakpoints in read-only mode

Read-only mode should not prevent listing and clearing any active breakpoints.

---
 arch/powerpc/xmon/xmon.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
arch/powerpc/xmon/xmon.c +10 -5
index d0620d762a5a..a98a354d46ac 100644
@@ -1045,10 +1045,6 @@ cmds(struct pt_regs *excp)
 			set_lpp_cmd();
 			break;
 		case 'b':
-			if (xmon_is_ro) {
-				printf(xmon_ro_msg);
-				break;
-			}
 			bpt_cmds();
 			break;
 		case 'C':
@@ -1317,11 +1313,16 @@ bpt_cmds(void)
 	struct bpt *bp;
 
 	cmd = inchar();
+
 	switch (cmd) {
 #ifndef CONFIG_PPC_8xx
 	static const char badaddr[] = "Only kernel addresses are permitted for breakpoints\n";
 	int mode;
 	case 'd':	/* bd - hardware data breakpoint */
+		if (xmon_is_ro) {
+			printf(xmon_ro_msg);
+			break;
+		}
 		if (!ppc_breakpoint_available()) {
 			printf("Hardware data breakpoint not supported on this cpu\n");
 			break;
@@ -1349,6 +1350,10 @@ bpt_cmds(void)
 		break;
 
 	case 'i':	/* bi - hardware instr breakpoint */
+		if (xmon_is_ro) {
+			printf(xmon_ro_msg);
+			break;
+		}
 		if (!cpu_has_feature(CPU_FTR_ARCH_207S)) {
 			printf("Hardware instruction breakpoint "
 			       "not supported on this cpu\n");
@@ -1407,7 +1412,7 @@ bpt_cmds(void)
 			break;
 		}
 		termch = cmd;
-		if (!scanhex(&a)) {
+		if (xmon_is_ro || !scanhex(&a)) {
 			/* print all breakpoints */
 			printf("   type            address\n");
 			if (dabr.enabled) {
Signature · 1 line
2.23.0
Tested-by Reviewed-by on v5 1/2
#2 lore raw

Re: [PATCH v5 1/2] powerpc/xmon: Allow listing and clearing breakpoints in read-only mode

Hi Chris,

Quoted 2 lines

Read-only mode should not prevent listing and clearing any active breakpoints.

I tested this and it works for me:

arch/powerpc/xmon/xmon.c bpt_cmds(void) · line 1415

Quoted 1 line
arch/powerpc/xmon/xmon.c +1 -0
+		if (xmon_is_ro || !scanhex(&a)) {

It took me a while to figure out what this line does: as I understand it, the 'b' command can also be used to install a breakpoint (as well as bi/bd). If we are in ro mode or if the input after 'b' doesn't scan as a hex string, print the list of breakpoints instead. Anyway, I'm now happy with it, so:

Regards,
Daniel

Quoted 5 lines
arch/powerpc/xmon/xmon.c +0 -0
 			/* print all breakpoints */
 			printf("   type            address\n");
 			if (dabr.enabled) {
Signature · 1 line
2.23.0
#3 lore raw

Re: [PATCH v5 1/2] powerpc/xmon: Allow listing and clearing breakpoints in read-only mode

Quoted 12 lines · Daniel Axtens

Hi Chris,

Quoted 2 lines

Read-only mode should not prevent listing and clearing any active breakpoints.

I tested this and it works for me:

Quoted 8 lines

arch/powerpc/xmon/xmon.c bpt_cmds(void) · line 1415

Quoted 1 line
arch/powerpc/xmon/xmon.c +1 -0
+		if (xmon_is_ro || !scanhex(&a)) {

It took me a while to figure out what this line does: as I understand it, the 'b' command can also be used to install a breakpoint (as well as bi/bd). If we are in ro mode or if the input after 'b' doesn't scan as a hex string, print the list of breakpoints instead. Anyway, I'm now happy with it, so:

I can add a comment to that effect in the next version. That entire section of code could probably be cleaned up a bit - but that's for another patch. Thanks for testing!

Quoted 11 lines

Regards,
Daniel

Quoted 5 lines
arch/powerpc/xmon/xmon.c +0 -0
 			/* print all breakpoints */
 			printf("   type            address\n");
 			if (dabr.enabled) {
Signature · 1 line
2.23.0
#4 lore raw

PATCH v5 2/2 powerpc/xmon: Restrict when kernel is locked down

In reply to Christopher M. Riedl

Xmon should be either fully or partially disabled depending on the kernel lockdown state.

Put xmon into read-only mode for lockdown=integrity and prevent user entry into xmon when lockdown=confidentiality. Xmon checks the lockdown state on every attempted entry:

(1) during early xmon'ing

(2) when triggered via sysrq

(3) when toggled via debugfs

(4) when triggered via a previously enabled breakpoint

The following lockdown state transitions are handled:

(1) lockdown=none -> lockdown=integrity
set xmon read-only mode

(2) lockdown=none -> lockdown=confidentiality clear all breakpoints, set xmon read-only mode, prevent user re-entry into xmon

(3) lockdown=integrity -> lockdown=confidentiality clear all breakpoints, set xmon read-only mode, prevent user re-entry into xmon

---
 arch/powerpc/xmon/xmon.c     | 85 ++++++++++++++++++++++++++++--------
 include/linux/security.h     |  2 +
 security/lockdown/lockdown.c |  2 +
 3 files changed, 72 insertions(+), 17 deletions(-)
arch/powerpc/xmon/xmon.c +68 -17
index a98a354d46ac..94a5fada3034 100644
@@ -25,6 +25,7 @@
 #include <linux/nmi.h>
 #include <linux/ctype.h>
 #include <linux/highmem.h>
+#include <linux/security.h>
 
 #include <asm/debugfs.h>
 #include <asm/ptrace.h>
@@ -187,6 +188,8 @@ static void dump_tlb_44x(void);
 static void dump_tlb_book3e(void);
 #endif
 
+static void clear_all_bpt(void);
+
 #ifdef CONFIG_PPC64
 #define REG		"%.16lx"
 #else
@@ -283,10 +286,38 @@ Commands:\n\
 "  U	show uptime information\n"
 "  ?	help\n"
 "  # n	limit output to n lines per page (for dp, dpa, dl)\n"
-"  zr	reboot\n\
-  zh	halt\n"
+"  zr	reboot\n"
+"  zh	halt\n"
 ;
 
+#ifdef CONFIG_SECURITY
+static bool xmon_is_locked_down(void)
+{
+	static bool lockdown;
+
+	if (!lockdown) {
+		lockdown = !!security_locked_down(LOCKDOWN_XMON_RW);
+		if (lockdown) {
+			printf("xmon: Disabled due to kernel lockdown\n");
+			xmon_is_ro = true;
+		}
+	}
+
+	if (!xmon_is_ro) {
+		xmon_is_ro = !!security_locked_down(LOCKDOWN_XMON_WR);
+		if (xmon_is_ro)
+			printf("xmon: Read-only due to kernel lockdown\n");
+	}
+
+	return lockdown;
+}
+#else /* CONFIG_SECURITY */
+static inline bool xmon_is_locked_down(void)
+{
+	return false;
+}
+#endif
+
 static struct pt_regs *xmon_regs;
 
 static inline void sync(void)
@@ -438,7 +469,10 @@ static bool wait_for_other_cpus(int ncpus)
 
 	return false;
 }
-#endif /* CONFIG_SMP */
+#else /* CONFIG_SMP */
+static inline void get_output_lock(void) {}
+static inline void release_output_lock(void) {}
+#endif
 
 static inline int unrecoverable_excp(struct pt_regs *regs)
 {
@@ -455,6 +489,7 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 	int cmd = 0;
 	struct bpt *bp;
 	long recurse_jmp[JMP_BUF_LEN];
+	bool locked_down;
 	unsigned long offset;
 	unsigned long flags;
 #ifdef CONFIG_SMP
@@ -465,6 +500,8 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 	local_irq_save(flags);
 	hard_irq_disable();
 
+	locked_down = xmon_is_locked_down();
+
 	tracing_enabled = tracing_is_on();
 	tracing_off();
 
@@ -516,7 +553,8 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 
 	if (!fromipi) {
 		get_output_lock();
-		excprint(regs);
+		if (!locked_down)
+			excprint(regs);
 		if (bp) {
 			printf("cpu 0x%x stopped at breakpoint 0x%tx (",
 			       cpu, BP_NUM(bp));
@@ -568,10 +606,14 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 		}
 		remove_bpts();
 		disable_surveillance();
-		/* for breakpoint or single step, print the current instr. */
-		if (bp || TRAP(regs) == 0xd00)
-			ppc_inst_dump(regs->nip, 1, 0);
-		printf("enter ? for help\n");
+
+		if (!locked_down) {
+			/* for breakpoint or single step, print curr insn */
+			if (bp || TRAP(regs) == 0xd00)
+				ppc_inst_dump(regs->nip, 1, 0);
+			printf("enter ? for help\n");
+		}
+
 		mb();
 		xmon_gate = 1;
 		barrier();
@@ -595,8 +637,9 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 			spin_cpu_relax();
 			touch_nmi_watchdog();
 		} else {
-			cmd = cmds(regs);
-			if (cmd != 0) {
+			if (!locked_down)
+				cmd = cmds(regs);
+			if (locked_down || cmd != 0) {
 				/* exiting xmon */
 				insert_bpts();
 				xmon_gate = 0;
@@ -633,13 +676,16 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 			       "can't continue\n");
 		remove_bpts();
 		disable_surveillance();
-		/* for breakpoint or single step, print the current instr. */
-		if (bp || TRAP(regs) == 0xd00)
-			ppc_inst_dump(regs->nip, 1, 0);
-		printf("enter ? for help\n");
+		if (!locked_down) {
+			/* for breakpoint or single step, print current insn */
+			if (bp || TRAP(regs) == 0xd00)
+				ppc_inst_dump(regs->nip, 1, 0);
+			printf("enter ? for help\n");
+		}
 	}
 
-	cmd = cmds(regs);
+	if (!locked_down)
+		cmd = cmds(regs);
 
 	insert_bpts();
 	in_xmon = 0;
@@ -668,7 +714,10 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 		}
 	}
 #endif
-	insert_cpu_bpts();
+	if (locked_down)
+		clear_all_bpt();
+	else
+		insert_cpu_bpts();
 
 	touch_nmi_watchdog();
 	local_irq_restore(flags);
@@ -3767,7 +3816,6 @@ static int __init setup_xmon_sysrq(void)
 device_initcall(setup_xmon_sysrq);
 #endif /* CONFIG_MAGIC_SYSRQ */
 
-#ifdef CONFIG_DEBUG_FS
 static void clear_all_bpt(void)
 {
 	int i;
@@ -3786,9 +3834,12 @@ static void clear_all_bpt(void)
 		dabr.enabled = 0;
 	}
 
+	get_output_lock();
 	printf("xmon: All breakpoints cleared\n");
+	release_output_lock();
 }
 
+#ifdef CONFIG_DEBUG_FS
 static int xmon_dbgfs_set(void *data, u64 val)
 {
 	xmon_on = !!val;
include/linux/security.h +2 -0
index 429f9f03372b..ba9d308689b6 100644
@@ -116,12 +116,14 @@ enum lockdown_reason {
 	LOCKDOWN_MODULE_PARAMETERS,
 	LOCKDOWN_MMIOTRACE,
 	LOCKDOWN_DEBUGFS,
+	LOCKDOWN_XMON_WR,
 	LOCKDOWN_INTEGRITY_MAX,
 	LOCKDOWN_KCORE,
 	LOCKDOWN_KPROBES,
 	LOCKDOWN_BPF_READ,
 	LOCKDOWN_PERF,
 	LOCKDOWN_TRACEFS,
+	LOCKDOWN_XMON_RW,
 	LOCKDOWN_CONFIDENTIALITY_MAX,
 };
 
security/lockdown/lockdown.c +2 -0
index 0068cec77c05..db85182d3f11 100644
@@ -31,12 +31,14 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
 	[LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",
 	[LOCKDOWN_MMIOTRACE] = "unsafe mmio",
 	[LOCKDOWN_DEBUGFS] = "debugfs access",
+	[LOCKDOWN_XMON_WR] = "xmon write access",
 	[LOCKDOWN_INTEGRITY_MAX] = "integrity",
 	[LOCKDOWN_KCORE] = "/proc/kcore access",
 	[LOCKDOWN_KPROBES] = "use of kprobes",
 	[LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM",
 	[LOCKDOWN_PERF] = "unsafe use of perf",
 	[LOCKDOWN_TRACEFS] = "use of tracefs",
+	[LOCKDOWN_XMON_RW] = "xmon read and write access",
 	[LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
 };
 
Signature · 1 line
2.23.0
Tested-by Reviewed-by on v5 2/2
#5 lore raw

Re: [PATCH v5 2/2] powerpc/xmon: Restrict when kernel is locked down

Hi,

Quoted 2 lines

Xmon should be either fully or partially disabled depending on the kernel lockdown state.

I've been kicking the tyres of this, and it seems to work well:

Quoted 18 lines

Put xmon into read-only mode for lockdown=integrity and prevent user entry into xmon when lockdown=confidentiality. Xmon checks the lockdown state on every attempted entry:

(1) during early xmon'ing

(2) when triggered via sysrq

(3) when toggled via debugfs

(4) when triggered via a previously enabled breakpoint

The following lockdown state transitions are handled:

(1) lockdown=none -> lockdown=integrity
set xmon read-only mode

Quoted 7 lines

(2) lockdown=none -> lockdown=confidentiality clear all breakpoints, set xmon read-only mode, prevent user re-entry into xmon

(3) lockdown=integrity -> lockdown=confidentiality clear all breakpoints, set xmon read-only mode, prevent user re-entry into xmon

I have one small nit: if I enter confidentiality mode and then try to enter xmon, I get 32 messages about clearing the breakpoints each time I try to enter xmon:

root@dja-guest:~# echo confidentiality > /sys/kernel/security/lockdown 
root@dja-guest:~# echo x >/proc/sysrq-trigger 
[  489.585400] sysrq: Entering xmon
xmon: Disabled due to kernel lockdown
xmon: All breakpoints cleared
xmon: All breakpoints cleared
xmon: All breakpoints cleared
xmon: All breakpoints cleared
xmon: All breakpoints cleared
...

Investigating, I see that this is because my vm has 32 vcpus, and I'm getting one per CPU.

Looking at the call sites, there's only one other caller, so I think you might be better served with this:

arch/powerpc/xmon/xmon.c +6 -5
index 94a5fada3034..fcaf1d568162 100644
@@ -3833,10 +3833,6 @@ static void clear_all_bpt(void)
                iabr = NULL;
                dabr.enabled = 0;
        }
-
-       get_output_lock();
-       printf("xmon: All breakpoints cleared\n");
-       release_output_lock();
 }
 
 #ifdef CONFIG_DEBUG_FS
@@ -3846,8 +3842,13 @@ static int xmon_dbgfs_set(void *data, u64 val)
        xmon_init(xmon_on);
 
        /* make sure all breakpoints removed when disabling */
-       if (!xmon_on)
+       if (!xmon_on) {
                clear_all_bpt();
+               get_output_lock();
+               printf("xmon: All breakpoints cleared\n");
+               release_output_lock();
+       }
+
        return 0;
 }
 

Apart from that:

Regards,
Daniel

Quoted 235 lines
---
 arch/powerpc/xmon/xmon.c     | 85 ++++++++++++++++++++++++++++--------
 include/linux/security.h     |  2 +
 security/lockdown/lockdown.c |  2 +
 3 files changed, 72 insertions(+), 17 deletions(-)
arch/powerpc/xmon/xmon.c +68 -17
index a98a354d46ac..94a5fada3034 100644
@@ -25,6 +25,7 @@
 #include <linux/nmi.h>
 #include <linux/ctype.h>
 #include <linux/highmem.h>
+#include <linux/security.h>
 
 #include <asm/debugfs.h>
 #include <asm/ptrace.h>
@@ -187,6 +188,8 @@ static void dump_tlb_44x(void);
 static void dump_tlb_book3e(void);
 #endif
 
+static void clear_all_bpt(void);
+
 #ifdef CONFIG_PPC64
 #define REG		"%.16lx"
 #else
@@ -283,10 +286,38 @@ Commands:\n\
 "  U	show uptime information\n"
 "  ?	help\n"
 "  # n	limit output to n lines per page (for dp, dpa, dl)\n"
-"  zr	reboot\n\
-  zh	halt\n"
+"  zr	reboot\n"
+"  zh	halt\n"
 ;
 
+#ifdef CONFIG_SECURITY
+static bool xmon_is_locked_down(void)
+{
+	static bool lockdown;
+
+	if (!lockdown) {
+		lockdown = !!security_locked_down(LOCKDOWN_XMON_RW);
+		if (lockdown) {
+			printf("xmon: Disabled due to kernel lockdown\n");
+			xmon_is_ro = true;
+		}
+	}
+
+	if (!xmon_is_ro) {
+		xmon_is_ro = !!security_locked_down(LOCKDOWN_XMON_WR);
+		if (xmon_is_ro)
+			printf("xmon: Read-only due to kernel lockdown\n");
+	}
+
+	return lockdown;
+}
+#else /* CONFIG_SECURITY */
+static inline bool xmon_is_locked_down(void)
+{
+	return false;
+}
+#endif
+
 static struct pt_regs *xmon_regs;
 
 static inline void sync(void)
@@ -438,7 +469,10 @@ static bool wait_for_other_cpus(int ncpus)
 
 	return false;
 }
-#endif /* CONFIG_SMP */
+#else /* CONFIG_SMP */
+static inline void get_output_lock(void) {}
+static inline void release_output_lock(void) {}
+#endif
 
 static inline int unrecoverable_excp(struct pt_regs *regs)
 {
@@ -455,6 +489,7 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 	int cmd = 0;
 	struct bpt *bp;
 	long recurse_jmp[JMP_BUF_LEN];
+	bool locked_down;
 	unsigned long offset;
 	unsigned long flags;
 #ifdef CONFIG_SMP
@@ -465,6 +500,8 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 	local_irq_save(flags);
 	hard_irq_disable();
 
+	locked_down = xmon_is_locked_down();
+
 	tracing_enabled = tracing_is_on();
 	tracing_off();
 
@@ -516,7 +553,8 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 
 	if (!fromipi) {
 		get_output_lock();
-		excprint(regs);
+		if (!locked_down)
+			excprint(regs);
 		if (bp) {
 			printf("cpu 0x%x stopped at breakpoint 0x%tx (",
 			       cpu, BP_NUM(bp));
@@ -568,10 +606,14 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 		}
 		remove_bpts();
 		disable_surveillance();
-		/* for breakpoint or single step, print the current instr. */
-		if (bp || TRAP(regs) == 0xd00)
-			ppc_inst_dump(regs->nip, 1, 0);
-		printf("enter ? for help\n");
+
+		if (!locked_down) {
+			/* for breakpoint or single step, print curr insn */
+			if (bp || TRAP(regs) == 0xd00)
+				ppc_inst_dump(regs->nip, 1, 0);
+			printf("enter ? for help\n");
+		}
+
 		mb();
 		xmon_gate = 1;
 		barrier();
@@ -595,8 +637,9 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 			spin_cpu_relax();
 			touch_nmi_watchdog();
 		} else {
-			cmd = cmds(regs);
-			if (cmd != 0) {
+			if (!locked_down)
+				cmd = cmds(regs);
+			if (locked_down || cmd != 0) {
 				/* exiting xmon */
 				insert_bpts();
 				xmon_gate = 0;
@@ -633,13 +676,16 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 			       "can't continue\n");
 		remove_bpts();
 		disable_surveillance();
-		/* for breakpoint or single step, print the current instr. */
-		if (bp || TRAP(regs) == 0xd00)
-			ppc_inst_dump(regs->nip, 1, 0);
-		printf("enter ? for help\n");
+		if (!locked_down) {
+			/* for breakpoint or single step, print current insn */
+			if (bp || TRAP(regs) == 0xd00)
+				ppc_inst_dump(regs->nip, 1, 0);
+			printf("enter ? for help\n");
+		}
 	}
 
-	cmd = cmds(regs);
+	if (!locked_down)
+		cmd = cmds(regs);
 
 	insert_bpts();
 	in_xmon = 0;
@@ -668,7 +714,10 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
 		}
 	}
 #endif
-	insert_cpu_bpts();
+	if (locked_down)
+		clear_all_bpt();
+	else
+		insert_cpu_bpts();
 
 	touch_nmi_watchdog();
 	local_irq_restore(flags);
@@ -3767,7 +3816,6 @@ static int __init setup_xmon_sysrq(void)
 device_initcall(setup_xmon_sysrq);
 #endif /* CONFIG_MAGIC_SYSRQ */
 
-#ifdef CONFIG_DEBUG_FS
 static void clear_all_bpt(void)
 {
 	int i;
@@ -3786,9 +3834,12 @@ static void clear_all_bpt(void)
 		dabr.enabled = 0;
 	}
 
+	get_output_lock();
 	printf("xmon: All breakpoints cleared\n");
+	release_output_lock();
 }
 
+#ifdef CONFIG_DEBUG_FS
 static int xmon_dbgfs_set(void *data, u64 val)
 {
 	xmon_on = !!val;
include/linux/security.h +2 -0
index 429f9f03372b..ba9d308689b6 100644
@@ -116,12 +116,14 @@ enum lockdown_reason {
 	LOCKDOWN_MODULE_PARAMETERS,
 	LOCKDOWN_MMIOTRACE,
 	LOCKDOWN_DEBUGFS,
+	LOCKDOWN_XMON_WR,
 	LOCKDOWN_INTEGRITY_MAX,
 	LOCKDOWN_KCORE,
 	LOCKDOWN_KPROBES,
 	LOCKDOWN_BPF_READ,
 	LOCKDOWN_PERF,
 	LOCKDOWN_TRACEFS,
+	LOCKDOWN_XMON_RW,
 	LOCKDOWN_CONFIDENTIALITY_MAX,
 };
 
security/lockdown/lockdown.c +2 -0
index 0068cec77c05..db85182d3f11 100644
@@ -31,12 +31,14 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
 	[LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",
 	[LOCKDOWN_MMIOTRACE] = "unsafe mmio",
 	[LOCKDOWN_DEBUGFS] = "debugfs access",
+	[LOCKDOWN_XMON_WR] = "xmon write access",
 	[LOCKDOWN_INTEGRITY_MAX] = "integrity",
 	[LOCKDOWN_KCORE] = "/proc/kcore access",
 	[LOCKDOWN_KPROBES] = "use of kprobes",
 	[LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM",
 	[LOCKDOWN_PERF] = "unsafe use of perf",
 	[LOCKDOWN_TRACEFS] = "use of tracefs",
+	[LOCKDOWN_XMON_RW] = "xmon read and write access",
 	[LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
 };
 
Signature · 1 line
2.23.0
#6 lore raw

Re: [PATCH v5 2/2] powerpc/xmon: Restrict when kernel is locked down

Quoted 13 lines · Daniel Axtens

Hi,

Quoted 2 lines

Xmon should be either fully or partially disabled depending on the kernel lockdown state.

I've been kicking the tyres of this, and it seems to work well:

Thank you for taking the time to test this!

Quoted 5 lines

I have one small nit: if I enter confidentiality mode and then try to enter xmon, I get 32 messages about clearing the breakpoints each time I try to enter xmon:

Ugh, that's annoying. I tested this on a vm w/ 2 vcpus but should have considered the case of more vcpus :(

Quoted 38 lines
root@dja-guest:~# echo confidentiality > /sys/kernel/security/lockdown 
root@dja-guest:~# echo x >/proc/sysrq-trigger 
[  489.585400] sysrq: Entering xmon
xmon: Disabled due to kernel lockdown
xmon: All breakpoints cleared
xmon: All breakpoints cleared
xmon: All breakpoints cleared
xmon: All breakpoints cleared
xmon: All breakpoints cleared
...

Investigating, I see that this is because my vm has 32 vcpus, and I'm getting one per CPU.

Looking at the call sites, there's only one other caller, so I think you might be better served with this:

arch/powerpc/xmon/xmon.c +0 -5
index 94a5fada3034..fcaf1d568162 100644
@@ -3833,10 +3833,6 @@ static void clear_all_bpt(void)
                iabr = NULL;
                dabr.enabled = 0;
        }
-
-       get_output_lock();
-       printf("xmon: All breakpoints cleared\n");
-       release_output_lock();
 }
 
 #ifdef CONFIG_DEBUG_FS
@@ -3846,8 +3842,13 @@ static int xmon_dbgfs_set(void *data, u64 val)
        xmon_init(xmon_on);
 
        /* make sure all breakpoints removed when disabling */
-       if (!xmon_on)

arch/powerpc/xmon/xmon.c static int xmon_dbgfs_set(void *data, u64 val) · line 3854

Quoted 10 lines
arch/powerpc/xmon/xmon.c +6 -0
+       if (!xmon_on) {
                clear_all_bpt();
+               get_output_lock();
+               printf("xmon: All breakpoints cleared\n");
+               release_output_lock();
+       }
+
        return 0;
 }
 

Good point, I will add this to the next version, thanks!

Quoted 7 lines

Apart from that:

Regards,
Daniel