Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2173235rdb; Thu, 7 Dec 2023 23:32:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFK6YJT/0Y+jxlNLbJHCVZPIp5T+4W4S3vdx75uE/ROfrwfi6ifETTLYV18p0SSodm+974l X-Received: by 2002:a17:902:be14:b0:1d0:7c75:d483 with SMTP id r20-20020a170902be1400b001d07c75d483mr2952380pls.91.1702020769168; Thu, 07 Dec 2023 23:32:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702020769; cv=none; d=google.com; s=arc-20160816; b=glIaxQSJ8AiU1TiNjhG1dNaqHsX0zmbJzG5mZK84e8Wcxq56hgCjymX/YbTvhLcHDH 4eJamUoihnexJ2xTfAcr/qtZkKGIf1kxaYgnj3husQRCBeYUSCkbGLHm5fvmstnidviY a/ggkVYutZ0gDGDqjZS0PMThOUi01cG3EeWt0alNnmHysxVJuXRFjLqK7pyUhD/KplOa s4gO9N1D0LKQMYJ4COxm5iI9+PMB4ga6xsmEwptm/DGJHWV3gClxKx7/3Y/E09ot6qMZ aAGzLuYTGrh9CvAp19rb9Zp3wfB6mqV7rr+mQyl+/8GTvMqYiv62/PbyIivrG3DhZH42 NppQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EjJS8HSQDSnXrxZ5dUx3kPD9L3rXlLFUfqrUorHps48=; fh=7Vq5JohoAajBxJ9urAArifpQ/XOy3z+sbqZD3TrFarc=; b=j1FVz6c1pzz83VOTSUOyKIBWzc6QcPzFFqSorE4qh3lZC7w3zF57d/CV5MeqpVEk9z QdT6IrOCEABNcjK48HkZGpMijrYP3bp6UcYiLmv7pIC+pMu8jV4o0U13N+CjdCDs8cR4 PqCNRXgXdAxHRfBd2nHElUxI/sAQf3Bfl1XNlfNGwBVg86cq70xSyTs1dtsI83wLxyab nlP5BiUzaAQKGbbqCbP9bj5IzakpU26IyznxVyr9XPCXKQuB0vixftjlFQD9jcV5LHE6 VORazsoFJwofvCzXmpm0XfPkGOVsUq2kbUoq0HSXeEp8otuaa4vCbHKIZEls//zA7EQo dFTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FDZLJDJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o18-20020a170902d4d200b001d07c3e89fesi1135930plg.478.2023.12.07.23.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 23:32:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FDZLJDJF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C189480EBCCE; Thu, 7 Dec 2023 23:32:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235801AbjLHHcd (ORCPT + 99 others); Fri, 8 Dec 2023 02:32:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573274AbjLHHcQ (ORCPT ); Fri, 8 Dec 2023 02:32:16 -0500 Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EA4019B4 for ; Thu, 7 Dec 2023 23:32:16 -0800 (PST) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1fb9884ee04so1214676fac.2 for ; Thu, 07 Dec 2023 23:32:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702020735; x=1702625535; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EjJS8HSQDSnXrxZ5dUx3kPD9L3rXlLFUfqrUorHps48=; b=FDZLJDJFun85ISpLG78cz5DUW62C7JMJx7JNPrFUNlo9cJ+lZHwJhlrTEgki8zaZFx B+XHvBtLWwHih5vQ78iNw2oDWo4B9Uo3tAH/ImccpURjwpFDQnqhzVdi410gB4Cfznv5 EzWHwnDpvJwA7Z4QVSa+2SCmjfG++lxhmxcNt0O4ofADrYRTvZW+Iq1AzPJ9VmezuJpr J1q5x4ILM8fXM0t+BLUFIq1m2vq3d0XpjpHrgr3Nsg9jDlu1r6exVOZFJb9cA6l5KGUT XEFrBymlriCji5VFHMGq5p3QxyKrpytr02DjC9FDBhQvxT00RIDVglrgCic6LbSVBY0w wsgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702020735; x=1702625535; h=content-transfer-encoding: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=EjJS8HSQDSnXrxZ5dUx3kPD9L3rXlLFUfqrUorHps48=; b=Nt7UOT2mbR6oiYKRAVZr2KIci/Q2JqxTSLG19jR2E3e0zdWsJ2aS+qG+ErptxC5pZ+ fbVDGAt2qToES9pGpsTRhL9klSgCfIMqNF8mrkAaBNF/1DM7TakFZCI4BlydNg3p8W88 UUzCDQRcYZ6of+CNefLaQgNKLmt9WoZDMTaaTvwVtQbsD4OC24lqL9bxjzAGcxITIcnK nOF65Hv2gMFq6+D6VTi6YT4O5LJitUDhjF1ufz254BKKM6EJh+PAlfcdaihmMVlsKX2b z3PDkjniH0IuiINMPkiZBL1Qgg3gJlmkJvtXGhlejrZio+WlnsWnuo3JR/iny+kkoJrY rbww== X-Gm-Message-State: AOJu0YyQ6V9avBrAGnOz15v9Y4hbQhBNcBcvWFlZfPEaVP+wh+AnGGUY muc/hEvgdAG1cppDUb2tnExk528KXHk02ZQaQnVe/wRkqCQ= X-Received: by 2002:a05:6870:9728:b0:1fa:df7d:754a with SMTP id n40-20020a056870972800b001fadf7d754amr4424706oaq.5.1702020735716; Thu, 07 Dec 2023 23:32:15 -0800 (PST) MIME-Version: 1.0 References: <20230902115026.13460-1-qiang.zhang1211@gmail.com> In-Reply-To: From: Xuewen Yan Date: Fri, 8 Dec 2023 15:32:04 +0800 Message-ID: Subject: Re: [PATCH] workqueue: Fix UAF report by KASAN in pwq_release_workfn() To: Z qiang Cc: Tejun Heo , jiangshanlai@gmail.com, linux-kernel@vger.kernel.org, guohua.yan@unisoc.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 07 Dec 2023 23:32:46 -0800 (PST) Hi qiang && Tejun On Tue, Sep 19, 2023 at 7:30=E2=80=AFPM Z qiang = wrote: > > > > > On Thu, Sep 07, 2023 at 10:13:23AM +0800, Z qiang wrote: > > > > > > > > On Wed, Sep 06, 2023 at 10:12:34AM +0800, Z qiang wrote: > > > > > Flush the pwq_release_worker is insufficient, the call_rcu() is > > > > > invoked to release wq > > > > > in pwq_release_workfn(), this is also asynchronous. > > > > > > > > But rcu_free_pwq() doesn't access wq or anything. The last access i= s from > > > > the work function. > > > > > > The rcu_free_wq() will access wq->cpu_pwq or unbound_attrs, > > > but at this time, the kfree(wq) may have been called in alloc_workqu= eue(). > > > > I'm not following. The only way alloc_and_link fails is if > > apply_wqattrs_prepare() fails and if prepare fails, none of the pwq's a= re > > installed and pwq_unbound_release_workfn() won't try to free the wq as = the > > pwq's don't have any reference on it. So, if you flush the pwq release = work > > items, there can be no rcu_free_wq() in flight. Can you please try to s= ee > > whether the problem is reproducible with flushing? > > > > you are right . sorry, I ignore if apply_wqattrs_prepare() fails, > none of the pwq is installed, > the install_unbound_pwq() is not invoked. I will resend v2 and test. I want to ask a question, why delete the v1? Although add the flush_work, the release work would release the lockdep key= , and at the last of alloc_workqueue, it would also unregister_lockdep_key tw= ice. And other question, why not free lockdep and just unregister_lockdep? 4136 if (is_last) { 4137 wq_unregister_lockdep(wq); 4138 call_rcu(&wq->rcu, rcu_free_wq); 4139 } I would really appreciate it if you could help explain it. Thanks! BR > > Thanks > Zqiang > > > > > Thanks. > > > > -- > > tejun