mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Ingo Molnar" <mingo@redhat.com>,
	"Juri Lelli" <juri.lelli@redhat.com>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Daniel Bristot de Oliveira" <bristot@redhat.com>,
	"Phil Auld" <pauld@redhat.com>,
	"Wenjie Li" <wenjieli@qti.qualcomm.com>,
	"David Wang 王标" <wangbiao3@xiaomi.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH-tip v2] sched: Fix use-after-free bug in dup_user_cpus_ptr()
Date: Thu, 22 Dec 2022 15:16:15 -0500	[thread overview]
Message-ID: <0b70f4c8-55ce-a5cd-cab7-7dfe70e60e99@redhat.com> (raw)
In-Reply-To: <Y6SxNwUn7/4/8IQa@hirez.programming.kicks-ass.net>


On 12/22/22 14:34, Peter Zijlstra wrote:
> On Mon, Dec 05, 2022 at 11:48:32AM -0500, Waiman Long wrote:
>> Since commit 07ec77a1d4e8 ("sched: Allow task CPU affinity to be
>> restricted on asymmetric systems"), the setting and clearing of
>> user_cpus_ptr are done under pi_lock for arm64 architecture. However,
>> dup_user_cpus_ptr() accesses user_cpus_ptr without any lock
>> protection. When racing with the clearing of user_cpus_ptr in
>> __set_cpus_allowed_ptr_locked(), it can lead to user-after-free and
>> double-free in arm64 kernel.
> How? the task cannot be in migrate_enable() and fork() at the same time,
> no?
>
I believe a task A can call sched_setaffinity() to modify the cpu 
affinity of a different task, say B, which can be under fork() at the 
same time. So we need to use the pi_lock to synchronize the access of 
user_cpus_ptr to avoid the kind of race that can cause double-free.

Cheers,
Longman


      reply	other threads:[~2022-12-22 20:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 16:48 Waiman Long
2022-12-22 19:34 ` Peter Zijlstra
2022-12-22 20:16   ` Waiman Long [this message]

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=0b70f4c8-55ce-a5cd-cab7-7dfe70e60e99@redhat.com \
    --to=longman@redhat.com \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=pauld@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=wangbiao3@xiaomi.com \
    --cc=wenjieli@qti.qualcomm.com \
    /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®