In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix racing between bpftimercancelandfree and bpftimercancel
The following race is possible between bpftimercancelandfree and bpftimercancel. It will lead a UAF on the timer->timer.
bpftimercancel(); spinlock(); t = timer->time; spinunlock();
bpf_timer_cancel_and_free();
spin_lock();
t = timer->timer;
timer->timer = NULL;
spin_unlock();
hrtimer_cancel(&t->timer);
kfree(t);
/* UAF on t */
hrtimer_cancel(&t->timer);
In bpftimercancelandfree, this patch frees the timer->timer after a rcu grace period. This requires a rcuhead addition to the "struct bpfhrtimer". Another kfree(t) happens in bpftimerinit, this does not need a kfreercu because it is still under the spinlock and timer->timer has not been visible by others yet.
In bpftimercancel, rcureadlock() is added because this helper can be used in a non rcu critical section context (e.g. from a sleepable bpf prog). Other timer->timer usages in helpers.c have been audited, bpftimercancel() is the only place where timer->timer is used outside of the spin_lock.
Another solution considered is to mark a t->flag in bpftimercancel and clear it after hrtimercancel() is done. In bpftimercanceland_free, it busy waits for the flag to be cleared before kfree(t). This patch goes with a straight forward solution and frees timer->timer after a rcu grace period.
{ "vanir_signatures": [ { "id": "CVE-2024-26737-03382f51", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "BPF_CALL_1" }, "signature_version": "v1", "digest": { "length": 400.0, "function_hash": "238598264745936296370193862989973024653" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@0281b919e175bb9c3128bd3872ac2903e9436e3f" }, { "id": "CVE-2024-26737-09bdb0a5", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "BPF_CALL_1" }, "signature_version": "v1", "digest": { "length": 400.0, "function_hash": "238598264745936296370193862989973024653" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5268bb02107b9eedfdcd51db75b407d10043368c" }, { "id": "CVE-2024-26737-0cc83c22", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "bpf_timer_cancel_and_free" }, "signature_version": "v1", "digest": { "length": 385.0, "function_hash": "279790273413285307361163931996564113722" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7d80a9e745fa5b47da3bca001f186c02485c7c33" }, { "id": "CVE-2024-26737-10df3c10", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "bpf_timer_cancel_and_free" }, "signature_version": "v1", "digest": { "length": 385.0, "function_hash": "279790273413285307361163931996564113722" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@addf5e297e6cbf5341f9c07720693ca9ba0057b5" }, { "id": "CVE-2024-26737-1babf4c5", "signature_type": "Line", "target": { "file": "kernel/bpf/helpers.c" }, "signature_version": "v1", "digest": { "line_hashes": [ "138461655890669710373815060390858788755", "7097597485216899987323467684187622917", "248291822126793367701810632853762933111", "289585970792630292651418038625990815601", "95004044934670641723732824068619176997", "102919242523873717854153279374758254539", "310242520630030139894809665314294094498", "157731722464649137114765182188930518571", "249547385452878111138668661443923482515", "226501091830974304948118132295409685419", "79684956514605334236694291327752681350", "284098970420251430019563469080979299615", "64026458641123611174860309368707026147", "177159336172652089292486604480016700418", "268299227815758475990156158663484206997", "216086117564603303544296917216648394861" ], "threshold": 0.9 }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@addf5e297e6cbf5341f9c07720693ca9ba0057b5" }, { "id": "CVE-2024-26737-20aaf321", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "BPF_CALL_1" }, "signature_version": "v1", "digest": { "length": 400.0, "function_hash": "238598264745936296370193862989973024653" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@addf5e297e6cbf5341f9c07720693ca9ba0057b5" }, { "id": "CVE-2024-26737-5568482a", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "bpf_timer_cancel_and_free" }, "signature_version": "v1", "digest": { "length": 385.0, "function_hash": "279790273413285307361163931996564113722" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8327ed12e8ebc5436bfaa1786c49988894f9c8a6" }, { "id": "CVE-2024-26737-58cf666b", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "bpf_timer_cancel_and_free" }, "signature_version": "v1", "digest": { "length": 385.0, "function_hash": "279790273413285307361163931996564113722" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5268bb02107b9eedfdcd51db75b407d10043368c" }, { "id": "CVE-2024-26737-5bc32cb4", "signature_type": "Line", "target": { "file": "kernel/bpf/helpers.c" }, "signature_version": "v1", "digest": { "line_hashes": [ "138461655890669710373815060390858788755", "7097597485216899987323467684187622917", "248291822126793367701810632853762933111", "289585970792630292651418038625990815601", "95004044934670641723732824068619176997", "102919242523873717854153279374758254539", "310242520630030139894809665314294094498", "157731722464649137114765182188930518571", "249547385452878111138668661443923482515", "226501091830974304948118132295409685419", "79684956514605334236694291327752681350", "284098970420251430019563469080979299615", "64026458641123611174860309368707026147", "177159336172652089292486604480016700418", "268299227815758475990156158663484206997", "216086117564603303544296917216648394861" ], "threshold": 0.9 }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@0281b919e175bb9c3128bd3872ac2903e9436e3f" }, { "id": "CVE-2024-26737-5db01659", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "BPF_CALL_1" }, "signature_version": "v1", "digest": { "length": 400.0, "function_hash": "238598264745936296370193862989973024653" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7d80a9e745fa5b47da3bca001f186c02485c7c33" }, { "id": "CVE-2024-26737-78d0710e", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "BPF_CALL_1" }, "signature_version": "v1", "digest": { "length": 400.0, "function_hash": "238598264745936296370193862989973024653" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8327ed12e8ebc5436bfaa1786c49988894f9c8a6" }, { "id": "CVE-2024-26737-8b9cc166", "signature_type": "Function", "target": { "file": "kernel/bpf/helpers.c", "function": "bpf_timer_cancel_and_free" }, "signature_version": "v1", "digest": { "length": 385.0, "function_hash": "279790273413285307361163931996564113722" }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@0281b919e175bb9c3128bd3872ac2903e9436e3f" }, { "id": "CVE-2024-26737-8df99e3d", "signature_type": "Line", "target": { "file": "kernel/bpf/helpers.c" }, "signature_version": "v1", "digest": { "line_hashes": [ "138461655890669710373815060390858788755", "7097597485216899987323467684187622917", "248291822126793367701810632853762933111", "289585970792630292651418038625990815601", "95004044934670641723732824068619176997", "102919242523873717854153279374758254539", "310242520630030139894809665314294094498", "157731722464649137114765182188930518571", "249547385452878111138668661443923482515", "226501091830974304948118132295409685419", "79684956514605334236694291327752681350", "284098970420251430019563469080979299615", "64026458641123611174860309368707026147", "177159336172652089292486604480016700418", "8818216259447168601555137438210919033", "22527797822950139026335694195094606824" ], "threshold": 0.9 }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@5268bb02107b9eedfdcd51db75b407d10043368c" }, { "id": "CVE-2024-26737-e0e70180", "signature_type": "Line", "target": { "file": "kernel/bpf/helpers.c" }, "signature_version": "v1", "digest": { "line_hashes": [ "138461655890669710373815060390858788755", "7097597485216899987323467684187622917", "248291822126793367701810632853762933111", "289585970792630292651418038625990815601", "95004044934670641723732824068619176997", "102919242523873717854153279374758254539", "310242520630030139894809665314294094498", "157731722464649137114765182188930518571", "249547385452878111138668661443923482515", "226501091830974304948118132295409685419", "79684956514605334236694291327752681350", "284098970420251430019563469080979299615", "64026458641123611174860309368707026147", "177159336172652089292486604480016700418", "268299227815758475990156158663484206997", "216086117564603303544296917216648394861" ], "threshold": 0.9 }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8327ed12e8ebc5436bfaa1786c49988894f9c8a6" }, { "id": "CVE-2024-26737-f8caf441", "signature_type": "Line", "target": { "file": "kernel/bpf/helpers.c" }, "signature_version": "v1", "digest": { "line_hashes": [ "138461655890669710373815060390858788755", "7097597485216899987323467684187622917", "248291822126793367701810632853762933111", "289585970792630292651418038625990815601", "95004044934670641723732824068619176997", "102919242523873717854153279374758254539", "310242520630030139894809665314294094498", "157731722464649137114765182188930518571", "249547385452878111138668661443923482515", "226501091830974304948118132295409685419", "79684956514605334236694291327752681350", "284098970420251430019563469080979299615", "64026458641123611174860309368707026147", "177159336172652089292486604480016700418", "268299227815758475990156158663484206997", "216086117564603303544296917216648394861" ], "threshold": 0.9 }, "deprecated": false, "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7d80a9e745fa5b47da3bca001f186c02485c7c33" } ] }