From: Hou Tao Date: Wed, 18 Jan 2023 08:46:30 +0000 (+0800) Subject: bpf: Fix off-by-one error in bpf_mem_cache_idx() X-Git-Tag: baikal/aarch64/sdk6.1~197 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=d43491e5a01aa084236f890407acccf1a06f6ce5;p=kernel.git bpf: Fix off-by-one error in bpf_mem_cache_idx() [ Upstream commit 36024d023d139a0c8b552dc3b7f4dc7b4c139e8f ] According to the definition of sizes[NUM_CACHES], when the size passed to bpf_mem_cache_size() is 256, it should return 6 instead 7. Fixes: bfb90de6b522 ("bpf: Introduce any context BPF specific memory allocator.") Signed-off-by: Hou Tao Acked-by: Yonghong Song Link: https://lore.kernel.org/r/20230118084630.3750680-1-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index 4901fa1048cd7..6187c28d266f0 100644 --- a/kernel/bpf/memalloc.c +++ b/kernel/bpf/memalloc.c @@ -71,7 +71,7 @@ static int bpf_mem_cache_idx(size_t size) if (size <= 192) return size_index[(size - 1) / 8] - 1; - return fls(size - 1) - 1; + return fls(size - 1) - 2; } #define NUM_CACHES 11