Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7086897rwl; Mon, 9 Jan 2023 17:52:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXtmDTDhbwX9DXgzbi5GN1bkIUTkk307ZuSGPgByAFQ4oYf2HOHxSX7uR2nU5/2LeDmfz4rs X-Received: by 2002:a05:6402:538d:b0:487:2ce6:2b80 with SMTP id ew13-20020a056402538d00b004872ce62b80mr42141712edb.8.1673315567061; Mon, 09 Jan 2023 17:52:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673315567; cv=none; d=google.com; s=arc-20160816; b=iIt9ziaPBCz1lSz6jRs05y5eBOMK3s9I5kF/rwzNTd6md09vqY80dv60rJLTYZYgh5 bZqLY8OOm4svATQY5MquHwM/j/inQr8yNNTNP5YOJfDyIa4IeqV/r1cm6KVwbAo/IbRn IjP5NW4oSVRl8AQWdhFoWOWKbJyK20lKgYhVrdMhdUaqUXh9YIOKjzttQNtWOEJVrokh II1gR1gcgEZjwy/46p5DDuo1m1dJJq3f8+pZYV+P2VO9xEZc7vbQAY+w0XmcosWxBBVs XYhaa33g7y+uRkSgyWYSfxU8Pfkphr8bL8AdlEhQdJbqRlN0+7iC8ZIjy/LfzLHy9T6U fxvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=bCQEHkZFU92catxkBEDSkllxhfGBYSOPJ6bS5OX+np4=; b=HWrkT6tpuC3wOd+St2LH7BVlRJWj9u22DXMs/ISUNFdsqYRsnxAGOvs6GiazCMNeJQ jPhPZamGvnhADxOwG1IkmJKmNfA8YYhk+x4S5Dx+OVZFfWnExzyYnguYgoWEFqqkmV6r o6tzK93vIrGPS681XD4XCMJqG1FPJM4MevJJxBbqjZgK84byUTanUpaDuguMCMDiSVeZ MGByTB0JDOj046NkrEzSm9fJMxO8k2J5m4NqAOYdDlOf5OD8R3z1xdpdI6QbYL1LN8Ap ya3c2Ma5XOx0fF3tVW232YB5k8+8NZjTzFO0UWmfgsxoHeDMaoNgdvYSmI8Kiob0lY8O YhgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UL7JuP9Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a056402280700b00487b286dfd3si12305546ede.23.2023.01.09.17.52.34; Mon, 09 Jan 2023 17:52:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UL7JuP9Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230156AbjAJBeA (ORCPT + 53 others); Mon, 9 Jan 2023 20:34:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230039AbjAJBd6 (ORCPT ); Mon, 9 Jan 2023 20:33:58 -0500 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05FC8395FA for ; Mon, 9 Jan 2023 17:33:58 -0800 (PST) Received: by mail-yb1-xb2b.google.com with SMTP id e21so10376012ybb.3 for ; Mon, 09 Jan 2023 17:33:57 -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=bCQEHkZFU92catxkBEDSkllxhfGBYSOPJ6bS5OX+np4=; b=UL7JuP9Qd87W93pYEySBGGXP/+5qmGlzT4yaZBTwaELe4YUCPteNRNGqWjcBOqaHB8 a7C2/rl1S6SS5Ie2sNWnfcszK6rVpC0/po53m5swA3G/l6V+7vWsJF57Gnwr/iqkNqv+ PMBqLoOZf3EpNhSmN2sNYOzl9ciKkCPf/OQ8pvLU4vcbFlDAs0bYiTCI3Mm9S3wWtHpJ BKOMvpKZk1eoiRILLlWV8TXFRRYB3PqdPQuM0ANR7NtwBG0HrvpVqnFpUkH57ivZ6Fn7 gRR5GQ6sJNufqc7C0RXdThcL0HDUOyMtyZj3DbDR9tYCmXT/98nFrSA6O+lM1W0DCSiI vPbg== 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=bCQEHkZFU92catxkBEDSkllxhfGBYSOPJ6bS5OX+np4=; b=yPqA3C6cz21Ok8L8sokgmW8q6oc/HHHiYhjyDh/3Bxyq6FGDnGWscftxUrdySIzR6N mnm3s4/tQBA5xECBlv4VIohUocU4U/y+7Gcp434jPtQ2Qnp7A9I2e52KLbbWIimbAzYU lSAj73934F8d1VT0YYFn55S4JZ4kK0+kb0OVF1ArgIfxgrt83uLj+zSuPFPPQEf+3OnU 0ML8uf6vZDy3RcSoFwe8x4NBcREbwApHv/nggvr0A0OIMoMDFKWda7TLRToj/bQcZLXn co8mluJfIHWUKy7phv6BBNo3mNZkPD+iBQ6kJ3KXLZtLFkgzs3li/3VZJr6N1SG5D3ci Fo8A== X-Gm-Message-State: AFqh2koulTeHaG94N/sn2ByuCugmcwQD3m7C0RTuBuDviXKqplom74dH UIWCqydL7FAkuR928UtlKKnDjVM07rfbD7uKRflE8iRvf6fHJShR X-Received: by 2002:a25:fc1:0:b0:7b9:66ba:4421 with SMTP id 184-20020a250fc1000000b007b966ba4421mr1294503ybp.340.1673314437033; Mon, 09 Jan 2023 17:33:57 -0800 (PST) MIME-Version: 1.0 References: <20230107080702.4907-1-hdanton@sina.com> <20230108222548.698721-1-kamatam@amazon.com> <20230108234917.5322-1-hdanton@sina.com> In-Reply-To: <20230108234917.5322-1-hdanton@sina.com> From: Suren Baghdasaryan Date: Mon, 9 Jan 2023 17:33:45 -0800 Message-ID: Subject: Re: another use-after-free in ep_remove_wait_queue() To: Hillf Danton Cc: Munehisa Kamata , hannes@cmpxchg.org, ebiggers@kernel.org, mengcc@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. [1] https://lore.kernel.org/lkml/20220111232309.1786347-1-surenb@google.com/ Thanks, Suren. > > Hillf