{"id":"CVE-2026-31477","aliases":["CVE-2026-31477"],"related":[],"kind":"vulnerability","state":"published","title":"ksmbd: fix memory leaks and NULL deref in smb2_lock()","summary":"In the Linux kernel, the following vulnerability has been resolved:\n\nksmbd: fix memory leaks and NULL deref in smb2_lock()\n\nsmb2_lock() has three error handling issues after list_del() detaches\nsmb_lock from lock_list at no_check_cl:\n\n1) If vfs_lock_file() returns an unexpected error in the non-UNLOCK\n   path, goto out leaks smb_lock and its flock because the out:\n   handler only iterates lock_list and rollback_list, neither of\n   which contains the detached smb_lock.\n\n2) If vfs_lock_file() returns -ENOENT in the UNLOCK path, goto out\n   leaks smb_lock and flock for the same reason.  The error code\n   returned to the dispatcher is also stale.\n\n3) In the rollback path, smb_flock_init() can return NULL on\n   allocation failure.  The result is dereferenced unconditionally,\n   causing a kernel NULL pointer dereference.  Add a NULL check to\n   prevent the crash and clean up the bookkeeping; the VFS lock\n   itself cannot be rolled back without the allocation and will be\n   released at file or connection teardown.\n\nFix cases 1 and 2 by hoisting the locks_free_lock()/kfree() to before\nthe if(!rc) check in the UNLOCK branch so all exit paths share one\nfree site, and by freeing smb_lock and flock before goto out in the\nnon-UNLOCK branch.  Propagate the correct error code in both cases.\nFix case 3 by wrapping the VFS unlock in an if(rlock) guard and adding\na NULL check for locks_free_lock(rlock) in the shared cleanup.\n\nFound via call-graph analysis using sqry.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"In the Linux kernel, the following vulnerability has been resolved:\n\nksmbd: fix memory leaks and NULL deref in smb2_lock()\n\nsmb2_lock() has three error handling issues after list_del() detaches\nsmb_lock from lock_list at no_check_cl:\n\n1) If vfs_lock_file() returns an unexpected error in the non-UNLOCK\n   path, goto out leaks smb_lock and its flock because the out:\n   handler only iterates lock_list and rollback_list, neither of\n   which contains the detached smb_lock.\n\n2) If vfs_lock_file() returns -ENOENT in the UNLOCK path, goto out\n   leaks smb_lock and flock for the same reason.  The error code\n   returned to the dispatcher is also stale.\n\n3) In the rollback path, smb_flock_init() can return NULL on\n   allocation failure.  The result is dereferenced unconditionally,\n   causing a kernel NULL pointer dereference.  Add a NULL check to\n   prevent the crash and clean up the bookkeeping; the VFS lock\n   itself cannot be rolled back without the allocation and will be\n   released at file or connection teardown.\n\nFix cases 1 and 2 by hoisting the locks_free_lock()/kfree() to before\nthe if(!rc) check in the UNLOCK branch so all exit paths share one\nfree site, and by freeing smb_lock and flock before goto out in the\nnon-UNLOCK branch.  Propagate the correct error code in both cases.\nFix case 3 by wrapping the VFS unlock in an if(rlock) guard and adding\na NULL check for locks_free_lock(rlock) in the shared cleanup.\n\nFound via call-graph analysis using sqry.","source":"cvelist"},{"lang":"es","text":"En el kernel de Linux, la siguiente vulnerabilidad ha sido resuelta:\n\nksmbd: corrige fugas de memoria y desreferencia NULL en smb2_lock()\n\nsmb2_lock() tiene tres problemas de gestión de errores después de que list_del() desvincula smb_lock de lock_list en no_check_cl:\n\n1) Si vfs_lock_file() devuelve un error inesperado en la ruta que no es UNLOCK, goto out filtra smb_lock y su flock porque el gestor out: solo itera lock_list y rollback_list, ninguna de las cuales contiene el smb_lock desvinculado.\n\n2) Si vfs_lock_file() devuelve -ENOENT en la ruta UNLOCK, goto out filtra smb_lock y flock por la misma razón. El código de error devuelto al despachador también está obsoleto.\n\n3) En la ruta de reversión, smb_flock_init() puede devolver NULL en caso de fallo de asignación. El resultado es desreferenciado incondicionalmente, causando una desreferencia de puntero NULL del kernel. Añadir una comprobación de NULL para evitar el fallo y limpiar la contabilidad; el bloqueo VFS en sí mismo no puede ser revertido sin la asignación y será liberado al finalizar el archivo o la conexión.\n\nSoluciona los casos 1 y 2 elevando locks_free_lock()/kfree() a antes de la comprobación if(!rc) en la rama UNLOCK para que todas las rutas de salida compartan un único sitio de liberación, y liberando smb_lock y flock antes de goto out en la rama que no es UNLOCK. Propagar el código de error correcto en ambos casos. Soluciona el caso 3 envolviendo el desbloqueo VFS en una guarda if(rlock) y añadiendo una comprobación de NULL para locks_free_lock(rlock) en la limpieza compartida.\n\nEncontrado mediante análisis de grafo de llamadas usando sqry.","source":"nvd"}],"published":"2026-04-22T13:54:05.470Z","modified":"2026-11-11T23:10:00.263Z","severity":{"scorer":"Linux","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"Linux","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-476"],"affected":[{"ranges":[{"type":"git","introduced":"e2f34481b24db2fd634b5edb0a5bd0e4d38cc6e9","fixed":"cdac6f7e7e428dc70e3b5898ac6999a72ed13993","status":"affected"},{"type":"git","introduced":"e2f34481b24db2fd634b5edb0a5bd0e4d38cc6e9","fixed":"c9b95ef6f5039f19e46c3a521a4fe1752d91dfe9","status":"affected"},{"type":"git","introduced":"e2f34481b24db2fd634b5edb0a5bd0e4d38cc6e9","fixed":"91aeaa7256006d79a37298f5a1df23325db91599","status":"affected"},{"type":"git","introduced":"e2f34481b24db2fd634b5edb0a5bd0e4d38cc6e9","fixed":"3cdacd11b41569ce75b3162142240f2355e04900","status":"affected"},{"type":"git","introduced":"e2f34481b24db2fd634b5edb0a5bd0e4d38cc6e9","fixed":"aab42f0795620cf0d3955a520f571f697d0f9a2a","status":"affected"},{"type":"git","introduced":"e2f34481b24db2fd634b5edb0a5bd0e4d38cc6e9","fixed":"309b44ed684496ed3f9c5715d10b899338623512","status":"affected"}],"vendor":"Linux","product":"Linux","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","source":"cvelist"},{"ranges":[{"version":"5.15","status":"affected"},{"type":"semver","introduced":"0","fixed":"5.15","status":"unaffected"},{"type":"semver","introduced":"6.1.168","lastAffected":"6.1.*","status":"unaffected"},{"type":"semver","introduced":"6.6.131","lastAffected":"6.6.*","status":"unaffected"},{"type":"semver","introduced":"6.12.80","lastAffected":"6.12.*","status":"unaffected"},{"type":"semver","introduced":"6.18.21","lastAffected":"6.18.*","status":"unaffected"},{"type":"semver","introduced":"6.19.11","lastAffected":"6.19.*","status":"unaffected"},{"type":"original_commit_for_fix","introduced":"7.0","lastAffected":"*","status":"unaffected"}],"vendor":"Linux","product":"Linux","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","source":"cvelist"},{"ranges":[{"status":"affected","introduced":"5.15.1","fixed":"6.1.168"},{"status":"affected","introduced":"6.2","fixed":"6.6.131"},{"status":"affected","introduced":"6.7","fixed":"6.12.80"},{"status":"affected","introduced":"6.13","fixed":"6.18.21"},{"status":"affected","introduced":"6.19","fixed":"6.19.11"},{"status":"affected","version":"5.15"},{"status":"affected","version":"7.0"},{"status":"affected","version":"7.0"},{"status":"affected","version":"7.0"},{"status":"affected","version":"7.0"},{"status":"affected","version":"7.0"},{"status":"affected","version":"7.0"},{"status":"affected","version":"7.0"}],"vendor":"linux","product":"linux_kernel","cpe":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://git.kernel.org/stable/c/cdac6f7e7e428dc70e3b5898ac6999a72ed13993","tags":["patch"],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/c9b95ef6f5039f19e46c3a521a4fe1752d91dfe9","tags":["patch"],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/91aeaa7256006d79a37298f5a1df23325db91599","tags":["patch"],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/3cdacd11b41569ce75b3162142240f2355e04900","tags":["patch"],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/aab42f0795620cf0d3955a520f571f697d0f9a2a","tags":["patch"],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/309b44ed684496ed3f9c5715d10b899338623512","tags":["patch"],"sources":["cvelist","nvd"]}],"credits":[],"assigner":"Linux","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-31477","url":"https://www.cve.org/CVERecord?id=CVE-2026-31477","licence":"CVE Terms of Use","modified":"2026-08-05T12:22:56.049Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-31477","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-31477","licence":"Public domain","modified":"2026-11-11T23:10:00.263Z"}],"updatedAt":"2026-11-25T22:59:19.282Z","epss":{"score":0.00711,"percentile":0.49318,"date":"2026-11-30T12:00:22.000Z"}}