CVE-2024-50140: sched/core: Disable page allocation in task_tick_mm_cid()
In the Linux kernel, the following vulnerability has been resolved:
sched/core: Disable page allocation in tasktickmmcid()
With KASAN and PREEMPTRT enabled, calling taskworkadd() in tasktickmmcid() may cause the following splat.
[ 63.696416] BUG: sleeping function called from invalid context at kernel/locking/spinlockrt.c:48 [ 63.696416] inatomic(): 1, irqsdisabled(): 1, nonblock: 0, pid: 610, name: modprobe [ 63.696416] preemptcount: 10001, expected: 0 [ 63.696416] RCU nest depth: 1, expected: 1
This problem is caused by the following call trace.
schedtick() [ acquire rq->lock ] -> tasktickmmcid() -> taskworkadd() -> kasanrecordauxstack() -> kasansavestack() -> stackdepotsaveflags() -> allocpagesmpolnoprof() -> allocpagesnoprof() -> getpagefromfreelist() -> rmqueue() -> rmqueuepcplist() -> rmqueuepcplist() -> rmqueuebulk() -> rtspinlock()
The rq lock is a rawspinlockt. We can't sleep while holding it. IOW, we can't call allocpages() in stackdepotsaveflags().
The tasktickmmcid() function with its taskworkadd() call was introduced by commit 223baf9d17f2 ("sched: Fix performance regression introduced by mmcid") in v6.4 kernel.
Fortunately, there is a kasanrecordauxstacknoalloc() variant that calls stackdepotsaveflags() while not allowing it to allocate new pages. To allow tasktickmmcid() to use taskwork without page allocation, a new TWAFNOALLOC flag is added to enable calling kasanrecordauxstacknoalloc() instead of kasanrecordauxstack() if set. The tasktickmmcid() function is modified to add this new flag.
The possible downside is the missing stack trace in a KASAN report due to new page allocation required when taskworkaddnoallloc() is called which should be rare.
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2024-50140?
CVE-2024-50140 is considered a moderate severity vulnerability affecting the Linux kernel.
How do I fix CVE-2024-50140?
To mitigate CVE-2024-50140, update to a patched version of the Linux kernel, such as 5.10.223-1, 6.1.123-1, or later.
Which versions of the Linux kernel are affected by CVE-2024-50140?
CVE-2024-50140 affects Linux kernel versions from 6.4 to 6.6.59, and specific release candidates 6.12-rc1, 6.12-rc2, and 6.12-rc3.
What triggers the vulnerability in CVE-2024-50140?
CVE-2024-50140 is triggered by calling task_work_add() within task_tick_mm_cid() when KASAN and PREEMPT_RT are enabled.
Is CVE-2024-50140 related to memory allocation issues?
Yes, CVE-2024-50140 involves an issue with page allocation that can lead to kernel errors under certain conditions.