Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp256933pxf; Wed, 24 Mar 2021 04:33:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygjBFAqBWC86gwUwGrXud7wQ8FRZ1h2oYXDbgSaR1GYXNPTud7F1+lDzba5jw7VbwHkcuC X-Received: by 2002:aa7:d4d2:: with SMTP id t18mr2945955edr.342.1616585635691; Wed, 24 Mar 2021 04:33:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616585635; cv=none; d=google.com; s=arc-20160816; b=ogl0iapoliu7s/8wftL7YqQMf1AoWTXzegR3DJNlR5+pzPBxViGTofdkQ4W/Em67vb 4Rel9+h0MdLhxmQ9h3uK2vg+KsJGt6vEJz9uOV3lIlmm2xUnIAWeNxND4IFnm/KXq4H1 ApZKQgbJbkoky90tNQKJWRiEVVQRbwLbCQcfVCcJdbthTQ/H01/NMY/4oVB1lSge8RAt 5ndylBR4xfKTi9hClSf93YviuQTNyHuAGlmNMSWQLqDTXkNtCyaOKQENVbQVcWH8lqnX 8+x9MOUWvwjqdYYP0no8Qq+0w9mRlgVRp4f4TIxGK0aK3uu1FEXpM7SpCBWb2d1YrdhV YaeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=QMLqwym9flE8lbkbE50aRSXeGQ8jV5p2RxKLL2xiNLM=; b=dRiP79k6rUjWCDxIIAxfU2zkuEGojNmrglfOUBP7TALmQwCcWSG/JqRAwCOgfhbjix YsN/0DqU2IR7PP/oDzCBlTXmDSvKEDcCd6nLbTI0vVQ7CcX+yM5k9fu21MdU9x0rlkqa bQlbL1J5Rv+/zdsrWfaASs/pkeGbcRDZQOsu7RRugUqiPVZptWvSmMlBs5iwc0MVHhSb 1Ux6CB3gIkRriTX9e21MjKGGTV9RJjTwbt+epI7X5aaGaa922iZqPZF0Ac67NcmRMC+d VQfiMWmYHCU+tQa6XqabpSQUUYI8aYbGjq7x5m88B0kDg9qe6ZhJnTx3fJlwFUZKWQiF XKVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gszfKc7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u27si1569891ejj.726.2021.03.24.04.33.32; Wed, 24 Mar 2021 04:33:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gszfKc7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231372AbhCXKYc (ORCPT + 99 others); Wed, 24 Mar 2021 06:24:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37547 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235713AbhCXKYV (ORCPT ); Wed, 24 Mar 2021 06:24:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616581460; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=QMLqwym9flE8lbkbE50aRSXeGQ8jV5p2RxKLL2xiNLM=; b=gszfKc7KCNEwx9TQ0HM/e+J8hQYXG7x4ApSiPEfUCdRc7c39/bJhe6DEwOn/iq0/cfL7Ck h+6Aq1JAAxowfjUFHsbPPe3mYUoBMVgoByMzBzDrWNgeBtXJ3Ojdmy/EpZTpSbUBl0dmJx bVQUR8AHUpZ9D3dwHYucqewHwjQmGNc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-458-F0cqRh6aPYuHEv4XexPcpA-1; Wed, 24 Mar 2021 06:24:16 -0400 X-MC-Unique: F0cqRh6aPYuHEv4XexPcpA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E1D881746C; Wed, 24 Mar 2021 10:24:13 +0000 (UTC) Received: from t480s.redhat.com (ovpn-115-66.ams2.redhat.com [10.36.115.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EAF910013D7; Wed, 24 Mar 2021 10:23:52 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , "Alexander A. Klimov" , Alexander Viro , Alexandre Belloni , Andrew Lunn , Andrew Morton , Andrey Zhizhikin , Arnd Bergmann , Benjamin Herrenschmidt , Brian Cain , Christian Borntraeger , Christophe Leroy , Chris Zankel , Corentin Labbe , "David S. Miller" , "Eric W. Biederman" , Geert Uytterhoeven , Gerald Schaefer , Greentime Hu , Greg Kroah-Hartman , Gregory Clement , Heiko Carstens , Helge Deller , Hillf Danton , huang ying , Ingo Molnar , Ivan Kokshaysky , "James E.J. Bottomley" , James Troup , Jiaxun Yang , Jonas Bonn , Jonathan Corbet , Kairui Song , Krzysztof Kozlowski , Kuninori Morimoto , Linus Torvalds , Linux API , Liviu Dudau , Lorenzo Pieralisi , Luc Van Oostenryck , Luis Chamberlain , Matthew Wilcox , Matt Turner , Max Filippov , Michael Ellerman , Michal Hocko , Mike Rapoport , Mikulas Patocka , Minchan Kim , Niklas Schnelle , Oleksiy Avramchenko , Palmer Dabbelt , Paul Mackerras , "Pavel Machek (CIP)" , Pavel Machek , "Peter Zijlstra (Intel)" , Pierre Morel , Randy Dunlap , Richard Henderson , Rich Felker , Robert Richter , Rob Herring , Russell King , Sam Ravnborg , Sebastian Andrzej Siewior , Sebastian Hesselbarth , Stafford Horne , Stefan Kristiansson , Steven Rostedt , Sudeep Holla , Theodore Dubois , Thomas Bogendoerfer , Thomas Gleixner , Vasily Gorbik , Viresh Kumar , William Cohen , Xiaoming Ni , Yoshinori Sato Subject: [PATCH v1 0/3] drivers/char: remove /dev/kmem for good Date: Wed, 24 Mar 2021 11:23:48 +0100 Message-Id: <20210324102351.6932-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's remove /dev/kmem, which is unused and obsolete. Description from patch #1: " 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 disable it: in Ubuntu it has been disabled for more than 10 years, in Debian since 2.6.31, in Fedora at least starting with FC3, in RHEL starting with RHEL4, in SUSE starting from 15sp2, and OpenSUSE has it disabled as well. 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" [4] 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 " RFC -> v1: - "drivers/char: remove /dev/kmem for good" -- Add more details to patch description regarding distributions - "mm/vmalloc: remove vwrite()" -- Also remove the nommu variant - Compile-tested on more archs/configs 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/nommu.c | 10 - mm/vmalloc.c | 118 +---------- 42 files changed, 6 insertions(+), 469 deletions(-) base-commit: 0d02ec6b3136c73c09e7859f0d0e4e2c4c07b49b -- 2.29.2