In the Linux kernel, the following vulnerability has been resolved:
ext4: fix slab-out-of-bounds in ext4mbfindgoodgroupavgfrag_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 ext4mbfindgoodgroupavgfraglists+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: dumpstacklvl+0x2c/0x50 kasanreport+0xb6/0xf0 ext4mbfindgoodgroupavgfraglists+0x8a/0x200 [ext4] ext4mbregularallocator+0x19e9/0x2370 [ext4] ext4mbnewblocks+0x88a/0x1370 [ext4] ext4extmapblocks+0x14f7/0x2390 [ext4] ext4mapblocks+0x569/0xea0 [ext4] ext4dowritepages+0x10f6/0x1bc0 [ext4]
The flow of issue triggering is as follows:
// Set smbgroupprealloc to 2147483647 via sysfs ext4mbnewblocks ext4mbnormalizerequest ext4mbnormalizegrouprequest ac->acgex.felen = EXT4SB(sb)->smbgroupprealloc ext4mbregularallocator ext4mbchoosenextgroup ext4mbchoosenextgroupbestavail mbavgfragmentsizeorder order = fls(len) - 2 = 29 ext4mbfindgoodgroupavgfraglists fraglist = &sbi->smbavgfragmentsize[order] if (listempty(frag_list)) // Trigger SOOB!
At 4k block size, the length of the smbavgfragmentsize list is 14, but an oversized smbgroup_prealloc is set, causing slab-out-of-bounds to be triggered by an attempt to access an element at index 29.
Add a new attrid attrclustersingroup with values in the range [0, sbi->sclusterspergroup] and declare mbgroupprealloc as that type to fix the issue. In addition avoid returning an order from mbavgfragmentsizeorder() greater than MBNUM_ORDERS(sb) and reduce some useless loops.
[
{
"id": "CVE-2024-40955-06bf65f0",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_mb_choose_next_group_best_avail",
"file": "fs/ext4/mballoc.c"
},
"digest": {
"length": 1177.0,
"function_hash": "91919650547634307144125065300556945468"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13df4d44a3aaabe61cd01d277b6ee23ead2a5206",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-08848e3c",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "mb_avg_fragment_size_order",
"file": "fs/ext4/mballoc.c"
},
"digest": {
"length": 181.0,
"function_hash": "153791406055196987960668338123604578856"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13df4d44a3aaabe61cd01d277b6ee23ead2a5206",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-159d881c",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "fs/ext4/mballoc.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"39721644310292476363521808788118789979",
"170823731717029789929430966074186030449",
"245307119853743255987417845997331499698",
"85088641324527079685729860382466532748",
"59823204139153382254078337305205703124",
"131156671546782507748032344488177916783",
"6946821057348556959740232985799205526",
"23385510778012978651460937013588446371"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@677ff4589f1501578fa903a25bb14831d0607992",
"signature_type": "Line"
},
{
"id": "CVE-2024-40955-3833bc3d",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "fs/ext4/mballoc.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"39721644310292476363521808788118789979",
"170823731717029789929430966074186030449",
"245307119853743255987417845997331499698",
"85088641324527079685729860382466532748",
"59823204139153382254078337305205703124",
"131156671546782507748032344488177916783",
"6946821057348556959740232985799205526",
"23385510778012978651460937013588446371"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13df4d44a3aaabe61cd01d277b6ee23ead2a5206",
"signature_type": "Line"
},
{
"id": "CVE-2024-40955-38ffdfa0",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "fs/ext4/sysfs.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"273084477898881614758550476315966995412",
"91142723389001659805969726754605584575",
"119305993483715813409617938695322949718",
"272442390459900454211091663456245529524",
"118659253683007082055754902507247617655",
"201360672329705427603370013258565436337",
"313294583667446827671616155160609800135",
"168493339920354618367048785774773577884",
"80017268624528881303212108903538348781",
"146750978022048267525125673610664064605",
"121984723042494256220399909069271023893",
"167819207698330529782805405548045071791",
"210109133161780438675722325473112388723",
"126207171614939410608443581734377986864",
"61458173896832370154729387451534113905",
"226794527639468943759366845134245697214",
"69186247518411810698614541479831846233",
"335225710081102766234704518254295414477",
"332272613640865980724139470006235373538",
"325028783880334738337636736504705288504",
"251027205035095671694075225144677502578",
"102951606183141966508323256673479468558",
"35718086299916677030030056880631192288"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@677ff4589f1501578fa903a25bb14831d0607992",
"signature_type": "Line"
},
{
"id": "CVE-2024-40955-533159d8",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_generic_attr_show",
"file": "fs/ext4/sysfs.c"
},
"digest": {
"length": 1015.0,
"function_hash": "84531026958008698969695216576219476767"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13df4d44a3aaabe61cd01d277b6ee23ead2a5206",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-53a40cfa",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_attr_show",
"file": "fs/ext4/sysfs.c"
},
"digest": {
"length": 2150.0,
"function_hash": "321857709272258536107459065484291437352"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@677ff4589f1501578fa903a25bb14831d0607992",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-72083d52",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "fs/ext4/mballoc.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"39721644310292476363521808788118789979",
"170823731717029789929430966074186030449",
"245307119853743255987417845997331499698",
"85088641324527079685729860382466532748",
"59823204139153382254078337305205703124",
"131156671546782507748032344488177916783",
"6946821057348556959740232985799205526",
"23385510778012978651460937013588446371"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b829687ae1229224262bcabf49accfa2dbf8db06",
"signature_type": "Line"
},
{
"id": "CVE-2024-40955-79590735",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "fs/ext4/sysfs.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"273084477898881614758550476315966995412",
"91142723389001659805969726754605584575",
"119305993483715813409617938695322949718",
"272442390459900454211091663456245529524",
"118659253683007082055754902507247617655",
"201360672329705427603370013258565436337",
"313294583667446827671616155160609800135",
"168493339920354618367048785774773577884",
"80017268624528881303212108903538348781",
"146750978022048267525125673610664064605",
"121984723042494256220399909069271023893",
"167819207698330529782805405548045071791",
"210109133161780438675722325473112388723",
"126207171614939410608443581734377986864",
"61458173896832370154729387451534113905",
"226794527639468943759366845134245697214",
"69186247518411810698614541479831846233",
"335225710081102766234704518254295414477",
"332272613640865980724139470006235373538",
"325028783880334738337636736504705288504",
"251027205035095671694075225144677502578",
"102951606183141966508323256673479468558",
"35718086299916677030030056880631192288"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b829687ae1229224262bcabf49accfa2dbf8db06",
"signature_type": "Line"
},
{
"id": "CVE-2024-40955-84cdf69d",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "fs/ext4/sysfs.c"
},
"digest": {
"threshold": 0.9,
"line_hashes": [
"273084477898881614758550476315966995412",
"91142723389001659805969726754605584575",
"119305993483715813409617938695322949718",
"272442390459900454211091663456245529524",
"118659253683007082055754902507247617655",
"201360672329705427603370013258565436337",
"313294583667446827671616155160609800135",
"168493339920354618367048785774773577884",
"80017268624528881303212108903538348781",
"146750978022048267525125673610664064605",
"121984723042494256220399909069271023893",
"167819207698330529782805405548045071791",
"210109133161780438675722325473112388723",
"126207171614939410608443581734377986864",
"61458173896832370154729387451534113905",
"337835094830656959776359796894896455844",
"209407421024080011657258907359821626508",
"153647603425151904560667281221827193728",
"173319711316502744818647235541407658861",
"325028783880334738337636736504705288504",
"251027205035095671694075225144677502578",
"40699202075470728934069711668086580378",
"2402655512173173613880873910218386791"
]
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13df4d44a3aaabe61cd01d277b6ee23ead2a5206",
"signature_type": "Line"
},
{
"id": "CVE-2024-40955-854ad84a",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_attr_show",
"file": "fs/ext4/sysfs.c"
},
"digest": {
"length": 2150.0,
"function_hash": "321857709272258536107459065484291437352"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b829687ae1229224262bcabf49accfa2dbf8db06",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-85b5e3b0",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "mb_avg_fragment_size_order",
"file": "fs/ext4/mballoc.c"
},
"digest": {
"length": 181.0,
"function_hash": "153791406055196987960668338123604578856"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@677ff4589f1501578fa903a25bb14831d0607992",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-86c4c02e",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "mb_avg_fragment_size_order",
"file": "fs/ext4/mballoc.c"
},
"digest": {
"length": 181.0,
"function_hash": "153791406055196987960668338123604578856"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b829687ae1229224262bcabf49accfa2dbf8db06",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-9e74e865",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_attr_store",
"file": "fs/ext4/sysfs.c"
},
"digest": {
"length": 1053.0,
"function_hash": "336786202378473398330914870493466063143"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@677ff4589f1501578fa903a25bb14831d0607992",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-b93a8115",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_mb_choose_next_group_best_avail",
"file": "fs/ext4/mballoc.c"
},
"digest": {
"length": 1191.0,
"function_hash": "41019187861389523888504955963308377047"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@677ff4589f1501578fa903a25bb14831d0607992",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-cace8cdd",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_attr_store",
"file": "fs/ext4/sysfs.c"
},
"digest": {
"length": 1053.0,
"function_hash": "336786202378473398330914870493466063143"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b829687ae1229224262bcabf49accfa2dbf8db06",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-e61176a2",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_mb_choose_next_group_best_avail",
"file": "fs/ext4/mballoc.c"
},
"digest": {
"length": 1177.0,
"function_hash": "91919650547634307144125065300556945468"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@b829687ae1229224262bcabf49accfa2dbf8db06",
"signature_type": "Function"
},
{
"id": "CVE-2024-40955-e7deb59a",
"deprecated": false,
"signature_version": "v1",
"target": {
"function": "ext4_generic_attr_store",
"file": "fs/ext4/sysfs.c"
},
"digest": {
"length": 669.0,
"function_hash": "209728422876054407950788752689235472818"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13df4d44a3aaabe61cd01d277b6ee23ead2a5206",
"signature_type": "Function"
}
]