CVE-2026-139215

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

Published Nov 30, 2026 CVSS n/a EPSS n/a KEV · Not listed
Description
In 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.

Analysis

AI-generated

Technical impact

In the Linux kernel, when a task calls setns() with CLONE_NEWUSER together with CLONE_NEWNS and at least one more namespace flag, a struct cred can be leaked whenever the call fails during the fs_struct copy. The bug arises because nsset->flags is only set on the success path, so on error the allocated cred is never released by put_nsset(). The leaked cred objects, along with references to user namespaces, accumulate over time, pinning namespaces that can then never be freed. Under memory pressure or a fault‑injecting attacker, the leak can grow enough to exhaust memory or prevent the reclamation of user namespaces, leading to a denial of service.

Affected Systems

All Linux kernels that include CONFIG_USER_NS and expose the setns() system call for use with CLONE_NEWUSER and at least one additional namespace flag are affected. The vulnerability exists in any kernel version released prior to the commit that sets nsset->flags at the start of prepare_nsset(). Specific downstream vendors are not listed; any distribution using an unpatched Linux kernel may be impacted.

Risk and Exploitability

No CVSS or EPSS score is published for this issue, and it is not listed in the CISA KEV catalog. The attack requires the ability to invoke setns() with the relevant flags; failure can be induced by a fault‑injecting attacker or by natural memory pressure. Because it primarily causes a memory leak and prevents namespace cleanup, the direct impact is denial of service rather than privilege escalation. The likelihood of exploitation in the wild is uncertain but non‑zero, especially in environments where setns() is used extensively or where memory pressure is a concern.

Remediation

No solution or workaround provided in the CVE record.

OpenCVE Recommended Actions

  • Upgrade the Linux kernel to a release that contains the commit setting nsset->flags before any failure paths are taken.
  • If a kernel upgrade cannot be performed immediately, reconfigure the system to disable CONFIG_USER_NS or restrict use of setns() with CLONE_NEWUSER and one or more additional namespace flags.
  • Monitor kernel memory usage and the number of user namespaces; investigate abnormal growth that may indicate leaked cred objects and consider tuning overcommit settings to mitigate potential resource exhaustion.

Generated by OpenCVE AI on November 30, 2026 at 20:11 UTC.

Tracking

Sign in to view the affected projects.

Advisories

No advisories available
History
Type Values Removed Values Added
Weaknesses CWE-401
Type Values Removed Values Added
Description In 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.
Title nsproxy: Fix cred leak in the error path of prepare_nsset()
First Time appeared Linux
Linux linux Kernel
CPEs cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
Vendors & Products Linux
Linux linux Kernel
References
Weaknesses
  • CWE-401

    Missing Release of Memory after Effective Lifetime

Sources

Status
PUBLISHED
Assigner
Linux
Published
Updated
Nov 30, 2026, 1:32 PM
Reserved
Nov 30, 2026, 1:22 PM
Status
Received
Published
Nov 30, 2026, 2:18 PM
Modified
Nov 30, 2026, 2:18 PM