From: Suren Baghdasaryan <surenb@google.com>
To: Munehisa Kamata <kamatam@amazon.com>
Cc: ebiggers@kernel.org, hannes@cmpxchg.org, hdanton@sina.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
mengcc@amazon.com
Subject: Re: another use-after-free in ep_remove_wait_queue()
Date: Fri, 13 Jan 2023 09:52:01 -0800 [thread overview]
Message-ID: <CAJuCfpEH7kC=S8S_SRLW-X483kpaL4xdn5b35Ou08V7b56QdJA@mail.gmail.com> (raw)
In-Reply-To: <20230113022555.2467724-1-kamatam@amazon.com>
On Thu, Jan 12, 2023 at 6:26 PM Munehisa Kamata <kamatam@amazon.com> wrote:
>
> On Thu, 2023-01-12 22:01:24 +0000, Suren Baghdasaryan <surenb@google.com> wrote:
> >
> > On Mon, Jan 9, 2023 at 7:06 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > >
> > > On Mon, Jan 9, 2023 at 5:33 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > > >
> > > > On Sun, Jan 8, 2023 at 3:49 PM Hillf Danton <hdanton@sina.com> wrote:
> > > > >
> > > > > On 8 Jan 2023 14:25:48 -0800 PM Munehisa Kamata <kamatam@amazon.com> wrote:
> > > > > >
> > > > > > That patch survived the repro in my original post, however, the waker
> > > > > > (rmdir) was getting stuck until a file descriptor of the epoll instance or
> > > > > > the pressure file got closed. So, if the following modified repro runs
> > > > > > with the patch, the waker never returns (unless the sleeper gets killed)
> > > > > > while holding cgroup_mutex. This doesn't seem to be what you expected to
> > > > > > see with the patch, does it? Even wake_up_all() does not appear to empty
> > > > > > the queue, but wake_up_pollfree() does.
> > > > >
> > > > > Thanks for your testing. And the debugging completes.
> > > > >
> > > > > Mind sending a patch with wake_up_pollfree() folded?
> > > >
> > > > I finally had some time to look into this issue. I don't think
> > > > delaying destruction in psi_trigger_destroy() because there are still
> > > > users of the trigger as Hillf suggested is a good way to go. Before
> > > > [1] correct trigger destruction was handled using a
> > > > psi_trigger.refcount. For some reason I thought it's not needed
> > > > anymore when we placed one-trigger-per-file restriction in that patch,
> > > > so I removed it. Obviously that was a wrong move, so I think the
> > > > cleanest way would be to bring back the refcounting. That way the last
> > > > user of the trigger (either psi_trigger_poll() or psi_fop_release())
> > > > will free the trigger.
> > > > I'll check once more to make sure I did not miss anything and if there
> > > > are no objections, will post a fix.
> > >
> > > Uh, I recalled now why refcounting was not helpful here. I'm making
> > > the same mistake of thinking that poll_wait() blocks until the call to
> > > wake_up() which is not the case. Let me think if there is anything
> > > better than wake_up_pollfree() for this case.
> >
> > Hi Munehisa,
> > Sorry for the delay. I was trying to reproduce the issue but even
> > after adding a delay before ep_remove_wait_queue() it did not happen.
>
> Hi Suren,
>
> Thank you for your help here.
>
> Just in case, do you have KASAN enabled in your config? If not, this may
> just silently corrupt a certain memory location and not immediately
> followed by obvious messages or noticeable event like oops.
Yes, KASAN was enabled in my build.
>
> > One thing about wake_up_pollfree() solution that does not seem right
> > to me is this comment at
> > https://elixir.bootlin.com/linux/latest/source/include/linux/wait.h#L253:
> >
> > `In the very rare cases where a ->poll() implementation uses a
> > waitqueue whose lifetime is tied to a task rather than to the 'struct
> > file' being polled, this function must be called before the waitqueue
> > is freed...`
> >
> > In our case we free the waitqueue from cgroup_pressure_release(),
> > which is the handler for `release` operation on cgroup psi files. The
> > other place calling psi_trigger_destroy() is psi_fop_release(), which
> > is also tied to the lifetime to the psi files. Therefore the lifetime
> > of the trigger's waitqueue is tied to the lifetime of the files and
> > IIUC, we should not be required to use wake_up_pollfree().
> > Could you please post your .config file? I might be missing some
> > configuration which prevents the issue from happening on my side.
>
> Sure, here is my config.
>
> https://gist.github.com/kamatam9/a078bdd9f695e7a0767b061c60e48d50
>
> I confirmed that it's reliably reproducible with v6.2-rc3 as shown below.
>
> https://gist.github.com/kamatam9/096a79cf59d8ed8785c4267e917b8675
Thanks! I'll try to figure out the difference.
Suren.
>
>
> Regards,
> Munehisa
>
>
> > Thanks,
> > Suren.
> >
> > >
> > >
> > > >
> > > > [1] https://lore.kernel.org/lkml/20220111232309.1786347-1-surenb@google.com/
> > > >
> > > > Thanks,
> > > > Suren.
> > > >
> > > > >
> > > > > Hillf
> >
> >
next prev parent reply other threads:[~2023-01-13 17:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230106224859.4123476-1-kamatam@amazon.com>
2023-01-07 8:07 ` another use-after-free in ep_remove_wait_queue() 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 [this message]
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
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='CAJuCfpEH7kC=S8S_SRLW-X483kpaL4xdn5b35Ou08V7b56QdJA@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 \
/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;
as well as URLs for NNTP newsgroup(s).