Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3791212pxf; Mon, 5 Apr 2021 23:40:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo6Wb5pDfRROB0SG4ru6QxiY02bxZ71s41AMcWDiAkaIX9WwjbTojy5cnXwzJjthygB3k0 X-Received: by 2002:a92:c5ae:: with SMTP id r14mr22536757ilt.194.1617691224367; Mon, 05 Apr 2021 23:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617691224; cv=none; d=google.com; s=arc-20160816; b=k/esv6fU8OWPg4IGbQRS6m83Whu0xcYvswgV1WNHIGEs4tQsmg2v7O3zYbZJnjh0+r 11aJ1Cro3b30kmJ+Bw51bjVjbvvOR9adI5QwXqZB5ZVQrn5Xo8HeNswJjeL7tIg7qkaf wLlHgGRYOPf1/kM4J3yjOsFuQv7FG4SAssQlrPhk10yceAQB77aALmFMnd8ppJGDwNmd RZUFX5yqStAEXmJyPUc7o01fkpNjMQUjlfkHGqKOJfFq92bclDc9GhfcprfZyMJ4l+CO LS/NXiUwSTmUT1QS7H8nMwwA9dW1YDE/Ks/NlQnKuA5dUSckP1FFcUihQzpeLp3EOJrW mPjw== 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=ai3CdCbkrXPSlQhahzdlfMoVkl12Ktt9EKKlkNpbqIk=; b=VilRQIZhgLvJqOuM+93+XO82DhXORU3swNpcbT/a+Bp8vYIFKe7oubLqYsdRRVKSG9 GJeRcUCCwBGvnk9IvrjNKtP3E1epKNa9sFck+4ZJQqmld87CjPvaWrcthL6TcAiPkARc MnduKlvUSKdy0kUk1q6C2Ny66njE8cI8toEBiaSWROtju4b66GmY8JtwWmwuX730bNOo y4U0EHNBPDo6AJfkV3a4nww1rPTbHtMfzwx7DwHiiG2OzY2tCZZgciZwFy3X/g1phoMr 1Ime7vRJMuROiXf+nkny9voVHdh/ZQBOV24gwtwI5uqNX+kwg0vRR/bJnIPkgVnjUFTd 1sqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=T5OZIJi1; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t12si18506593iof.82.2021.04.05.23.40.12; Mon, 05 Apr 2021 23:40:24 -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=@chromium.org header.s=google header.b=T5OZIJi1; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237235AbhDERQp (ORCPT + 99 others); Mon, 5 Apr 2021 13:16:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235641AbhDERQo (ORCPT ); Mon, 5 Apr 2021 13:16:44 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16562C061788 for ; Mon, 5 Apr 2021 10:16:38 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id z22-20020a17090a0156b029014d4056663fso1287813pje.0 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=HzjsC/NneDhI4GD9TrMjZMgn4wTkw3TSv+OaISji7ZSZfKm3QDnZEZPs09xTkc4/vZ q3NTk4OiyGwfBgHGwXGZBB9RTky9iXUryMPAVmpYYlaBdSza4jCjZXJAnse5xE1JuebR 5jdVCJhFZnWYipS2ClB9icu1VE6g5ycUCuTvURAnCGoYiahie/tYnuvdy96Hn4ijA/J4 8V8xWXCsZ1gBOadfcYpBEvufpRJNuF+8VdOlLQ4QJzhQBMkExtjCXpQzU9+2YVNAvdNe hjCkg2wTqNpEBjVllIcYSw8e5FExtPXx0HdLZAkOx8Zswo+x8L/E+nAF7mW3tmXTYXHs TLCA== X-Gm-Message-State: AOAM531QJIekcj+OEJ6gG91BMMggDs7u/tvEWtZRALPANbLVgaIFDVsw n/ls+xUPR0zrpiFSaCkQe4pFyA== X-Received: by 2002:a17:902:6546:b029:e9:1e31:3351 with SMTP id d6-20020a1709026546b02900e91e313351mr3882734pln.26.1617642997543; 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 t18sm16339996pfh.57.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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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