In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix a kernel verifier crash in stacksafe()
Daniel Hodges reported a kernel verifier crash when playing with sched-ext. Further investigation shows that the crash is due to invalid memory access in stacksafe(). More specifically, it is the following code:
if (exact != NOT_EXACT &&
old->stack[spi].slot_type[i % BPF_REG_SIZE] !=
cur->stack[spi].slot_type[i % BPF_REG_SIZE])
return false;
The 'i' iterates old->allocatedstack. If cur->allocatedstack < old->allocated_stack the out-of-bound access will happen.
To fix the issue add 'i >= cur->allocatedstack' check such that if the condition is true, stacksafe() should fail. Otherwise, cur->stack[spi].slottype[i % BPFREGSIZE] memory access is legal.
[
{
"signature_version": "v1",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7cad3174cc79519bf5f6c4441780264416822c08",
"deprecated": false,
"id": "CVE-2024-45020-3643fa61",
"signature_type": "Function",
"digest": {
"length": 2138.0,
"function_hash": "282396486014554947654918895250695619621"
},
"target": {
"function": "stacksafe",
"file": "kernel/bpf/verifier.c"
}
},
{
"signature_version": "v1",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@bed2eb964c70b780fb55925892a74f26cb590b25",
"deprecated": false,
"id": "CVE-2024-45020-722d608d",
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"322198325282551150497597915949366478266",
"35115837087594568153765789816046257035",
"254103083496380533287246688785723376362",
"334916770808929024351956086150989644671",
"233574285408353597226430589877391362589"
]
},
"target": {
"file": "kernel/bpf/verifier.c"
}
},
{
"signature_version": "v1",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@6e3987ac310c74bb4dd6a2fa8e46702fe505fb2b",
"deprecated": false,
"id": "CVE-2024-45020-74fc0fe5",
"signature_type": "Function",
"digest": {
"length": 2400.0,
"function_hash": "77733944842172065930539484698791680204"
},
"target": {
"function": "stacksafe",
"file": "kernel/bpf/verifier.c"
}
},
{
"signature_version": "v1",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7cad3174cc79519bf5f6c4441780264416822c08",
"deprecated": false,
"id": "CVE-2024-45020-8e792229",
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"204083033786109607836391573259958389595",
"43839925826951805008661102202440986195",
"222729727237513844910155366609305440080",
"277052818649110265999816295053174173815",
"117742637082276244784587530016622594125"
]
},
"target": {
"file": "kernel/bpf/verifier.c"
}
},
{
"signature_version": "v1",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@6e3987ac310c74bb4dd6a2fa8e46702fe505fb2b",
"deprecated": false,
"id": "CVE-2024-45020-e18ed6f6",
"signature_type": "Line",
"digest": {
"threshold": 0.9,
"line_hashes": [
"322198325282551150497597915949366478266",
"35115837087594568153765789816046257035",
"254103083496380533287246688785723376362",
"334916770808929024351956086150989644671",
"233574285408353597226430589877391362589"
]
},
"target": {
"file": "kernel/bpf/verifier.c"
}
},
{
"signature_version": "v1",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@bed2eb964c70b780fb55925892a74f26cb590b25",
"deprecated": false,
"id": "CVE-2024-45020-f4d65afd",
"signature_type": "Function",
"digest": {
"length": 2400.0,
"function_hash": "77733944842172065930539484698791680204"
},
"target": {
"function": "stacksafe",
"file": "kernel/bpf/verifier.c"
}
}
]