CVE-2026-31477: ksmbd: fix memory leaks and NULL deref in smb2_lock()
In the Linux kernel, the following vulnerability has been resolved:
ksmbd: fix memory leaks and NULL deref in smb2_lock()
smb2_lock() has three error handling issues after list_del() detaches
smb_lock from lock_list at no_check_cl:
1) If vfs_lock_file() returns an unexpected error in the non-UNLOCK
path, goto out leaks smb_lock and its flock because the out:
handler only iterates lock_list and rollback_list, neither of
which contains the detached smb_lock.
2) If vfs_lock_file() returns -ENOENT in the UNLOCK path, goto out
leaks smb_lock and flock for the same reason. The error code
returned to the dispatcher is also stale.
3) In the rollback path, smb_flock_init() can return NULL on
allocation failure. The result is dereferenced unconditionally,
causing a kernel NULL pointer dereference. Add a NULL check to
prevent the crash and clean up the bookkeeping; the VFS lock
itself cannot be rolled back without the allocation and will be
released at file or connection teardown.
Fix cases 1 and 2 by hoisting the locks_free_lock()/kfree() to before
the if(!rc) check in the UNLOCK branch so all exit paths share one
free site, and by freeing smb_lock and flock before goto out in the
non-UNLOCK branch. Propagate the correct error code in both cases.
Fix case 3 by wrapping the VFS unlock in an if(rlock) guard and adding
a NULL check for locks_free_lock(rlock) in the shared cleanup.
Found via call-graph analysis using sqry.
Security readout for executives and security teams
Plain-English summary
A flaw in Linux’s in-kernel SMB server, ksmbd, can leak kernel memory or trigger a kernel crash while processing SMB file-lock errors. The supplied CVSS assessment indicates remote, unauthenticated impact to availability, with no user interaction required. Confidentiality and integrity impact are not identified.
Executive priority
Prioritize internet-facing or widely reachable ksmbd servers for prompt review and patching. The principal business risk is service or host disruption. Systems without ksmbd enabled have materially lower likely exposure, but configuration and vendor patch status should be verified.
Technical view
In smb2_lock(), error paths can lose references to detached lock objects, causing memory leaks and stale error reporting. A separate rollback path may dereference NULL if smb_flock_init() fails. The upstream changes free detached objects consistently, propagate correct errors, and guard allocation failure during rollback.
Likely exposure
Exposure is most relevant where ksmbd is enabled and reachable over a network. The supplied affected-version data spans several Linux release lines but is not sufficiently clear for exact package-level conclusions. Distribution backports may change status, so kernel build numbers alone are insufficient.
Exploitation context
The CVSS vector rates this as network-accessible, low-complexity, unauthenticated, and availability-only. However, the bundle reports KEV as false and provides no evidence of active exploitation or a public exploit. The faulty behavior occurs in SMB locking error and rollback paths.
Researcher notes
The defect combines two detached-object leaks with a NULL dereference after rollback allocation failure. The fix also corrects stale error propagation. The bundle does not establish whether ordinary remote inputs can reliably force every prerequisite error, so practical exploitability and denial-of-service reliability remain unconfirmed.
Mitigation direction
Apply a vendor kernel update containing the applicable upstream fix.
Check distribution advisories for backported fixes and package-specific status.
Disable ksmbd if it is unnecessary for business operations.
Restrict network access to SMB services to trusted systems.
Validation and detection
Inventory systems with ksmbd loaded, enabled, or configured.
Identify externally or broadly reachable SMB endpoints using ksmbd.
Map installed vendor kernels to their security advisories and backports.
Confirm the applicable upstream fix commit is present after updating.
Review kernel logs for ksmbd crashes or unusual memory pressure.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cve · low confidence lookup
CVE-2026-31477 mapping review
Open the CVE-to-ATT&CK bridge for reviewed, inferred, or future official mappings tied to this CVE.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.
1CVSS vectors
3Timeline events
0ADP providers
7Source links
CVSS vector scores
1 official score
We collect every scored CVSS vector available in the official CNA and ADP containers. When more than one version is present, the table keeps the source vectors side by side instead of collapsing them into the highest score.