Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C996C2ED for ; Thu, 7 Nov 2024 09:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730972111; cv=none; b=p8M7fNzyB+F936JEb/4RR0pGLdCWEr1oTMEmoSxD1bC1wC/xKsfAAuIZv+1AJ/peICx/aLl5veK1DhleIBOQZH7Zz1lcr11PsQCQF3Rntopiv2Pz54FH+3lcIOx/4uiPScG24kIrD//7U2wgQLkYm5bH06PTfGfTkA9hRLX7kj0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730972111; c=relaxed/simple; bh=7sCI7wrp2kC71y/lf2wndr2hIlcfHHhAUgF99LEx/38=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sLAvVqNGAJztHfLtRSF0AVTeHzNM7XB1dZr4qiKyQVQI0B6X28INbhHSj3ltGXlhOz6FILZfeM7/68WhB90GEDAoUcF+P3gqpjDIKkgqYADadnrV6UCDfIRFt+QASb5XaOsklQosAn/EHre8j+Rz0mAWTtSzMimi4DNVfSyg+MM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1AipQ0AB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1AipQ0AB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59792C4CECC; Thu, 7 Nov 2024 09:35:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730972110; bh=7sCI7wrp2kC71y/lf2wndr2hIlcfHHhAUgF99LEx/38=; h=From:To:Cc:Subject:Date:Reply-to:From; b=1AipQ0ABqDOHtpnHUDRt1jXR3FhMZxXdYooa2Y1XKfcO/pGLbP/JmnuZTZz01aFCr MLRDCcOCScGpXYR/LgNPKKo/Kj0JpihBdjki5Bceow+/33bj7uMkbsmob/atUZlBvL mTIzAZq/Pzd+/rIU114D0g19Oz5w+exNg5a2Vq78= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-50140: sched/core: Disable page allocation in task_tick_mm_cid() Date: Thu, 7 Nov 2024 10:34:40 +0100 Message-ID: <2024110742-CVE-2024-50140-2371@gregkh> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=3657; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=7sCI7wrp2kC71y/lf2wndr2hIlcfHHhAUgF99LEx/38=; b=owGbwMvMwCRo6H6F97bub03G02pJDOk6nZsivpUsPTzDkdH4ffRZrqBdij9V9xvMtm2Pbf8z0 72yY97njlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZjIhmKGBbNeqWzgDPHmWxk+ VVHkp76Aebjmb4Z5Sp/OfVr9IlKc6Qf7tRlFMY4Gh0ysAQ== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: sched/core: Disable page allocation in task_tick_mm_cid() With KASAN and PREEMPT_RT enabled, calling task_work_add() in task_tick_mm_cid() may cause the following splat. [ 63.696416] BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48 [ 63.696416] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 610, name: modprobe [ 63.696416] preempt_count: 10001, expected: 0 [ 63.696416] RCU nest depth: 1, expected: 1 This problem is caused by the following call trace. sched_tick() [ acquire rq->__lock ] -> task_tick_mm_cid() -> task_work_add() -> __kasan_record_aux_stack() -> kasan_save_stack() -> stack_depot_save_flags() -> alloc_pages_mpol_noprof() -> __alloc_pages_noprof() -> get_page_from_freelist() -> rmqueue() -> rmqueue_pcplist() -> __rmqueue_pcplist() -> rmqueue_bulk() -> rt_spin_lock() The rq lock is a raw_spinlock_t. We can't sleep while holding it. IOW, we can't call alloc_pages() in stack_depot_save_flags(). The task_tick_mm_cid() function with its task_work_add() call was introduced by commit 223baf9d17f2 ("sched: Fix performance regression introduced by mm_cid") in v6.4 kernel. Fortunately, there is a kasan_record_aux_stack_noalloc() variant that calls stack_depot_save_flags() while not allowing it to allocate new pages. To allow task_tick_mm_cid() to use task_work without page allocation, a new TWAF_NO_ALLOC flag is added to enable calling kasan_record_aux_stack_noalloc() instead of kasan_record_aux_stack() if set. The task_tick_mm_cid() 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 task_work_add_noallloc() is called which should be rare. The Linux kernel CVE team has assigned CVE-2024-50140 to this issue. Affected and fixed versions =========================== Issue introduced in 6.4 with commit 223baf9d17f2 and fixed in 6.6.59 with commit 509c29d0d26f Issue introduced in 6.4 with commit 223baf9d17f2 and fixed in 6.11.6 with commit ce0241ef83ee Issue introduced in 6.4 with commit 223baf9d17f2 and fixed in 6.12-rc4 with commit 73ab05aa46b0 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2024-50140 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: include/linux/task_work.h kernel/sched/core.c kernel/task_work.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/509c29d0d26f68a6f6d0a05cb1a89725237e2b87 https://git.kernel.org/stable/c/ce0241ef83eed55f675376e8a3605d23de53d875 https://git.kernel.org/stable/c/73ab05aa46b02d96509cb029a8d04fca7bbde8c7