Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/pseries: block untrusted device tree changes when locked down

The /proc/powerpc/ofdt interface allows the root user to freely alter
the in-kernel device tree, enabling arbitrary physical address writes
via drivers that could bind to malicious device nodes, thus making it
possible to disable lockdown.

Historically this interface has been used on the pseries platform to
facilitate the runtime addition and removal of processor, memory, and
device resources (aka Dynamic Logical Partitioning or DLPAR). Years
ago, the processor and memory use cases were migrated to designs that
happen to be lockdown-friendly: device tree updates are communicated
directly to the kernel from firmware without passing through untrusted
user space. I/O device DLPAR via the "drmgr" command in powerpc-utils
remains the sole legitimate user of /proc/powerpc/ofdt, but it is
already broken in lockdown since it uses /dev/mem to allocate argument
buffers for the rtas syscall. So only illegitimate uses of the
interface should see a behavior change when running on a locked down
kernel.

Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Acked-by: Paul Moore <paul@paul-moore.com> (LSM)
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220926131643.146502-2-nathanl@linux.ibm.com

authored by

Nathan Lynch and committed by
Michael Ellerman
99df7a28 6bd7ff49

+7
+5
arch/powerpc/platforms/pseries/reconfig.c
··· 10 10 #include <linux/kernel.h> 11 11 #include <linux/notifier.h> 12 12 #include <linux/proc_fs.h> 13 + #include <linux/security.h> 13 14 #include <linux/slab.h> 14 15 #include <linux/of.h> 15 16 ··· 361 360 int rv; 362 361 char *kbuf; 363 362 char *tmp; 363 + 364 + rv = security_locked_down(LOCKDOWN_DEVICE_TREE); 365 + if (rv) 366 + return rv; 364 367 365 368 kbuf = memdup_user_nul(buf, count); 366 369 if (IS_ERR(kbuf))
+1
include/linux/security.h
··· 114 114 LOCKDOWN_IOPORT, 115 115 LOCKDOWN_MSR, 116 116 LOCKDOWN_ACPI_TABLES, 117 + LOCKDOWN_DEVICE_TREE, 117 118 LOCKDOWN_PCMCIA_CIS, 118 119 LOCKDOWN_TIOCSSERIAL, 119 120 LOCKDOWN_MODULE_PARAMETERS,
+1
security/security.c
··· 52 52 [LOCKDOWN_IOPORT] = "raw io port access", 53 53 [LOCKDOWN_MSR] = "raw MSR access", 54 54 [LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables", 55 + [LOCKDOWN_DEVICE_TREE] = "modifying device tree contents", 55 56 [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", 56 57 [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", 57 58 [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",