Skip to content

Commit 8d76afe

Browse files
committed
nstree: tighten permission checks for listing
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-3-d2c2853313bd@kernel.org Fixes: 76b6f5d ("nstree: add listns()") Reviewed-by: Jeff Layton <jlayton@kernel.org> Cc: stable@kernel.org # v6.19+ Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent d2324a9 commit 8d76afe

1 file changed

Lines changed: 4 additions & 25 deletions

File tree

kernel/nstree.c

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -515,32 +515,11 @@ static inline bool __must_check ns_requested(const struct klistns *kls,
515515
static inline bool __must_check may_list_ns(const struct klistns *kls,
516516
struct ns_common *ns)
517517
{
518-
if (kls->user_ns) {
519-
if (kls->userns_capable)
520-
return true;
521-
} else {
522-
struct ns_common *owner;
523-
struct user_namespace *user_ns;
524-
525-
owner = ns_owner(ns);
526-
if (owner)
527-
user_ns = to_user_ns(owner);
528-
else
529-
user_ns = &init_user_ns;
530-
if (ns_capable_noaudit(user_ns, CAP_SYS_ADMIN))
531-
return true;
532-
}
533-
534-
if (is_current_namespace(ns))
518+
if (kls->user_ns && kls->userns_capable)
535519
return true;
536-
537-
if (ns->ns_type != CLONE_NEWUSER)
538-
return false;
539-
540-
if (ns_capable_noaudit(to_user_ns(ns), CAP_SYS_ADMIN))
520+
if (is_current_namespace(ns))
541521
return true;
542-
543-
return false;
522+
return may_see_all_namespaces();
544523
}
545524

546525
static inline void ns_put(struct ns_common *ns)
@@ -600,7 +579,7 @@ static ssize_t do_listns_userns(struct klistns *kls)
600579

601580
ret = 0;
602581
head = &to_ns_common(kls->user_ns)->ns_owner_root.ns_list_head;
603-
kls->userns_capable = ns_capable_noaudit(kls->user_ns, CAP_SYS_ADMIN);
582+
kls->userns_capable = may_see_all_namespaces();
604583

605584
rcu_read_lock();
606585

0 commit comments

Comments
 (0)