Skip to contentSkip to conversation

cgroup: free cset links on find_css_set() failure

PATCH In review Kaushlendra Kumar 2 participants 3 messages Feb 18 – Feb 21 cgroup

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup: free cset links on find_css_set() failure

When the recursive find_css_set() call for the domain cset fails, tmp_links allocated earlier are not freed, causing a memory leak.

Free tmp_links before returning NULL to prevent the leak.

Fixes 454000adaa2a ("cgroup: introduce cgroup->dom_cgrp and threaded css_set handling")
---
 kernel/cgroup/cgroup.c | 1 +
 1 file changed, 1 insertion(+)
kernel/cgroup/cgroup.c +1 -0
index 5f0d33b04910..b1f66311e8d3 100644
@@ -1308,6 +1308,7 @@ static struct css_set *find_css_set(struct css_set *old_cset,
 		dcset = find_css_set(cset, cset->dfl_cgrp->dom_cgrp);
 		if (!dcset) {
 			put_css_set(cset);
+			free_cgrp_cset_links(&tmp_links);
 			return NULL;
 		}
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hello,

[This is an AI-assisted review.]

Quoted 5 lines · Kaushlendra Kumar

When the recursive find_css_set() call for the domain cset fails, tmp_links allocated earlier are not freed, causing a memory leak.

Free tmp_links before returning NULL to prevent the leak.

tmp_links entries are consumed by link_css_set() which list_move_tail()'s each entry off tmp_links and into cgrp->cset_links and cset->cgrp_links. The BUG_ON(!list_empty(&tmp_links)) right after the linking loop (line 1281) confirms that tmp_links is empty by the time we reach the threaded cset handling code below.

The links, now owned by cset->cgrp_links, are properly freed by put_css_set(cset) which is already called on this error path.

So the added free_cgrp_cset_links() call would just iterate an empty list and is a no-op. There is no leak here.

Thanks.

--
tejun

#2 lore raw
Quoted 7 lines · Tejun Heo

tmp_links entries are consumed by link_css_set() which list_move_tail()'s each entry off tmp_links and into cgrp->cset_links and cset->cgrp_links. The BUG_ON (!list_empty(&tmp_links)) right after the linking loop (line 1281) confirms that tmp_links is empty by the time we reach the threaded cset handling code below.

Quoted 7 lines

The links, now owned by cset->cgrp_links, are properly freed by put_css_set(cset) which is already called on this error path.

So the added free_cgrp_cset_links() call would just iterate an empty list and is a no-op. There is no leak here.

You are right.
put_css_set() already handles the cleanup.

The added call is indeed a no-op. Dropping this patch.

BR,
Kaushlendra