nsproxy: Fix cred leak in the error path of prepare_nsset()

Summary

CVECVE-2026-139215
StatePUBLISHED
AssignerLinux
Source PriorityCVE Program / NVD first with legacy fallback
Published2026-11-30 14:18:41 UTC
Updated2026-11-30 14:18:41 UTC
DescriptionIn the Linux kernel, the following vulnerability has been resolved: nsproxy: Fix cred leak in the error path of prepare_nsset() A task that calls setns() with CLONE_NEWUSER together with CLONE_NEWNS and at least one more namespace flag leaks a struct cred (and the user_namespace, ucounts and group_info references it holds) whenever the call fails at the fs_struct copy. On a kernel with CONFIG_USER_NS the leak is one cred per failed setns(); under memory pressure, or driven by a fault-injecting attacker, it accumulates and pins user namespaces that can then never be freed. prepare_nsset() sets nsset->flags only on the success path: if (flags & CLONE_NEWUSER) nsset->cred = prepare_creds(); ... } else if (flags & CLONE_NEWNS) { nsset->fs = copy_fs_struct(me->fs); if (!nsset->fs) goto out; /* flags still 0 here */ } nsset->flags = flags; return 0; out: put_nsset(nsset); put_nsset() decides what to release from nsset->flags: if (flags & CLONE_NEWUSER) put_cred(nsset_cred(nsset)); On the copy_fs_struct() failure arm prepare_creds() has already allocated the cred, but nsset->flags is still the zero from the caller's "struct nsset nsset = {}", so put_nsset() does not see CLONE_NEWUSER and never drops it. The caller (__do_sys_setns) returns the error without touching nsset, so the cred is lost. Set nsset->flags at the start of prepare_nsset(), before anything can fail, so every error exit through put_nsset() releases what was taken. commit_nsset(), which clears nsset->cred on success, is unaffected. Reproduced on x86_64 under QEMU with failslab aimed at the fs_struct cache and kmemleak enabled: 500 calls of setns(pidfd, CLONE_NEWUSER | CLONE_NEWNS | CLONE_NEWUTS) each fail with -ENOMEM and leave 851 unreferenced cred objects allocated from prepare_creds() via setns() before the fix, and none after (the program is in the notes below). Found by formal verification of kernel/nsproxy.c.

Vendor Declared Affected Products

SourceVendorProductVersionPlatforms
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 85ecdfd12f4a6a2b91479ffe9dd7bd51f21a6f4f git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 43cbb8cdb829ef735824eff286a3ecd8e5c820e4 git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 6097ae45077b4066e478f898653430c719ec8102 git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 4de99588da937b13ed8fbb92369d19eee969700a git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 39b61af703ab5beb810edd5ac1f854e6fe3411ba git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 3ba6455f58f9bd307dc093e177fa302c19ba7da5 git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 09a5a04a2d36c33881e323ddf7d84cf252bf6682 git Not specified
CNA Linux Linux affected 303cc571d107b3641d6487061b748e70ffe15ce4 e08601d3a7b2236f4915497dca353dcf117bab5c git Not specified
CNA Linux Linux affected 5.8 Not specified
CNA Linux Linux unaffected 5.8 semver Not specified
CNA Linux Linux unaffected 5.10.275 5.10.* semver Not specified
CNA Linux Linux unaffected 5.15.226 5.15.* semver Not specified
CNA Linux Linux unaffected 6.1.193 6.1.* semver Not specified
CNA Linux Linux unaffected 6.6.163 6.6.* semver Not specified
CNA Linux Linux unaffected 6.12.119 6.12.* semver Not specified
CNA Linux Linux unaffected 6.18.65 6.18.* semver Not specified
CNA Linux Linux unaffected 7.3.6 7.3.* semver Not specified
CNA Linux Linux unaffected 7.4-rc1 * original_commit_for_fix Not specified

References

ReferenceSourceLinkTags
git.kernel.org/stable/c/39b61af703ab5beb810edd5ac1f854e6fe3411ba 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/09a5a04a2d36c33881e323ddf7d84cf252bf6682 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/85ecdfd12f4a6a2b91479ffe9dd7bd51f21a6f4f 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/4de99588da937b13ed8fbb92369d19eee969700a 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/3ba6455f58f9bd307dc093e177fa302c19ba7da5 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/6097ae45077b4066e478f898653430c719ec8102 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/e08601d3a7b2236f4915497dca353dcf117bab5c 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
git.kernel.org/stable/c/43cbb8cdb829ef735824eff286a3ecd8e5c820e4 416baaa9-dc9f-4396-8d5f-8c081fb06d67 git.kernel.org
CVE Program record CVE.ORG www.cve.org canonical
NVD vulnerability detail NVD nvd.nist.gov canonical, analysis

© CVE.report 2026

Use of this information constitutes acceptance for use in an AS IS condition. There are NO warranties, implied or otherwise, with regard to this information or its use. Any use of this information is at the user's risk. It is the responsibility of user to evaluate the accuracy, completeness or usefulness of any information, opinion, advice or other content. EACH USER WILL BE SOLELY RESPONSIBLE FOR ANY consequences of his or her direct or indirect use of this web site. ALL WARRANTIES OF ANY KIND ARE EXPRESSLY DISCLAIMED. This site will NOT BE LIABLE FOR ANY DIRECT, INDIRECT or any other kind of loss.

CVE, CWE, and OVAL are registred trademarks of The MITRE Corporation and the authoritative source of CVE content is MITRE's CVE web site. This site includes MITRE data granted under the following license.

Free CVE JSON API cve.report/api

CVE.report and Source URL Uptime Status status.cve.report