linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Dan Williams <dan.j.williams@intel.com>
Cc: gregkh@linuxfoundation.org, Arnd Bergmann <arnd@arndb.de>,
	Ingo Molnar <mingo@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Russell King <linux@arm.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v4] /dev/mem: Revoke mappings when a driver claims the region
Date: Wed, 6 Apr 2022 12:45:56 -0700	[thread overview]
Message-ID: <202204061243.FB134CA4B1@keescook> (raw)
In-Reply-To: <202005211950.D56130B81@keescook>

*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 <keescook@chromium.org>
> 
> 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


  reply	other threads:[~2022-04-06 19:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 21:06 Dan Williams
2020-05-22  3:01 ` Kees Cook
2022-04-06 19:45   ` Kees Cook [this message]
2022-04-07 18:47     ` Dan Williams
2022-04-07 23:43       ` Dan Williams
2022-04-08  3:35         ` Kees Cook
2022-04-08  6:51           ` Dan Williams
2022-04-07 23:46       ` Kees Cook
2021-05-27 20:58 ` Bjorn Helgaas
2021-05-27 21:30   ` Dan Williams
2021-05-28  8:58     ` David Hildenbrand
2021-05-28 16:42       ` Dan Williams
2021-05-28 16:51         ` David Hildenbrand
2021-06-03  3:39     ` Bjorn Helgaas
2021-06-03  4:15       ` Dan Williams
2021-06-03 18:11         ` Bjorn Helgaas
2021-06-03 18:28           ` Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202204061243.FB134CA4B1@keescook \
    --to=keescook@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mingo@redhat.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox