drivers/char: remove /dev/kmem for good
Subsystems (22)
RFC PATCH 1/3 drivers/char: remove /dev/kmem for good
In reply to David HildenbrandExploring /dev/kmem and /dev/mem in the context of memory hot(un)plug and memory ballooning, I started questioning the existance of /dev/kmem.
Comparing it with the /proc/kcore implementation, it does not seem to be able to deal with things like
a) Pages unmapped from the direct mapping (e.g., to be used by secretmem) -> kern_addr_valid(). virt_addr_valid() is not sufficient.
b) Special cases like gart aperture memory that is not to be touched -> mem_pfn_is_ram()
Unless I am missing something, it's at least broken in some cases and might fault/crash the machine.
Looks like its existance has been questioned before in 2005 and 2010 [1], after ~11 additional years, it might make sense to revive the discussion.
CONFIG_DEVKMEM is only enabled in a single defconfig (on purpose or by mistake?). All distributions I looked at disable it.
1) /dev/kmem was popular for rootkits [2] before it got disabled basically everywhere. Ubuntu documents [3] "There is no modern user of /dev/kmem any more beyond attackers using it to load kernel rootkits.". RHEL documents in a BZ [5] "it served no practical purpose other than to serve as a potential security problem or to enable binary module drivers to access structures/functions they shouldn't be touching"
2) /proc/kcore is a decent interface to have a controlled way to read kernel memory for debugging puposes. (will need some extensions to deal with memory offlining/unplug, memory ballooning, and poisoned pages, though)
3) It might be useful for corner case debugging [1]. KDB/KGDB might be a better fit, especially, to write random memory; harder to shoot yourself into the foot.
4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems to be incompatible with 64bit [1]. For educational purposes, /proc/kcore might be used to monitor value updates -- or older kernels can be used.
5) It's broken on arm64, and therefore, completely disabled there.
Looks like it's essentially unused and has been replaced by better suited interfaces for individual tasks (/proc/kcore, KDB/KGDB). Let's just remove it.
[1] https://lwn.net/Articles/147901/
[2] https://www.linuxjournal.com/article/10505
[3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
[4] https://sourceforge.net/projects/kme/
[5] https://bugzilla.redhat.com/show_bug.cgi?id=154796
--- Documentation/admin-guide/devices.txt | 2 +- arch/arm/configs/dove_defconfig | 1 - arch/arm/configs/magician_defconfig | 1 - arch/arm/configs/moxart_defconfig | 1 - arch/arm/configs/mps2_defconfig | 1 - arch/arm/configs/mvebu_v5_defconfig | 1 - arch/arm/configs/xcep_defconfig | 1 - arch/h8300/configs/edosk2674_defconfig | 1 - arch/h8300/configs/h8300h-sim_defconfig | 1 - arch/h8300/configs/h8s-sim_defconfig | 1 - arch/hexagon/configs/comet_defconfig | 1 - arch/m68k/configs/amcore_defconfig | 1 - arch/openrisc/configs/or1ksim_defconfig | 1 - arch/sh/configs/edosk7705_defconfig | 1 - arch/sh/configs/se7206_defconfig | 1 - arch/sh/configs/sh2007_defconfig | 1 - arch/sh/configs/sh7724_generic_defconfig | 1 - arch/sh/configs/sh7770_generic_defconfig | 1 - arch/sh/configs/sh7785lcr_32bit_defconfig | 1 - arch/sparc/configs/sparc64_defconfig | 1 - arch/xtensa/configs/xip_kc705_defconfig | 1 - drivers/char/Kconfig | 10 - drivers/char/mem.c | 231 ---------------------- include/linux/fs.h | 2 +- include/linux/vmalloc.h | 2 +- kernel/configs/android-base.config | 1 - mm/ksm.c | 2 +- mm/vmalloc.c | 2 +- 28 files changed, 5 insertions(+), 267 deletions(-)
Documentation/admin-guide/devices.txt +1 -1
@@ -4,7 +4,7 @@ 1 char Memory devices 1 = /dev/mem Physical memory access - 2 = /dev/kmem Kernel virtual memory access + 2 = /dev/kmem OBSOLETE - replaced by /proc/kcore 3 = /dev/null Null device 4 = /dev/port I/O port access 5 = /dev/zero Null byte source
arch/arm/configs/dove_defconfig +0 -1
@@ -63,7 +63,6 @@ CONFIG_INPUT_EVDEV=y # CONFIG_MOUSE_PS2 is not set # CONFIG_SERIO is not set CONFIG_LEGACY_PTY_COUNT=16 -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=y CONFIG_SERIAL_8250_CONSOLE=y CONFIG_SERIAL_8250_RUNTIME_UARTS=2
arch/arm/configs/magician_defconfig +0 -1
@@ -72,7 +72,6 @@ CONFIG_INPUT_TOUCHSCREEN=y CONFIG_INPUT_MISC=y CONFIG_INPUT_UINPUT=m # CONFIG_SERIO is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_PXA=y # CONFIG_LEGACY_PTYS is not set # CONFIG_HW_RANDOM is not set
arch/arm/configs/moxart_defconfig +0 -1
@@ -79,7 +79,6 @@ CONFIG_INPUT_EVBUG=y # CONFIG_SERIO is not set # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=y CONFIG_SERIAL_8250_CONSOLE=y CONFIG_SERIAL_8250_NR_UARTS=1
arch/arm/configs/mps2_defconfig +0 -1
@@ -69,7 +69,6 @@ CONFIG_SMSC911X=y # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set CONFIG_SERIAL_NONSTANDARD=y -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_MPS2_UART_CONSOLE=y CONFIG_SERIAL_MPS2_UART=y # CONFIG_HW_RANDOM is not set
arch/arm/configs/mvebu_v5_defconfig +0 -1
@@ -100,7 +100,6 @@ CONFIG_INPUT_EVDEV=y CONFIG_KEYBOARD_GPIO=y # CONFIG_INPUT_MOUSE is not set CONFIG_LEGACY_PTY_COUNT=16 -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=y CONFIG_SERIAL_8250_CONSOLE=y CONFIG_SERIAL_8250_RUNTIME_UARTS=2
arch/arm/configs/xcep_defconfig +0 -1
@@ -53,7 +53,6 @@ CONFIG_NET_ETHERNET=y # CONFIG_INPUT_KEYBOARD is not set # CONFIG_INPUT_MOUSE is not set # CONFIG_SERIO is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_PXA=y CONFIG_SERIAL_PXA_CONSOLE=y # CONFIG_LEGACY_PTYS is not set
arch/h8300/configs/edosk2674_defconfig +0 -1
@@ -32,7 +32,6 @@ CONFIG_BINFMT_FLAT=y # CONFIG_VT is not set # CONFIG_UNIX98_PTYS is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_CONSOLE=y # CONFIG_HW_RANDOM is not set
arch/h8300/configs/h8300h-sim_defconfig +0 -1
@@ -32,7 +32,6 @@ CONFIG_BINFMT_FLAT=y # CONFIG_VT is not set # CONFIG_UNIX98_PTYS is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_EARLYCON=y # CONFIG_HW_RANDOM is not set
arch/h8300/configs/h8s-sim_defconfig +0 -1
@@ -32,7 +32,6 @@ CONFIG_BINFMT_FLAT=y # CONFIG_VT is not set # CONFIG_UNIX98_PTYS is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_CONSOLE=y # CONFIG_HW_RANDOM is not set
arch/hexagon/configs/comet_defconfig +0 -1
@@ -34,7 +34,6 @@ CONFIG_NET_ETHERNET=y # CONFIG_SERIO is not set # CONFIG_CONSOLE_TRANSLATIONS is not set CONFIG_LEGACY_PTY_COUNT=64 -# CONFIG_DEVKMEM is not set # CONFIG_HW_RANDOM is not set CONFIG_SPI=y CONFIG_SPI_DEBUG=y
arch/m68k/configs/amcore_defconfig +0 -1
@@ -60,7 +60,6 @@ CONFIG_DM9000=y # CONFIG_VT is not set # CONFIG_UNIX98_PTYS is not set # CONFIG_DEVMEM is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_MCF=y CONFIG_SERIAL_MCF_BAUDRATE=115200 CONFIG_SERIAL_MCF_CONSOLE=y
arch/openrisc/configs/or1ksim_defconfig +0 -1
@@ -43,7 +43,6 @@ CONFIG_MICREL_PHY=y # CONFIG_SERIO is not set # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=y CONFIG_SERIAL_8250_CONSOLE=y CONFIG_SERIAL_OF_PLATFORM=y
arch/sh/configs/edosk7705_defconfig +0 -1
@@ -23,7 +23,6 @@ CONFIG_SH_PCLK_FREQ=31250000 # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set # CONFIG_UNIX98_PTYS is not set # CONFIG_LEGACY_PTYS is not set # CONFIG_HW_RANDOM is not set
arch/sh/configs/se7206_defconfig +0 -1
@@ -71,7 +71,6 @@ CONFIG_SMC91X=y # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_NR_UARTS=4 CONFIG_SERIAL_SH_SCI_CONSOLE=y
arch/sh/configs/sh2007_defconfig +0 -1
@@ -75,7 +75,6 @@ CONFIG_INPUT_FF_MEMLESS=y # CONFIG_INPUT_MOUSE is not set # CONFIG_SERIO is not set CONFIG_VT_HW_CONSOLE_BINDING=y -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_CONSOLE=y # CONFIG_LEGACY_PTYS is not set
arch/sh/configs/sh7724_generic_defconfig +0 -1
@@ -18,7 +18,6 @@ CONFIG_CPU_IDLE=y # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_NR_UARTS=6 CONFIG_SERIAL_SH_SCI_CONSOLE=y
arch/sh/configs/sh7770_generic_defconfig +0 -1
@@ -20,7 +20,6 @@ CONFIG_CPU_IDLE=y # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_NR_UARTS=6 CONFIG_SERIAL_SH_SCI_CONSOLE=y
arch/sh/configs/sh7785lcr_32bit_defconfig +0 -1
@@ -66,7 +66,6 @@ CONFIG_INPUT_FF_MEMLESS=m CONFIG_INPUT_EVDEV=y CONFIG_INPUT_EVBUG=m CONFIG_VT_HW_CONSOLE_BINDING=y -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=y CONFIG_SERIAL_SH_SCI_NR_UARTS=6 CONFIG_SERIAL_SH_SCI_CONSOLE=y
arch/sparc/configs/sparc64_defconfig +0 -1
@@ -122,7 +122,6 @@ CONFIG_INPUT_SPARCSPKR=y # CONFIG_SERIO_SERPORT is not set CONFIG_SERIO_PCIPS2=m CONFIG_SERIO_RAW=m -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SUNSU=y CONFIG_SERIAL_SUNSU_CONSOLE=y CONFIG_SERIAL_SUNSAB=y
arch/xtensa/configs/xip_kc705_defconfig +0 -1
@@ -72,7 +72,6 @@ CONFIG_MARVELL_PHY=y # CONFIG_INPUT_KEYBOARD is not set # CONFIG_INPUT_MOUSE is not set # CONFIG_SERIO is not set -CONFIG_DEVKMEM=y CONFIG_SERIAL_8250=y # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set CONFIG_SERIAL_8250_CONSOLE=y
drivers/char/Kconfig +0 -10
@@ -334,16 +334,6 @@ config DEVMEM memory. When in doubt, say "Y". -config DEVKMEM - bool "/dev/kmem virtual device support" - # On arm64, VMALLOC_START < PAGE_OFFSET, which confuses kmem read/write - depends on !ARM64 - help - Say Y here if you want to support the /dev/kmem device. The - /dev/kmem device is rarely used, but can be used for certain - kind of kernel debugging operations. - When in doubt, say "N". - config NVRAM tristate "/dev/nvram support" depends on X86 || HAVE_ARCH_NVRAM_OPS
drivers/char/mem.c +0 -231
255 lines not on this page · raw message
include/linux/fs.h +1 -1
@@ -144,7 +144,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,/* Expect random access pattern */ #define FMODE_RANDOM ((__force fmode_t)0x1000) -/* File is huge (eg. /dev/kmem): treat loff_t as unsigned */ +/* File is huge (eg. /dev/mem): treat loff_t as unsigned */ #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)0x2000)/* File is opened with O_PATH; almost nothing can be done with it */
include/linux/vmalloc.h +1 -1
@@ -198,7 +198,7 @@ static inline void set_vm_flush_reset_perms(void *addr) }#endif -/* for /dev/kmem */ +/* for /proc/kcore */ extern long vread (char *buf,char *addr,unsigned long count);extern long vwrite (char *buf,char *addr,unsigned long count);
kernel/configs/android-base.config +0 -1
@@ -1,5 +1,4 @@ # KEEP ALPHABETICALLY SORTED -# CONFIG_DEVKMEM is not set # CONFIG_DEVMEM is not set # CONFIG_FHANDLE is not set # CONFIG_INET_LRO is not set
mm/ksm.c +1 -1
@@ -461,7 +461,7 @@ static inline bool ksm_test_exit(struct mm_struct *mm)* but taking great care only to touch a ksm page, in a VM_MERGEABLE vma, * in case the application has unmapped and remapped mm,addr meanwhile. * Could a ksm page appear anywhere else? Actually yes, in a VM_PFNMAP -* mmap of /dev/mem or /dev/kmem, where we would not want to touch it. +* mmap of /dev/mem, where we would not want to touch it. * * FAULT_FLAG/FOLL_REMOTE are because we do this outside the context * of the process that owns 'vma'. We also do not want to enforce
mm/vmalloc.c +1 -1
@@ -2875,7 +2875,7 @@ static int aligned_vwrite(char *buf, char *addr, unsigned long count)* Note: In usual ops, vread() is never necessary because the caller * should know vmalloc() area is valid and can use memcpy(). * This is for routines which have to access vmalloc area without -* any information, as /dev/kmem. +* any information, as /proc/kcore. * * Return: number of bytes for which addr and buf should be increased * (same number as @count) or %0 if [addr...addr+count) doesn't
Signature · 1 line
2.29.2
RFC PATCH 2/3 mm: remove xlate_dev_kmem_ptr()
In reply to David HildenbrandSince /dev/kmem has been removed, let's remove the xlate_dev_kmem_ptr() leftovers.
--- arch/alpha/include/asm/io.h | 5 ----- arch/arm/include/asm/io.h | 5 ----- arch/hexagon/include/asm/io.h | 1 - arch/ia64/include/asm/io.h | 1 - arch/ia64/include/asm/uaccess.h | 18 ------------------ arch/m68k/include/asm/io_mm.h | 5 ----- arch/mips/include/asm/io.h | 5 ----- arch/parisc/include/asm/io.h | 5 ----- arch/powerpc/include/asm/io.h | 5 ----- arch/s390/include/asm/io.h | 5 ----- arch/sh/include/asm/io.h | 5 ----- arch/sparc/include/asm/io_64.h | 5 ----- include/asm-generic/io.h | 11 ----------- 13 files changed, 76 deletions(-)
arch/alpha/include/asm/io.h +0 -5
@@ -602,11 +602,6 @@ extern void outsl (unsigned long port, const void *src, unsigned long count);*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -#endif /* __KERNEL__ */ #endif /* __ALPHA_IO_H */
arch/arm/include/asm/io.h +0 -5
@@ -430,11 +430,6 @@ extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -#include <asm-generic/io.h> #ifdef CONFIG_MMU
arch/hexagon/include/asm/io.h +0 -1
@@ -64,7 +64,6 @@ static inline void *phys_to_virt(unsigned long address)* convert a physical pointer to a virtual kernel pointer for * /dev/mem access. */ -#define xlate_dev_kmem_ptr (p) __va(p)#define xlate_dev_mem_ptr (p) __va(p)/*
arch/ia64/include/asm/io.h +0 -1
@@ -277,7 +277,6 @@ extern void memset_io(volatile void __iomem *s, int c, long n);#define memcpy_fromio memcpy_fromio#define memcpy_toio memcpy_toio#define memset_io memset_io -#define xlate_dev_kmem_ptr xlate_dev_kmem_ptr#define xlate_dev_mem_ptr xlate_dev_mem_ptr#include <asm-generic/io.h> #undef PCI_IOBASE
arch/ia64/include/asm/uaccess.h +0 -18
@@ -272,22 +272,4 @@ xlate_dev_mem_ptr(phys_addr_t p) return ptr; } -/* -* Convert a virtual cached kernel memory pointer to an uncached pointer -*/ -static __inline__void * -xlate_dev_kmem_ptr (void *p) -{ -struct page *page; -void *ptr; - - page =virt_to_page ((unsigned long )p); -if (PageUncached (page)) - ptr = (void *)__pa (p) + __IA64_UNCACHED_OFFSET; -else - ptr = p; - -return ptr; -} -#endif /* _ASM_IA64_UACCESS_H */
arch/m68k/include/asm/io_mm.h +0 -5
@@ -397,11 +397,6 @@ static inline void isa_delay(void)*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -#define readb_relaxed (addr) readb(addr)#define readw_relaxed (addr) readw(addr)#define readl_relaxed (addr) readl(addr)
arch/mips/include/asm/io.h +0 -5
@@ -552,11 +552,6 @@ extern void (*_dma_cache_inv)(unsigned long start, unsigned long size);*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -void __ioread64_copy (void *to,const void __iomem *from,size_t count);#endif /* _ASM_IO_H */
arch/parisc/include/asm/io.h +0 -5
@@ -316,11 +316,6 @@ extern void iowrite64be(u64 val, void __iomem *addr);*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -extern int devmem_is_allowed (unsigned long pfn);#endif
arch/powerpc/include/asm/io.h +0 -5
@@ -662,11 +662,6 @@ static inline void name at \*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -/* * We don't do relaxed operations yet, at least not with this semantic */
arch/s390/include/asm/io.h +0 -5
@@ -20,11 +20,6 @@ void *xlate_dev_mem_ptr(phys_addr_t phys);#define unxlate_dev_mem_ptr unxlate_dev_mem_ptrvoid unxlate_dev_mem_ptr (phys_addr_t phys,void *addr); -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -#define IO_SPACE_LIMIT 0void __iomem *ioremap_prot (phys_addr_t addr,size_t size,unsigned long prot);
arch/sh/include/asm/io.h +0 -5
@@ -283,11 +283,6 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -#define ARCH_HAS_VALID_PHYS_ADDR_RANGE int valid_phys_addr_range (phys_addr_t addr,size_t size);int valid_mmap_phys_addr_range (unsigned long pfn,size_t size);
arch/sparc/include/asm/io_64.h +0 -5
@@ -450,11 +450,6 @@ void sbus_set_sbus64(struct device *, int);*/ #define xlate_dev_mem_ptr (p) __va(p) -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#define xlate_dev_kmem_ptr (p) p -#endif #endif /* !(__SPARC64_IO_H) */
include/asm-generic/io.h +0 -11
@@ -1045,17 +1045,6 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)#endif #endif /* CONFIG_GENERIC_IOMAP */ -/* -* Convert a virtual cached pointer to an uncached pointer -*/ -#ifndef xlate_dev_kmem_ptr -#define xlate_dev_kmem_ptr xlate_dev_kmem_ptr -static inline void *xlate_dev_kmem_ptr (void *addr) -{ -return addr; -} -#endif -#ifndef xlate_dev_mem_ptr#define xlate_dev_mem_ptr xlate_dev_mem_ptrstatic inline void *xlate_dev_mem_ptr (phys_addr_t addr)
Signature · 1 line
2.29.2
cover drivers/char: remove /dev/kmem for good
Let's start a discussion if /dev/kmem is worth keeping around and fixing/maintaining or if we should just remove it now for good.
More details / findings in patch #1. Patch #2 and #3 perform minor cleanups based on removed /dev/kmem support.
Only compile-tested on x86-64 -- good enough for discussing the general topic (RFC).
David Hildenbrand (3):
drivers/char: remove /dev/kmem for good
mm: remove xlate_dev_kmem_ptr()
mm/vmalloc: remove vwrite()
Documentation/admin-guide/devices.txt | 2 +- arch/alpha/include/asm/io.h | 5 - arch/arm/configs/dove_defconfig | 1 - arch/arm/configs/magician_defconfig | 1 - arch/arm/configs/moxart_defconfig | 1 - arch/arm/configs/mps2_defconfig | 1 - arch/arm/configs/mvebu_v5_defconfig | 1 - arch/arm/configs/xcep_defconfig | 1 - arch/arm/include/asm/io.h | 5 - arch/h8300/configs/edosk2674_defconfig | 1 - arch/h8300/configs/h8300h-sim_defconfig | 1 - arch/h8300/configs/h8s-sim_defconfig | 1 - arch/hexagon/configs/comet_defconfig | 1 - arch/hexagon/include/asm/io.h | 1 - arch/ia64/include/asm/io.h | 1 - arch/ia64/include/asm/uaccess.h | 18 -- arch/m68k/configs/amcore_defconfig | 1 - arch/m68k/include/asm/io_mm.h | 5 - arch/mips/include/asm/io.h | 5 - arch/openrisc/configs/or1ksim_defconfig | 1 - arch/parisc/include/asm/io.h | 5 - arch/powerpc/include/asm/io.h | 5 - arch/s390/include/asm/io.h | 5 - arch/sh/configs/edosk7705_defconfig | 1 - arch/sh/configs/se7206_defconfig | 1 - arch/sh/configs/sh2007_defconfig | 1 - arch/sh/configs/sh7724_generic_defconfig | 1 - arch/sh/configs/sh7770_generic_defconfig | 1 - arch/sh/configs/sh7785lcr_32bit_defconfig | 1 - arch/sh/include/asm/io.h | 5 - arch/sparc/configs/sparc64_defconfig | 1 - arch/sparc/include/asm/io_64.h | 5 - arch/xtensa/configs/xip_kc705_defconfig | 1 - drivers/char/Kconfig | 10 - drivers/char/mem.c | 231 ---------------------- include/asm-generic/io.h | 11 -- include/linux/fs.h | 2 +- include/linux/vmalloc.h | 3 +- kernel/configs/android-base.config | 1 - mm/ksm.c | 2 +- mm/vmalloc.c | 113 +---------- 41 files changed, 5 insertions(+), 455 deletions(-)
Signature · 1 line
2.29.2
RFC PATCH 3/3 mm/vmalloc: remove vwrite()
The last user (/dev/kmem) is gone. Let's drop it.
--- include/linux/vmalloc.h | 1 - mm/vmalloc.c | 111 ---------------------------------------- 2 files changed, 112 deletions(-)
include/linux/vmalloc.h +0 -1
@@ -200,7 +200,6 @@ static inline void set_vm_flush_reset_perms(void *addr)/* for /proc/kcore */ extern long vread (char *buf,char *addr,unsigned long count); -extern long vwrite (char *buf,char *addr,unsigned long count);/* * Internals. Dont't use..
mm/vmalloc.c +0 -111
123 lines not on this page · raw message
Signature · 1 line
2.29.2
Quoted 5 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.More details / findings in patch #1. Patch #2 and #3 perform minor cleanups based on removed
/dev/kmemsupport.
As some arch maintainers are only cced on patch #2 (grml), patch #1 is
https://lkml.kernel.org/r/[email protected]
and the description is:
"
Exploring /dev/kmem and /dev/mem in the context of memory hot(un)plug and memory ballooning, I started questioning the existance of /dev/kmem.
Comparing it with the /proc/kcore implementation, it does not seem to be able to deal with things like
a) Pages unmapped from the direct mapping (e.g., to be used by secretmem) -> kern_addr_valid(). virt_addr_valid() is not sufficient.
b) Special cases like gart aperture memory that is not to be touched -> mem_pfn_is_ram()
Unless I am missing something, it's at least broken in some cases and might fault/crash the machine.
Looks like its existance has been questioned before in 2005 and 2010 [1], after ~11 additional years, it might make sense to revive the discussion.
CONFIG_DEVKMEM is only enabled in a single defconfig (on purpose or by mistake?). All distributions I looked at disable it.
1) /dev/kmem was popular for rootkits [2] before it got disabled basically everywhere. Ubuntu documents [3] "There is no modern user of /dev/kmem any more beyond attackers using it to load kernel rootkits.". RHEL documents in a BZ [5] "it served no practical purpose other than to serve as a potential security problem or to enable binary module drivers to access structures/functions they shouldn't be touching"
2) /proc/kcore is a decent interface to have a controlled way to read kernel memory for debugging puposes. (will need some extensions to deal with memory offlining/unplug, memory ballooning, and poisoned pages, though)
3) It might be useful for corner case debugging [1]. KDB/KGDB might be a better fit, especially, to write random memory; harder to shoot yourself into the foot.
4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems to be incompatible with 64bit [1]. For educational purposes, /proc/kcore might be used to monitor value updates -- or older kernels can be used.
5) It's broken on arm64, and therefore, completely disabled there.
Looks like it's essentially unused and has been replaced by better suited interfaces for individual tasks (/proc/kcore, KDB/KGDB). Let's just remove it.
[1] https://lwn.net/Articles/147901/
[2] https://www.linuxjournal.com/article/10505
[3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
[4] https://sourceforge.net/projects/kme/
[5] https://bugzilla.redhat.com/show_bug.cgi?id=154796
"
Signature · 3 lines
Thanks, David / dhildenb
Re: [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr()
In reply to David HildenbrandQuoted 6 lines · David Hildenbrand
Since
/dev/kmemhas been removed, let's remove thexlate_dev_kmem_ptr()leftovers.Signed-off-by David Hildenbrand <[email protected]>arch/m68k/include/asm/io_mm.h | 5 -----
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.
I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
I can confirm that it's certainly not enabled on any of the machines I have, but..
Linus
Quoted 10 lines · Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
I can confirm that it's certainly not enabled on any of the machines I have, but..
Debian has CONFIG_DEVKMEM disabled since 2.6.31.
Quoted 1 line
Linus
Sebastian
Quoted 2 lines · On Fri, 19 Mar 2021 15:34:49 +0100 David Hildenbrand <[email protected]> wrote:
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.
The last time I used /dev/kmem was in 2003. While in Germany, my home firewall (in the US) got rooted. I could ssh into the box but had no way to shut it down because the rootkit took over all those commands (luckily it still allowed me to become root). I finally killed the box with:
# ls -lR / > /dev/kmem
;-)
But today I have other means of killing the box (or at least crippling it). Thus, it's obsolete in my book.
-- Steve
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
FWIW, it's been disabled in Ubuntu for over 10 years now:
https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
Signature · 1 line
James
kernel test robot
build botRe: [PATCH RFC 3/3] mm/vmalloc: remove vwrite()
In reply to David Hildenbrand[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi David,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on m68k/for-next]
[also build test WARNING on sparc/master char-misc/char-misc-testing linus/master v5.12-rc3 next-20210319] [cannot apply to uclinux-h8/h8300-next hnaz-linux-mm/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/David-Hildenbrand/drivers-char-remove-dev-kmem-for-good/20210319-223811 base: https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next config: arm-randconfig-r014-20210318 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project fcc1ce00931751ac02498986feb37744e9ace8de)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install arm cross compiling tool for clang build
# apt-get install binutils-arm-linux-gnueabi
# https://github.com/0day-ci/linux/commit/7c68ea58a063d3f2d811e4b9cc0cee3514bed08f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review David-Hildenbrand/drivers-char-remove-dev-kmem-for-good/20210319-223811 git checkout 7c68ea58a063d3f2d811e4b9cc0cee3514bed08f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> mm/nommu.c:213:6: warning: no previous prototype for function 'vwrite' [-Wmissing-prototypes]
long vwrite(char *buf, char *addr, unsigned long count)
^
mm/nommu.c:213:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
long vwrite(char *buf, char *addr, unsigned long count)
^
static
mm/nommu.c:1658:15: warning: no previous prototype for function 'arch_get_unmapped_area' [-Wmissing-prototypes]
unsigned long arch_get_unmapped_area(struct file *file, unsigned long addr,
^ mm/nommu.c:1658:1: note: declare 'static' if the function is not intended to be used outside of this translation unit unsigned long arch_get_unmapped_area(struct file *file, unsigned long addr,
^
static
2 warnings generated.
vim +/vwrite +213 mm/nommu.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 212
^1da177e4c3f41 Linus Torvalds 2005-04-16 @213 long vwrite(char *buf, char *addr, unsigned long count)
^1da177e4c3f41 Linus Torvalds 2005-04-16 214 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 215 /* Don't allow overflow */
^1da177e4c3f41 Linus Torvalds 2005-04-16 216 if ((unsigned long) addr + count < count)
^1da177e4c3f41 Linus Torvalds 2005-04-16 217 count = -(unsigned long) addr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 218
^1da177e4c3f41 Linus Torvalds 2005-04-16 219 memcpy(addr, buf, count);
ac7149045d9fcc Choi Gi-yong 2014-04-07 220 return count;
^1da177e4c3f41 Linus Torvalds 2005-04-16 221 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 222 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
kernel test robot
build botRe: [PATCH RFC 3/3] mm/vmalloc: remove vwrite()
In reply to David Hildenbrand[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi David,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on m68k/for-next]
[also build test WARNING on sparc/master char-misc/char-misc-testing linus/master v5.12-rc3 next-20210319] [cannot apply to uclinux-h8/h8300-next hnaz-linux-mm/master sparc-next/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/David-Hildenbrand/drivers-char-remove-dev-kmem-for-good/20210319-223811 base: https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git for-next config: h8300-randconfig-r004-20210318 (attached as .config) compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/7c68ea58a063d3f2d811e4b9cc0cee3514bed08f
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review David-Hildenbrand/drivers-char-remove-dev-kmem-for-good/20210319-223811 git checkout 7c68ea58a063d3f2d811e4b9cc0cee3514bed08f
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=h8300
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
In file included from arch/h8300/include/asm/page.h:5,
from arch/h8300/include/asm/thread_info.h:12,
from include/linux/thread_info.h:58,
from include/asm-generic/preempt.h:5,
from ./arch/h8300/include/generated/asm/preempt.h:1,
from include/linux/preempt.h:78,
from include/linux/spinlock.h:51,
from include/linux/mmzone.h:8,
from include/linux/gfp.h:6,
from include/linux/mm.h:10,
from mm/nommu.c:20:
mm/nommu.c: In function 'kobjsize':
include/asm-generic/page.h:89:50: warning: ordered comparison of pointer with null pointer [-Wextra]
89 | #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
| ^~
mm/nommu.c:81:16: note: in expansion of macro 'virt_addr_valid'
81 | if (!objp || !virt_addr_valid(objp))
| ^~~~~~~~~~~~~~~
mm/nommu.c: At top level:
>> mm/nommu.c:213:6: warning: no previous prototype for 'vwrite' [-Wmissing-prototypes] 213 | long vwrite(char *buf, char *addr, unsigned long count)
| ^~~~~~
mm/nommu.c:1658:15: warning: no previous prototype for 'arch_get_unmapped_area' [-Wmissing-prototypes]
1658 | unsigned long arch_get_unmapped_area(struct file *file, unsigned long addr,
| ^~~~~~~~~~~~~~~~~~~~~~
vim +/vwrite +213 mm/nommu.c
^1da177e4c3f41 Linus Torvalds 2005-04-16 212
^1da177e4c3f41 Linus Torvalds 2005-04-16 @213 long vwrite(char *buf, char *addr, unsigned long count)
^1da177e4c3f41 Linus Torvalds 2005-04-16 214 {
^1da177e4c3f41 Linus Torvalds 2005-04-16 215 /* Don't allow overflow */
^1da177e4c3f41 Linus Torvalds 2005-04-16 216 if ((unsigned long) addr + count < count)
^1da177e4c3f41 Linus Torvalds 2005-04-16 217 count = -(unsigned long) addr;
^1da177e4c3f41 Linus Torvalds 2005-04-16 218
^1da177e4c3f41 Linus Torvalds 2005-04-16 219 memcpy(addr, buf, count);
ac7149045d9fcc Choi Gi-yong 2014-04-07 220 return count;
^1da177e4c3f41 Linus Torvalds 2005-04-16 221 }
^1da177e4c3f41 Linus Torvalds 2005-04-16 222 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
Thanks, let's wait if someone speaks up. I'll add any details that come up to patch #1 and resend before the next merge window, properly compile-testing on other archs.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 6 lines · Steven Rostedt
Quoted 2 lines · On Fri, 19 Mar 2021 15:34:49 +0100 David Hildenbrand <[email protected]> wrote:
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.
Quoted 8 lines
The last time I used
/dev/kmemwas in 2003. While in Germany, my home firewall (in the US) got rooted. I could ssh into the box but had no way to shut it down because the rootkit took over all those commands (luckily it still allowed me to become root). I finally killed the box with:# ls -lR / > /dev/kmem;-)
Wonder if "echo c > /proc/sysrq-trigger" already existed and would have worked back then. :)
Signature · 3 lines
Thanks, David / dhildenb
Quoted 7 lines · Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
SLES (starting from 15sp2) and OpenSUSE kernels have it disabled as well.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 105 lines · David Hildenbrand
Exploring
/dev/kmemand/dev/memin the context of memory hot(un)plug and memory ballooning, I started questioning the existance of/dev/kmem.Comparing it with the
/proc/kcoreimplementation, it does not seem to be able to deal with things like
a) Pages unmapped from the direct mapping (e.g., to be used by secretmem) ->kern_addr_valid().virt_addr_valid()is not sufficient.
b) Special cases like gart aperture memory that is not to be touched ->mem_pfn_is_ram()
Unless I am missing something, it's at least broken in some cases and might fault/crash the machine.Looks like its existance has been questioned before in 2005 and 2010 [1], after ~11 additional years, it might make sense to revive the discussion.
CONFIG_DEVKMEMis only enabled in a single defconfig (on purpose or by mistake?). All distributions I looked at disable it.1)
/dev/kmemwas popular for rootkits [2] before it got disabled basically everywhere. Ubuntu documents [3] "There is no modern user of/dev/kmemany more beyond attackers using it to load kernel rootkits.". RHEL documents in a BZ [5] "it served no practical purpose other than to serve as a potential security problem or to enable binary module drivers to access structures/functions they shouldn't be touching"2)
/proc/kcoreis a decent interface to have a controlled way to read kernel memory for debugging puposes. (will need some extensions to deal with memory offlining/unplug, memory ballooning, and poisoned pages, though)3) It might be useful for corner case debugging [1]. KDB/KGDB might be a better fit, especially, to write random memory; harder to shoot yourself into the foot.
4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems to be incompatible with 64bit [1]. For educational purposes,
/proc/kcoremight be used to monitor value updates -- or older kernels can be used.5) It's broken on arm64, and therefore, completely disabled there.
Looks like it's essentially unused and has been replaced by better suited interfaces for individual tasks (
/proc/kcore, KDB/KGDB). Let's just remove it.[1] https://lwn.net/Articles/147901/
[2] https://www.linuxjournal.com/article/10505
[3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
[4] https://sourceforge.net/projects/kme/
[5] https://bugzilla.redhat.com/show_bug.cgi?id=154796Cc Andrew Morton <[email protected]>Cc Hillf Danton <[email protected]>Cc Michal Hocko <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Oleksiy Avramchenko <[email protected]>Cc Steven Rostedt <[email protected]>Cc Minchan Kim <[email protected]>Cc huang ying <[email protected]>Cc Jonathan Corbet <[email protected]>Cc Russell King <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sudeep Holla <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Andrew Lunn <[email protected]>Cc Gregory Clement <[email protected]>Cc Sebastian Hesselbarth <[email protected]>Cc Yoshinori Sato <[email protected]>Cc Brian Cain <[email protected]>Cc Geert Uytterhoeven <[email protected]>Cc Jonas Bonn <[email protected]>Cc Stefan Kristiansson <[email protected]>Cc Stafford Horne <[email protected]>Cc Rich Felker <[email protected]>Cc "David S. Miller" <[email protected]>Cc Chris Zankel <[email protected]>Cc Max Filippov <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Alexander Viro <[email protected]>Cc Rob Herring <[email protected]>Cc "Pavel Machek (CIP)" <[email protected]>Cc Theodore Dubois <[email protected]>Cc "Alexander A. Klimov" <[email protected]>Cc Pavel Machek <[email protected]>Cc Sam Ravnborg <[email protected]>Cc Alexandre Belloni <[email protected]>Cc Andrey Zhizhikin <[email protected]>Cc Randy Dunlap <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Viresh Kumar <[email protected]>Cc "Eric W. Biederman" <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Xiaoming Ni <[email protected]>Cc Robert Richter <[email protected]>Cc William Cohen <[email protected]>Cc Corentin Labbe <[email protected]>Cc Kairui Song <[email protected]>Cc Linus Torvalds <[email protected]>
Quoted 8 lines
Cc Linux API <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH RFC 3/3] mm/vmalloc: remove vwrite()
In reply to David HildenbrandQuoted 11 lines · David Hildenbrand
The last user (
/dev/kmem) is gone. Let's drop it.Cc Andrew Morton <[email protected]>Cc Hillf Danton <[email protected]>Cc Michal Hocko <[email protected]>Cc Matthew Wilcox <[email protected]>Cc Oleksiy Avramchenko <[email protected]>Cc Steven Rostedt <[email protected]>Cc Minchan Kim <[email protected]>Cc huang ying <[email protected]>Signed-off-by David Hildenbrand <[email protected]>
Quoted 148 lines
--- include/linux/vmalloc.h | 1 - mm/vmalloc.c | 111 ---------------------------------------- 2 files changed, 112 deletions(-)include/linux/vmalloc.h +0
-1@@ -200,7 +200,6 @@ static inline void set_vm_flush_reset_perms(void *addr)/* for /proc/kcore */ extern long vread (char *buf,char *addr,unsigned long count); -extern long vwrite (char *buf,char *addr,unsigned long count);/* * Internals. Dont't use.. mm/vmalloc.c +0
-111@@ -2820,43 +2820,6 @@ static int aligned_vread(char *buf, char *addr, unsigned long count)return copied; } -static int aligned_vwrite (char *buf,char *addr,unsigned long count) -{ -struct page *p; -int copied =0 ; - -while (count) { -unsigned long offset, length; - - offset =offset_in_page (addr); - length =PAGE_SIZE - offset; -if (length > count) - length = count; - p =vmalloc_to_page (addr); -/* -* To do safe access to this _mapped_ area, we need -* lock. But adding lock here means that we need to add -* overhead of vmalloc()/vfree() calles for this _debug_ -* interface, rarely used. Instead of that, we'll use -* kmap() and get small overhead in this access function. -*/ -if (p) { -/* -* we can expect USER0 is not used (see vread/vwrite's -* function description) -*/ -void *map =kmap_atomic (p); -memcpy (map + offset, buf, length); -kunmap_atomic (map); - } - addr += length; - buf += length; - copied += length; - count -= length; - } -return copied; -} -/** * vread() - read vmalloc area in a safe way. * @buf: buffer for reading data @@ -2936,80 +2899,6 @@ long vread(char *buf, char *addr, unsigned long count)return buflen; } -/** -* vwrite() - write vmalloc area in a safe way. -* @buf: buffer for source data -* @addr: vm address. -* @count: number of bytes to be read. -* -* This function checks that addr is a valid vmalloc'ed area, and -* copy data from a buffer to the given addr. If specified range of -* [addr...addr+count) includes some valid address, data is copied from -* proper area of @buf. If there are memory holes, no copy to hole. -* IOREMAP area is treated as memory hole and no copy is done. -* -* If [addr...addr+count) doesn't includes any intersects with alive -* vm_struct area, returns 0. @buf should be kernel's buffer. -* -* Note: In usual ops, vwrite() is never necessary because the caller -* should know vmalloc() area is valid and can use memcpy(). -* This is for routines which have to access vmalloc area without -* any information, as /dev/kmem. -* -* Return: number of bytes for which addr and buf should be -* increased (same number as @count) or %0 if [addr...addr+count) -* doesn't include any intersection with valid vmalloc area -*/ -long vwrite (char *buf,char *addr,unsigned long count) -{ -struct vmap_area *va; -struct vm_struct *vm; -char *vaddr; -unsigned long n, buflen; -int copied =0 ; - -/* Don't allow overflow */ -if ((unsigned long ) addr + count < count) - count = -(unsigned long ) addr; - buflen = count; - -spin_lock (&vmap_area_lock); -list_for_each_entry (va, &vmap_area_list, list) { -if (!count) -break ; - -if (!va->vm) -continue ; - - vm = va->vm; - vaddr = (char *) vm->addr; -if (addr >= vaddr +get_vm_area_size (vm)) -continue ; -while (addr < vaddr) { -if (count ==0 ) - goto finished; - buf++; - addr++; - count--; - } - n = vaddr +get_vm_area_size (vm) - addr; -if (n > count) - n = count; -if (!(vm->flags &VM_IOREMAP )) { -aligned_vwrite (buf, addr, n); - copied++; - } - buf += n; - addr += n; - count -= n; - } -finished: -spin_unlock (&vmap_area_lock); -if (!copied) -return 0 ; -return buflen; -} -/** * remap_vmalloc_range_partial - map vmalloc pages to userspace * @vma: vma to cover Signature · 1 line
2.29.2
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 5 lines · On Mon, 22 Mar 2021 11:08:47 +0100 David Hildenbrand <[email protected]> wrote:
Wonder if "echo c >
/proc/sysrq-trigger" already existed and would have worked back then. :)
Looks like sysrq-c was added in 2005:
commit 86b1ae38c0a62 ("kdump: sysrq trigger mechanism for kexec based crashdumps")
Thus the answer is "No, it would not have worked back then".
-- Steve
Greg Kroah-Hartman
maintainerQuoted 8 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.More details / findings in patch #1. Patch #2 and #3 perform minor cleanups based on removed
/dev/kmemsupport.Only compile-tested on x86-64 -- good enough for discussing the general topic (RFC).
I'll gladly take this in my char/misc tree for now, to show up in linux-next to get some testing to see if anyone complains.
Let me know if that will help out.
thanks,
greg k-h
Quoted 7 lines · Greg Kroah-Hartman
Quoted 6 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.More details / findings in patch #1. Patch #2 and #3 perform minor cleanups based on removed
/dev/kmemsupport.
Quoted 7 lines
Quoted 2 lines
Only compile-tested on x86-64 -- good enough for discussing the general topic (RFC).
I'll gladly take this in my char/misc tree for now, to show up in linux-next to get some testing to see if anyone complains.
Let me know if that will help out.
Sure! I'll resend as v1 this week (also removing vwrite() from nommu code in patch #3).
Thanks
Signature · 3 lines
Thanks, David / dhildenb
Quoted 6 lines · Sebastian Andrzej Siewior
Quoted 5 lines · Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.
Quoted 7 lines
Quoted 5 lines
I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
I can confirm that it's certainly not enabled on any of the machines I have, but..
Debian has
CONFIG_DEVKMEMdisabled since 2.6.31.
SLES, too. (but no idea since when exactly)
--mtx
Signature · 8 lines
--- Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren GPG/PGP-Schlüssel zu. --- Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Quoted 10 lines · metux IT consult
Quoted 9 lines · Sebastian Andrzej Siewior
Quoted 8 lines · Linus Torvalds
Quoted 3 lines · David Hildenbrand
Let's start a discussion if
/dev/kmemis worth keeping around and fixing/maintaining or if we should just remove it now for good.I'll happily do this for the next merge window, but would really want distros to confirm that they don't enable it.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I can confirm that it's certainly not enabled on any of the machines I have, but..
Debian has
CONFIG_DEVKMEMdisabled since 2.6.31.SLES, too. (but no idea since when exactly)
15-SP2 IIRC
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 52 lines · David Hildenbrand
Exploring
/dev/kmemand/dev/memin the context of memory hot(un)plug and memory ballooning, I started questioning the existance of/dev/kmem.Comparing it with the
/proc/kcoreimplementation, it does not seem to be able to deal with things like
a) Pages unmapped from the direct mapping (e.g., to be used by secretmem) ->kern_addr_valid().virt_addr_valid()is not sufficient.
b) Special cases like gart aperture memory that is not to be touched ->mem_pfn_is_ram()
Unless I am missing something, it's at least broken in some cases and might fault/crash the machine.Looks like its existance has been questioned before in 2005 and 2010 [1], after ~11 additional years, it might make sense to revive the discussion.
CONFIG_DEVKMEMis only enabled in a single defconfig (on purpose or by mistake?). All distributions I looked at disable it.1)
/dev/kmemwas popular for rootkits [2] before it got disabled basically everywhere. Ubuntu documents [3] "There is no modern user of/dev/kmemany more beyond attackers using it to load kernel rootkits.". RHEL documents in a BZ [5] "it served no practical purpose other than to serve as a potential security problem or to enable binary module drivers to access structures/functions they shouldn't be touching"2)
/proc/kcoreis a decent interface to have a controlled way to read kernel memory for debugging puposes. (will need some extensions to deal with memory offlining/unplug, memory ballooning, and poisoned pages, though)3) It might be useful for corner case debugging [1]. KDB/KGDB might be a better fit, especially, to write random memory; harder to shoot yourself into the foot.
4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems to be incompatible with 64bit [1]. For educational purposes,
/proc/kcoremight be used to monitor value updates -- or older kernels can be used.5) It's broken on arm64, and therefore, completely disabled there.
Looks like it's essentially unused and has been replaced by better suited interfaces for individual tasks (
/proc/kcore, KDB/KGDB). Let's just remove it.[1] https://lwn.net/Articles/147901/
[2] https://www.linuxjournal.com/article/10505
[3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
[4] https://sourceforge.net/projects/kme/
[5] https://bugzilla.redhat.com/show_bug.cgi?id=154796
Quoted 3 lines
Yes please! As James Troup pointed out already, this was turned off in Ubuntu in 2008. I don't remember a single complaint from anyone who wasn't a rootkit author. ;)
Signature · 1 line
Kees Cook