On Thu, Aug 18, 2022 at 10:46:33AM +0800, Pu Lehui wrote:[...]
On 2022/8/17 4:39, Andrii Nakryiko wrote:
On Sat, Aug 13, 2022 at 6:11 AM Pu Lehui <pulehui@xxxxxxxxxx> wrote:
Failslab injection will cause kmalloc fail and fall back to
purge_effective_progs. The problem is that cg2 have attached another prog,
so when go through cg2 layer, iteration will add pos to 1, and subsequent
operations will be skipped by the following condition, and cg will meet
NULL in the end.
`if (pos && !(cg->bpf.flags[atype] & BPF_F_ALLOW_MULTI))`
The NULL cg means no link or prog match, this is as expected, and it's not
a bug. So here just skip the no match situation.
Fixes: 4c46091ee985 ("bpf: Fix KASAN use-after-free Read in compute_effective_progs")
Signed-off-by: Pu Lehui <pulehui@xxxxxxxxxx>
---
kernel/bpf/cgroup.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index 59b7eb60d5b4..4a400cd63731 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -921,8 +921,10 @@ static void purge_effective_progs(struct cgroup *cgrp, struct bpf_prog *prog,
pos++;
}
}
+
+ /* no link or prog match, skip the cgroup of this layer */
+ continue;
found:
- BUG_ON(!cg);
I don't think it's necessary to remove this BUG_ON(), but it also
feels unnecessary for purge_effective_progs, so I don't mind it.
Acked-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
Will this patch be accepted? I think we should CC stable.