Skip to content

Commit 3ac1707

Browse files
lizf-oshtejun
authored andcommitted
cgroup: fix an off-by-one bug which may trigger BUG_ON()
The 3rd parameter of flex_array_prealloc() is the number of elements, not the index of the last element. The effect of the bug is, when opening cgroup.procs, a flex array will be allocated and all elements of the array is allocated with GFP_KERNEL flag, but the last one is GFP_ATOMIC, and if we fail to allocate memory for it, it'll trigger a BUG_ON(). Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org> Cc: stable@vger.kernel.org
1 parent 80f36c2 commit 3ac1707

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎kernel/cgroup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ static int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader)
20762076
if (!group)
20772077
return -ENOMEM;
20782078
/* pre-allocate to guarantee space while iterating in rcu read-side. */
2079-
retval = flex_array_prealloc(group, 0, group_size - 1, GFP_KERNEL);
2079+
retval = flex_array_prealloc(group, 0, group_size, GFP_KERNEL);
20802080
if (retval)
20812081
goto out_free_group_list;
20822082

0 commit comments

Comments
 (0)