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 169BC16EBEE for ; Fri, 12 Jul 2024 12:33:46 +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=1720787626; cv=none; b=i7ZCVCxGF8WDQWZl9L1zS17xSI8Jmd3g3P3cJPBXf6cMME6P0EPq10JRA/Mxz2TQcJWthQqd3NjZAS7DzSszVkJ8x70h/BTqjFKsmRRbG5/ZyRkZCjwatTuv7T0+iLqX7PK9aNA1vKj1HvWZQRWjxpwe1CAhfXsN+mcai8hFHoc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720787626; c=relaxed/simple; bh=WbVktZT9At1NOF1dj5TAW/fUNeQjEqwiKTX938t0qLI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=EwyKdvKAqQSPSBVYErcgdkQRcBfQ6XJOU7dTOgLpPCL07baudPvSvrssoTbA4A36BCxm12A/q4Hy+79bR3OatlEIkFSQGIQ+jCzGrJdNwmGGZnRbklA9Kkrop5ffiHSSo4lQgvof0Tz+KWJ0u4MJFtrMPANVxIOyfvlMKdqGHXw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=x8ZTMa7A; 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="x8ZTMa7A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E97BC32786; Fri, 12 Jul 2024 12:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720787626; bh=WbVktZT9At1NOF1dj5TAW/fUNeQjEqwiKTX938t0qLI=; h=From:To:Cc:Subject:Date:Reply-to:From; b=x8ZTMa7AYJr1xj9SzeQ4/7bj4vGddoJC1vNS8VDhs1L+G2V1Ngt56Qgw1Zc7KV5rY ja8eKEOURuSmAiZAO65nbdIs99OYb0Wj5/RFDYxKxEXt1lppFiuf+qauLydeVHO5+5 rLFKMRwt+ldECjTuNYnVD90+xeXwDDOe4jDDMjQY= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-40955: ext4: fix slab-out-of-bounds in ext4_mb_find_good_group_avg_frag_lists() Date: Fri, 12 Jul 2024 14:32:31 +0200 Message-ID: <2024071224-CVE-2024-40955-43e2@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=3889; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=WbVktZT9At1NOF1dj5TAW/fUNeQjEqwiKTX938t0qLI=; b=owGbwMvMwCRo6H6F97bub03G02pJDGkTlSKUGX+IzvRe/FcybNfaaLkPp9YteVVWJ5zXGvVG8 sjiPwu1O2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAi/7kZZrOqh67r+VLYF591 Y9ffbjVuK/csH4b5fjvDJ5dpnw8Onvmr37iT2fVB+O8TAA== 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: ext4: fix slab-out-of-bounds in ext4_mb_find_good_group_avg_frag_lists() We can trigger a slab-out-of-bounds with the following commands: mkfs.ext4 -F /dev/$disk 10G mount /dev/$disk /tmp/test echo 2147483647 > /sys/fs/ext4/$disk/mb_group_prealloc echo test > /tmp/test/file && sync ================================================================== BUG: KASAN: slab-out-of-bounds in ext4_mb_find_good_group_avg_frag_lists+0x8a/0x200 [ext4] Read of size 8 at addr ffff888121b9d0f0 by task kworker/u2:0/11 CPU: 0 PID: 11 Comm: kworker/u2:0 Tainted: GL 6.7.0-next-20240118 #521 Call Trace: dump_stack_lvl+0x2c/0x50 kasan_report+0xb6/0xf0 ext4_mb_find_good_group_avg_frag_lists+0x8a/0x200 [ext4] ext4_mb_regular_allocator+0x19e9/0x2370 [ext4] ext4_mb_new_blocks+0x88a/0x1370 [ext4] ext4_ext_map_blocks+0x14f7/0x2390 [ext4] ext4_map_blocks+0x569/0xea0 [ext4] ext4_do_writepages+0x10f6/0x1bc0 [ext4] [...] ================================================================== The flow of issue triggering is as follows: // Set s_mb_group_prealloc to 2147483647 via sysfs ext4_mb_new_blocks ext4_mb_normalize_request ext4_mb_normalize_group_request ac->ac_g_ex.fe_len = EXT4_SB(sb)->s_mb_group_prealloc ext4_mb_regular_allocator ext4_mb_choose_next_group ext4_mb_choose_next_group_best_avail mb_avg_fragment_size_order order = fls(len) - 2 = 29 ext4_mb_find_good_group_avg_frag_lists frag_list = &sbi->s_mb_avg_fragment_size[order] if (list_empty(frag_list)) // Trigger SOOB! At 4k block size, the length of the s_mb_avg_fragment_size list is 14, but an oversized s_mb_group_prealloc is set, causing slab-out-of-bounds to be triggered by an attempt to access an element at index 29. Add a new attr_id attr_clusters_in_group with values in the range [0, sbi->s_clusters_per_group] and declare mb_group_prealloc as that type to fix the issue. In addition avoid returning an order from mb_avg_fragment_size_order() greater than MB_NUM_ORDERS(sb) and reduce some useless loops. The Linux kernel CVE team has assigned CVE-2024-40955 to this issue. Affected and fixed versions =========================== Issue introduced in 6.5 with commit 7e170922f06b and fixed in 6.6.36 with commit 677ff4589f15 Issue introduced in 6.5 with commit 7e170922f06b and fixed in 6.9.7 with commit b829687ae122 Issue introduced in 6.5 with commit 7e170922f06b and fixed in 6.10-rc1 with commit 13df4d44a3aa 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-40955 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: fs/ext4/mballoc.c fs/ext4/sysfs.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/677ff4589f1501578fa903a25bb14831d0607992 https://git.kernel.org/stable/c/b829687ae1229224262bcabf49accfa2dbf8db06 https://git.kernel.org/stable/c/13df4d44a3aaabe61cd01d277b6ee23ead2a5206