In the Linux kernel, the following vulnerability has been resolved:
bootconfig: use memblockfreelate to free xbc memory to buddy
On the time to free xbc memory in xbcexit(), memblock may has handed over memory to buddy allocator. So it doesn't make sense to free memory back to memblock. memblockfree() called by xbcexit() even causes UAF bugs on architectures with CONFIGARCHKEEPMEMBLOCK disabled like x86. Following KASAN logs shows this case.
This patch fixes the xbc memory free problem by calling memblockfree() in early xbc init error rewind path and calling memblockfree_late() in xbc exit path to free memory to buddy allocator.
[ 9.410890] ================================================================== [ 9.418962] BUG: KASAN: use-after-free in memblockisolaterange+0x12d/0x260 [ 9.426850] Read of size 8 at addr ffff88845dd30000 by task swapper/0/1
[ 9.435901] CPU: 9 PID: 1 Comm: swapper/0 Tainted: G U 6.9.0-rc3-00208-g586b5dfb51b9 #5 [ 9.446403] Hardware name: Intel Corporation RPLP LP5 (CPU:RaptorLake)/RPLP LP5 (ID:13), BIOS IRPPN02.01.01.00.00.19.015.D-00000000 Dec 28 2023 [ 9.460789] Call Trace: [ 9.463518] <TASK> [ 9.465859] dumpstacklvl+0x53/0x70 [ 9.469949] printreport+0xce/0x610 [ 9.473944] ? _virtaddrvalid+0xf5/0x1b0 [ 9.478619] ? memblockisolaterange+0x12d/0x260 [ 9.483877] kasanreport+0xc6/0x100 [ 9.487870] ? memblockisolaterange+0x12d/0x260 [ 9.493125] memblockisolaterange+0x12d/0x260 [ 9.498187] memblockphysfree+0xb4/0x160 [ 9.502762] ? _pfxmemblockphysfree+0x10/0x10 [ 9.508021] ? mutexunlock+0x7e/0xd0 [ 9.512111] ? _pfxmutexunlock+0x10/0x10 [ 9.516786] ? kernelinitfreeable+0x2d4/0x430 [ 9.521850] ? _pfxkernelinit+0x10/0x10 [ 9.526426] xbcexit+0x17/0x70 [ 9.529935] kernelinit+0x38/0x1e0 [ 9.533829] ? rawspinunlockirq+0xd/0x30 [ 9.538601] retfromfork+0x2c/0x50 [ 9.542596] ? _pfxkernelinit+0x10/0x10 [ 9.547170] retfromforkasm+0x1a/0x30 [ 9.551552] </TASK>
[ 9.555649] The buggy address belongs to the physical page: [ 9.561875] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x1 pfn:0x45dd30 [ 9.570821] flags: 0x200000000000000(node=0|zone=2) [ 9.576271] page_type: 0xffffffff() [ 9.580167] raw: 0200000000000000 ffffea0011774c48 ffffea0012ba1848 0000000000000000 [ 9.588823] raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000 [ 9.597476] page dumped because: kasan: bad access detected
[ 9.605362] Memory state around the buggy address: [ 9.610714] ffff88845dd2ff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 9.618786] ffff88845dd2ff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 9.626857] >ffff88845dd30000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 9.634930] ^ [ 9.638534] ffff88845dd30080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 9.646605] ffff88845dd30100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [ 9.654675] ==================================================================
[ { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@89f9a1e876b5a7ad884918c03a46831af202c8a0", "signature_version": "v1", "target": { "file": "lib/bootconfig.c" }, "digest": { "threshold": 0.9, "line_hashes": [ "325527792105353865429254591216184515090", "61222898466788361585433952793081681645", "66874924429408153079145686339894927917", "291317985249204685954983017296106319494", "55212846518392774450888741232303356975", "29200382304164673267717306117259316933", "44063933118291608606741338346220070219", "223555562210940817552243850056128059016", "34888949334301617067408006215882895077", "280374727754205991984393911358054180942", "187395665454025113983253350050407994380", "81759420635810481259403652339345502144", "21549632843390073693264042718140022939", "275903806590130658965096747053235403784", "285751885052538115268388961412358015687", "228051936453359395154805409465080317388", "30852991469831967898432498480712427056", "193730986572570840666928492756320320296", "286578814117939360395346226894174770643", "49783370438792404306093244909458549586", "10435999745351380797902789110429746883", "272974554951072346769050686958360192748", "221353396823458671248423707776387619733", "247030626515740661613789679638955472723", "110401573555248488579368945759952516066", "266682681299245287452014434713629678880", "28587892604432600954321114786460090923", "224531537563966048955792729741377695995" ] }, "id": "CVE-2024-26983-0bb35bd0" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1e7feb31a18c197d63a5e606025ed63c762f8918", "signature_version": "v1", "target": { "function": "xbc_init", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "327229837985875790870524859540221701460", "length": 1059.0 }, "id": "CVE-2024-26983-0cd51359" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5a7dfb8fcd3f29fc93161100179b27f24f3d5f35", "signature_version": "v1", "target": { "function": "xbc_exit", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "37910208234632831169999384252115599275", "length": 221.0 }, "id": "CVE-2024-26983-146aaa5f" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1e7feb31a18c197d63a5e606025ed63c762f8918", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "27873218432337956706185208633024670999", "length": 93.0 }, "id": "CVE-2024-26983-19f02206" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5a7dfb8fcd3f29fc93161100179b27f24f3d5f35", "signature_version": "v1", "target": { "function": "xbc_init", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "327229837985875790870524859540221701460", "length": 1059.0 }, "id": "CVE-2024-26983-1fbb4b58" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5a7dfb8fcd3f29fc93161100179b27f24f3d5f35", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "249043324392463159741821554798328017003", "length": 85.0 }, "id": "CVE-2024-26983-215f565c" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@89f9a1e876b5a7ad884918c03a46831af202c8a0", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "249043324392463159741821554798328017003", "length": 85.0 }, "id": "CVE-2024-26983-2aa32fad" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e46d3be714ad9652480c6db129ab8125e2d20ab7", "signature_version": "v1", "target": { "function": "xbc_exit", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "37910208234632831169999384252115599275", "length": 221.0 }, "id": "CVE-2024-26983-4b58eb53" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@89f9a1e876b5a7ad884918c03a46831af202c8a0", "signature_version": "v1", "target": { "function": "xbc_exit", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "37910208234632831169999384252115599275", "length": 221.0 }, "id": "CVE-2024-26983-5712e751" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5a7dfb8fcd3f29fc93161100179b27f24f3d5f35", "signature_version": "v1", "target": { "file": "lib/bootconfig.c" }, "digest": { "threshold": 0.9, "line_hashes": [ "325527792105353865429254591216184515090", "61222898466788361585433952793081681645", "66874924429408153079145686339894927917", "291317985249204685954983017296106319494", "55212846518392774450888741232303356975", "29200382304164673267717306117259316933", "44063933118291608606741338346220070219", "223555562210940817552243850056128059016", "34888949334301617067408006215882895077", "280374727754205991984393911358054180942", "187395665454025113983253350050407994380", "81759420635810481259403652339345502144", "21549632843390073693264042718140022939", "275903806590130658965096747053235403784", "285751885052538115268388961412358015687", "228051936453359395154805409465080317388", "30852991469831967898432498480712427056", "193730986572570840666928492756320320296", "286578814117939360395346226894174770643", "49783370438792404306093244909458549586", "10435999745351380797902789110429746883", "272974554951072346769050686958360192748", "221353396823458671248423707776387619733", "247030626515740661613789679638955472723", "110401573555248488579368945759952516066", "266682681299245287452014434713629678880", "28587892604432600954321114786460090923", "224531537563966048955792729741377695995" ] }, "id": "CVE-2024-26983-60b3f0e2" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5a7dfb8fcd3f29fc93161100179b27f24f3d5f35", "signature_version": "v1", "target": { "file": "include/linux/bootconfig.h" }, "digest": { "threshold": 0.9, "line_hashes": [ "100564265710934537184941233536251125202", "250448634874634421258881547265915036120", "99333521464973839793429846444999964918", "104110263643112386827017423649297912261" ] }, "id": "CVE-2024-26983-634805ea" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1e7feb31a18c197d63a5e606025ed63c762f8918", "signature_version": "v1", "target": { "function": "xbc_exit", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "37910208234632831169999384252115599275", "length": 221.0 }, "id": "CVE-2024-26983-64c43374" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e46d3be714ad9652480c6db129ab8125e2d20ab7", "signature_version": "v1", "target": { "file": "include/linux/bootconfig.h" }, "digest": { "threshold": 0.9, "line_hashes": [ "100564265710934537184941233536251125202", "250448634874634421258881547265915036120", "99333521464973839793429846444999964918", "104110263643112386827017423649297912261" ] }, "id": "CVE-2024-26983-80364aee" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@89f9a1e876b5a7ad884918c03a46831af202c8a0", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "27873218432337956706185208633024670999", "length": 93.0 }, "id": "CVE-2024-26983-942339cd" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@89f9a1e876b5a7ad884918c03a46831af202c8a0", "signature_version": "v1", "target": { "function": "xbc_init", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "327229837985875790870524859540221701460", "length": 1059.0 }, "id": "CVE-2024-26983-a5898708" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e46d3be714ad9652480c6db129ab8125e2d20ab7", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "27873218432337956706185208633024670999", "length": 93.0 }, "id": "CVE-2024-26983-b2bb028f" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1e7feb31a18c197d63a5e606025ed63c762f8918", "signature_version": "v1", "target": { "file": "include/linux/bootconfig.h" }, "digest": { "threshold": 0.9, "line_hashes": [ "100564265710934537184941233536251125202", "250448634874634421258881547265915036120", "99333521464973839793429846444999964918", "104110263643112386827017423649297912261" ] }, "id": "CVE-2024-26983-b40432f9" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1e7feb31a18c197d63a5e606025ed63c762f8918", "signature_version": "v1", "target": { "file": "lib/bootconfig.c" }, "digest": { "threshold": 0.9, "line_hashes": [ "325527792105353865429254591216184515090", "61222898466788361585433952793081681645", "66874924429408153079145686339894927917", "291317985249204685954983017296106319494", "55212846518392774450888741232303356975", "29200382304164673267717306117259316933", "44063933118291608606741338346220070219", "223555562210940817552243850056128059016", "34888949334301617067408006215882895077", "280374727754205991984393911358054180942", "187395665454025113983253350050407994380", "81759420635810481259403652339345502144", "21549632843390073693264042718140022939", "275903806590130658965096747053235403784", "285751885052538115268388961412358015687", "228051936453359395154805409465080317388", "30852991469831967898432498480712427056", "193730986572570840666928492756320320296", "286578814117939360395346226894174770643", "49783370438792404306093244909458549586", "10435999745351380797902789110429746883", "272974554951072346769050686958360192748", "221353396823458671248423707776387619733", "247030626515740661613789679638955472723", "110401573555248488579368945759952516066", "266682681299245287452014434713629678880", "28587892604432600954321114786460090923", "224531537563966048955792729741377695995" ] }, "id": "CVE-2024-26983-d3270b2a" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e46d3be714ad9652480c6db129ab8125e2d20ab7", "signature_version": "v1", "target": { "file": "lib/bootconfig.c" }, "digest": { "threshold": 0.9, "line_hashes": [ "325527792105353865429254591216184515090", "61222898466788361585433952793081681645", "66874924429408153079145686339894927917", "291317985249204685954983017296106319494", "55212846518392774450888741232303356975", "29200382304164673267717306117259316933", "44063933118291608606741338346220070219", "223555562210940817552243850056128059016", "34888949334301617067408006215882895077", "280374727754205991984393911358054180942", "187395665454025113983253350050407994380", "81759420635810481259403652339345502144", "21549632843390073693264042718140022939", "275903806590130658965096747053235403784", "285751885052538115268388961412358015687", "228051936453359395154805409465080317388", "30852991469831967898432498480712427056", "193730986572570840666928492756320320296", "286578814117939360395346226894174770643", "49783370438792404306093244909458549586", "10435999745351380797902789110429746883", "272974554951072346769050686958360192748", "221353396823458671248423707776387619733", "247030626515740661613789679638955472723", "110401573555248488579368945759952516066", "266682681299245287452014434713629678880", "28587892604432600954321114786460090923", "224531537563966048955792729741377695995" ] }, "id": "CVE-2024-26983-db2d1571" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e46d3be714ad9652480c6db129ab8125e2d20ab7", "signature_version": "v1", "target": { "function": "xbc_init", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "327229837985875790870524859540221701460", "length": 1059.0 }, "id": "CVE-2024-26983-e9f04ae8" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e46d3be714ad9652480c6db129ab8125e2d20ab7", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "249043324392463159741821554798328017003", "length": 85.0 }, "id": "CVE-2024-26983-ea6adfda" }, { "signature_type": "Line", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@89f9a1e876b5a7ad884918c03a46831af202c8a0", "signature_version": "v1", "target": { "file": "include/linux/bootconfig.h" }, "digest": { "threshold": 0.9, "line_hashes": [ "100564265710934537184941233536251125202", "250448634874634421258881547265915036120", "99333521464973839793429846444999964918", "104110263643112386827017423649297912261" ] }, "id": "CVE-2024-26983-eb40ad42" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1e7feb31a18c197d63a5e606025ed63c762f8918", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "249043324392463159741821554798328017003", "length": 85.0 }, "id": "CVE-2024-26983-ef16bc44" }, { "signature_type": "Function", "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5a7dfb8fcd3f29fc93161100179b27f24f3d5f35", "signature_version": "v1", "target": { "function": "xbc_free_mem", "file": "lib/bootconfig.c" }, "digest": { "function_hash": "27873218432337956706185208633024670999", "length": 93.0 }, "id": "CVE-2024-26983-f806590c" } ]