CVE-2021-47303

EUVD-2021-34308
In the Linux kernel, the following vulnerability has been resolved:

bpf: Track subprog poke descriptors correctly and fix use-after-free

Subprograms are calling map_poke_track(), but on program release there is no
hook to call map_poke_untrack(). However, on program release, the aux memory
(and poke descriptor table) is freed even though we still have a reference to
it in the element list of the map aux data. When we run map_poke_run(), we then
end up accessing free'd memory, triggering KASAN in prog_array_map_poke_run():

  [...]
  [  402.824689] BUG: KASAN: use-after-free in prog_array_map_poke_run+0xc2/0x34e
  [  402.824698] Read of size 4 at addr ffff8881905a7940 by task hubble-fgs/4337
  [  402.824705] CPU: 1 PID: 4337 Comm: hubble-fgs Tainted: G          I       5.12.0+ #399
  [  402.824715] Call Trace:
  [  402.824719]  dump_stack+0x93/0xc2
  [  402.824727]  print_address_description.constprop.0+0x1a/0x140
  [  402.824736]  ? prog_array_map_poke_run+0xc2/0x34e
  [  402.824740]  ? prog_array_map_poke_run+0xc2/0x34e
  [  402.824744]  kasan_report.cold+0x7c/0xd8
  [  402.824752]  ? prog_array_map_poke_run+0xc2/0x34e
  [  402.824757]  prog_array_map_poke_run+0xc2/0x34e
  [  402.824765]  bpf_fd_array_map_update_elem+0x124/0x1a0
  [...]

The elements concerned are walked as follows:

    for (i = 0; i < elem->aux->size_poke_tab; i++) {
           poke = &elem->aux->poke_tab[i];
    [...]

The access to size_poke_tab is a 4 byte read, verified by checking offsets
in the KASAN dump:

  [  402.825004] The buggy address belongs to the object at ffff8881905a7800
                 which belongs to the cache kmalloc-1k of size 1024
  [  402.825008] The buggy address is located 320 bytes inside of
                 1024-byte region [ffff8881905a7800, ffff8881905a7c00)

The pahole output of bpf_prog_aux:

  struct bpf_prog_aux {
    [...]
    /* --- cacheline 5 boundary (320 bytes) --- */
    u32                        size_poke_tab;        /*   320     4 */
    [...]

In general, subprograms do not necessarily manage their own data structures.
For example, BTF func_info and linfo are just pointers to the main program
structure. This allows reference counting and cleanup to be done on the latter
which simplifies their management a bit. The aux->poke_tab struct, however,
did not follow this logic. The initial proposed fix for this use-after-free
bug further embedded poke data tracking into the subprogram with proper
reference counting. However, Daniel and Alexei questioned why we were treating
these objects special; I agree, its unnecessary. The fix here removes the per
subprogram poke table allocation and map tracking and instead simply points
the aux->poke_tab pointer at the main programs poke table. This way, map
tracking is simplified to the main program and we do not need to manage them
per subprogram.

This also means, bpf_prog_free_deferred(), which unwinds the program reference
counting and kfrees objects, needs to ensure that we don't try to double free
the poke_tab when free'ing the subprog structures. This is easily solved by
NULL'ing the poke_tab pointer. The second detail is to ensure that per
subprogram JIT logic only does fixups on poke_tab[] entries it owns. To do
this, we add a pointer in the poke structure to point at the subprogram value
so JITs can easily check while walking the poke_tab structure if the current
entry belongs to the current program. The aux pointer is stable and therefore
suitable for such comparison. On the jit_subprogs() error path, we omit
cleaning up the poke->aux field because these are only ever referenced from
the JIT side, but on error we will never make it to the JIT, so its fine to
leave them dangling. Removing these pointers would complicate the error path
for no reason. However, we do need to untrack all poke descriptors from the
main program as otherwise they could race with the freeing of JIT memory from
the subprograms. Lastly, a748c6975dea3 ("bpf: propagate poke des
---truncated---
ProviderTypeBase ScoreAtk. VectorAtk. ComplexityPriv. RequiredVector
NISTPrimary
7.8 HIGH
LOCAL
LOW
LOW
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Base Score
CVSS 3.x
EPSS Score
Percentile: 26%
Affected Products (NVD)
VendorProductVersion
linuxlinux_kernel
5.10 ≤
𝑥
< 5.10.53
linuxlinux_kernel
5.11 ≤
𝑥
< 5.13.5
linuxlinux_kernel
5.14:rc1
𝑥
= 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
fixed
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
focal
dne
jammy
dne
mantic
dne
noble
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
focal
dne
jammy
dne
mantic
dne
noble
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
focal
dne
jammy
dne
mantic
dne
noble
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