public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Mirsad Todorovac <mirsad.todorovac@alu.hr>,
	Tejun Heo <tj@kernel.org>, Zefan Li <lizefan.x@bytedance.com>,
	Johannes Weiner <hannes@cmpxchg.org>
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] cgroup/cpuset: Fix a memory leak in update_exclusive_cpumask()
Date: Wed, 28 Feb 2024 10:08:37 -0500	[thread overview]
Message-ID: <3ec14dfe-6d69-4c41-804d-3e4e67828ae1@redhat.com> (raw)
In-Reply-To: <bc055871-9aa7-4165-bb54-39520349dc16@domac.alu.unizg.hr>


On 2/28/24 08:56, Mirsad Todorovac wrote:
> Hi,
>
> On 2/28/2024 1:58 AM, Waiman Long wrote:
>> Fix a possible memory leak in update_exclusive_cpumask() by moving the
>> alloc_cpumasks() down after the validate_change() check which can fail
>> and still before the temporary cpumasks are needed.
>>
>> Fixes: e2ffe502ba45 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2")
>> Reported-by: Mirsad Todorovac <mirsad.todorovac@alu.hr>
>> Closes: 
>> https://lore.kernel.org/lkml/14915689-27a3-4cd8-80d2-9c30d0c768b6@alu.unizg.hr
>> Signed-off-by: Waiman Long <longman@redhat.com>
>> ---
>>   kernel/cgroup/cpuset.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index ba36c073304a..7260f095802a 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -2598,9 +2598,6 @@ static int update_exclusive_cpumask(struct 
>> cpuset *cs, struct cpuset *trialcs,
>>       if (cpumask_equal(cs->exclusive_cpus, trialcs->exclusive_cpus))
>>           return 0;
>>   -    if (alloc_cpumasks(NULL, &tmp))
>> -        return -ENOMEM;
>> -
>>       if (*buf)
>>           compute_effective_exclusive_cpumask(trialcs, NULL);
>>   @@ -2615,6 +2612,9 @@ static int update_exclusive_cpumask(struct 
>> cpuset *cs, struct cpuset *trialcs,
>>       if (retval)
>>           return retval;
>>   +    if (alloc_cpumasks(NULL, &tmp))
>> +        return -ENOMEM;
>> +
>>       if (old_prs) {
>>           if (cpumask_empty(trialcs->effective_xcpus)) {
>>               invalidate = true;Great work at such a short notice! (I 
>> failed to find the culprit myself.)
>
> The leak is no longer present.
>
> Please feel free to add:
>
> Tested-by: Mirsad Todorovac <mtodorov@alu.unizg.hr>
>
> Best regards, Mirsad Todorovac
>
> P.S. APologies for the previous email accidentally sent as HTML.

Thanks for verifying the fix.

Cheers,
Longman


  reply	other threads:[~2024-02-28 15:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28  0:58 [PATCH] cgroup/cpuset: Fix a memory leak in update_exclusive_cpumask() Waiman Long
2024-02-28 13:56 ` Mirsad Todorovac
2024-02-28 15:08   ` Waiman Long [this message]
2024-02-28 18:04 ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3ec14dfe-6d69-4c41-804d-3e4e67828ae1@redhat.com \
    --to=longman@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan.x@bytedance.com \
    --cc=mirsad.todorovac@alu.hr \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox