From: nicolas.bouchinet@oss.cyber.gouv.fr
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Olivier Bal-Petre <olivier.bal-petre@oss.cyber.gouv.fr>,
Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
Subject: [PATCH] fs: hidepid: Fixes hidepid non dumpable behavior
Date: Fri, 18 Jul 2025 10:47:48 +0200 [thread overview]
Message-ID: <20250718-hidepid_fix-v1-1-3fd5566980bc@ssi.gouv.fr> (raw)
From: Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
The hidepid mount option documentation defines the following modes:
- "noaccess": user may not access any `/proc/<pid>/ directories but
their own.
- "invisible": all `/proc/<pid>/` will be fully invisible to other users.
- "ptraceable": means that procfs should only contain `/proc/<pid>/`
directories that the caller can ptrace.
We thus expect that with "noaccess" and "invisible" users would be able to
see their own processes in `/proc/<pid>/`.
The implementation of hidepid however control accesses using the
`ptrace_may_access()` function in any cases. Thus, if a process set
itself as non-dumpable using the `prctl(PR_SET_DUMPABLE,
SUID_DUMP_DISABLE)` it becomes invisible to the user.
This patch fixes the `has_pid_permissions()` function in order to make
its behavior to match the documentation.
Note that since `ptrace_may_access()` is not called anymore with
"noaccess" and "invisible", the `security_ptrace_access_check()` will no
longer be called either.
Signed-off-by: Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
---
fs/proc/base.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index c667702dc69b8ca2531e88e12ed7a18533f294dd..fb128cb5f95fe65016fce96c75aee18c762a30f2 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -746,9 +746,12 @@ static bool has_pid_permissions(struct proc_fs_info *fs_info,
struct task_struct *task,
enum proc_hidepid hide_pid_min)
{
+ const struct cred *cred = current_cred(), *tcred;
+ kuid_t caller_uid;
+ kgid_t caller_gid;
/*
- * If 'hidpid' mount option is set force a ptrace check,
- * we indicate that we are using a filesystem syscall
+ * If 'hidepid=ptraceable' mount option is set, force a ptrace check.
+ * We indicate that we are using a filesystem syscall
* by passing PTRACE_MODE_READ_FSCREDS
*/
if (fs_info->hide_pid == HIDEPID_NOT_PTRACEABLE)
@@ -758,7 +761,25 @@ static bool has_pid_permissions(struct proc_fs_info *fs_info,
return true;
if (in_group_p(fs_info->pid_gid))
return true;
- return ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS);
+
+ task_lock(task);
+ rcu_read_lock();
+ caller_uid = cred->fsuid;
+ caller_gid = cred->fsgid;
+ tcred = __task_cred(task);
+ if (uid_eq(caller_uid, tcred->euid) &&
+ uid_eq(caller_uid, tcred->suid) &&
+ uid_eq(caller_uid, tcred->uid) &&
+ gid_eq(caller_gid, tcred->egid) &&
+ gid_eq(caller_gid, tcred->sgid) &&
+ gid_eq(caller_gid, tcred->gid)) {
+ rcu_read_unlock();
+ task_unlock(task);
+ return true;
+ }
+ rcu_read_unlock();
+ task_unlock(task);
+ return false;
}
---
base-commit: 884a80cc9208ce75831b2376f2b0464018d7f2c4
change-id: 20250718-hidepid_fix-d0743d0540e7
Best regards,
--
Nicolas Bouchinet <nicolas.bouchinet@ssi.gouv.fr>
next reply other threads:[~2025-07-18 8:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 8:47 nicolas.bouchinet [this message]
2025-07-18 8:59 ` [PATCH] fs: hidepid: Fixes hidepid non dumpable behavior Nicolas Bouchinet
2025-07-18 9:36 ` Aleksa Sarai
2025-07-18 11:40 ` Aleksa Sarai
2025-07-18 12:17 ` Nicolas Bouchinet
2025-07-18 14:45 ` Jann Horn
2025-07-18 15:47 ` Nicolas Bouchinet
2025-07-18 16:48 ` Jann Horn
2025-07-22 11:30 ` Nicolas Bouchinet
[not found] <20250717-hidepid_fix-v1-1-dd211d6eca6e@ssi.gouv.fr>
2025-07-30 8:22 ` Nicolas Bouchinet
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=20250718-hidepid_fix-v1-1-3fd5566980bc@ssi.gouv.fr \
--to=nicolas.bouchinet@oss.cyber.gouv.fr \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.bouchinet@ssi.gouv.fr \
--cc=olivier.bal-petre@oss.cyber.gouv.fr \
/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;
as well as URLs for NNTP newsgroup(s).