]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
proc: Fix broken error paths for namespace links
authorJann Horn <jannh@google.com>
Mon, 6 Jul 2026 18:22:42 +0000 (20:22 +0200)
committerChristian Brauner <brauner@kernel.org>
Wed, 22 Jul 2026 13:37:24 +0000 (15:37 +0200)
Don't return the return value of down_read_killable() (0) when a ptrace
access check fails, return -EACCES as intended.

Reported-by: Magnus Lindholm <linmag7@gmail.com>
Closes: https://lore.kernel.org/r/20260706170735.2941493-1-linmag7@gmail.com
Fixes: 6650527444da ("proc: protect ptrace_may_access() with exec_update_lock (part 1)")
Cc: stable@vger.kernel.org
Signed-off-by: Jann Horn <jannh@google.com>
Link: https://patch.msgid.link/20260706-procfs-ns-eacces-fix-v1-1-a69ab14c02e6@google.com
Tested-by: Magnus Lindholm <linmag7@gmail.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
fs/proc/namespaces.c

index 2f46f13967445c0a5a41aa911afb6ef7223d7b1f..ea6ec61a0430b95cd77c36ccc0acf90c00925604 100644 (file)
@@ -46,7 +46,7 @@ static const char *proc_ns_get_link(struct dentry *dentry,
        const struct proc_ns_operations *ns_ops = PROC_I(inode)->ns_ops;
        struct task_struct *task;
        struct path ns_path;
-       int error = -EACCES;
+       int error;
 
        if (!dentry)
                return ERR_PTR(-ECHILD);
@@ -59,6 +59,7 @@ static const char *proc_ns_get_link(struct dentry *dentry,
        if (error)
                goto out_put_task;
 
+       error = -EACCES;
        if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS))
                goto out;
 
@@ -90,6 +91,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl
        if (res)
                goto out_put_task;
 
+       res = -EACCES;
        if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) {
                res = ns_get_name(name, sizeof(name), task, ns_ops);
                if (res >= 0)