Message ID | 20230118084630.3750680-1-houtao@huaweicloud.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 36024d023d139a0c8b552dc3b7f4dc7b4c139e8f |
Delegated to: | BPF |
Headers | show |
Series | [bpf] bpf: Fix off-by-one error in bpf_mem_cache_idx() | expand |
On 1/18/23 12:46 AM, Hou Tao wrote: > From: Hou Tao <houtao1@huawei.com> > > 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. More importantly, e.g., if the size is 4096, illegal memory access may happen. > > Fixes: 7c8199e24fa0 ("bpf: Introduce any context BPF specific memory allocator.") > Signed-off-by: Hou Tao <houtao1@huawei.com> Acked-by: Yonghong Song <yhs@fb.com> > --- > kernel/bpf/memalloc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c > index ebcc3dd0fa19..1db156405b68 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
On Wed, Jan 18, 2023 at 9:58 AM Yonghong Song <yhs@meta.com> wrote: > > > > > - return fls(size - 1) - 1; > > + return fls(size - 1) - 2; Wow. Thanks. Not sure how I missed it and why the tests didn't catch it. test_maps goes through many key/value sizes. Applied.
Hello: This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <ast@kernel.org>: On Wed, 18 Jan 2023 16:46:30 +0800 you wrote: > From: Hou Tao <houtao1@huawei.com> > > 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: 7c8199e24fa0 ("bpf: Introduce any context BPF specific memory allocator.") > Signed-off-by: Hou Tao <houtao1@huawei.com> > > [...] Here is the summary with links: - [bpf] bpf: Fix off-by-one error in bpf_mem_cache_idx() https://git.kernel.org/bpf/bpf/c/36024d023d13 You are awesome, thank you!
diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index ebcc3dd0fa19..1db156405b68 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