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=-3.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 36805C433DF for ; Wed, 20 May 2020 05:44:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DBB83207C4 for ; Wed, 20 May 2020 05:44:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="hnlUkCfq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBB83207C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7DBDE80062; Wed, 20 May 2020 01:44:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7637C8002C; Wed, 20 May 2020 01:44:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 652A380062; Wed, 20 May 2020 01:44:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 4F0478002C for ; Wed, 20 May 2020 01:44:41 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1471B8248068 for ; Wed, 20 May 2020 05:44:41 +0000 (UTC) X-FDA: 76836007962.03.toys21_45f253fe6140e X-HE-Tag: toys21_45f253fe6140e X-Filterd-Recvd-Size: 5092 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 May 2020 05:44:40 +0000 (UTC) Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 352652075F; Wed, 20 May 2020 05:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589953479; bh=ZSFGZSaSAHQFHwCrw/WChCi7NvAdkE7dPM4CwL7wCgc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hnlUkCfqrT8CtMlGqxFJacI9Br3vxlAhOyNgh5yz7gQ6VZei0HpH913A1355N/HPD vS6j6TR7wPc47peYKA+fjP+hKf4F8n3C2pJ0dSFMIOxd3CUAZ/MdqEUo21XZKqiTdT 55mAM/K6awkz0qC1KHpIZ+0N0cOwhUoem4MOJez0= Date: Wed, 20 May 2020 07:44:36 +0200 From: Greg KH To: Dan Williams Cc: Arnd Bergmann , Ingo Molnar , Kees Cook , Russell King , Andrew Morton , Linux Kernel Mailing List , Linux MM Subject: Re: [PATCH v2] /dev/mem: Revoke mappings when a driver claims the region Message-ID: <20200520054436.GC2180554@kroah.com> References: <158987153989.4000084.17143582803685077783.stgit@dwillia2-desk3.amr.corp.intel.com> <20200519121115.GC332015@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Tue, May 19, 2020 at 11:27:02AM -0700, Dan Williams wrote: > On Tue, May 19, 2020 at 5:11 AM Greg KH wrote: > > > > On Tue, May 19, 2020 at 12:03:06AM -0700, Dan Williams wrote: > > > Close the hole of holding a mapping over kernel driver takeover event of > > > a given address range. > > > > > > Commit 90a545e98126 ("restrict /dev/mem to idle io memory ranges") > > > introduced CONFIG_IO_STRICT_DEVMEM with the goal of protecting the > > > kernel against scenarios where a /dev/mem user tramples memory that a > > > kernel driver owns. However, this protection only prevents *new* read(), > > > write() and mmap() requests. Established mappings prior to the driver > > > calling request_mem_region() are left alone. > > > > > > Especially with persistent memory, and the core kernel metadata that is > > > stored there, there are plentiful scenarios for a /dev/mem user to > > > violate the expectations of the driver and cause amplified damage. > > > > > > Teach request_mem_region() to find and shoot down active /dev/mem > > > mappings that it believes it has successfully claimed for the exclusive > > > use of the driver. Effectively a driver call to request_mem_region() > > > becomes a hole-punch on the /dev/mem device. > > > > > > The typical usage of unmap_mapping_range() is part of > > > truncate_pagecache() to punch a hole in a file, but in this case the > > > implementation is only doing the "first half" of a hole punch. Namely it > > > is just evacuating current established mappings of the "hole", and it > > > relies on the fact that /dev/mem establishes mappings in terms of > > > absolute physical address offsets. Once existing mmap users are > > > invalidated they can attempt to re-establish the mapping, or attempt to > > > continue issuing read(2) / write(2) to the invalidated extent, but they > > > will then be subject to the CONFIG_IO_STRICT_DEVMEM checking that can > > > block those subsequent accesses. > > > > > > Cc: Arnd Bergmann > > > Cc: Ingo Molnar > > > Cc: Kees Cook > > > Cc: Russell King > > > Cc: Andrew Morton > > > Cc: Greg Kroah-Hartman > > > Fixes: 90a545e98126 ("restrict /dev/mem to idle io memory ranges") > > > Signed-off-by: Dan Williams > > > --- > > > Changes since v1 [1]: > > > > > > - updated the changelog to describe the usage of unmap_mapping_range(). > > > No other logic changes: > > > > > > [1]: http://lore.kernel.org/r/158662721802.1893045.12301414116114602646.stgit@dwillia2-desk3.amr.corp.intel.com > > > > > > Greg, Andrew, > > > > > > I have a regression test for this case now. This was found by an > > > intermittent data corruption scenario on pmem from a test tool using > > > /dev/mem. > > > > Ick, why are test tools messing around in /dev/mem :) > > Yeah, I'm all for useful tools, just not at the expense of kernel integrity. > > > Anyway, this seems sane to me, want me to take it through my tree? > > Yes please, seems to belong with the driver core. Ok, will wait for a v3 to handle the issue that was just found in review. thanks, greg k-h