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=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 C9CFEC433E0 for ; Tue, 19 May 2020 18:27:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 95EC2207C4 for ; Tue, 19 May 2020 18:27:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=intel-com.20150623.gappssmtp.com header.i=@intel-com.20150623.gappssmtp.com header.b="AXuLfz4Z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95EC2207C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3CFA480020; Tue, 19 May 2020 14:27:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33CB5900002; Tue, 19 May 2020 14:27:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D26380020; Tue, 19 May 2020 14:27:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 01D27900002 for ; Tue, 19 May 2020 14:27:15 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C02DD281F for ; Tue, 19 May 2020 18:27:15 +0000 (UTC) X-FDA: 76834300830.20.roof01_7980b51c01a07 X-HE-Tag: roof01_7980b51c01a07 X-Filterd-Recvd-Size: 5906 Received: from mail-ed1-f66.google.com (mail-ed1-f66.google.com [209.85.208.66]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Tue, 19 May 2020 18:27:14 +0000 (UTC) Received: by mail-ed1-f66.google.com with SMTP id d24so349865eds.11 for ; Tue, 19 May 2020 11:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EE4DNOBMavO7IZ4rNX59iIePh4zF+lvNEi66QnnKnCE=; b=AXuLfz4ZzY37jAmrhDap2PxzbyMy8lDBdhunupa7OTJ4aw9/+o7d4HMJKIP1EIRV0G GI0Yai6wZFyMg61X4/Qc+Wwft+wSUaCbhSFuk8mNd0o1eS/a+lwlO4bq+f8oav+Fux2G Bwvp82AMeEb3p4PmACGeu8iwsBpNROchx23Z8xFrpbBs+pFVjCxJBVRSj99NSI76VMTP fS0Fj5lRs5MVOF7S3ahejgm61hkffvMvqskDc68lfqdfnha6eyFzI8bENQ8fAyYxGWvG wQ+9mvKwU/BpJSM7+5nueLTgKeXn3O7sTqwBsKVXOXcZol1iY3W38x0EUTU47S0p560Q qSfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EE4DNOBMavO7IZ4rNX59iIePh4zF+lvNEi66QnnKnCE=; b=EOUlGmzOlORb01PaxFCE3TDY8IEXJHbKXHdfqUMMeiQjR12+Ja1w61zsyRWv1jRK+t ygM0C7CYXKV7z+CjPrw7GRwRpcHz3J2zqVrRxE6LfDXNLnO1MWCuzGKoT9s6TeB5awFB +UajyvNHjbT8TFZprCPIaKyc79nPHpzreAv7KwUOMLFWxMXhx/yhw1QI068/theAfo1F 4/+0uG663TP9uiT8CK92VX1gt3sJtP0DPx9MpgvHEzIWR4yvi/TjbJMQU57rtCGUkRVe DX22kZZSVt1U4os40EjnmD+JEuSQbX1dAC4IV4HMOvD9s8k/P1uFec+XVGV9V9eASHEU 6+BA== X-Gm-Message-State: AOAM531DkKWdrwmJfEvN4De4CzQgV2FJtNBtTdzVkCeA7c4LZd0IXtmJ y+j8o+P8Kq+JVZcjuiHKt7+bxrJbsmMyVY+gHMsAZ9GNJtY= X-Google-Smtp-Source: ABdhPJxH4swItD3dIgSTnKIJ51ANtghX84k0sbelvVaXdBdX7PXJvEUUsea7iWlT+xv92Mkd6Iz00oKGUp1l8IdYQSg= X-Received: by 2002:a50:c2d9:: with SMTP id u25mr215498edf.123.1589912833400; Tue, 19 May 2020 11:27:13 -0700 (PDT) MIME-Version: 1.0 References: <158987153989.4000084.17143582803685077783.stgit@dwillia2-desk3.amr.corp.intel.com> <20200519121115.GC332015@kroah.com> In-Reply-To: <20200519121115.GC332015@kroah.com> From: Dan Williams Date: Tue, 19 May 2020 11:27:02 -0700 Message-ID: Subject: Re: [PATCH v2] /dev/mem: Revoke mappings when a driver claims the region To: Greg KH Cc: Arnd Bergmann , Ingo Molnar , Kees Cook , Russell King , Andrew Morton , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" 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 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. Thanks!