From: Matthew Garrett Date: Wed, 8 Nov 2017 15:11:32 +0000 (+0000) Subject: Restrict /dev/{mem,kmem,port} when the kernel is locked down X-Git-Tag: archive/raspbian/4.15.17-1+rpi1^2~50 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=df5604ce2317762417642ec3c7535ef36a409d04;p=linux.git Restrict /dev/{mem,kmem,port} when the kernel is locked down 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 Signed-off-by: David Howells Reviewed-by: "Lee, Chun-Yi" Gbp-Pq: Topic features/all/lockdown Gbp-Pq: Name 0005-Restrict-dev-mem-kmem-port-when-the-kernel-is-locked.patch --- diff --git a/drivers/char/mem.c b/drivers/char/mem.c index ffeb60d3434..b2fca26e576 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -784,6 +784,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; }