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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A17ADC636D3 for ; Thu, 2 Feb 2023 21:11:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbjBBVLv (ORCPT ); Thu, 2 Feb 2023 16:11:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232196AbjBBVLt (ORCPT ); Thu, 2 Feb 2023 16:11:49 -0500 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48C2F73767 for ; Thu, 2 Feb 2023 13:11:48 -0800 (PST) Received: by mail-yb1-xb2a.google.com with SMTP id i2so677328ybt.2 for ; Thu, 02 Feb 2023 13:11:48 -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=j+CqMtFrVSGkYiD3673aMvxsTntB2I4HLVlj0tiHNNI=; b=CnXXTWGbi5MfdiGnHvkf0MWLYlJ/KDP9fWsDIjlvZ8/zcosRgAlSxNOwf3hzUd0Ky/ EE8s0lpWmM5P0/d4HqZs6wpEXwUpLd2hgQ97yZRHONrj2x3FiI7c3nXdrndTKbp0xq+S sllzBBNnXErmDfXPo1Dub1ZTMsPWgoHAk98QPByIyPrd7SBFtorjpFkKXgOZ3/QMH75z NFQ5nbbqcotZid+T1RaUMDRM7HQqEiHaTtLRE2+70QbdyHSLN0xThX06XWXu55efO/7a kQVySGOuMwbRMu3SfC+SqQBiJiLCM/sJyKEOCKrwjGUwS/Rdx7feRXMYgLvweeBxZiPt pbaw== 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=j+CqMtFrVSGkYiD3673aMvxsTntB2I4HLVlj0tiHNNI=; b=mSUUwk28GoAtZHxHlOc72RYiGrWYr6AnIA2z4A26jOScIlAvudGYXgayc0vyMfxAUz HeYmRwNE152UUIEM6OBrU2rPrrokGDv4u740K3fI2YJsW1g9gl7F0I0IXx4TbcHyo9gh 0DlP9cvOSeIJmpccGz1sRgRo3kt2psH7bXGF+zwnXQM7eKccjTbc2yu8PnsY1C3ShR+U yW5WDNORu8DZ8bVbo8rffqscifHxhbTDbFG7PllALk9gAFD+Wzp7Vk/BOr03vTjZ29A5 4qnnBgAhmqlNx8frlVzm8erhVCO5vFKmafquZMcLYLQ01grP18ZzACuIdFfbPbynGrJw rM8A== X-Gm-Message-State: AO0yUKU+gm5PUgnaoYUHJ16wLxlTmK1rjO8LXkUVfCuY14w4uRVzpozR 1dY1klHfu4Sum0YjnJ9+4jVia3DPrEyipVsZBOi80DEBIGC94dTLh/g= X-Google-Smtp-Source: AK7set8dW/3ELqgHnqlRkiGKJao9L8VMiVvIhM/4TdKtluEAMjhR7nAYm8zA9yi2w+T372MxrWk7KDkhWrmxtayFHUM= X-Received: by 2002:a25:5007:0:b0:80f:4da9:d5dc with SMTP id e7-20020a255007000000b0080f4da9d5dcmr846491ybb.431.1675372307335; Thu, 02 Feb 2023 13:11:47 -0800 (PST) MIME-Version: 1.0 References: <20230202030023.1847084-1-kamatam@amazon.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 2 Feb 2023 13:11:36 -0800 Message-ID: Subject: Re: [PATCH] sched/psi: fix use-after-free in ep_remove_wait_queue() To: Eric Biggers Cc: Munehisa Kamata , hannes@cmpxchg.org, hdanton@sina.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mengcc@amazon.com, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 1, 2023 at 8:56 PM Eric Biggers 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. Thanks, Suren. > > - Eric