Restrict /dev/{mem,kmem,port} when the kernel is locked down
authorMatthew Garrett <mjg59@srcf.ucam.org>
Mon, 18 Feb 2019 12:44:58 +0000 (12:44 +0000)
committerSalvatore Bonaccorso <carnil@debian.org>
Thu, 26 Sep 2019 12:19:06 +0000 (13:19 +0100)
Allowing users to read and write to core kernel memory makes it possible
for the kernel to be subverted, avoiding module loading restrictions, and
also to steal cryptographic information.

Disallow /dev/mem and /dev/kmem from being opened this when the kernel has
been locked down to prevent this.

Also disallow /dev/port from being opened to prevent raw ioport access and
thus DMA from being used to accomplish the same thing.

Signed-off-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: "Lee, Chun-Yi" <jlee@suse.com>
Gbp-Pq: Topic features/all/lockdown
Gbp-Pq: Name 0005-Restrict-dev-mem-kmem-port-when-the-kernel-is-locked.patch

drivers/char/mem.c

index b08dc50f9f26026730c5eb12ee8e4be47012c2f8..0a2f2e75d5f450a1a74190b3452b2c38549c9bc2 100644 (file)
@@ -786,6 +786,8 @@ static loff_t memory_lseek(struct file *file, loff_t offset, int orig)
 
 static int open_port(struct inode *inode, struct file *filp)
 {
+       if (kernel_is_locked_down("/dev/mem,kmem,port"))
+               return -EPERM;
        return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }