From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>, wangbiao3@xiaomi.com
Cc: mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, brauner@kernel.org,
bsegall@google.com, linux-kernel@vger.kernel.org,
wenjieli@qti.qualcomm.com, chenguanyou@xiaomi.com,
Will Deacon <will@kernel.org>
Subject: Re: [PATCH 1/1] sched: fix user_mask double free
Date: Tue, 22 Nov 2022 13:13:35 -0500 [thread overview]
Message-ID: <1c3ce8c4-354d-2f00-1dc6-e13cbe389828@redhat.com> (raw)
In-Reply-To: <a7fb3cac-176f-3928-f3a3-23c25ab9677e@redhat.com>
On 11/22/22 10:39, Waiman Long wrote:
>
> On 11/22/22 09:05, Peter Zijlstra wrote:
>> So you failed:
>>
>> - to Cc the original author of this code (Will Deacon)
>> - to report what version this is against (apparently Linus' tree)
>> - to check if this still applies to the latest tree (it doesn't)
>> - to Cc the author of the code it now conflicts with (Waiman)
>> - write something coherent in the changelog.
>> - to include a Fixes tag.
>>
>> Still, let me try and make sense of things...
>>
>> On Mon, Nov 21, 2022 at 06:04:20PM +0800, wangbiao3@xiaomi.com wrote:
>>> From: wangbiao3 <wangbiao3@xiaomi.com>
>>>
>>> Clone/Fork a new task,call
>>> dup_task_struct->arch_dup_task_struct(tsk,orig)
>>> which copy the data of parent/sibling task inclding p->user_cpus_ptr,so
>>> the user_cpus_ptr of newtask is the same with orig task's.When
>>> dup_task_struct call dup_user_cpus_ptr(tsk, orig, node),it return 0
>>> dircetly if src->user_cpus_ptris free by other task,in this case ,
>>> the newtask's address of user_cpus_ptr is not changed.
>> (even just inserting some whitespace would've made it so much easier to
>> read)
>>
>> But, the only way that would be possible is if
>> force_compatible_cpus_allowed_ptr() were to be called on !current, and
>> that just doesn't happen, the only callsite is:
>>
>> arch/arm64/kernel/process.c: force_compatible_cpus_allowed_ptr(current);
>>
>> And you can't be in fork() and exec() at the same time.
>>
>> If it were possible to call restrict_cpus_allowed_ptr() on a non-current
>> task then yes, absolutely, which is why:
>>
>> 8f9ea86fdf99 ("sched: Always preserve the user requested cpumask")
>>
>> also wraps the thing in pi_lock, but looking at it now, perhaps it needs
>> to do the alloc/copy first and swap under pi_lock instead.
>
> With the latest change, user_cpus_ptr, once set, will not be cleared
> until when the task dies. That is why I don't recheck if user_cpus_ptr
> is NULL under pi_lock. The user_cpus_ptr value can certainly changes
> during its lifetime, but it will be stable under pi_lock.
> clear_user_cpus_ptr() is called by release_user_cpus_ptr() only. As
> said before, it is only call when the task dies at free_task() and so
> there shouldn't be any other racing conditions that can happen at the
> same time.
On second thought, do_set_cpus_allowed() can put NULL into
user_cpus_ptr. So I think we should do null check in dup_user_cpus_ptr()
inside the pi_lock. Will send a patch to do that.
Cheers,
Longman
next prev parent reply other threads:[~2022-11-22 18:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 10:04 [PATCH 0/1] " wangbiao3
2022-11-21 10:04 ` [PATCH 1/1] " wangbiao3
2022-11-22 13:18 ` Quentin Perret
2022-11-22 14:05 ` Peter Zijlstra
2022-11-22 14:06 ` Peter Zijlstra
2022-11-22 15:39 ` Waiman Long
2022-11-22 18:13 ` Waiman Long [this message]
[not found] ` <1fe9abbdd12b41fc87c92b60550fc909@xiaomi.com>
[not found] ` <9a6b10cd-855d-ca15-01e9-2c95a8b692be@redhat.com>
[not found] ` <9cc51697705f472e99a620eee8569a32@xiaomi.com>
2022-11-24 3:59 ` 答复: [External Mail]Re: " Waiman Long
2022-11-24 12:04 ` Wenjie Li (Evan)
2022-11-25 2:08 ` Waiman Long
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=1c3ce8c4-354d-2f00-1dc6-e13cbe389828@redhat.com \
--to=longman@redhat.com \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=chenguanyou@xiaomi.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
--cc=wangbiao3@xiaomi.com \
--cc=wenjieli@qti.qualcomm.com \
--cc=will@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
all inboxes | Powered by JetHome®