This is a note to let you know that I've just added the patch titled bpf: Add missed allocation hint for bpf_mem_cache_alloc_flags() to the 6.6-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: bpf-add-missed-allocation-hint-for-bpf_mem_cache_all.patch and it can be found in the queue-6.6 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 171ecabddb1b78ea242bb66a1bcbd2900df067a1 Author: Hou Tao <houtao1@xxxxxxxxxx> Date: Sat Nov 11 12:38:21 2023 +0800 bpf: Add missed allocation hint for bpf_mem_cache_alloc_flags() [ Upstream commit 75a442581d05edaee168222ffbe00d4389785636 ] bpf_mem_cache_alloc_flags() may call __alloc() directly when there is no free object in free list, but it doesn't initialize the allocation hint for the returned pointer. It may lead to bad memory dereference when freeing the pointer, so fix it by initializing the allocation hint. Fixes: 822fb26bdb55 ("bpf: Add a hint to allocated objects.") Signed-off-by: Hou Tao <houtao1@xxxxxxxxxx> Acked-by: Yonghong Song <yonghong.song@xxxxxxxxx> Link: https://lore.kernel.org/r/20231111043821.2258513-1-houtao@xxxxxxxxxxxxxxx Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index d93ddac283d40..956f80ee6f5c5 100644 --- a/kernel/bpf/memalloc.c +++ b/kernel/bpf/memalloc.c @@ -958,6 +958,8 @@ void notrace *bpf_mem_cache_alloc_flags(struct bpf_mem_alloc *ma, gfp_t flags) memcg = get_memcg(c); old_memcg = set_active_memcg(memcg); ret = __alloc(c, NUMA_NO_NODE, GFP_KERNEL | __GFP_NOWARN | __GFP_ACCOUNT); + if (ret) + *(struct bpf_mem_cache **)ret = c; set_active_memcg(old_memcg); mem_cgroup_put(memcg); }