From: Kees Cook <kees@kernel.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>,
linux-mm@kvack.org, Jann Horn <jannh@google.com>
Subject: Re: [DESIGN] Hardening page allocator against type confusion
Date: Fri, 4 Oct 2024 11:01:26 -0700 [thread overview]
Message-ID: <202410041058.AFA68FF11@keescook> (raw)
In-Reply-To: <Zv7LXxI8Yud3sP-P@casper.infradead.org>
On Thu, Oct 03, 2024 at 05:50:39PM +0100, Matthew Wilcox wrote:
> On Thu, Oct 03, 2024 at 04:27:12PM +0200, Vlastimil Babka wrote:
> > On 9/25/24 21:46, Matthew Wilcox wrote:
> > > Kees and I had a fun discussion at Plumbers.
> > >
> > > We're trying to harden against type confusion, where we think we have
> > > a pointer to one thing, but it turns out to be a pointer to a different
> > > thing. There's various ways this can be harmful, which Kees has laid out
> > > before when adding slab buckets. eg see https://lwn.net/Articles/978976/
> > >
> > > Not all allocations come from slab though. If we free a slab object
> > > and the slab it was in gets freed back to the page allocator, it can
> > > turn into almost anything else _quickly_ as the page allocator fronts
> > > the buddy allocator with a stack of recently-freed pages (called PCP,
> > > not to be confused with percpu memory), so if the attacker can arrange
> > > for a page table allocation to come in soon after a slab free, it is
> > > very likely to be the memory they have access to.
> > >
> > > My proposal is that we resolve this "type confusion" by having separate
> > > PCP lists for different types of pages. We'll need to have this for
> > > memdescs anyway, so this is just shifting some of the work left.
> > >
> > > We'd reduce the exploitability of type confusion by using a per-CPU,
> > > per-type stack of recently used pages. To turn a slab page into a page
> > > table page, the attacker would have to cause a dozen slabs to be freed on
> > > this CPU, pushing this one into the buddy allocator. Then they'd have
> > > to cause the allocating task to empty its stack of page table pages,
> > > causing the attackable slab to be pulled from the buddy. It's still
> > > possible, but it's harder.
> > >
> > > Harder enough? I don't know, hence this email. We can get into the
> > > API design (and then the implementation design) if we have agreement
> > > that this is the right approach to be taking.
> >
> > Not a security expert but I doubt it's harder enough?
> >
> > I thought the robust mitigation here was SLAB_VIRTUAL
>
> Well, this is for allocations that _don't_ come from slab. Like page
> tables and page cache or anoymous memory.
I'd really like to hear Jann's thoughts on this.
My instinct is that if it makes it harder to attack but provides some
better performance or reliability characteristics, it's very worth it.
:)
--
Kees Cook
prev parent reply other threads:[~2024-10-04 18:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 19:46 Matthew Wilcox
2024-10-03 14:27 ` Vlastimil Babka
2024-10-03 16:50 ` Matthew Wilcox
2024-10-04 14:04 ` Vlastimil Babka
2024-10-04 18:01 ` Kees Cook [this message]
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=202410041058.AFA68FF11@keescook \
--to=kees@kernel.org \
--cc=jannh@google.com \
--cc=linux-mm@kvack.org \
--cc=vbabka@suse.cz \
--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