CVE-2021-47209

EUVD-2021-33857
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---
ProviderTypeBase ScoreAtk. VectorAtk. ComplexityPriv. RequiredVector
NISTPrimary
5.5 MEDIUM
LOCAL
LOW
LOW
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H
Base Score
CVSS 3.x
EPSS Score
Percentile: 3%
Affected Products (NVD)
VendorProductVersion
linuxlinux_kernel
5.13 ≤
𝑥
< 5.15.5
𝑥
= Vulnerable software versions
Debian logo
Debian Releases
Debian Product
Codename
linux
bookworm
6.1.106-3
fixed
bookworm (security)
6.1.112-1
fixed
bullseye
5.10.223-1
not-affected
bullseye (security)
5.10.226-1
fixed
buster
not-affected
sid
6.11.6-1
fixed
trixie
6.11.5-1
fixed
Ubuntu logo
Ubuntu Releases
Ubuntu Product
Codename
linux
bionic
not-affected
focal
not-affected
jammy
not-affected
mantic
not-affected
noble
not-affected
trusty
not-affected
xenial
not-affected
linux-allwinner-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-aws
bionic
not-affected
focal
not-affected
jammy
not-affected
mantic
not-affected
noble
not-affected
trusty
not-affected
xenial
not-affected
linux-aws-5.0
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-aws-5.11
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-aws-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-aws-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-aws-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-aws-5.3
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-aws-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-aws-5.8
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-aws-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-aws-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-aws-fips
bionic
dne
focal
dne
jammy
dne
mantic
dne
noble
dne
trusty
dne
xenial
dne
linux-aws-hwe
focal
dne
jammy
dne
mantic
dne
noble
dne
xenial
not-affected
linux-azure
bionic
ignored
focal
not-affected
jammy
not-affected
mantic
not-affected
noble
not-affected
trusty
not-affected
xenial
not-affected
linux-azure-4.15
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-azure-5.11
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-azure-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-azure-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-azure-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-azure-5.3
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-azure-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-azure-5.8
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-azure-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-azure-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-azure-edge
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-azure-fde
focal
ignored
jammy
not-affected
mantic
dne
noble
dne
linux-azure-fde-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-azure-fde-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-azure-fde-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-azure-fips
bionic
dne
focal
dne
jammy
dne
mantic
dne
noble
dne
trusty
dne
xenial
dne
linux-bluefield
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-fips
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-gcp
bionic
ignored
focal
not-affected
jammy
not-affected
mantic
not-affected
noble
not-affected
xenial
not-affected
linux-gcp-4.15
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-gcp-5.11
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-gcp-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-gcp-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-gcp-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-gcp-5.3
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-gcp-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-gcp-5.8
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-gcp-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-gcp-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-gcp-fips
bionic
dne
focal
dne
jammy
dne
mantic
dne
noble
dne
trusty
dne
xenial
dne
linux-gke
focal
ignored
jammy
not-affected
mantic
dne
noble
not-affected
linux-gke-4.15
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-gke-5.15
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-gke-5.4
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-gkeop
focal
not-affected
jammy
not-affected
mantic
dne
noble
dne
linux-gkeop-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-gkeop-5.4
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-hwe
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
xenial
not-affected
linux-hwe-5.11
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-hwe-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-hwe-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-hwe-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-hwe-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-hwe-5.8
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-hwe-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-hwe-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-hwe-edge
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
xenial
ignored
linux-ibm
focal
not-affected
jammy
not-affected
mantic
ignored
noble
not-affected
linux-ibm-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-ibm-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-intel
bionic
dne
focal
dne
jammy
dne
mantic
dne
noble
not-affected
trusty
dne
xenial
dne
linux-intel-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-intel-iotg
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-intel-iotg-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-iot
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-kvm
bionic
not-affected
focal
not-affected
jammy
not-affected
mantic
dne
noble
dne
xenial
not-affected
linux-laptop
focal
dne
jammy
dne
mantic
not-affected
noble
dne
linux-lowlatency
focal
dne
jammy
not-affected
mantic
not-affected
noble
not-affected
linux-lowlatency-hwe-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-lowlatency-hwe-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-lowlatency-hwe-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-lowlatency-hwe-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-lts-xenial
focal
dne
jammy
dne
mantic
dne
noble
dne
trusty
not-affected
linux-nvidia
focal
dne
jammy
not-affected
mantic
dne
noble
not-affected
linux-nvidia-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-nvidia-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-nvidia-6.8
bionic
dne
focal
dne
jammy
not-affected
noble
dne
trusty
dne
xenial
dne
linux-nvidia-lowlatency
bionic
dne
focal
dne
jammy
dne
noble
not-affected
trusty
dne
xenial
dne
linux-oem
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-oem-5.10
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oem-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oem-5.14
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oem-5.17
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-oem-5.6
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oem-6.0
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-oem-6.1
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-oem-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-oem-6.8
bionic
dne
focal
dne
jammy
dne
mantic
dne
noble
not-affected
trusty
dne
xenial
dne
linux-oracle
bionic
not-affected
focal
not-affected
jammy
not-affected
mantic
not-affected
noble
not-affected
xenial
not-affected
linux-oracle-5.0
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-oracle-5.11
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oracle-5.13
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oracle-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-oracle-5.3
bionic
ignored
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-oracle-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-oracle-5.8
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-oracle-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-raspi
focal
not-affected
jammy
not-affected
mantic
not-affected
noble
not-affected
linux-raspi-5.4
bionic
not-affected
focal
dne
jammy
dne
mantic
dne
noble
dne
linux-raspi2
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-riscv
focal
ignored
jammy
ignored
mantic
not-affected
noble
not-affected
linux-riscv-5.11
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-riscv-5.15
focal
not-affected
jammy
dne
mantic
dne
noble
dne
linux-riscv-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-riscv-5.8
focal
ignored
jammy
dne
mantic
dne
noble
dne
linux-riscv-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-starfive
focal
dne
jammy
dne
mantic
not-affected
noble
dne
linux-starfive-5.19
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-starfive-6.2
focal
dne
jammy
ignored
mantic
dne
noble
dne
linux-starfive-6.5
focal
dne
jammy
not-affected
mantic
dne
noble
dne
linux-xilinx-zynqmp
focal
not-affected
jammy
not-affected
mantic
dne
noble
dne