CVE-2021-47069

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

ipc/mqueue, msg, sem: avoid relying on a stack reference past its expiry

do_mq_timedreceive calls wq_sleep with a stack local address.  The
sender (do_mq_timedsend) uses this address to later call pipelined_send.

This leads to a very hard to trigger race where a do_mq_timedreceive
call might return and leave do_mq_timedsend to rely on an invalid
address, causing the following crash:

  RIP: 0010:wake_q_add_safe+0x13/0x60
  Call Trace:
   __x64_sys_mq_timedsend+0x2a9/0x490
   do_syscall_64+0x80/0x680
   entry_SYSCALL_64_after_hwframe+0x44/0xa9
  RIP: 0033:0x7f5928e40343

The race occurs as:

1. do_mq_timedreceive calls wq_sleep with the address of `struct
   ext_wait_queue` on function stack (aliased as `ewq_addr` here) - it
   holds a valid `struct ext_wait_queue *` as long as the stack has not
   been overwritten.

2. `ewq_addr` gets added to info->e_wait_q[RECV].list in wq_add, and
   do_mq_timedsend receives it via wq_get_first_waiter(info, RECV) to call
   __pipelined_op.

3. Sender calls __pipelined_op::smp_store_release(&this->state,
   STATE_READY).  Here is where the race window begins.  (`this` is
   `ewq_addr`.)

4. If the receiver wakes up now in do_mq_timedreceive::wq_sleep, it
   will see `state == STATE_READY` and break.

5. do_mq_timedreceive returns, and `ewq_addr` is no longer guaranteed
   to be a `struct ext_wait_queue *` since it was on do_mq_timedreceive's
   stack.  (Although the address may not get overwritten until another
   function happens to touch it, which means it can persist around for an
   indefinite time.)

6. do_mq_timedsend::__pipelined_op() still believes `ewq_addr` is a
   `struct ext_wait_queue *`, and uses it to find a task_struct to pass to
   the wake_q_add_safe call.  In the lucky case where nothing has
   overwritten `ewq_addr` yet, `ewq_addr->task` is the right task_struct.
   In the unlucky case, __pipelined_op::wake_q_add_safe gets handed a
   bogus address as the receiver's task_struct causing the crash.

do_mq_timedsend::__pipelined_op() should not dereference `this` after
setting STATE_READY, as the receiver counterpart is now free to return.
Change __pipelined_op to call wake_q_add_safe on the receiver's
task_struct returned by get_task_struct, instead of dereferencing `this`
which sits on the receiver's stack.

As Manfred pointed out, the race potentially also exists in
ipc/msg.c::expunge_all and ipc/sem.c::wake_up_sem_queue_prepare.  Fix
those in the same way.
ProviderTypeBase ScoreAtk. VectorAtk. ComplexityPriv. RequiredVector
NISTNIST
7 HIGH
LOCAL
HIGH
LOW
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H
LinuxCNA
---
---
CISA-ADPADP
---
---
CVEADP
---
---
Base Score
CVSS 3.x
EPSS Score
Percentile: 1%
VendorProductVersion
linuxlinux_kernel
5.6 ≤
𝑥
< 5.10.40
linuxlinux_kernel
5.11 ≤
𝑥
< 5.12.7
linuxlinux_kernel
5.13:rc1
linuxlinux_kernel
5.13:rc2
𝑥
= 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
trixie
6.11.5-1
fixed
sid
6.11.6-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