From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH 1/5] cred: record how far up CAP_SETFCAP reaches
Date: Tue, 06 Oct 2026 15:58:26 +0000 [thread overview]
Message-ID: <20261006155826.E3E451F0089B@smtp.kernel.org> (raw)
In-Reply-To: <20261006-b4-setfcap-userns-v1-1-f47e7ed66072@toxicpanda.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] cred: use-after-put of user_ns in userns_install()
--
commit 4646fadaf7eaab13c361fe3e2861493a87f5e140
Author: Josef Bacik <josef@toxicpanda.com>
cred: record how far up CAP_SETFCAP reaches
This patch introduces cred->setfcap_level to track how far up the user
namespace hierarchy a CAP_SETFCAP capability extends. It sets this value
in set_cred_user_ns() when entering a new user namespace.
> diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
> index 1b23d819d3983..6b45df3a8d826 100644
> --- a/kernel/user_namespace.c
> +++ b/kernel/user_namespace.c
> @@ -44,6 +44,9 @@ static void dec_user_namespaces(struct ucounts *ucounts)
>
> static void set_cred_user_ns(struct cred *cred, struct user_namespace *user_ns)
> {
> + /* The last chance to see what we can do outside of the new namespace. */
> + cred->setfcap_level = cap_setfcap_level(cred, user_ns->parent);
> +
[Severity: Low]
Could this result in a logical use-after-put of cred->user_ns when called
from userns_install()?
Looking at userns_install() in kernel/user_namespace.c, the reference to
cred->user_ns is relinquished right before calling set_cred_user_ns():
userns_install() {
...
put_user_ns(cred->user_ns);
set_cred_user_ns(cred, get_user_ns(user_ns));
...
}
Inside the newly added call to cap_setfcap_level(), the provided cred
object is dereferenced. Specifically, cap_setfcap_level() checks
cap_capable(), which inspects cred->user_ns, and later uses
cred->user_ns->level as a fallback.
While the object is independently kept alive by current->real_cred->user_ns
during the setns system call, does this pattern violate object lifecycle
semantics by relying on a logically dropped pointer?
Should the reference to cred->user_ns be saved to a temporary variable and
put only after set_cred_user_ns returns?
> /* Start with the same capabilities as init but useless for doing
> * anything as the capabilities are bound to the new user namespace.
> */
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261006-b4-setfcap-userns-v1-0-f47e7ed66072@toxicpanda.com?part=1
next prev parent reply other threads:[~2026-10-06 15:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 15:44 [PATCH 0/5] capabilities: close the ways around the CAP_SETFCAP rule for uid 0 Josef Bacik
2026-10-06 15:44 ` [PATCH 1/5] cred: record how far up CAP_SETFCAP reaches Josef Bacik
2026-10-06 15:58 ` sashiko-bot [this message]
2026-10-06 15:44 ` [PATCH 2/5] userns: don't let setns() lend the right to map uid 0 Josef Bacik
2026-10-06 15:54 ` sashiko-bot
2026-10-06 15:44 ` [PATCH 3/5] userns: check the writer too before mapping " Josef Bacik
2026-10-06 15:52 ` sashiko-bot
2026-10-06 15:44 ` [PATCH 4/5] capabilities: limit fscaps to where CAP_SETFCAP reaches Josef Bacik
2026-10-06 15:53 ` sashiko-bot
2026-10-06 15:44 ` [PATCH 5/5] capabilities: don't let ptrace borrow CAP_SETFCAP Josef Bacik
2026-10-06 15:51 ` sashiko-bot
2026-10-08 13:57 ` [PATCH 0/5] capabilities: close the ways around the CAP_SETFCAP rule for uid 0 Serge E. Hallyn
2026-10-08 15:39 ` Josef Bacik
2026-10-08 16:13 ` Serge E. Hallyn
2026-10-09 7:41 ` Christian Brauner
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=20261006155826.E3E451F0089B@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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