Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1931453ybk; Thu, 21 May 2020 20:05:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHN8IgcoFsyK/Qq9veVuyvY8XvAReBZecUGPrtbEut5xD7pWJH4azqp1fR+0TuM6RUTb0x X-Received: by 2002:a17:906:3912:: with SMTP id f18mr6604926eje.539.1590116748948; Thu, 21 May 2020 20:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590116748; cv=none; d=google.com; s=arc-20160816; b=kPRLXa+uB/96VEWfiM7t+xc1PoKDJdAlnQQ+Zpm9/ZJCIvL9pM3//Rl7myewtbQeiX sGtKm0qAiKY2kO+UPiImGeTb4GpATxmkx6lIsWd53y7ahdzWC82frNBalTMLBSe/a7B7 jeJzyfHyFEuZQJvDtKv2GBlm2IPmfQvKCBA5QwL87FdsfVRZgOuEbJF/dehu5VQmAY22 +a4pamVZeR0XF8SehO+2yrNJBBIjQEoD/pRHO3acEoPeurHP7M85VaHcrEcOxBk9TOlM Skiy6v5x6jG5oPCEQf1EUvorURaynXEQk/btyvMom6ZnnyfAS7pnjyFWeEoHhlnw+qNE k2vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=11dG9PEoV3wf+UvltnJpE6YCCFo+AkuBxx0Uh1epyW8=; b=MhCDgcmYu/QNzQwh667zDxLcbMDIeOq74vHGsx1kWhnGQXRNLnqvwFk1wtjWrZMT6j 23HWObM4qHeeIp/zP6xNxPygO1FIxjv4p3SjZh+o+zN2otzEhIWHtO2vppbpUc/fBjKJ YpR4FMXO4h4mX7b3EOm19ncmkuU5sHuMRpcQG+bUHxaynNxY6FbhIBARDjOMcqQUFIGO LP7WeJB4lD6QARh4yHa1rz/4KWCG2mSIjLsVVLBeTPE9+a5mf2XncRnr2zxLWgJuTKVT vQNThbzrokhNkKqGW8kGBvxgNANigXW/fZQnR4aCIExhK8yUsdFwjZhYJ9rWsVU/Hkzc LJTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mFSTO+U1; 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 cx19si4163091edb.89.2020.05.21.20.05.25; Thu, 21 May 2020 20:05:48 -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=mFSTO+U1; 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 S1727812AbgEVDB5 (ORCPT + 99 others); Thu, 21 May 2020 23:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727024AbgEVDB4 (ORCPT ); Thu, 21 May 2020 23:01:56 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE21C061A0E for ; Thu, 21 May 2020 20:01:56 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id n11so4297497pgl.9 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=ennbGz/O3bcChjQQJK4HsB5z4AlWpPMej9KEfgLZzlyfWaN7JV4qVaYwdIIXkQ1NeV ecH8+0nyUby79l0GtKhnB1YFIrcgPrE0KdhmYvdtPq/WA/24akKOK8rVgniR++KiZTbX 7XO3U9KxR8zPZZbw3T3ajdLbZzxVVCp0PiqZLvBQLkF/Fw60y13mQMmX3QWoS3AmHWRv qL6UB79pSnyXPCL2SWghxeAfq3vFu4/tSFuVsio3K1pSavjX6FTFb8jdGmqL5WP2s7lb OgvDAQFlKBUlxoLOnxHVtPotx8jOwdTHLx84jyOz5K3dEHlDZmM9G0UMFLQDb2Otb6Wx +/tA== X-Gm-Message-State: AOAM5307yGdWNt9pFzxco56FngM4zYCN2Qh8HuvfefA1y2uCFXgQXAJr aAUwrn8EvrjxA7slUOWNNgwApQ== 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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