From: Christian Brauner <brauner@kernel.org>
To: danieldurning.work@gmail.com
Cc: linux-fsdevel@vger.kernel.org,
linux-security-module@vger.kernel.org, selinux@vger.kernel.org,
viro@zeniv.linux.org.uk, jack@suse.cz, paul@paul-moore.com,
stephen.smalley.work@gmail.com, omosnace@redhat.com,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [RFC PATCH] fs/pidfs: Add permission check to pidfd_info()
Date: Mon, 9 Feb 2026 15:01:20 +0100 [thread overview]
Message-ID: <20260209-spanplatten-zerrt-73851db30f18@brauner> (raw)
In-Reply-To: <20260206180248.12418-1-danieldurning.work@gmail.com>
On Fri, Feb 06, 2026 at 06:02:48PM +0000, danieldurning.work@gmail.com wrote:
> From: Daniel Durning <danieldurning.work@gmail.com>
>
> Added a permission check to pidfd_info(). Originally, process info
> could be retrieved with a pidfd even if proc was mounted with hidepid
> enabled, allowing pidfds to be used to bypass those protections. We
> now call ptrace_may_access() to perform some DAC checking as well
> as call the appropriate LSM hook.
>
> The downside to this approach is that there are now more restrictions
> on accessing this info from a pidfd than when just using proc (without
> hidepid). I am open to suggestions if anyone can think of a better way
> to handle this.
This isn't really workable since this would regress userspace quite a
bit. I think we need a different approach. I've given it some thought
and everything's kinda ugly but this might work.
In struct pid_namespace record whether anyone ever mounted a procfs
with hidepid turned on for this pidns. In pidfd_info() we check whether
hidepid was ever turned on. If it wasn't we're done and can just return
the info. This will be the common case. If hidepid was ever turned on
use kern_path("/proc") to lookup procfs. If not found check
ptrace_may_access() to decide whether to return the info or not. If
/proc is found check it's hidepid settings and make a decision based on
that.
You can probably reorder this to call ptrace_may_access() first and then
do the procfs lookup dance. Thoughts?
> I have also noticed that it is possible to use pidfds to poll on any
> process regardless of whether the process is a child of the caller,
> has a different UID, or has a different security context. Is this
> also worth addressing? If so, what exactly should the DAC checks be?
Oleg and I had discusses this and decided that such polling isn't
sensitive information so by default this should just work and it's
relied upon in Android and in a bunch of other workloads. An LSM can of
course restrict access via security_file_ioctl().
Fwiw, pidfds now support persistent trusted extended attributes so if
the LSM folks wanted we can add security.* extended attribute support
and they can mark pidfds with persistent security labels - persistent as
in for the lifetime of the task.
> Signed-off-by: Daniel Durning <danieldurning.work@gmail.com>
> ---
> fs/pidfs.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index dba703d4ce4a..058a7d798bca 100644
> --- a/fs/pidfs.c
> +++ b/fs/pidfs.c
> @@ -365,6 +365,13 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
> goto copy_out;
> }
>
> + /*
> + * Do a filesystem cred ptrace check to verify access
> + * to the task's info.
> + */
> + if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS))
> + return -EACCES;
> +
> c = get_task_cred(task);
> if (!c)
> return -ESRCH;
> --
> 2.52.0
>
next prev parent reply other threads:[~2026-02-09 14:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 18:02 [RFC PATCH] fs/pidfs: Add permission check to pidfd_info() danieldurning.work
2026-02-09 14:01 ` Christian Brauner [this message]
2026-02-11 19:43 ` Daniel Durning
2026-02-17 12:01 ` Christian Brauner
2026-02-20 20:45 ` Daniel Durning
2026-02-24 11:18 ` Christian Brauner
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=20260209-spanplatten-zerrt-73851db30f18@brauner \
--to=brauner@kernel.org \
--cc=danieldurning.work@gmail.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=omosnace@redhat.com \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
--cc=stephen.smalley.work@gmail.com \
--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