From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49187C54EBD for ; Fri, 13 Jan 2023 17:52:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9960D8E0002; Fri, 13 Jan 2023 12:52:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 946778E0001; Fri, 13 Jan 2023 12:52:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80DD08E0002; Fri, 13 Jan 2023 12:52:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 707B78E0001 for ; Fri, 13 Jan 2023 12:52:15 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4721A14055C for ; Fri, 13 Jan 2023 17:52:15 +0000 (UTC) X-FDA: 80350519830.24.8A12015 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by imf24.hostedemail.com (Postfix) with ESMTP id B9106180012 for ; Fri, 13 Jan 2023 17:52:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=spT5XiaL; spf=pass (imf24.hostedemail.com: domain of surenb@google.com designates 209.85.219.173 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673632333; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xeo8qLgvq3RAyROFUCt35wkutSfWDp8XJ4vtPJZ25wQ=; b=BEIJLRTk8gCXjXBWY6Bg4BFPEynJEd1tDmUbH3rz9/qA4ryxcDtXL99TrFny5xlJacsfSq w85O6tOEyo7tRS662WNYugnOcBBKnrT8/gkrM2At2qpVL4bmY+kYuOZPjvq7j3TP+f+twP qZPMXBuu+qJs0C/c407jSCUUWlsuRPc= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=spT5XiaL; spf=pass (imf24.hostedemail.com: domain of surenb@google.com designates 209.85.219.173 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673632333; a=rsa-sha256; cv=none; b=7sgfaE8YBPSfViudHayxkTX6iYAkwx9SrdJZgoaZ0ftzLSEUZogcRfHiqb/BndDfyRi0Dx fVxzIyTNGnpTIbC1vRIgwXBYXSDph/c7OdtGbscR5ZsrtixLktOMl5Y3ndPf1DJlsKHcLH lPRy2AZwnQ90BSms5iWpS6nYQMdDfAs= Received: by mail-yb1-f173.google.com with SMTP id g4so23247497ybg.7 for ; Fri, 13 Jan 2023 09:52:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xeo8qLgvq3RAyROFUCt35wkutSfWDp8XJ4vtPJZ25wQ=; b=spT5XiaL0xTK/sMQVdD9NnklrwAgoXK3aun0hemMPSyc2CPUZD08GVesdpQsjm3d8D UeBTZCDzbTkq7SxeWvGB4hwMCrJX86W7S2CHWDDXgLVM2xZBZFw3nn6gFUeUHIxbiyIX gqixKmK+aORuZUp8Wie8OYLH5L6TK3bfT0rqVp9UPD1Ez//Ghs4txvCyLQMhsrqGohTJ bejCHVrade0Rxj2u6bYgmkRBpTNkmWyVMgvK274+YZghm0aTNMN7U22ZdqlUKLAWu7Pr L9QdprBSrEzDYqgyDc945Fm4hkbwHaO9deXzeaTt0kTncG2fQo1e34Zwt2IBReSdghpr UKzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xeo8qLgvq3RAyROFUCt35wkutSfWDp8XJ4vtPJZ25wQ=; b=DDwAJYCX5JdcMJL3o7ZsxG5VoVykBF2BqXqYk/291k+6GrAu8035wJsh/XozJWqVgK FpJK9IDjNCD7nztsbYFurgfEomtzFMZaDQ2/Jrx7qIowwD2G3Khi+RgXvpNuxEign+u5 h4zPEyxfnGAv5XF+h82ZUSIT42x3attm5iQquUtKW9lkEH4iY9qHU6nwYh3WUm9aCLlq ZI4MN76MSzsEVueA9zw3j+Xxw9uFm9guqQ+5ad7U9oEfVXvVFFV1DvR1APACTgCori4I W8/DvR9xxoaXsw1l4E66xbsx7JNSZlOunbzkbCdsu/EV5scMBkJB/kWrVt5QCCPv6WUq QdZA== X-Gm-Message-State: AFqh2kp2NUhZKqjN32+w7f9sRKgmBbT5iT9mff05cZGi/pKe39gAt+ur ziFAjgnfoF5TUh2UYPurzbncrlphd8NC/HvGG3P4+g== X-Google-Smtp-Source: AMrXdXsQ8E6MeaHNSVCi6nZJNWDRD1UukV9PyuUENt+uWBToTATvEIb46yk8oi/VMFhJ0GLP3X9kCsnvKTyJEYWsnaw= X-Received: by 2002:a25:bdcc:0:b0:714:2cb3:2450 with SMTP id g12-20020a25bdcc000000b007142cb32450mr8305881ybk.431.1673632332567; Fri, 13 Jan 2023 09:52:12 -0800 (PST) MIME-Version: 1.0 References: <20230113022555.2467724-1-kamatam@amazon.com> In-Reply-To: <20230113022555.2467724-1-kamatam@amazon.com> From: Suren Baghdasaryan Date: Fri, 13 Jan 2023 09:52:01 -0800 Message-ID: Subject: Re: another use-after-free in ep_remove_wait_queue() To: Munehisa Kamata Cc: ebiggers@kernel.org, hannes@cmpxchg.org, hdanton@sina.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mengcc@amazon.com Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: u5hohgt7mgiyx8mh9y3nfuq7r8a69ak1 X-Rspamd-Queue-Id: B9106180012 X-HE-Tag: 1673632333-881038 X-HE-Meta: U2FsdGVkX1+Tu1o6+UsEZskSA8QzX3IIqKg6bLVJP+ks+ay6jSvFx23vFCa9hvOV+M74pqHjNMSJJt4f/6NJpn3QjU0qxw8cMWpibp8boHQ3qVLDN+zvSWqXFOaIv7/HQXq52+Eo3o8gHEegj5lH0lif8g/8FKunwe7E2umg09GeaeauMA++Hz8lnr3EGSLlme+CHIXExYuCC9wD77w711VA7dLFbw+SKjZT9i86G9rD6sH6uBSF2HhT+fWg9mmtM7AKEWWJjMTO6ujEfOAt2v4473SdhWS0ZxvWIdo00Aac/aTWY8EucY+XB1uupSMm5GxOCxXNP4A1hj+YUtQioYXu78iXC3GYlh/awhKcv2iGQ4hTweZMIpzcEFbWFmnmDuxMdd479dyfp9yxIKQM+0vyD9S3e5RBho37tbRrRi6KLOxFluw8GjtK9mUlJSHNchpl7BhSIV9jyTw2GvV25386FR08p2eW+Eg1m6FMnJqnyVJODnbTQ6lpkTvwTu+S6cFA+1qUMx8R7Y97ZBhfO9BJDB02K3JHvRCSwMI+8k4PYT9ETUNX8TLNHIfKfy2GayjHqReCUHUG42R/SE7ZaOxmgclt8iYtWGCYG3Kps6YyHAjHhN+AIJ/DW09vq6om2/cqnIKj3lpwCrprQWBeGITeZnaqUJYS52kvgnqR5oAJS0lbQRLY1JBoyxhmiDFkXAl33bUErXAtlC3eN/vgDUxxyQcKq1aPvoR+cis3PoTJYi5yTkia+WKjWta+lRAfg6h2lL3mIwl1tNkd2NV89CT7eLF9+Apmig5eKsKbHWSG1Y8vFMmlHDxtBR9csUYJNasAyw8GOV5pgW8C1iy9hG0OP+5xOz2dfwwPvXK9zAOR+LPCkUVkVfYKgWSFz0KLxldoz5IZnZ1C+9RfO9ThSWIumdQXpWnlbfHgutflQKXhR/UEEiIxmNt6A7r0+5ycqH8ZhXqUokwT9M3zqq/ BQTfiC3h 99EERmIOBAMxqPlCaX3n/sRt3UdtjBfjcFkwSnYM3sIurAHgQbUILUNdm3A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000175, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Jan 12, 2023 at 6:26 PM Munehisa Kamata wrote: > > On Thu, 2023-01-12 22:01:24 +0000, Suren Baghdasaryan wrote: > > > > On Mon, Jan 9, 2023 at 7:06 PM Suren Baghdasaryan wrote: > > > > > > On Mon, Jan 9, 2023 at 5:33 PM Suren Baghdasaryan wrote: > > > > > > > > On Sun, Jan 8, 2023 at 3:49 PM Hillf Danton wrote: > > > > > > > > > > On 8 Jan 2023 14:25:48 -0800 PM Munehisa Kamata 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 > > > >