Re: [PATCH] cgroup: fixed the cset refcnt leak when fork() failed

From: Waiman Long
Date: Mon Jun 05 2023 - 10:52:55 EST



On 6/5/23 10:12, Waiman Long wrote:
kernel/cgroup/cgroup.c | 5 +++++
  1 file changed, 5 insertions(+)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index d18c2ef..5ecd706 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -6284,6 +6284,11 @@ void cgroup_cancel_fork(struct task_struct *child,
          if (ss->cancel_fork)
              ss->cancel_fork(child, kargs->cset);
  +    if (!(kargs->flags & CLONE_INTO_CGROUP) &&
+            kargs->cset) {
+        put_css_set(kargs->cset);
+    }
+
I believe the out_revert error path of cgroup_can_fork() has a similar issue. Perhaps you may want to put the put_css_set() call in cgroup_css_set_put_fork().

Sorry, it should not be done in cgroup_css_set_put_fork(). As the increase in reference is properly matched in css_post_fork(). That means similar change will be needed in cgroup_can_fork().

Cheers,
Longman