lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 15 Oct 2021 10:45:06 -0700
From:   Kees Cook <>
To:     Suren Baghdasaryan <>
Cc:     David Hildenbrand <>,
        Michal Hocko <>, Pavel Machek <>,
        Rasmus Villemoes <>,
        John Hubbard <>,
        Andrew Morton <>,
        Colin Cross <>,
        Sumit Semwal <>,
        Dave Hansen <>,
        Matthew Wilcox <>,
        "Kirill A . Shutemov" <>,
        Vlastimil Babka <>,
        Johannes Weiner <>,
        Jonathan Corbet <>,
        Al Viro <>,
        Randy Dunlap <>,
        Kalesh Singh <>,
        Peter Xu <>,,
        Peter Zijlstra <>,
        Catalin Marinas <>,,
        Chinwen Chang (張錦文) 
        Axel Rasmussen <>,
        Andrea Arcangeli <>,
        Jann Horn <>,,
        Yu Zhao <>, Will Deacon <>,,,
        Hugh Dickins <>,,
        Jason Gunthorpe <>, Roman Gushchin <>,
        Thomas Gleixner <>,,
        Chris Hyser <>,
        Peter Collingbourne <>,
        "Eric W. Biederman" <>,
        Jens Axboe <>,,
        Rolf Eike Beer <>,
        Cyrill Gorcunov <>,
        Muchun Song <>,
        Viresh Kumar <>,
        Thomas Cedeno <>,,, LKML <>,,,
        linux-mm <>,
        kernel-team <>
Subject: Re: [PATCH v10 3/3] mm: add anonymous vma name refcounting

On Fri, Oct 15, 2021 at 09:30:09AM -0700, Suren Baghdasaryan wrote:
> On Fri, Oct 15, 2021 at 1:04 AM David Hildenbrand <> wrote:
> >
> > On 14.10.21 22:16, Suren Baghdasaryan wrote:
> > > [...]
> > > 3. Leaves an fd exposed, even briefly, which may lead to unexpected
> > > flaws (e.g. anything using mmap MAP_SHARED could allow exposures or
> > > overwrites). Even MAP_PRIVATE, if an attacker writes into the file
> > > after ftruncate() and before mmap(), can cause private memory to be
> > > initialized with unexpected data.
> >
> > I don't quite follow. Can you elaborate what exactly the issue here is?
> > We use a temporary fd, yes, but how is that a problem?
> >
> > Any attacker can just write any random memory memory in the address
> > space, so I don't see the issue.
> It feels to me that introducing another handle to the memory region is
> a potential attack vector but I'm not a security expert. Maybe Kees
> can assess this better?

This case is kind of just an extension of "we don't need an fd, we need
a name". There is a lot of resulting baggage suddenly added to using
anonymous VMA (fork overhead to deal with the fds, etc), but for me, this
particular situation above is what really demonstrates the "unexpected
side-effects" of trying to swap an anonymous mmap for a memfd: there is
now an _external handle_ attached to memory that doesn't pass through
any of the existing security boundaries normally associated with process
memory (i.e. ptrace). Here's the example race:

victim process			attacker process (same uid)
memfd_create(name, flags);
	-> /proc/$pid/fd/3
ftruncate(3, size);
				open("/proc/$victim/fd/3", O_RDWR)
					-> 3
				mmap(NULL, size,
				     MAP_SHARED, 3, 0);
					-> addr
				memset(addr, 0xFF, size);

mmap(NULL, size, prot,
     MAP_PRIVATE, 3, 0);
	-> addr

surprise, addr[0] != 0x00

And again, yes, we could program defensively, but it's a surprising
situation with new corner cases that haven't been present for years of
Just Using Anon VMAs. :) I would be worried about other vectors we
haven't imagined yet.

So, I think between both the overhead of files and the expanded attack
surface make memfd unsuited for this use-case.


Kees Cook

Powered by blists - more mailing lists