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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9DD9C433EF for ; Wed, 6 Apr 2022 19:46:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42ED06B0071; Wed, 6 Apr 2022 15:46:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E0676B0073; Wed, 6 Apr 2022 15:46:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27E506B0074; Wed, 6 Apr 2022 15:46:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id 14FF46B0071 for ; Wed, 6 Apr 2022 15:46:10 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id C5DBE18311456 for ; Wed, 6 Apr 2022 19:45:59 +0000 (UTC) X-FDA: 79327484838.23.D4CFD30 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf05.hostedemail.com (Postfix) with ESMTP id 41BB710000D for ; Wed, 6 Apr 2022 19:45:59 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id o20so2860087pla.13 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=iFNsYlqT869Mlq5oyzs64YwC1n+xzZSupJNVAFfewR14R769fYtyLOORDkplWJO6/5 r0Bqtaz6rOXjMjSBPe4jOJDoVD77gdZ9YjueMKyj5H0WB/3J5s690i8pLLuB7nMjofC2 uqWMBc4pjXDHh1SOBZMNS94zMIo3n7YzXB2V0Q+cAo5Yb0isZ2SUPpGG2cfjniWJ2O78 5ftewcsoon+JeRzO+t96wEOyewFapDuMbNrFpj7HaV42GbD1ew8wV3x8L2497FjlCUF+ +m0Fwa+YLt9/EB3LNKthK9aG2SElQgAMDt6lAZjkne96KKPiK+p53CbhGMe+UdDswfsR 64uQ== X-Gm-Message-State: AOAM533zKJgi32hnmh38lO7A+Cbl/RlWfIHptlUV5xX/YaW0oH0lakE5 1bIawP9qkXNjqzcdA3goPpzYug== X-Google-Smtp-Source: ABdhPJyCWXEiXug5j/YhyTe7l4u20Ek1Ou2bigp3Nxso9GCPynFzuly95CtpgeKIIzozmjXBLpkCvA== 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-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bT3Y0W3I; spf=pass (imf05.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.175 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 41BB710000D X-Stat-Signature: 5wcgd6p11554sc5apjpqzy8zz9z35o33 X-HE-Tag: 1649274359-973543 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: *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