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 143C916DEC3 for ; Fri, 12 Jul 2024 12:27:50 +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=1720787270; cv=none; b=nQ545i3K+zOAsUwkq1psmHX/53pve4T8X2e6dni560t9frZNcr9TQnacmlXROpbjD47azDAzwVjs2zI+ZHfUJkHXmH9eIGx/I8i4tZ0mLbfXEAxF0rf1Y4GfAQ40JaKa/aHkzKGGQEnX5B+XqaANE0bXX6VHQ27jvBz64lSlv1w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720787270; c=relaxed/simple; bh=PbV/05Ei/TJLg+nEqG42ZmZbc9ttwi7tppkb1bmRMlw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XiU53LRn1P+eBgwgly3f63+T0WLY4GT4tekPQLTJvqmaNtdruveb0oA8lvSqoDg8qd8pz0uAMsvm8kPA/b9uAAFYxqZg7qAH3euxhuR0eYtm+JO84b/Q8CuFj6I5X0i040eTZK7wmtKid7mLiNryrIeyWYgpD4kSmc1q5svoXjU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sNtmzqys; 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="sNtmzqys" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85463C32786; Fri, 12 Jul 2024 12:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720787269; bh=PbV/05Ei/TJLg+nEqG42ZmZbc9ttwi7tppkb1bmRMlw=; h=From:To:Cc:Subject:Date:Reply-to:From; b=sNtmzqysKEIvL5aNoSFyd8sLtbLdtJuA0UC1gTqWh+dRbswWzoPiOx8wHJOebt0fB oJ7xgbF/Eb7WDabVDg8CZIjt1vNfV5v3ljA8c4/mAns+VUAz713PRMybCyH1ffQH1G fyIOu9ohw9e7M0Emv5W7O5NP8oi6nDj38AaHYcqY= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-40915: riscv: rewrite __kernel_map_pages() to fix sleeping in invalid context Date: Fri, 12 Jul 2024 14:27:13 +0200 Message-ID: <2024071211-CVE-2024-40915-ba8c@gregkh> X-Mailer: git-send-email 2.45.2 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=3761; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=PbV/05Ei/TJLg+nEqG42ZmZbc9ttwi7tppkb1bmRMlw=; b=owGbwMvMwCRo6H6F97bub03G02pJDGkTFeVfKLA1xd9Onnosci2L37Mol5owF1b/z8lfOmedW JV6reNARywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAEzk2G6G+S5XtLaeN993ZME9 i4viVnypeiU2sQxzhRTEP09MntN5JmT7/GObZIuczU7OBwA= 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: riscv: rewrite __kernel_map_pages() to fix sleeping in invalid context __kernel_map_pages() is a debug function which clears the valid bit in page table entry for deallocated pages to detect illegal memory accesses to freed pages. This function set/clear the valid bit using __set_memory(). __set_memory() acquires init_mm's semaphore, and this operation may sleep. This is problematic, because __kernel_map_pages() can be called in atomic context, and thus is illegal to sleep. An example warning that this causes: BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1578 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 2, name: kthreadd preempt_count: 2, expected: 0 CPU: 0 PID: 2 Comm: kthreadd Not tainted 6.9.0-g1d4c6d784ef6 #37 Hardware name: riscv-virtio,qemu (DT) Call Trace: [] dump_backtrace+0x1c/0x24 [] show_stack+0x2c/0x38 [] dump_stack_lvl+0x5a/0x72 [] dump_stack+0x14/0x1c [] __might_resched+0x104/0x10e [] __might_sleep+0x3e/0x62 [] down_write+0x20/0x72 [] __set_memory+0x82/0x2fa [] __kernel_map_pages+0x5a/0xd4 [] __alloc_pages_bulk+0x3b2/0x43a [] __vmalloc_node_range+0x196/0x6ba [] copy_process+0x72c/0x17ec [] kernel_clone+0x60/0x2fe [] kernel_thread+0x82/0xa0 [] kthreadd+0x14a/0x1be [] ret_from_fork+0xe/0x1c Rewrite this function with apply_to_existing_page_range(). It is fine to not have any locking, because __kernel_map_pages() works with pages being allocated/deallocated and those pages are not changed by anyone else in the meantime. The Linux kernel CVE team has assigned CVE-2024-40915 to this issue. Affected and fixed versions =========================== Issue introduced in 5.7 with commit 5fde3db5eb02 and fixed in 6.1.95 with commit 919f8626099d Issue introduced in 5.7 with commit 5fde3db5eb02 and fixed in 6.6.35 with commit 8661a7af0499 Issue introduced in 5.7 with commit 5fde3db5eb02 and fixed in 6.9.6 with commit d5257ceb19d9 Issue introduced in 5.7 with commit 5fde3db5eb02 and fixed in 6.10-rc1 with commit fb1cf0878328 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-40915 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: arch/riscv/mm/pageattr.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/919f8626099d9909b9a9620b05e8c8ab06581876 https://git.kernel.org/stable/c/8661a7af04991201640863ad1a0983173f84b5eb https://git.kernel.org/stable/c/d5257ceb19d92069195254866421f425aea42915 https://git.kernel.org/stable/c/fb1cf0878328fe75d47f0aed0a65b30126fcefc4