Skip to content

Commit e6b899f

Browse files
committed
nsfs: tighten permission checks for ns iteration ioctls
Even privileged services should not necessarily be able to see other privileged service's namespaces so they can't leak information to each other. Use may_see_all_namespaces() helper that centralizes this policy until the nstree adapts. Link: https://patch.msgid.link/20260226-work-visibility-fixes-v1-1-d2c2853313bd@kernel.org Fixes: a1d220d ("nsfs: iterate through mount namespaces") Reviewed-by: Jeff Layton <jlayton@kernel.org> Cc: stable@kernel.org # v6.12+ Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent a0b4c7a commit e6b899f

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

fs/nsfs.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ static bool nsfs_ioctl_valid(unsigned int cmd)
199199
return false;
200200
}
201201

202+
static bool may_use_nsfs_ioctl(unsigned int cmd)
203+
{
204+
switch (_IOC_NR(cmd)) {
205+
case _IOC_NR(NS_MNT_GET_NEXT):
206+
fallthrough;
207+
case _IOC_NR(NS_MNT_GET_PREV):
208+
return may_see_all_namespaces();
209+
}
210+
return true;
211+
}
212+
202213
static long ns_ioctl(struct file *filp, unsigned int ioctl,
203214
unsigned long arg)
204215
{
@@ -214,6 +225,8 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl,
214225

215226
if (!nsfs_ioctl_valid(ioctl))
216227
return -ENOIOCTLCMD;
228+
if (!may_use_nsfs_ioctl(ioctl))
229+
return -EPERM;
217230

218231
ns = get_proc_ns(file_inode(filp));
219232
switch (ioctl) {

include/linux/ns_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ static __always_inline bool is_ns_init_id(const struct ns_common *ns)
5555

5656
#define ns_common_free(__ns) __ns_common_free(to_ns_common((__ns)))
5757

58+
bool may_see_all_namespaces(void);
59+
5860
static __always_inline __must_check int __ns_ref_active_read(const struct ns_common *ns)
5961
{
6062
return atomic_read(&ns->__ns_ref_active);

kernel/nscommon.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,9 @@ void __ns_ref_active_get(struct ns_common *ns)
309309
return;
310310
}
311311
}
312+
313+
bool may_see_all_namespaces(void)
314+
{
315+
return (task_active_pid_ns(current) == &init_pid_ns) &&
316+
ns_capable_noaudit(init_pid_ns.user_ns, CAP_SYS_ADMIN);
317+
}

0 commit comments

Comments
 (0)