commit | f8324f10a1785f88899da4c83b7192f519721a29 | [log] [tgz] |
---|---|---|
author | Tatsuhiko Yasumatsu <[email protected]> | Thu Sep 30 22:55:45 2021 +0900 |
committer | Meena Shanmugam <[email protected]> | Sat Oct 16 03:43:26 2021 +0000 |
tree | 0a39430b80434d8c7d3855360f585057cbee7273 | |
parent | 88dcca730a10cbe0ede8df92db857dd3ffb66211 [diff] |
bpf: Fix integer overflow in prealloc_elems_and_freelist() [ Upstream commit 30e29a9a2bc6a4888335a6ede968b75cd329657a ] In prealloc_elems_and_freelist(), the multiplication to calculate the size passed to bpf_map_area_alloc() could lead to an integer overflow. As a result, out-of-bounds write could occur in pcpu_freelist_populate() as reported by KASAN: [...] [ 16.968613] BUG: KASAN: slab-out-of-bounds in pcpu_freelist_populate+0xd9/0x100 [ 16.969408] Write of size 8 at addr ffff888104fc6ea0 by task crash/78 [ 16.970038] [ 16.970195] CPU: 0 PID: 78 Comm: crash Not tainted 5.15.0-rc2+ #1 [ 16.970878] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 [ 16.972026] Call Trace: [ 16.972306] dump_stack_lvl+0x34/0x44 [ 16.972687] print_address_description.constprop.0+0x21/0x140 [ 16.973297] ? pcpu_freelist_populate+0xd9/0x100 [ 16.973777] ? pcpu_freelist_populate+0xd9/0x100 [ 16.974257] kasan_report.cold+0x7f/0x11b [ 16.974681] ? pcpu_freelist_populate+0xd9/0x100 [ 16.975190] pcpu_freelist_populate+0xd9/0x100 [ 16.975669] stack_map_alloc+0x209/0x2a0 [ 16.976106] __sys_bpf+0xd83/0x2ce0 [...] The possibility of this overflow was originally discussed in [0], but was overlooked. Fix the integer overflow by changing elem_size to u64 from u32. [0] https://lore.kernel.org/bpf/[email protected]/ Fixes: 557c0c6e7df8 ("bpf: convert stackmap to pre-allocation") Signed-off-by: Tatsuhiko Yasumatsu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Sasha Levin <[email protected]> BUG=b/202643468 TEST=Presubmit RELEASE_NOTE=Fixes CVE-2021-41864. cos-patch: security-moderate Change-Id: I93ca1a54985fdff0b273da92cd33f3ad5469e573 Reviewed-on: https://cos-review.googlesource.com/c/third_party/kernel/+/24071 Reviewed-by: Vaibhav Rustagi <[email protected]> Reviewed-by: Roy Yang <[email protected]> Tested-by: Cusky Presubmit Bot <[email protected]>