CVE-2021-47128

In the Linux kernel, the following vulnerability has been resolved:

bpf, lockdown, audit: Fix buggy SELinux lockdown permission checks

Commit 59438b46471a ("security,lockdown,selinux: implement SELinux lockdown")
added an implementation of the locked_down LSM hook to SELinux, with the aim
to restrict which domains are allowed to perform operations that would breach
lockdown. This is indirectly also getting audit subsystem involved to report
events. The latter is problematic, as reported by Ondrej and Serhei, since it
can bring down the whole system via audit:

  1) The audit events that are triggered due to calls to security_locked_down()
     can OOM kill a machine, see below details [0].

  2) It also seems to be causing a deadlock via avc_has_perm()/slow_avc_audit()
     when trying to wake up kauditd, for example, when using trace_sched_switch()
     tracepoint, see details in [1]. Triggering this was not via some hypothetical
     corner case, but with existing tools like runqlat & runqslower from bcc, for
     example, which make use of this tracepoint. Rough call sequence goes like:

     rq_lock(rq) -> -------------------------+
       trace_sched_switch() ->               |
         bpf_prog_xyz() ->                   +-> deadlock
           selinux_lockdown() ->             |
             audit_log_end() ->              |
               wake_up_interruptible() ->    |
                 try_to_wake_up() ->         |
                   rq_lock(rq) --------------+

What's worse is that the intention of 59438b46471a to further restrict lockdown
settings for specific applications in respect to the global lockdown policy is
completely broken for BPF. The SELinux policy rule for the current lockdown check
looks something like this:

  allow <who> <who> : lockdown { <reason> };

However, this doesn't match with the 'current' task where the security_locked_down()
is executed, example: httpd does a syscall. There is a tracing program attached
to the syscall which triggers a BPF program to run, which ends up doing a
bpf_probe_read_kernel{,_str}() helper call. The selinux_lockdown() hook does
the permission check against 'current', that is, httpd in this example. httpd
has literally zero relation to this tracing program, and it would be nonsensical
having to write an SELinux policy rule against httpd to let the tracing helper
pass. The policy in this case needs to be against the entity that is installing
the BPF program. For example, if bpftrace would generate a histogram of syscall
counts by user space application:

  bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }'

bpftrace would then go and generate a BPF program from this internally. One way
of doing it [for the sake of the example] could be to call bpf_get_current_task()
helper and then access current->comm via one of bpf_probe_read_kernel{,_str}()
helpers. So the program itself has nothing to do with httpd or any other random
app doing a syscall here. The BPF program _explicitly initiated_ the lockdown
check. The allow/deny policy belongs in the context of bpftrace: meaning, you
want to grant bpftrace access to use these helpers, but other tracers on the
system like my_random_tracer _not_.

Therefore fix all three issues at the same time by taking a completely different
approach for the security_locked_down() hook, that is, move the check into the
program verification phase where we actually retrieve the BPF func proto. This
also reliably gets the task (current) that is trying to install the BPF tracing
program, e.g. bpftrace/bcc/perf/systemtap/etc, and it also fixes the OOM since
we're moving this out of the BPF helper's fast-path which can be called several
millions of times per second.

The check is then also in line with other security_locked_down() hooks in the
system where the enforcement is performed at open/load time, for example,
open_kcore() for /proc/kcore access or module_sig_check() for module signatures
just to pick f
---truncated---
ProviderTypeBase ScoreAtk. VectorAtk. ComplexityPriv. RequiredVector
NISTNIST
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
LinuxCNA
---
---
CISA-ADPADP
---
---
CVEADP
---
---
Base Score
CVSS 3.x
EPSS Score
Percentile: 1%
VendorProductVersion
linuxlinux_kernel
5.6 ≤
𝑥
< 5.10.43
linuxlinux_kernel
5.11 ≤
𝑥
< 5.12.10
linuxlinux_kernel
5.13:rc1
linuxlinux_kernel
5.13:rc2
linuxlinux_kernel
5.13:rc3
linuxlinux_kernel
5.13:rc4
𝑥
= Vulnerable software versions
Debian logo
Debian Releases
Debian Product
Codename
linux
bullseye
5.10.223-1
fixed
buster
not-affected
bullseye (security)
5.10.226-1
fixed
bookworm
6.1.106-3
fixed
bookworm (security)
6.1.112-1
fixed
sid
6.11.5-1
fixed
trixie
6.11.5-1
fixed
Ubuntu logo
Ubuntu Releases
Ubuntu Product
Codename
linux
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
not-affected
bionic
not-affected
xenial
not-affected
trusty
not-affected
linux-allwinner-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-aws
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
not-affected
bionic
not-affected
xenial
not-affected
trusty
not-affected
linux-aws-5.0
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-aws-5.11
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-aws-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-aws-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-aws-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-aws-5.3
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-aws-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-aws-5.8
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-aws-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-aws-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-aws-fips
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-aws-hwe
noble
dne
mantic
dne
jammy
dne
focal
dne
xenial
not-affected
linux-azure
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
not-affected
bionic
ignored
xenial
not-affected
trusty
not-affected
linux-azure-4.15
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-azure-5.11
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-azure-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-azure-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-azure-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-azure-5.3
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-azure-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-azure-5.8
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-azure-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-azure-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-azure-edge
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-azure-fde
noble
dne
mantic
dne
jammy
not-affected
focal
ignored
linux-azure-fde-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-azure-fde-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-azure-fde-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-azure-fips
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-bluefield
noble
dne
mantic
dne
jammy
not-affected
focal
not-affected
linux-fips
noble
dne
mantic
dne
jammy
dne
focal
dne
linux-gcp
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
not-affected
bionic
ignored
xenial
not-affected
linux-gcp-4.15
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-gcp-5.11
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-gcp-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-gcp-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-gcp-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-gcp-5.3
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-gcp-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-gcp-5.8
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-gcp-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-gcp-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-gcp-fips
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-gke
noble
not-affected
mantic
dne
jammy
not-affected
focal
ignored
linux-gke-4.15
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-gke-5.15
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-gke-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-gkeop
noble
dne
mantic
dne
jammy
not-affected
focal
not-affected
linux-gkeop-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-gkeop-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-hwe
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
xenial
not-affected
linux-hwe-5.11
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-hwe-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-hwe-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-hwe-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-hwe-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-hwe-5.8
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-hwe-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-hwe-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-hwe-edge
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
xenial
ignored
linux-ibm
noble
not-affected
mantic
ignored
jammy
not-affected
focal
not-affected
linux-ibm-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-ibm-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-intel
noble
not-affected
mantic
dne
jammy
dne
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-intel-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-intel-iotg
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-intel-iotg-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-iot
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-kvm
noble
dne
mantic
dne
jammy
not-affected
focal
not-affected
bionic
not-affected
xenial
not-affected
linux-laptop
noble
dne
mantic
not-affected
jammy
dne
focal
dne
linux-lowlatency
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
dne
linux-lowlatency-hwe-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-lowlatency-hwe-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-lowlatency-hwe-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-lowlatency-hwe-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-lts-xenial
noble
dne
mantic
dne
jammy
dne
focal
dne
trusty
not-affected
linux-nvidia
noble
not-affected
mantic
dne
jammy
not-affected
focal
dne
linux-nvidia-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-nvidia-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-nvidia-6.8
noble
dne
jammy
not-affected
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-nvidia-lowlatency
noble
not-affected
jammy
dne
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-oem
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-oem-5.10
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oem-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oem-5.14
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oem-5.17
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-oem-5.6
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oem-6.0
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-oem-6.1
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-oem-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-oem-6.8
noble
not-affected
mantic
dne
jammy
dne
focal
dne
bionic
dne
xenial
dne
trusty
dne
linux-oracle
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
not-affected
bionic
not-affected
xenial
not-affected
linux-oracle-5.0
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-oracle-5.11
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oracle-5.13
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oracle-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-oracle-5.3
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
ignored
linux-oracle-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-oracle-5.8
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-oracle-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-raspi
noble
not-affected
mantic
not-affected
jammy
not-affected
focal
not-affected
linux-raspi-5.4
noble
dne
mantic
dne
jammy
dne
focal
dne
bionic
not-affected
linux-raspi2
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-riscv
noble
not-affected
mantic
not-affected
jammy
ignored
focal
ignored
linux-riscv-5.11
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-riscv-5.15
noble
dne
mantic
dne
jammy
dne
focal
not-affected
linux-riscv-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-riscv-5.8
noble
dne
mantic
dne
jammy
dne
focal
ignored
linux-riscv-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-starfive
noble
dne
mantic
not-affected
jammy
dne
focal
dne
linux-starfive-5.19
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-starfive-6.2
noble
dne
mantic
dne
jammy
ignored
focal
dne
linux-starfive-6.5
noble
dne
mantic
dne
jammy
not-affected
focal
dne
linux-xilinx-zynqmp
noble
dne
mantic
dne
jammy
not-affected
focal
not-affected