Skip to content

Commit 8a46067

Browse files
committed
pidfs: check for valid pid namespace
When we access a no-current task's pid namespace we need check that the task hasn't been reaped in the meantime and it's pid namespace isn't accessible anymore. The user namespace is fine because it is only released when the last reference to struct task_struct is put and exit_creds() is called. Link: https://lore.kernel.org/r/20240926-klebt-altgedienten-0415ad4d273c@brauner Fixes: 5b08bd4 ("pidfs: allow retrieval of namespace file descriptors") CC: [email protected] # v6.11 Signed-off-by: Christian Brauner <[email protected]>
1 parent 2cf3632 commit 8a46067

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/pidfs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
120120
struct nsproxy *nsp __free(put_nsproxy) = NULL;
121121
struct pid *pid = pidfd_pid(file);
122122
struct ns_common *ns_common = NULL;
123+
struct pid_namespace *pid_ns;
123124

124125
if (arg)
125126
return -EINVAL;
@@ -202,7 +203,9 @@ static long pidfd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
202203
case PIDFD_GET_PID_NAMESPACE:
203204
if (IS_ENABLED(CONFIG_PID_NS)) {
204205
rcu_read_lock();
205-
ns_common = to_ns_common( get_pid_ns(task_active_pid_ns(task)));
206+
pid_ns = task_active_pid_ns(task);
207+
if (pid_ns)
208+
ns_common = to_ns_common(get_pid_ns(pid_ns));
206209
rcu_read_unlock();
207210
}
208211
break;

0 commit comments

Comments
 (0)