]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpf: fix potential 32-bit overflow when accessing ARRAY map element
authorAndrii Nakryiko <andrii@kernel.org>
Fri, 15 Jul 2022 05:31:43 +0000 (22:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 Aug 2022 12:41:08 +0000 (14:41 +0200)
commit063e092534d4c6785228e5b1eb6e9329f66ccbe4
tree39f82a136db0608ad7784afbcdf52358bc299c91
parentf0462d38589422bc9e27fd3c6343dfeb6b3db2f9
bpf: fix potential 32-bit overflow when accessing ARRAY map element

[ Upstream commit 87ac0d600943994444e24382a87aa19acc4cd3d4 ]

If BPF array map is bigger than 4GB, element pointer calculation can
overflow because both index and elem_size are u32. Fix this everywhere
by forcing 64-bit multiplication. Extract this formula into separate
small helper and use it consistently in various places.

Speculative-preventing formula utilizing index_mask trick is left as is,
but explicit u64 casts are added in both places.

Fixes: c85d69135a91 ("bpf: move memory size checks to bpf_map_charge_init()")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20220715053146.1291891-2-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/arraymap.c