In the Linux kernel, the following vulnerability has been resolved:
bpf: Fix memory leaks in _checkfunc_call
kmemleak reports this issue:
unreferenced object 0xffff88817139d000 (size 2048): comm "testprogs", pid 33246, jiffies 4307381979 (age 45851.820s) hex dump (first 32 bytes): 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<0000000045f075f0>] kmalloctrace+0x27/0xa0 [<0000000098b7c90a>] _checkfunccall+0x316/0x1230 [<00000000b4c3c403>] checkhelpercall+0x172e/0x4700 [<00000000aa3875b7>] docheck+0x21d8/0x45e0 [<000000001147357b>] docheckcommon+0x767/0xaf0 [<00000000b5a595b4>] bpfcheck+0x43e3/0x5bc0 [<0000000011e391b1>] bpfprogload+0xf26/0x1940 [<0000000007f765c0>] _sysbpf+0xd2c/0x3650 [<00000000839815d6>] _x64sysbpf+0x75/0xc0 [<00000000946ee250>] dosyscall64+0x3b/0x90 [<0000000000506b7f>] entrySYSCALL64afterhwframe+0x63/0xcd
The root case here is: In function preparefuncexit(), the callee is not released in the abnormal scenario after "state->curframe--;". To fix, move "state->curframe--;" to the very bottom of the function, right when we free callee and reset frame[] pointer to NULL, as Andrii suggested.
In addition, function _checkfunccall() has a similar problem. In the abnormal scenario before "state->curframe++;", the callee also should be released by freefunc_state().
{ "vanir_signatures": [ { "target": { "function": "prepare_func_exit", "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-0cc082c0", "deprecated": false, "digest": { "length": 1176.0, "function_hash": "188297220053834182253863127899973761391" }, "signature_type": "Function", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@eb86559a691cea5fa63e57a03ec3dc9c31e97955" }, { "target": { "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-25247760", "deprecated": false, "digest": { "threshold": 0.9, "line_hashes": [ "198888559158825559273704487103918259569", "71179026944372562532721694825969965964", "153100273676350872538387302952506698792", "111398772219605569591774706636286750112", "201768859871564643504014622802779389714", "61318605400894410068973940403765409635", "69708250920132672661064519053549824048", "22591020599247189304726861734144172929", "146768271325495802519104346009467271099", "334020884404847435274214174098237390571", "241267916452078491197658849421475249290", "232490596694873434721092689220320323600", "105616815507719300125239371070106723308", "53579629468902761353420560664412072303", "160300239059679054483312391336871468751", "8750144334112259249574747374149575343", "171804441324078647551963472024133375280", "319627414764373660513893234959723065533", "332823148888275548975366874669896350417", "153883346597009859901786559341536881696" ] }, "signature_type": "Line", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@eb86559a691cea5fa63e57a03ec3dc9c31e97955" }, { "target": { "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-4d5d581c", "deprecated": false, "digest": { "threshold": 0.9, "line_hashes": [ "198888559158825559273704487103918259569", "71179026944372562532721694825969965964", "153100273676350872538387302952506698792", "111398772219605569591774706636286750112", "201768859871564643504014622802779389714", "61318605400894410068973940403765409635", "69708250920132672661064519053549824048", "22591020599247189304726861734144172929", "146768271325495802519104346009467271099", "334020884404847435274214174098237390571", "241267916452078491197658849421475249290", "232490596694873434721092689220320323600", "105616815507719300125239371070106723308", "53579629468902761353420560664412072303", "326651447049434660512962910488280025425", "43398512636898431800439488893548478299", "171804441324078647551963472024133375280", "319627414764373660513893234959723065533", "332823148888275548975366874669896350417", "153883346597009859901786559341536881696" ] }, "signature_type": "Line", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@83946d772e756734a900ef99dbe0aeda506adf37" }, { "target": { "function": "prepare_func_exit", "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-52ada497", "deprecated": false, "digest": { "length": 1155.0, "function_hash": "272252974701117569517311906309777204990" }, "signature_type": "Function", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d4944497827a3d14bc5a26dbcfb7433eb5a956c0" }, { "target": { "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-64ff7926", "deprecated": false, "digest": { "threshold": 0.9, "line_hashes": [ "198888559158825559273704487103918259569", "71179026944372562532721694825969965964", "153100273676350872538387302952506698792", "111398772219605569591774706636286750112", "201768859871564643504014622802779389714", "61318605400894410068973940403765409635", "69708250920132672661064519053549824048", "67804201637205135786715908201618762667", "283461213329161507051990804429777547648", "334020884404847435274214174098237390571", "241267916452078491197658849421475249290", "232490596694873434721092689220320323600", "105616815507719300125239371070106723308", "53579629468902761353420560664412072303", "326651447049434660512962910488280025425", "43398512636898431800439488893548478299", "1040836760672942811244095623808936706", "319627414764373660513893234959723065533", "332823148888275548975366874669896350417", "153883346597009859901786559341536881696" ] }, "signature_type": "Line", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d4944497827a3d14bc5a26dbcfb7433eb5a956c0" }, { "target": { "function": "__check_func_call", "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-b839d2c4", "deprecated": false, "digest": { "length": 2387.0, "function_hash": "41882388813172101977486574329109168667" }, "signature_type": "Function", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@eb86559a691cea5fa63e57a03ec3dc9c31e97955" }, { "target": { "function": "__check_func_call", "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-b9b90f01", "deprecated": false, "digest": { "length": 2387.0, "function_hash": "41882388813172101977486574329109168667" }, "signature_type": "Function", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@83946d772e756734a900ef99dbe0aeda506adf37" }, { "target": { "function": "prepare_func_exit", "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-ccf50afb", "deprecated": false, "digest": { "length": 1169.0, "function_hash": "67234432624514369908960338650559698652" }, "signature_type": "Function", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@83946d772e756734a900ef99dbe0aeda506adf37" }, { "target": { "function": "__check_func_call", "file": "kernel/bpf/verifier.c" }, "id": "CVE-2022-49837-e7518a7b", "deprecated": false, "digest": { "length": 2373.0, "function_hash": "304409669295167218962869456555177565375" }, "signature_type": "Function", "signature_version": "v1", "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d4944497827a3d14bc5a26dbcfb7433eb5a956c0" } ] }