CVE-2025-38349 (GCVE-0-2025-38349)
Vulnerability from cvelistv5
Published
2025-07-18 07:53
Modified
2025-08-19 06:05
Severity ?
VLAI Severity ?
EPSS score ?
Summary
In the Linux kernel, the following vulnerability has been resolved:
eventpoll: don't decrement ep refcount while still holding the ep mutex
Jann Horn points out that epoll is decrementing the ep refcount and then
doing a
mutex_unlock(&ep->mtx);
afterwards. That's very wrong, because it can lead to a use-after-free.
That pattern is actually fine for the very last reference, because the
code in question will delay the actual call to "ep_free(ep)" until after
it has unlocked the mutex.
But it's wrong for the much subtler "next to last" case when somebody
*else* may also be dropping their reference and free the ep while we're
still using the mutex.
Note that this is true even if that other user is also using the same ep
mutex: mutexes, unlike spinlocks, can not be used for object ownership,
even if they guarantee mutual exclusion.
A mutex "unlock" operation is not atomic, and as one user is still
accessing the mutex as part of unlocking it, another user can come in
and get the now released mutex and free the data structure while the
first user is still cleaning up.
See our mutex documentation in Documentation/locking/mutex-design.rst,
in particular the section [1] about semantics:
"mutex_unlock() may access the mutex structure even after it has
internally released the lock already - so it's not safe for
another context to acquire the mutex and assume that the
mutex_unlock() context is not using the structure anymore"
So if we drop our ep ref before the mutex unlock, but we weren't the
last one, we may then unlock the mutex, another user comes in, drops
_their_ reference and releases the 'ep' as it now has no users - all
while the mutex_unlock() is still accessing it.
Fix this by simply moving the ep refcount dropping to outside the mutex:
the refcount itself is atomic, and doesn't need mutex protection (that's
the whole _point_ of refcounts: unlike mutexes, they are inherently
about object lifetimes).
References
Impacted products
{ "containers": { "cna": { "affected": [ { "defaultStatus": "unaffected", "product": "Linux", "programFiles": [ "fs/eventpoll.c" ], "repo": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git", "vendor": "Linux", "versions": [ { "lessThan": "521e9ff0b67c66a17d6f9593dfccafaa984aae4c", "status": "affected", "version": "58c9b016e12855286370dfb704c08498edbc857a", "versionType": "git" }, { "lessThan": "6dee745bd0aec9d399df674256e7b1ecdb615444", "status": "affected", "version": "58c9b016e12855286370dfb704c08498edbc857a", "versionType": "git" }, { "lessThan": "605c18698ecfa99165f36b7f59d3ed503e169814", "status": "affected", "version": "58c9b016e12855286370dfb704c08498edbc857a", "versionType": "git" }, { "lessThan": "8c2e52ebbe885c7eeaabd3b7ddcdc1246fc400d2", "status": "affected", "version": "58c9b016e12855286370dfb704c08498edbc857a", "versionType": "git" } ] }, { "defaultStatus": "affected", "product": "Linux", "programFiles": [ "fs/eventpoll.c" ], "repo": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git", "vendor": "Linux", "versions": [ { "status": "affected", "version": "6.4" }, { "lessThan": "6.4", "status": "unaffected", "version": "0", "versionType": "semver" }, { "lessThanOrEqual": "6.6.*", "status": "unaffected", "version": "6.6.99", "versionType": "semver" }, { "lessThanOrEqual": "6.12.*", "status": "unaffected", "version": "6.12.39", "versionType": "semver" }, { "lessThanOrEqual": "6.15.*", "status": "unaffected", "version": "6.15.7", "versionType": "semver" }, { "lessThanOrEqual": "*", "status": "unaffected", "version": "6.16", "versionType": "original_commit_for_fix" } ] } ], "cpeApplicability": [ { "nodes": [ { "cpeMatch": [ { "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*", "versionEndExcluding": "6.6.99", "versionStartIncluding": "6.4", "vulnerable": true }, { "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*", "versionEndExcluding": "6.12.39", "versionStartIncluding": "6.4", "vulnerable": true }, { "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*", "versionEndExcluding": "6.15.7", "versionStartIncluding": "6.4", "vulnerable": true }, { "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*", "versionEndExcluding": "6.16", "versionStartIncluding": "6.4", "vulnerable": true } ], "negate": false, "operator": "OR" } ] } ], "descriptions": [ { "lang": "en", "value": "In the Linux kernel, the following vulnerability has been resolved:\n\neventpoll: don\u0027t decrement ep refcount while still holding the ep mutex\n\nJann Horn points out that epoll is decrementing the ep refcount and then\ndoing a\n\n mutex_unlock(\u0026ep-\u003emtx);\n\nafterwards. That\u0027s very wrong, because it can lead to a use-after-free.\n\nThat pattern is actually fine for the very last reference, because the\ncode in question will delay the actual call to \"ep_free(ep)\" until after\nit has unlocked the mutex.\n\nBut it\u0027s wrong for the much subtler \"next to last\" case when somebody\n*else* may also be dropping their reference and free the ep while we\u0027re\nstill using the mutex.\n\nNote that this is true even if that other user is also using the same ep\nmutex: mutexes, unlike spinlocks, can not be used for object ownership,\neven if they guarantee mutual exclusion.\n\nA mutex \"unlock\" operation is not atomic, and as one user is still\naccessing the mutex as part of unlocking it, another user can come in\nand get the now released mutex and free the data structure while the\nfirst user is still cleaning up.\n\nSee our mutex documentation in Documentation/locking/mutex-design.rst,\nin particular the section [1] about semantics:\n\n\t\"mutex_unlock() may access the mutex structure even after it has\n\t internally released the lock already - so it\u0027s not safe for\n\t another context to acquire the mutex and assume that the\n\t mutex_unlock() context is not using the structure anymore\"\n\nSo if we drop our ep ref before the mutex unlock, but we weren\u0027t the\nlast one, we may then unlock the mutex, another user comes in, drops\n_their_ reference and releases the \u0027ep\u0027 as it now has no users - all\nwhile the mutex_unlock() is still accessing it.\n\nFix this by simply moving the ep refcount dropping to outside the mutex:\nthe refcount itself is atomic, and doesn\u0027t need mutex protection (that\u0027s\nthe whole _point_ of refcounts: unlike mutexes, they are inherently\nabout object lifetimes)." } ], "providerMetadata": { "dateUpdated": "2025-08-19T06:05:12.677Z", "orgId": "416baaa9-dc9f-4396-8d5f-8c081fb06d67", "shortName": "Linux" }, "references": [ { "url": "https://git.kernel.org/stable/c/521e9ff0b67c66a17d6f9593dfccafaa984aae4c" }, { "url": "https://git.kernel.org/stable/c/6dee745bd0aec9d399df674256e7b1ecdb615444" }, { "url": "https://git.kernel.org/stable/c/605c18698ecfa99165f36b7f59d3ed503e169814" }, { "url": "https://git.kernel.org/stable/c/8c2e52ebbe885c7eeaabd3b7ddcdc1246fc400d2" }, { "url": "https://project-zero.issues.chromium.org/issues/430541637" } ], "title": "eventpoll: don\u0027t decrement ep refcount while still holding the ep mutex", "x_generator": { "engine": "bippy-1.2.0" } } }, "cveMetadata": { "assignerOrgId": "416baaa9-dc9f-4396-8d5f-8c081fb06d67", "assignerShortName": "Linux", "cveId": "CVE-2025-38349", "datePublished": "2025-07-18T07:53:16.434Z", "dateReserved": "2025-04-16T04:51:24.006Z", "dateUpdated": "2025-08-19T06:05:12.677Z", "state": "PUBLISHED" }, "dataType": "CVE_RECORD", "dataVersion": "5.1", "vulnerability-lookup:meta": { "nvd": "{\"cve\":{\"id\":\"CVE-2025-38349\",\"sourceIdentifier\":\"416baaa9-dc9f-4396-8d5f-8c081fb06d67\",\"published\":\"2025-07-18T08:15:27.543\",\"lastModified\":\"2025-08-19T06:15:32.513\",\"vulnStatus\":\"Awaiting Analysis\",\"cveTags\":[],\"descriptions\":[{\"lang\":\"en\",\"value\":\"In the Linux kernel, the following vulnerability has been resolved:\\n\\neventpoll: don\u0027t decrement ep refcount while still holding the ep mutex\\n\\nJann Horn points out that epoll is decrementing the ep refcount and then\\ndoing a\\n\\n mutex_unlock(\u0026ep-\u003emtx);\\n\\nafterwards. That\u0027s very wrong, because it can lead to a use-after-free.\\n\\nThat pattern is actually fine for the very last reference, because the\\ncode in question will delay the actual call to \\\"ep_free(ep)\\\" until after\\nit has unlocked the mutex.\\n\\nBut it\u0027s wrong for the much subtler \\\"next to last\\\" case when somebody\\n*else* may also be dropping their reference and free the ep while we\u0027re\\nstill using the mutex.\\n\\nNote that this is true even if that other user is also using the same ep\\nmutex: mutexes, unlike spinlocks, can not be used for object ownership,\\neven if they guarantee mutual exclusion.\\n\\nA mutex \\\"unlock\\\" operation is not atomic, and as one user is still\\naccessing the mutex as part of unlocking it, another user can come in\\nand get the now released mutex and free the data structure while the\\nfirst user is still cleaning up.\\n\\nSee our mutex documentation in Documentation/locking/mutex-design.rst,\\nin particular the section [1] about semantics:\\n\\n\\t\\\"mutex_unlock() may access the mutex structure even after it has\\n\\t internally released the lock already - so it\u0027s not safe for\\n\\t another context to acquire the mutex and assume that the\\n\\t mutex_unlock() context is not using the structure anymore\\\"\\n\\nSo if we drop our ep ref before the mutex unlock, but we weren\u0027t the\\nlast one, we may then unlock the mutex, another user comes in, drops\\n_their_ reference and releases the \u0027ep\u0027 as it now has no users - all\\nwhile the mutex_unlock() is still accessing it.\\n\\nFix this by simply moving the ep refcount dropping to outside the mutex:\\nthe refcount itself is atomic, and doesn\u0027t need mutex protection (that\u0027s\\nthe whole _point_ of refcounts: unlike mutexes, they are inherently\\nabout object lifetimes).\"},{\"lang\":\"es\",\"value\":\"En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: eventpoll: no decrementar el recuento de referencias de ep mientras se mantiene el mutex de ep. Jann Horn se\u00f1ala que epoll decrementa el recuento de referencias de ep y luego ejecuta un mutex_unlock(\u0026amp;ep-\u0026gt;mtx);. Esto es totalmente err\u00f3neo, ya que puede provocar un use-after-free. Este patr\u00f3n funciona correctamente para la \u00faltima referencia, ya que el c\u00f3digo en cuesti\u00f3n retrasar\u00e1 la llamada a \\\"ep_free(ep)\\\" hasta despu\u00e9s de desbloquear el mutex. Sin embargo, es incorrecto para el caso mucho m\u00e1s sutil del pen\u00faltimo, cuando alguien *m\u00e1s* tambi\u00e9n podr\u00eda eliminar su referencia y liberar el ep mientras a\u00fan usamos el mutex. Cabe destacar que esto es cierto incluso si ese otro usuario tambi\u00e9n usa el mismo mutex de ep: los mutex, a diferencia de los spinlocks, no se pueden usar para la propiedad de objetos, incluso si garantizan la exclusi\u00f3n mutua. Una operaci\u00f3n de desbloqueo de mutex no es at\u00f3mica, y como un usuario sigue accediendo al mutex durante el proceso de desbloqueo, otro usuario puede acceder y obtener el mutex liberado, liberando as\u00ed la estructura de datos mientras el primer usuario realiza la limpieza. Consulte nuestra documentaci\u00f3n sobre mutex en Documentation/locking/mutex-design.rst, en particular la secci\u00f3n [1] sobre sem\u00e1ntica: \u00abmutex_unlock() puede acceder a la estructura del mutex incluso despu\u00e9s de haber liberado el bloqueo internamente; por lo tanto, no es seguro que otro contexto adquiera el mutex y asuma que el contexto mutex_unlock() ya no utiliza la estructura\u00bb. Por lo tanto, si eliminamos nuestra referencia ep antes del desbloqueo del mutex, pero no fuimos los \u00faltimos, podr\u00edamos desbloquear el mutex; otro usuario entra, elimina su referencia y libera el \u0027ep\u0027, ya que ya no tiene usuarios, todo mientras mutex_unlock() sigue accediendo a \u00e9l. Arregle esto simplemente moviendo el refcount ep que cae fuera del mutex: el refcount en s\u00ed es at\u00f3mico y no necesita protecci\u00f3n de mutex (ese es el _objetivo_ de los refcounts: a diferencia de los mutex, son inherentemente acerca de la duraci\u00f3n de los objetos).\"}],\"metrics\":{},\"references\":[{\"url\":\"https://git.kernel.org/stable/c/521e9ff0b67c66a17d6f9593dfccafaa984aae4c\",\"source\":\"416baaa9-dc9f-4396-8d5f-8c081fb06d67\"},{\"url\":\"https://git.kernel.org/stable/c/605c18698ecfa99165f36b7f59d3ed503e169814\",\"source\":\"416baaa9-dc9f-4396-8d5f-8c081fb06d67\"},{\"url\":\"https://git.kernel.org/stable/c/6dee745bd0aec9d399df674256e7b1ecdb615444\",\"source\":\"416baaa9-dc9f-4396-8d5f-8c081fb06d67\"},{\"url\":\"https://git.kernel.org/stable/c/8c2e52ebbe885c7eeaabd3b7ddcdc1246fc400d2\",\"source\":\"416baaa9-dc9f-4396-8d5f-8c081fb06d67\"},{\"url\":\"https://project-zero.issues.chromium.org/issues/430541637\",\"source\":\"416baaa9-dc9f-4396-8d5f-8c081fb06d67\"}]}}" } }
Loading…
Loading…
Sightings
Author | Source | Type | Date |
---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or seen somewhere by the user.
- Confirmed: The vulnerability is confirmed from an analyst perspective.
- Exploited: This vulnerability was exploited and seen by the user reporting the sighting.
- Patched: This vulnerability was successfully patched by the user reporting the sighting.
- Not exploited: This vulnerability was not exploited or seen by the user reporting the sighting.
- Not confirmed: The user expresses doubt about the veracity of the vulnerability.
- Not patched: This vulnerability was not successfully patched by the user reporting the sighting.
Loading…
Loading…