Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3441718pxf; Mon, 22 Mar 2021 06:37:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZlqTmsLHaRN8aeonLUnCJc9LHlc4v+lMLhtr0EAKxw9xpWyvx1rkjtLIiOAtC9KD6xuO4 X-Received: by 2002:a50:f311:: with SMTP id p17mr26801453edm.188.1616420236906; Mon, 22 Mar 2021 06:37:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616420236; cv=none; d=google.com; s=arc-20160816; b=QfwKK0ddnQ8RNhjstb9y9TsBZ1I3EyUqpDySX60xtedJPNOIDQE4wS1vNRsk7e8dIL jIrUeoJGBn/OyBxYQc08UZZkNqezjcyHsnP3vcrf1ULEgVPXqjCPXQ+zLM+ve5rJELp1 NMW+UnSL14nHvVoWDc0frYk6XtGmEW1ZomX/WyX62kSZcBElkzVpKSbuWZJqr8SncPcp zRVLEFVJuRPLgsSf+Ux/repDVivPSznxcxQ+N3QKw70Nt0nSYznlI0NufZRldmldP59P yt3IxXyuS80u3zqtWtJJZgYk4S3uuKG5X3q8sW9nf1LjwHcFnoCLldvpWDDgVU/QDoYB saDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bNwpWnU/mOEb8vDk9U6PPMjzkSSiO3GF6Uf0hvYy86c=; b=YorLAfQbHgWFQ6/TYGC9llMF++/fxbxgu3qUv7L08Qa4Jj8tJRpB0DArDqx1BY2XtG xV0LeroIW83yNfYelCV7sLYbtC5GUPaYEHd6QG0qZmFODOAF8eYvmVA3/Q6jFQbhapTv pLbpnLlDAFkN5DeL4omI9jVQxeslbDWhKXnu4y2dT1CG4lZwUrs+WsMHrqA9PSsdCEcX uD6/lM/FA1LC/nU0bIuTls4r0kDf3kGgyeNT9LHSdpPphYyXuZFLy2bh2Oc7C07sOmpe 2ksjuLhvwbEFEq9QsDyGSISlfqCbfaBWL9FjyER4VJPOYZVmON75eFMRuaOq7m3NDw2w xLRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="T/88LUer"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si10707926ejs.150.2021.03.22.06.36.54; Mon, 22 Mar 2021 06:37:16 -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=@suse.com header.s=susede1 header.b="T/88LUer"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbhCVNgE (ORCPT + 99 others); Mon, 22 Mar 2021 09:36:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:52782 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230164AbhCVNfo (ORCPT ); Mon, 22 Mar 2021 09:35:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1616420142; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bNwpWnU/mOEb8vDk9U6PPMjzkSSiO3GF6Uf0hvYy86c=; b=T/88LUerDCEZ5aLb09F83ICr41UqeH2rh4J7zrGpXp20VeYsZHJpi/YuD6UnXQW4pyzMJd jBAgDV46TT0Kz09FM1vI9JNZIIaETu438nFrfjiK/6ELDm8IlG80pWXjuPGHfOvQ9qSqDa nwk9Za/1Mcrl0+PJNnBW15dSnFPW4Rw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2DDD7AC1F; Mon, 22 Mar 2021 13:35:42 +0000 (UTC) Date: Mon, 22 Mar 2021 14:35:41 +0100 From: Michal Hocko To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Hillf Danton , Matthew Wilcox , Oleksiy Avramchenko , Steven Rostedt , Minchan Kim , huang ying , Jonathan Corbet , Russell King , Liviu Dudau , Sudeep Holla , Lorenzo Pieralisi , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Yoshinori Sato , Brian Cain , Geert Uytterhoeven , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Rich Felker , "David S. Miller" , Chris Zankel , Max Filippov , Arnd Bergmann , Greg Kroah-Hartman , Alexander Viro , Rob Herring , "Pavel Machek (CIP)" , Theodore Dubois , "Alexander A. Klimov" , Pavel Machek , Sam Ravnborg , Alexandre Belloni , Andrey Zhizhikin , Randy Dunlap , Krzysztof Kozlowski , Viresh Kumar , "Eric W. Biederman" , Thomas Gleixner , Xiaoming Ni , Robert Richter , William Cohen , Corentin Labbe , Kairui Song , Linus Torvalds , linux-doc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, uclinux-h8-devel@lists.sourceforge.jp, linux-hexagon@vger.kernel.org, linux-m68k@lists.linux-m68k.org, openrisc@lists.librecores.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-fsdevel@vger.kernel.org, Linux API Subject: Re: [PATCH RFC 1/3] drivers/char: remove /dev/kmem for good Message-ID: References: <20210319143452.25948-1-david@redhat.com> <20210319143452.25948-2-david@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210319143452.25948-2-david@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri 19-03-21 15:34:50, David Hildenbrand wrote: > 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 > > Cc: Andrew Morton > Cc: Hillf Danton > Cc: Michal Hocko > Cc: Matthew Wilcox > Cc: Oleksiy Avramchenko > Cc: Steven Rostedt > Cc: Minchan Kim > Cc: huang ying > Cc: Jonathan Corbet > Cc: Russell King > Cc: Liviu Dudau > Cc: Sudeep Holla > Cc: Lorenzo Pieralisi > Cc: Andrew Lunn > Cc: Gregory Clement > Cc: Sebastian Hesselbarth > Cc: Yoshinori Sato > Cc: Brian Cain > Cc: Geert Uytterhoeven > Cc: Jonas Bonn > Cc: Stefan Kristiansson > Cc: Stafford Horne > Cc: Rich Felker > Cc: "David S. Miller" > Cc: Chris Zankel > Cc: Max Filippov > Cc: Arnd Bergmann > Cc: Greg Kroah-Hartman > Cc: Alexander Viro > Cc: Rob Herring > Cc: "Pavel Machek (CIP)" > Cc: Theodore Dubois > Cc: "Alexander A. Klimov" > Cc: Pavel Machek > Cc: Sam Ravnborg > Cc: Alexandre Belloni > Cc: Andrey Zhizhikin > Cc: Randy Dunlap > Cc: Krzysztof Kozlowski > Cc: Viresh Kumar > Cc: "Eric W. Biederman" > Cc: Thomas Gleixner > Cc: Xiaoming Ni > Cc: Robert Richter > Cc: William Cohen > Cc: Corentin Labbe > Cc: Kairui Song > Cc: Linus Torvalds > Cc: linux-doc@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > Cc: linux-arm-kernel@lists.infradead.org > Cc: uclinux-h8-devel@lists.sourceforge.jp > Cc: linux-hexagon@vger.kernel.org > Cc: linux-m68k@lists.linux-m68k.org > Cc: openrisc@lists.librecores.org > Cc: linux-sh@vger.kernel.org > Cc: sparclinux@vger.kernel.org > Cc: linux-xtensa@linux-xtensa.org > Cc: linux-fsdevel@vger.kernel.org > Cc: Linux API > Signed-off-by: David Hildenbrand Acked-by: Michal Hocko -- Michal Hocko SUSE Labs