Message ID | 20231021014959.3563841-1-houtao@huaweicloud.com (mailing list archive) |
---|---|
State | Accepted |
Commit | c421c12586b3f00fb96b5c9af15c9a051a9090b1 |
Delegated to: | BPF |
Headers | show |
Series | [bpf-next] bpf: Add more WARN_ON_ONCE checks for mismatched alloc and free | expand |
Hello: This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <daniel@iogearbox.net>: On Sat, 21 Oct 2023 09:49:59 +0800 you wrote: > From: Hou Tao <houtao1@huawei.com> > > There are two possible mismatched alloc and free cases in bpf memory > allocator: > 1) allocate from cache X but free by cache Y with a different unit_size > 2) allocate from per-cpu cache but free by kmalloc cache or vice versa > > [...] Here is the summary with links: - [bpf-next] bpf: Add more WARN_ON_ONCE checks for mismatched alloc and free https://git.kernel.org/bpf/bpf-next/c/c421c12586b3 You are awesome, thank you!
diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index 5308e386380af..63b909d277d47 100644 --- a/kernel/bpf/memalloc.c +++ b/kernel/bpf/memalloc.c @@ -340,6 +340,7 @@ static void free_bulk(struct bpf_mem_cache *c) int cnt; WARN_ON_ONCE(tgt->unit_size != c->unit_size); + WARN_ON_ONCE(tgt->percpu_size != c->percpu_size); do { inc_active(c, &flags); @@ -365,6 +366,9 @@ static void __free_by_rcu(struct rcu_head *head) struct bpf_mem_cache *tgt = c->tgt; struct llist_node *llnode; + WARN_ON_ONCE(tgt->unit_size != c->unit_size); + WARN_ON_ONCE(tgt->percpu_size != c->percpu_size); + llnode = llist_del_all(&c->waiting_for_gp); if (!llnode) goto out;