From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4A9EC43470 for ; Mon, 5 Apr 2021 17:16:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2FF1D6127A for ; Mon, 5 Apr 2021 17:16:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FF1D6127A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B352B6B0070; Mon, 5 Apr 2021 13:16:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE4D86B0073; Mon, 5 Apr 2021 13:16:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90F956B0075; Mon, 5 Apr 2021 13:16:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 75AFC6B0070 for ; Mon, 5 Apr 2021 13:16:39 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2AB691803A554 for ; Mon, 5 Apr 2021 17:16:39 +0000 (UTC) X-FDA: 77998967718.18.43164FC Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf29.hostedemail.com (Postfix) with ESMTP id 53430F4 for ; Mon, 5 Apr 2021 17:16:37 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id s11so8581429pfm.1 for ; Mon, 05 Apr 2021 10:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ai3CdCbkrXPSlQhahzdlfMoVkl12Ktt9EKKlkNpbqIk=; b=T5OZIJi1a+S0UmB8ju9dRtp9RWLpyoSfUudALSFJBsooFu63xRQSZft0M3qzy93k0r z7x2JAHldp19Jlo5384VoYUVNQ2yeLvjJ5z5R7QVmttinVeV9VjzoAdj8fejaeiR8lyF 62143nJ12x8hml5vfS8LwEeOZj9TXLo/W5cC4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ai3CdCbkrXPSlQhahzdlfMoVkl12Ktt9EKKlkNpbqIk=; b=BBP7gedzGzm7sdQznzkEw+AF4MjPrLtkoxDnoO5VwFSDSZhg9S1XifaMZ9xtbtMEcS Sumrgg77AOq7yUXIzkyO92aZ10r7um5ol520Zd8kjQp8Pda/KEbQK4uekQpGe4O35iQW 2Hej2ErNGpfBx8RF3g6rDIBYJ93Uxayc2BkwydrTaRjiOPZeZRnHW32nWd19010I+fv7 5nymOKihPq3KyF7Gtpd7ZUMgG4ih653RPz3B4nH+c2/c3xIirXCvvceAcL8w/y+Zv/80 kaPD4y/pbrLypXYI45S1DoInvcDVkr5uq8GMqubjP9ihj7ndrLgQpp9GHv2oqTH9TAGc AhLQ== X-Gm-Message-State: AOAM533rwRVM/tUDye7fVnhKnOTQvVAiJC1pmKT53IMhcLSU71VaVKL5 r6cI5QFCAaLBexNQ7rbZxvaeAQ== X-Google-Smtp-Source: ABdhPJzeC0ByHI7nQCydlnTXLn+PCcFS3ix/VPjfDTJClWjlj4ukWG1IoY9lD9yJRxSqNyL/TIxgvw== X-Received: by 2002:a65:5282:: with SMTP id y2mr18489152pgp.293.1617642997590; Mon, 05 Apr 2021 10:16:37 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h29sm4545893pgb.3.2021.04.05.10.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Apr 2021 10:16:36 -0700 (PDT) Date: Mon, 5 Apr 2021 10:16:35 -0700 From: Kees Cook To: David Hildenbrand Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Hillf Danton , Michal Hocko , 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: <202104051013.F432CAC4@keescook> 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> X-Rspamd-Queue-Id: 53430F4 X-Stat-Signature: ywqpw1me3n5gs8i1gqg7nc673yy5n1iu X-Rspamd-Server: rspam02 Received-SPF: none (chromium.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-pf1-f173.google.com; client-ip=209.85.210.173 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617642997-798055 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Mar 19, 2021 at 03:34:50PM +0100, 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: Linux API > Signed-off-by: David Hildenbrand 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. ;) Acked-by: Kees Cook -- Kees Cook