All of lore.kernel.org
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: Eric Biggers <ebiggers@kernel.org>
Cc: Munehisa Kamata <kamatam@amazon.com>,
	hannes@cmpxchg.org, hdanton@sina.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	mengcc@amazon.com, stable@vger.kernel.org
Subject: Re: [PATCH] sched/psi: fix use-after-free in ep_remove_wait_queue()
Date: Thu, 9 Feb 2023 11:13:02 -0800	[thread overview]
Message-ID: <CAJuCfpECvLiEdp+VfDo=_ZmhakEbtL2JzcwDfFahUk4XBOYNpg@mail.gmail.com> (raw)
In-Reply-To: <Y+U/k678tB5w5hJP@gmail.com>

On Thu, Feb 9, 2023 at 10:46 AM Eric Biggers <ebiggers@kernel.org> wrote:
>
> On Thu, Feb 09, 2023 at 09:09:03AM -0800, Suren Baghdasaryan wrote:
> > On Thu, Feb 2, 2023 at 1:11 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > >
> > > On Wed, Feb 1, 2023 at 8:56 PM Eric Biggers <ebiggers@kernel.org> wrote:
> > > >
> > > > On Wed, Feb 01, 2023 at 07:00:23PM -0800, Munehisa Kamata wrote:
> > > > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
> > > > > index 8ac8b81bfee6..6e66c15f6450 100644
> > > > > --- a/kernel/sched/psi.c
> > > > > +++ b/kernel/sched/psi.c
> > > > > @@ -1343,10 +1343,11 @@ void psi_trigger_destroy(struct psi_trigger *t)
> > > > >
> > > > >       group = t->group;
> > > > >       /*
> > > > > -      * Wakeup waiters to stop polling. Can happen if cgroup is deleted
> > > > > -      * from under a polling process.
> > > > > +      * Wakeup waiters to stop polling and clear the queue to prevent it from
> > > > > +      * being accessed later. Can happen if cgroup is deleted from under a
> > > > > +      * polling process otherwise.
> > > > >        */
> > > > > -     wake_up_interruptible(&t->event_wait);
> > > > > +     wake_up_pollfree(&t->event_wait);
> > > > >
> > > > >       mutex_lock(&group->trigger_lock);
> > > >
> > > > wake_up_pollfree() should only be used in extremely rare cases.  Why can't the
> > > > lifetime of the waitqueue be fixed instead?
> > >
> > > waitqueue lifetime in this case is linked to cgroup_file_release(),
> > > which seems appropriate to me here. Unfortunately
> > > cgroup_file_release() is not directly linked to the file's lifetime.
> > > For more details see:
> > > https://lore.kernel.org/all/CAJuCfpFZ3B4530TgsSHqp5F_gwfrDujwRYewKReJru==MdEHQg@mail.gmail.com/#t
> > > .
> > > So, if we want to fix the lifetime of the waitqueue, we would have to
> > > tie cgroup_file_release() to the fput() somehow. IOW, the fix would
> > > have to be done at the cgroups or higher (kernfs?) layer.
> >
> > Hi Eric,
> > Do you still object to using wake_up_pollfree() for this case?
> > Changing higher levels to make cgroup_file_release() be tied to fput()
> > would be ideal but I think that would be a big change for this one
> > case. If you agree I'll Ack this patch.
> > Thanks,
> > Suren.
> >
>
> I haven't read the code closely in this case.  I'm just letting you know that
> wake_up_pollfree() is very much a last-resort option for when the waitqueue
> lifetime can't be fixed.

Got it. Thanks for the warning.
I think it can be fixed but the right fix would require a sizable
higher level refactoring which might be more justifiable if we have
more such cases in the future.

>  So if you want to use wake_up_pollfree(), you need to
> explain why no other fix is possible.  For example maybe the UAPI depends on the
> waitqueue having a nonstandard lifetime.

I think the changelog should explain that the waitqueue lifetime in
cases of non-root cgroups is tied to cgroup_file_release() callback,
which in turn is not tied to file's lifetime. That's the reason for
waitqueue and the file having different lifecycles. Would that suffice
as the justification?
Again, I'm not saying that no other fix is possible, but that the
right fix would be much more complex.
Thanks,
Suren.

>
> - Eric

  reply	other threads:[~2023-02-09 19:13 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 22:48 another use-after-free in ep_remove_wait_queue() Munehisa Kamata
2023-01-06 23:34 ` Suren Baghdasaryan
2023-01-07  8:07 ` Hillf Danton
2023-01-08 22:25   ` Munehisa Kamata
2023-01-08 23:49     ` Hillf Danton
2023-01-10  1:33       ` Suren Baghdasaryan
2023-01-10  3:06         ` Suren Baghdasaryan
2023-01-12 22:01           ` Suren Baghdasaryan
2023-01-13  2:25             ` Munehisa Kamata
2023-01-13 17:52               ` Suren Baghdasaryan
2023-01-19  3:06                 ` Suren Baghdasaryan
2023-01-19 21:01                   ` Suren Baghdasaryan
2023-01-19 22:25                     ` Johannes Weiner
2023-01-20  1:30                     ` Hillf Danton
2023-01-20  1:37                       ` Suren Baghdasaryan
2023-01-20  2:46                         ` Munehisa Kamata
2023-01-20  2:52                           ` Munehisa Kamata
2023-01-20  9:00                         ` Hillf Danton
2023-01-20 16:28                           ` Suren Baghdasaryan
2023-01-21  5:17                             ` Hillf Danton
2023-01-22  3:01                               ` Suren Baghdasaryan
2023-01-20  1:45                     ` Munehisa Kamata
2023-02-02  3:00                     ` [PATCH] sched/psi: fix " Munehisa Kamata
2023-02-02  4:56                       ` Eric Biggers
2023-02-02 21:11                         ` Suren Baghdasaryan
2023-02-09 17:09                           ` Suren Baghdasaryan
2023-02-09 18:46                             ` Eric Biggers
2023-02-09 19:13                               ` Suren Baghdasaryan [this message]
2023-02-13 23:50                                 ` Suren Baghdasaryan
2023-02-14  7:04                                   ` [PATCH v2] " Munehisa Kamata
2023-02-14 17:10                                     ` Suren Baghdasaryan
2023-02-14 18:13                                       ` [PATCH v3] " Munehisa Kamata
2023-02-14 18:28                                         ` Suren Baghdasaryan
2023-02-14 18:29                                           ` Suren Baghdasaryan
2023-02-14 18:55                                         ` Eric Biggers
2023-02-14 19:13                                           ` Suren Baghdasaryan
2023-02-14 18:37                                       ` [PATCH v2] " Munehisa Kamata

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='CAJuCfpECvLiEdp+VfDo=_ZmhakEbtL2JzcwDfFahUk4XBOYNpg@mail.gmail.com' \
    --to=surenb@google.com \
    --cc=ebiggers@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=hdanton@sina.com \
    --cc=kamatam@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mengcc@amazon.com \
    --cc=stable@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.