CVE-2026-138992: nilfs2: fix checkpoint root lifetime on sysfs errors
In the Linux kernel, the following vulnerability has been resolved:
nilfs2: fix checkpoint root lifetime on sysfs errors
nilfsfindorcreateroot() links a new checkpoint root into the checkpoint tree and drops nscptreelock before creating the root's sysfs group. If nilfssysfscreatesnapshotgroup() then fails, the root is freed while it is still reachable from nscptree, so a concurrent nilfslookuproot() can dereference freed memory.
nilfssysfscreatesnapshotgroup() allocates memory and creates sysfs nodes and may sleep, so it cannot run under the nscptreelock spinlock. Reorder the creation path so that the sysfs group is set up before the root is published: initialize the root, create its sysfs group outside the lock, and only then take nscptreelock to link it into the tree. On sysfs failure the root was never visible and is freed directly; in the unlikely case a root with the same checkpoint number is already present, the sysfs group of the new root is removed before it is freed. Concurrent insertions are already serialized by nssnapshotmountmutex, so only the race against nilfslookuproot() needs to be closed.
Because kobjectput() does not guarantee that the embedded kobject's release callback has run by the time it returns (CONFIGDEBUGKOBJECTRELEASE defers it), the container must not be freed until the release completes. Keep that waitforcompletion() of snapshotkobjunregister inside the sysfs helpers, so both the creation error path and nilfssysfsdeletesnapshotgroup() wait for the release before their callers free the root.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
In nilfs_find_or_create_root(), initialize the checkpoint root and create its sysfs group outside ns_cptree_lock before linking the root into the checkpoint tree; ensure the sysfs unregister helpers wait for the kobject release callback to complete before the root is freed.