CVE-2021-47209

In the Linux kernel, the following vulnerability has been resolved: sched/fair: Prevent dead task groups from regaining cfs_rq's Kevin is reporting crashes which point to a use-after-free of a cfs_rq in update_blocked_averages(). Initial debugging revealed that we've live cfs_rq's (on_list=1) in an about to be kfree()'d task group in free_fair_sched_group(). However, it was unclear how that can happen. His kernel config happened to lead to a layout of struct sched_entity that put the 'my_q' member directly into the middle of the object which makes it incidentally overlap with SLUB's freelist pointer. That, in combination with SLAB_FREELIST_HARDENED's freelist pointer mangling, leads to a reliable access violation in form of a #GP which made the UAF fail fast. Michal seems to have run into the same issue[1]. He already correctly diagnosed that commit a7b359fc6a37 ("sched/fair: Correctly insert cfs_rq's to list on unthrottle") is causing the preconditions for the UAF to happen by re-adding cfs_rq's also to task groups that have no more running tasks, i.e. also to dead ones. His analysis, however, misses the real root cause and it cannot be seen from the crash backtrace only, as the real offender is tg_unthrottle_up() getting called via sched_cfs_period_timer() via the timer interrupt at an inconvenient time. When unregister_fair_sched_group() unlinks all cfs_rq's from the dying task group, it doesn't protect itself from getting interrupted. If the timer interrupt triggers while we iterate over all CPUs or after unregister_fair_sched_group() has finished but prior to unlinking the task group, sched_cfs_period_timer() will execute and walk the list of task groups, trying to unthrottle cfs_rq's, i.e. re-add them to the dying task group. These will later -- in free_fair_sched_group() -- be kfree()'ed while still being linked, leading to the fireworks Kevin and Michal are seeing. To fix this race, ensure the dying task group gets unlinked first. However, simply switching the order of unregistering and unlinking the task group isn't sufficient, as concurrent RCU walkers might still see it, as can be seen below: CPU1: CPU2: : timer IRQ: : do_sched_cfs_period_timer(): : : : distribute_cfs_runtime(): : rcu_read_lock(); : : : unthrottle_cfs_rq(): sched_offline_group(): : : walk_tg_tree_from(…,tg_unthrottle_up,…): list_del_rcu(&tg->list); : (1) : list_for_each_entry_rcu(child, &parent->children, siblings) : : (2) list_del_rcu(&tg->siblings); : : tg_unthrottle_up(): unregister_fair_sched_group(): struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; : : list_del_leaf_cfs_rq(tg->cfs_rq[cpu]); : : : : if (!cfs_rq_is_decayed(cfs_rq) || cfs_rq->nr_running) (3) : list_add_leaf_cfs_rq(cfs_rq); : : : : : : : : : ---truncated---
Configurations

Configuration 1 (hide)

cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*

History

27 Mar 2025, 21:16

Type Values Removed Values Added
CPE cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
CVSS v2 : unknown
v3 : unknown
v2 : unknown
v3 : 5.5
CWE CWE-416
References () https://git.kernel.org/stable/c/512e21c150c1c3ee298852660f3a796e267e62ec - () https://git.kernel.org/stable/c/512e21c150c1c3ee298852660f3a796e267e62ec - Patch
References () https://git.kernel.org/stable/c/b027789e5e50494c2325cc70c8642e7fd6059479 - () https://git.kernel.org/stable/c/b027789e5e50494c2325cc70c8642e7fd6059479 - Patch
First Time Linux
Linux linux Kernel

21 Nov 2024, 06:35

Type Values Removed Values Added
Summary
  • (es) En el kernel de Linux, se ha resuelto la siguiente vulnerabilidad: sched/fair: Evitar que los grupos de tareas inactivos recuperen cfs_rq Kevin informa fallos que apuntan a un use-after-free de un cfs_rq en update_blocked_averages(). La depuración inicial reveló que tenemos cfs_rq activos (on_list=1) en un grupo de tareas a punto de ser kfree() en free_fair_sched_group(). Sin embargo, no estaba claro cómo puede suceder eso. Su configuración del kernel resultó en un diseño de struct sched_entity que coloca el miembro 'my_q' directamente en el medio del objeto, lo que hace que se superponga incidentalmente con el puntero de lista libre de SLUB. Eso, en combinación con la manipulación del puntero de lista libre de SLAB_FREELIST_HARDENED, conduce a una violación de acceso confiable en forma de un #GP que hizo que el UAF fallara rápidamente. Michal parece haberse topado con el mismo problema[1]. Él ya diagnosticó correctamente que el commit a7b359fc6a37 ("sched/fair: Insertar correctamente cfs_rq en la lista al desregular") está causando que se cumplan las condiciones previas para que se produzca la UAF al volver a agregar cfs_rq también a los grupos de tareas que ya no tienen tareas en ejecución, es decir, también a los que están inactivos. Sin embargo, su análisis no detecta la causa raíz real y no se puede ver solo desde el backtrace del bloqueo, ya que el verdadero infractor es tg_unthrottle_up() que se llama a través de sched_cfs_period_timer() mediante la interrupción del temporizador en un momento inconveniente. Cuando unregister_fair_sched_group() desvincula todos los cfs_rq del grupo de tareas que está inactivo, no se protege a sí mismo de ser interrumpido. Si la interrupción del temporizador se activa mientras iteramos sobre todas las CPU o después de que unregister_fair_sched_group() haya terminado pero antes de desvincular el grupo de tareas, sched_cfs_period_timer() se ejecutará y recorrerá la lista de grupos de tareas, intentando liberar cfs_rq, es decir, volver a agregarlos al grupo de tareas moribundo. Estos serán posteriormente -- en free_fair_sched_group() -- kfree()'ed mientras siguen vinculados, lo que lleva a los fuegos artificiales que Kevin y Michal están viendo. Para solucionar esta ejecución, asegúrese de que el grupo de tareas moribundo se desvincule primero. Sin embargo, simplemente cambiar el orden de anulación del registro y desvinculación del grupo de tareas no es suficiente, ya que los caminantes de RCU concurrentes aún podrían verlo, como se puede ver a continuación: CPU1: CPU2: : timer IRQ: : do_sched_cfs_period_timer(): : : : distributed_cfs_runtime(): : rcu_read_lock(); : : : unthrottle_cfs_rq(): sched_offline_group(): : : walk_tg_tree_from(…,tg_unthrottle_up,…): list_del_rcu(&tg->list); : (1) : list_for_each_entry_rcu(child, &parent->children, brothers) : : (2) list_del_rcu(&tg->siblings); : : tg_unthrottle_up(): anular_registro_justo_sched_group(): struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)]; : : list_del_leaf_cfs_rq(tg->cfs_rq[cpu]); : : : : si (!cfs_rq_está_decaído(cfs_rq) || cfs_rq->nr_en_ejecución) (3) : lista_agregar_hoja_cfs_rq(cfs_rq); : : : : : : : : : ---truncado---
References () https://git.kernel.org/stable/c/512e21c150c1c3ee298852660f3a796e267e62ec - () https://git.kernel.org/stable/c/512e21c150c1c3ee298852660f3a796e267e62ec -
References () https://git.kernel.org/stable/c/b027789e5e50494c2325cc70c8642e7fd6059479 - () https://git.kernel.org/stable/c/b027789e5e50494c2325cc70c8642e7fd6059479 -

10 Apr 2024, 19:15

Type Values Removed Values Added
New CVE

Information

Published : 2024-04-10 19:15

Updated : 2025-03-27 21:16


NVD link : CVE-2021-47209

Mitre link : CVE-2021-47209

CVE.ORG link : CVE-2021-47209


JSON object : View

Products Affected

linux

  • linux_kernel
CWE
CWE-416

Use After Free