From: Christian Brauner <brauner@kernel.org>
To: Nickolai Zeldovich <nickolai@csail.mit.edu>
Cc: Christian Brauner <brauner@kernel.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Kara <jack@suse.cz>, Shuah Khan <shuah@kernel.org>,
Jann Horn <jannh@google.com>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>,
Luca Boccassi <luca.boccassi@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] pidfs: do not report fields that do not fit into the caller's struct
Date: Wed, 21 Oct 2026 12:42:51 +0200 [thread overview]
Message-ID: <20261021-trauen-wirft-hegen-847ed3b60f61@brauner> (raw)
In-Reply-To: <20261017020634.792390-1-nickolai@csail.mit.edu>
> The documentation of struct pidfd_info promises that "If the structure
> size is too small to contain a field (requested or not), to avoid
> confusion the mask will not contain a bit for that field", and asks
> userspace to trust the returned mask when deciding which fields hold
> valid data.
>
> pidfd_info() does not keep that promise. It builds kinfo.mask without
> looking at the size encoded in the ioctl command, and
> copy_struct_to_user() then truncates the copy to that size. A caller
> that passes a 64-byte struct (PIDFD_INFO_SIZE_VER0) and requests
> PIDFD_INFO_COREDUMP or PIDFD_INFO_SUPPORTED_MASK gets a mask with
> PIDFD_INFO_COREDUMP, PIDFD_INFO_COREDUMP_SIGNAL, PIDFD_INFO_COREDUMP_CODE
> and PIDFD_INFO_SUPPORTED_MASK set, while the coredump_* and
> supported_mask fields behind the 64 bytes were never written. Trusting
> the mask as documented, userspace then reads whatever its own buffer
> held at those offsets. The same happens for a 72- or 80-byte struct
> and the fields added after it.
>
> Clear the bits of the fields that lie beyond the caller's size before
> the copy, in the one place that knows both the final mask and the size.
> A request for a field that cannot be returned is thereby answered the
> way the header describes: the field is simply absent from the mask.
>
> The added selftest issues PIDFD_GET_INFO with the first published size
> over a full-size, poisoned struct and checks that the mask names none
> of the fields beyond that size and that the poison is intact. It fails
> on an unpatched kernel and passes with this change.
>
> Found by formal verification of fs/pidfs.c against the kernel binary.
>
> Fixes: 1d8db6fd698d ("pidfs, coredump: add PIDFD_INFO_COREDUMP")
> Signed-off-by: Nickolai Zeldovich <nickolai@csail.mit.edu>
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
> ---
> Notes:
> The three size thresholds follow the field layout: coredump_mask and
> coredump_signal end at PIDFD_INFO_SIZE_VER1 (72), coredump_code at
> PIDFD_INFO_SIZE_VER2 (80), supported_mask at PIDFD_INFO_SIZE_VER3 (88).
> Masking the request bits early instead (before the coredump and
> supported_mask blocks run) would save a little work for such callers
> but leaves the bits set in the task->mm fallback path; clearing the
> result once before copy_struct_to_user() covers every way a bit can be
> set. No stable tag: the only callers affected pass a struct size
> smaller than the fields they request, and the consequence is a wrong
> mask bit, not a crash or corruption.
>
> fs/pidfs.c | 8 ++++
> tools/testing/selftests/pidfd/pidfd.h | 16 +++++++
> .../testing/selftests/pidfd/pidfd_info_test.c | 48 +++++++++++++++++++
Semantic changes and selftest changes in separate patches, please.
--
next prev parent reply other threads:[~2026-10-21 10:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-17 2:06 Nickolai Zeldovich
2026-10-21 10:42 ` Christian Brauner [this message]
2026-10-24 4:13 ` [PATCH v2 0/2] " Nickolai Zeldovich
2026-10-24 4:13 ` [PATCH v2 1/2] " Nickolai Zeldovich
2026-10-24 9:06 ` Luca Boccassi
2026-10-24 4:13 ` [PATCH v2 2/2] selftests/pidfd: test that fields beyond the struct size are not reported Nickolai Zeldovich
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=20261021-trauen-wirft-hegen-847ed3b60f61@brauner \
--to=brauner@kernel.org \
--cc=alexander@mihalicyn.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luca.boccassi@gmail.com \
--cc=nickolai@csail.mit.edu \
--cc=shuah@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®