Re: [PATCH bpf] bpf: Fix off-by-one error in bpf_mem_cache_idx()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 1/18/23 12:46 AM, Hou Tao wrote:
From: Hou Tao <houtao1@xxxxxxxxxx>

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@xxxxxxxxxx>

Acked-by: Yonghong Song <yhs@xxxxxx>

---
  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



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux