Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1423417pxb; Wed, 6 Apr 2022 18:34:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzryE9iYJXBAkVtY3zJoumZC49ygDHozQaN7LTn2a4jU04jUki08lC9IWkNqfmBZvmu3aNZ X-Received: by 2002:a17:907:6d1f:b0:6e8:318d:1df0 with SMTP id sa31-20020a1709076d1f00b006e8318d1df0mr1250389ejc.192.1649295277114; Wed, 06 Apr 2022 18:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649295277; cv=none; d=google.com; s=arc-20160816; b=IPV/71tUT9yXYy6zUtmxvIMYqMpSTbs+8XgEAZdmHS6rKmcfHYfZ0Qv/XySaA3cDKi 5nnOZb7GAKy4rbNSc+yt1i3RtjDCLixgBRsUiNq7JHrPqtDJeB0m0fM3RNEdwnpq/E0Q fHuHSARrG+YYdNUiPeTwiez1451Hccz31WVTSyr0J0YViwMnjB2sE2fUQznCmTXHCrb+ FWweCHbkvU7NJ7UoIqHPT/RDDG5fgQ4c4rf46KRwOfXyj/HUJX07tkvin1MPv5E1xnAx m6+Ziq1siOUcmp3BGQX7d+WqurLQQ2o2RLFoHSJ5JWjJAFfFMXMznGv9lqIHETKuLTPB ezmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QR9VBOF3kjexQACzq2xyx6513mlIANmHO5eMnNtR5po=; b=ct1jTeKYlNz5lDNUqLpW59XwI4jItRZ1xxKsXg7QH9jFsDmTNn37yKagk9ycoxC0xj LOtAkG3KtaO1iGTawWkdfQKVvoYyzjJ7OYCNDmKWCcXXYieIcWDiDDNnHgaLJPXZl0UX TGp1cqgN8R1/CX3RYZtFSQCV4DWPq+AgIV38NHlt5S4zW06P+sPkqimuUyvtiysmZV9d 1X391CinzPuZZrgGDfdtyPONKpV3zw3pDDGIOEKinn0cGNMebHODQcdV/xAjBzs/rMtM Y2b3s74y0Q7KoG9/cVCK6W0qZEFKb97ogOubZfBICxaDeafQcRbnptoe84Oq2ufDwlC6 cVsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bT3Y0W3I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f23-20020a17090684d700b006df76385c1asi8317226ejy.186.2022.04.06.18.34.12; Wed, 06 Apr 2022 18:34:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bT3Y0W3I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S235384AbiDFVIe (ORCPT + 99 others); Wed, 6 Apr 2022 17:08:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235180AbiDFVIS (ORCPT ); Wed, 6 Apr 2022 17:08:18 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92617C31C7 for ; Wed, 6 Apr 2022 12:45:58 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id n18so2888900plg.5 for ; Wed, 06 Apr 2022 12:45:58 -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=QR9VBOF3kjexQACzq2xyx6513mlIANmHO5eMnNtR5po=; b=bT3Y0W3IY0MmXP4LbGQ7myD11Um/f2YwBybIgcW8/e4c9JpleLbA6fMIUTdyWsq/l/ QmvXqnGNGoGzXsZfEBfGRMR13NfFSEfDzAM5Qtkl20Tg7G/K80nI3UWpt95zVYe5+NI0 5ZErY1G03Yw+yaXfTkhXXqCrWnbJcxjyhgpOQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QR9VBOF3kjexQACzq2xyx6513mlIANmHO5eMnNtR5po=; b=Lj64icFwUyRQ8KnW95HXqqDI9lCSNarXoeI6vlCBXRQL9yQ452hsrXOgD1ciBzM0+D 9NIfjjGMdUC/FRR8IVPCW0P7yn1r9I7M3kqD7BKA1t9D/GRvJ53xRlHYstz68PqxeobK lwTb0zjbUzHmWw4eZYqEoa8uiNdtAmRi3Flc/MzLNiVU6leuUnP2HOju/FvRSL0wH66H aj5DGR6Gn1ctTrvYDX8uaof8X8qO/jXb22H18tP+FbQtNkJxcxhFgRq7lZcHpyj2YUv7 oibcMpXVAjd3QKNpc9gw/OktGOx2K2XQGjepWN2CguJfEPzn+P0MVtMC1cnhYB6B2QPY W1uQ== X-Gm-Message-State: AOAM531SmlGeoMfiWSlB8Bo4SfOKQbHLaFrongGrn4Glxxzz6xt2khPf MragNQPemkmII0n/o/FMEfe6kQ== X-Received: by 2002:a17:902:a9c5:b0:156:32bf:b526 with SMTP id b5-20020a170902a9c500b0015632bfb526mr10440281plr.46.1649274358106; Wed, 06 Apr 2022 12:45:58 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id l4-20020a056a0016c400b004f79504ef9csm19854441pfc.3.2022.04.06.12.45.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 12:45:57 -0700 (PDT) Date: Wed, 6 Apr 2022 12:45:56 -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: <202204061243.FB134CA4B1@keescook> References: <159009507306.847224.8502634072429766747.stgit@dwillia2-desk3.amr.corp.intel.com> <202005211950.D56130B81@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202005211950.D56130B81@keescook> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org *thread necromancy* Hi Dan, I'm doing a KSPP bug scrub and am reviewing https://github.com/KSPP/linux/issues/74 again. Do you have a chance to look at this? I'd love a way to make mmap() behave the same way as read() for the first meg of /dev/mem. -Kees On Thu, May 21, 2020 at 08:01:53PM -0700, Kees Cook wrote: > 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 -- Kees Cook