From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Jann Horn <jannh@google.com>, Pedro Falcato <pfalcato@suse.de>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Lance Yang <lance.yang@linux.dev>,
syzbot+c181d3198e98f8aef8b9@syzkaller.appspotmail.com
Subject: Re: [PATCH] drivers/char/mem: mmap readonly MAP_SHARED-/dev/zero correctly
Date: Mon, 28 Sep 2026 16:08:27 +0100 [thread overview]
Message-ID: <arqC3n_o-Xdu3xYO@gremlin> (raw)
In-Reply-To: <f78d2f52-1135-425c-a3e8-460a6e80e19b@kernel.org>
On Mon, Sep 28, 2026 at 01:59:47PM +0200, David Hildenbrand (Arm) wrote:
>
> >
> > It then becomes a question about how to get readonly memory.
> >
> >>
> >> We can
> >>
> >> a) Disallow allocating an anon_vma and fail gracefully. So only a shared
> >> zeropage could ever get mapped there. Might break the s390x
> >> mm_forbids_zeropage(). But given that's only used in hypervisors like QEMU,
> >> unlikely.
> >
> > Something like:
> >
> > /* about to maybe prep anon_vma */
> >
> > if (!vma_cow_mapping(vma) && vma_test(vma, VMA_MAYSHARE_BIT)) {
> > /* don't prep anon give zero page */
> > }
> >
> > ?
>
> Something like that, but really just failing directly from anon-vma preparation
> in a !vma_cow_mapping(vma), maybe using a special error code.
>
> But the less we have to hack around this special case, the better.
>
> >
> > I think though it's surely the only case (I hope!) where you can possibly be
> > both anon (as in missing vm_ops) and !CoW? I hope? :)
> >
> > So it feels better to fix it at the source.
> >
> > OTOH maybe it's worth special-casing so we don't allocate on read.
> >
> > But that brings me to c)...
> >
> >
> >>
> >> b) Do what Lorenzo proposes. This will allocate real memory. Someone decided to
> >> use MAP_SHARED, for unknown reasons, so I'd assume it's unlikely that
> >> something breaks, but you have a point.
> >
> > I would say this patch is the right fix for the moment to fix the assert, and we
> > can chase up with other approaches afterwards.
>
> It will get backported, so we better be careful.
>
> IIUC, the real change is only for /dev/zero users that
>
> fd = open("/dev/zero", O_RDONLY);
> mmap(fd, MAP_SHARED, PROT_READ);
>
> Which is rather something odd to do indeed.
>
> Letting AI do some digging ... it says there are not known users (I don't trust
> it, but I suspect at least there are no prominent users, which makes sense ...).
>
>
> Getting shared memory when requesting MAP_SHARED does sound like the right thing
> to do ...
>
> So let's try this:
>
> Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Thanks!
Yeah let's revisit this one later more broadly.
>
> --
> Cheers,
>
> David
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-09-28 15:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 14:48 [PATCH] drivers/char/mem: mmap readonly MAP_SHARED-/dev/zero correctly Lorenzo Stoakes (ARM)
2026-09-24 15:08 ` Greg Kroah-Hartman
2026-09-24 15:29 ` Lorenzo Stoakes (ARM)
2026-09-24 15:42 ` Greg Kroah-Hartman
2026-09-24 15:37 ` David Hildenbrand (Arm)
2026-09-25 2:58 ` Andrew Morton
2026-09-25 7:29 ` David Hildenbrand (Arm)
2026-09-25 8:38 ` Lorenzo Stoakes (ARM)
2026-09-28 11:59 ` David Hildenbrand (Arm)
2026-09-28 15:08 ` Lorenzo Stoakes (ARM) [this message]
2026-09-29 0:26 ` Andrew Morton
2026-09-29 6:14 ` David Hildenbrand (Arm)
2026-10-07 2:14 ` Lance Yang
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=arqC3n_o-Xdu3xYO@gremlin \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=david@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jannh@google.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=syzbot+c181d3198e98f8aef8b9@syzkaller.appspotmail.com \
--cc=vbabka@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.