Skip to contentSkip to conversation

Lock down kprobes

RFC PATCH In review David Howells 2 participants 4 messages Nov 8, 2017 – Nov 9, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Lock down kprobes

Hi,

I need to lock down kprobes under secure boot conditions as part of the patch series that can be found here:

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=efi-lock-down

Can you tell me that if the attached patch is sufficient to the cause?

---
commit 9b736b76fbd7b23b54b4340e80c66f87df54016c

Author: David Howells <[email protected]>
Date:   Wed Nov 8 16:14:12 2017 +0000

Lock down kprobes

Disallow the creation of kprobes when the kernel is locked down. This patch restricts writing to /sys/kernel/debug/tracing/kprobe_events; writing to /sys/kernel/debug/kprobes/enabled is disabled by the patch that locks down debugfs.

kernel/trace/trace_kprobe.c +3 -0
index 8a907e12b6b9..b44f046d2582 100644
@@ -907,6 +907,9 @@ static int probes_open(struct inode *inode, struct file *file)
 static ssize_t probes_write(struct file *file, const char __user *buffer,
 			    size_t count, loff_t *ppos)
 {
+	if (kernel_is_locked_down("Use of kprobes"))
+		return -EPERM;
+
 	return traceprobe_probes_write(file, buffer, count, ppos,
 			create_trace_kprobe);
 }

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 8 lines · David Howells

Hi,

I need to lock down kprobes under secure boot conditions as part of the patch series that can be found here:

https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/log/?h=efi-lock-down

Can you tell me that if the attached patch is sufficient to the cause?

This will not prevent the raw kprobe events from working. If your intention is to prevent *any* kprobe registration, the best place to do that is in register_kprobe() in kernel/probes.c

Ananth

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

So this?

Thanks,
David
---
commit b5bb759d5e7f99c357b82b8066a9106b817de965

Author: David Howells <[email protected]>
Date:   Wed Nov 8 16:14:12 2017 +0000

Lock down kprobes

Disallow the creation of kprobes when the kernel is locked down by preventing their registration.

kernel/kprobes.c +3 -0
index a1606a4224e1..f06023b0936c 100644
@@ -1530,6 +1530,9 @@ int register_kprobe(struct kprobe *p)
 	struct module *probed_mod;
 	kprobe_opcode_t *addr;
 
+	if (kernel_is_locked_down("Use of kprobes"))
+		return -EPERM;
+
 	/* Adjust probe address from symbol */
 	addr = kprobe_addr(p);
 	if (IS_ERR(addr))

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html