From: Jann Horn <jannh@google.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org,
cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org,
akpm@linux-foundation.org, corbet@lwn.net,
derek.kiernan@amd.com, dragan.cvetic@amd.com, arnd@arndb.de,
gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk,
brauner@kernel.org, jack@suse.cz, tj@kernel.org,
hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev,
shakeel.butt@linux.dev, muchun.song@linux.dev,
Liam.Howlett@oracle.com, vbabka@suse.cz, shuah@kernel.org,
vegard.nossum@oracle.com, vattunuru@marvell.com,
schalla@marvell.com, david@redhat.com, willy@infradead.org,
osalvador@suse.de, usama.anjum@collabora.com, andrii@kernel.org,
ryan.roberts@arm.com, peterx@redhat.com, oleg@redhat.com,
tandersen@netflix.com, rientjes@google.com, gthelen@google.com,
linux-hardening@vger.kernel.org,
Kernel Hardening <kernel-hardening@lists.openwall.com>
Subject: Re: [RFCv1 0/6] Page Detective
Date: Mon, 18 Nov 2024 13:53:46 +0100 [thread overview]
Message-ID: <CAG48ez2vG0tr=H8csGes7HN_5HPQAh4WZU8U1G945K1GKfABPg@mail.gmail.com> (raw)
In-Reply-To: <a0372f7f-9a85-4d3e-ba20-b5911a8189e3@lucifer.local>
On Mon, Nov 18, 2024 at 12:17 PM Lorenzo Stoakes
<lorenzo.stoakes@oracle.com> wrote:
> On Sat, Nov 16, 2024 at 05:59:16PM +0000, Pasha Tatashin wrote:
> > It operates through the Linux debugfs interface, with two files: "virt"
> > and "phys".
> >
> > The "virt" file takes a virtual address and PID and outputs information
> > about the corresponding page.
> >
> > The "phys" file takes a physical address and outputs information about
> > that page.
> >
> > The output is presented via kernel log messages (can be accessed with
> > dmesg), and includes information such as the page's reference count,
> > mapping, flags, and memory cgroup. It also shows whether the page is
> > mapped in the kernel page table, and if so, how many times.
>
> I mean, even though I'm not a huge fan of kernel pointer hashing etc. this
> is obviously leaking as much information as you might want about kernel
> internal state to the point of maybe making the whole kernel pointer
> hashing thing moot.
>
> I know this requires CAP_SYS_ADMIN, but there are things that also require
> that which _still_ obscure kernel pointers.
>
> And you're outputting it all to dmesg.
>
> So yeah, a security person (Jann?) would be better placed to comment on
> this than me, but are we sure we want to do this when not in a
> CONFIG_DEBUG_VM* kernel?
I guess there are two parts to this - what root is allowed to do, and
what information we're fine with exposing to dmesg.
If the lockdown LSM is not set to LOCKDOWN_CONFIDENTIALITY_MAX, the
kernel allows root to read kernel memory through some interfaces - in
particular, BPF allows reading arbitrary kernel memory, and perf
allows reading at least some stuff (like kernel register states). With
lockdown in the most restrictive mode, the kernel tries to prevent
root from reading arbitrary kernel memory, but we don't really change
how much information goes into dmesg. (And I imagine you could
probably still get kernel pointers out of BPF somehow even in the most
restrictive lockdown mode, but that's probably not relevant.)
The main issue with dmesg is that some systems make its contents
available to code that is not running with root privileges; and I
think it is also sometimes stored persistently in unencrypted form
(like in EFI pstore) even when everything else on the system is
encrypted.
So on one hand, we definitely shouldn't print the contents of random
chunks of memory into dmesg without a good reason; on the other hand,
for example we do already print kernel register state on WARN() (which
often includes kernel pointers and could theoretically include more
sensitive data too).
So I think showing page metadata to root when requested is probably
okay as a tradeoff? And dumping that data into dmesg is maybe not
great, but acceptable as long as only root can actually trigger this?
I don't really have a strong opinion on this...
To me, a bigger issue is that dump_page() looks like it might be racy,
which is maybe not terrible in debugging code that only runs when
something has already gone wrong, but bad if it is in code that root
can trigger on demand? __dump_page() copies the given page with
memcpy(), which I don't think guarantees enough atomicity with
concurrent updates of page->mapping or such, so dump_mapping() could
probably run on a bogus pointer. Even without torn pointers, I think
there could be a UAF if the page's mapping is destroyed while we're
going through dump_page(), since the page might not be locked. And in
dump_mapping(), the strncpy_from_kernel_nofault() also doesn't guard
against concurrent renaming of the dentry, which I think again would
probably result in UAF.
So I think dump_page() in its current form is not something we should
expose to a userspace-reachable API.
next prev parent reply other threads:[~2024-11-18 12:54 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-16 17:59 Pasha Tatashin
2024-11-16 17:59 ` [RFCv1 1/6] mm: Make get_vma_name() function public Pasha Tatashin
2024-11-18 10:26 ` Lorenzo Stoakes
2024-11-18 20:40 ` Pasha Tatashin
2024-11-18 20:44 ` Matthew Wilcox
2024-11-18 22:26 ` Pasha Tatashin
2024-11-16 17:59 ` [RFCv1 2/6] pagewalk: Add a page table walker for init_mm page table Pasha Tatashin
2024-11-18 6:49 ` Christoph Hellwig
2024-11-18 10:32 ` Lorenzo Stoakes
2024-11-18 20:42 ` Pasha Tatashin
2024-11-16 17:59 ` [RFCv1 3/6] mm: Add a dump_page variant that accept log level argument Pasha Tatashin
2024-11-16 17:59 ` [RFCv1 4/6] misc/page_detective: Introduce Page Detective Pasha Tatashin
2024-11-16 22:20 ` Jonathan Corbet
2024-11-18 20:43 ` Pasha Tatashin
2024-11-18 11:11 ` Lorenzo Stoakes
2024-11-18 21:55 ` Jann Horn
2024-11-16 17:59 ` [RFCv1 5/6] misc/page_detective: enable loadable module Pasha Tatashin
2024-11-16 17:59 ` [RFCv1 6/6] selftests/page_detective: Introduce self tests for Page Detective Pasha Tatashin
2024-11-17 6:25 ` Muhammad Usama Anjum
2024-11-18 20:27 ` Pasha Tatashin
2024-11-18 11:17 ` [RFCv1 0/6] " Lorenzo Stoakes
2024-11-18 12:53 ` Jann Horn [this message]
2024-11-18 22:24 ` Pasha Tatashin
2024-11-19 0:39 ` Jann Horn
2024-11-19 1:29 ` Pasha Tatashin
2024-11-19 12:52 ` Jann Horn
2024-11-19 15:14 ` Pasha Tatashin
2024-11-19 15:53 ` Jann Horn
2024-11-19 18:51 ` Matthew Wilcox
2024-11-18 19:11 ` Roman Gushchin
2024-11-18 22:08 ` Pasha Tatashin
2024-11-19 1:09 ` Greg KH
2024-11-19 15:08 ` Pasha Tatashin
2024-11-19 18:23 ` Roman Gushchin
2024-11-19 19:30 ` Pasha Tatashin
2024-11-19 19:35 ` Yosry Ahmed
2024-11-19 20:57 ` Roman Gushchin
2024-11-20 16:13 ` Pasha Tatashin
2024-11-20 17:33 ` Yosry Ahmed
2024-11-20 17:46 ` Pasha Tatashin
2024-11-20 15:29 ` Andi Kleen
2024-11-20 16:40 ` Pasha Tatashin
2024-11-20 19:14 ` Andi Kleen
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='CAG48ez2vG0tr=H8csGes7HN_5HPQAh4WZU8U1G945K1GKfABPg@mail.gmail.com' \
--to=jannh@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=derek.kiernan@amd.com \
--cc=dragan.cvetic@amd.com \
--cc=gregkh@linuxfoundation.org \
--cc=gthelen@google.com \
--cc=hannes@cmpxchg.org \
--cc=jack@suse.cz \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=oleg@redhat.com \
--cc=osalvador@suse.de \
--cc=pasha.tatashin@soleen.com \
--cc=peterx@redhat.com \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=schalla@marvell.com \
--cc=shakeel.butt@linux.dev \
--cc=shuah@kernel.org \
--cc=tandersen@netflix.com \
--cc=tj@kernel.org \
--cc=usama.anjum@collabora.com \
--cc=vattunuru@marvell.com \
--cc=vbabka@suse.cz \
--cc=vegard.nossum@oracle.com \
--cc=viro@zeniv.linux.org.uk \
--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