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=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, 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 38A63C433E0 for ; Fri, 22 May 2020 03:01:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E8B6D207FB for ; Fri, 22 May 2020 03:01:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="mFSTO+U1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8B6D207FB 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 8E90A80008; Thu, 21 May 2020 23:01:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8980180007; Thu, 21 May 2020 23:01:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AD6480008; Thu, 21 May 2020 23:01:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 5F80C80007 for ; Thu, 21 May 2020 23:01:57 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1AA5E181AEF21 for ; Fri, 22 May 2020 03:01:57 +0000 (UTC) X-FDA: 76842855474.05.metal43_4b368a069744e X-HE-Tag: metal43_4b368a069744e X-Filterd-Recvd-Size: 4388 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 03:01:56 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id u5so4310404pgn.5 for ; Thu, 21 May 2020 20:01:56 -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=11dG9PEoV3wf+UvltnJpE6YCCFo+AkuBxx0Uh1epyW8=; b=mFSTO+U1AdIXstE4FPu4IrX9krnbPJI1UwEd/NFyHQEkjp0NWzPjPYMF+bJUa/DdQE Y9oenRABP+tyS0RQg/M+SBckFv+C8AM/gT9vwTj5E59CLzW4B0emNS4yz3c5R7gLEJ19 f9snByrZJlD04TkBLOe+sGplhsPTzhM8aMtw0= 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=11dG9PEoV3wf+UvltnJpE6YCCFo+AkuBxx0Uh1epyW8=; b=kqsIW+ud4IOsFod5sdO2kPhMeyUjiSST+ksJ+eHYFnmd0TPZeiMjaFh6p8h0h2Qxhi aE6OPX6f7yviIdU6XPt3Xc7RBi2fVk72ZKmXeokD4gu/qfIxQBlRnomHlTMQAiTFwo1z rVZgfSIO8izPeJv9jeAoGJZo7ey72YiIs1QlNFE5Pbfbhv3wCHlivAKH2vfc5gZP+rIz GQIiS6kz9LJu1WH1mjejpPxfbk3YYwwMk9Bla1S4EGie+2o3WQzUnI+qpIglT4vzcEQi T9R1MXClSomQ1EKIrfTYmgxsh2i9PJ0thz5BxqUyXqRyje0FreIyOUKVU9xfv3u4Va+U sFyA== X-Gm-Message-State: AOAM532ETo6wegJJ9GTK+Yxlb9nyk6Lk1rHLBygnyPg+2iLEU8PuuEl0 AOtBcQKamiBk3mr/OHZu0tmvZA== X-Google-Smtp-Source: ABdhPJx1U5V5Jfl/NgxmZJ7wtt8+x1uXW6sBJMURJZobe+S6nyjAMFyIFihw3HhmWAk18QXkuf6chA== X-Received: by 2002:aa7:9532:: with SMTP id c18mr1800933pfp.255.1590116515654; Thu, 21 May 2020 20:01:55 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id n23sm5151785pjq.18.2020.05.21.20.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 20:01:54 -0700 (PDT) Date: Thu, 21 May 2020 20:01:53 -0700 From: Kees Cook To: Dan Williams Cc: gregkh@linuxfoundation.org, Arnd Bergmann , Ingo Molnar , Matthew Wilcox , Russell King , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v4] /dev/mem: Revoke mappings when a driver claims the region Message-ID: <202005211950.D56130B81@keescook> References: <159009507306.847224.8502634072429766747.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <159009507306.847224.8502634072429766747.stgit@dwillia2-desk3.amr.corp.intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000089, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, May 21, 2020 at 02:06:17PM -0700, Dan Williams wrote: > 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. Nice! Reviewed-by: Kees Cook And a thread hijack... ;) I think this is very close to providing a way to solve another issue I've had with /dev/mem, which is to zero the view of the first 1MB of /dev/mem via mmap. I only fixed the read/write accesses: a4866aa81251 ("mm: Tighten x86 /dev/mem with zeroing reads") I.e. the low 1MB range should be considered allowed, but any reads will see zeros. > + unmap_mapping_range(inode->i_mapping, res->start, resource_size(res), 1); Is unmap_mapping_range() sufficient for this? Would it need to happen once during open_port() or something more special during mmap_mem()? -- Kees Cook