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 A5A61C433E1 for ; Tue, 19 May 2020 12:11:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C2922081A for ; Tue, 19 May 2020 12:11:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="hKGWS3lA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C2922081A 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 06447900003; Tue, 19 May 2020 08:11:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 013C3900002; Tue, 19 May 2020 08:11:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6D21900003; Tue, 19 May 2020 08:11:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id CBDB5900002 for ; Tue, 19 May 2020 08:11:19 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8088A824556B for ; Tue, 19 May 2020 12:11:19 +0000 (UTC) X-FDA: 76833353478.28.wash84_28a07442ac630 X-HE-Tag: wash84_28a07442ac630 X-Filterd-Recvd-Size: 4378 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 May 2020 12:11:19 +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 A78BD2072C; Tue, 19 May 2020 12:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589890278; bh=lDb46p/0XzvV+nIWSNwOG8PA6sEkz0i+9XCjntJ0NAo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hKGWS3lAAwsrm2uxA/yEA91/u81l9RD6W7nThOe/ZFoqNkfekIVw8oqq0z34EoFO4 BNZWIp7vKXQywos1ApLMyhSFb4K95fhJRhmO8FFhLDQ0XGfK1n9VO+g0VU378o8cUn HFr23bVdmzNjDYEgPtEVHU2kHjWIBnzqy1k1Gc0Y= Date: Tue, 19 May 2020 14:11:15 +0200 From: Greg KH To: Dan Williams Cc: Arnd Bergmann , Ingo Molnar , Kees Cook , Russell King , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] /dev/mem: Revoke mappings when a driver claims the region Message-ID: <20200519121115.GC332015@kroah.com> References: <158987153989.4000084.17143582803685077783.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <158987153989.4000084.17143582803685077783.stgit@dwillia2-desk3.amr.corp.intel.com> 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 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 :) Anyway, this seems sane to me, want me to take it through my tree? thanks, greg k-h