Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2190209rdb; Fri, 8 Dec 2023 00:18:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDTkPVgNXyTJvtQ1XesLSny2KG5VOZWyvvZpLYhp+S2+WyMvr95H8X9Y12ABZ1hqRUs2sv X-Received: by 2002:a05:6e02:1a65:b0:35d:a38a:fc83 with SMTP id w5-20020a056e021a6500b0035da38afc83mr2378436ilv.67.1702023511187; Fri, 08 Dec 2023 00:18:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702023511; cv=none; d=google.com; s=arc-20160816; b=kZeuvlRcjL3dP+dvfP7hgjwTIbBZDK8Xg6uU8oI/mLlQ0HRJ9TWGrRIjjOrG0PpBo5 sJUsz9hCKVomD9BBZK2Wch7c/oRG7Mo/9w+irq9RHcGJ0qaFG7z0xSQkJXUI/T4kJbVH ZIxNIIxJM0R/TgE8db5MNoEkDB8PBMHjVtkvaVgT4IWkK1gt1b0ZGzz+kmDBZW7n3BVM PR6XRBdvGH7TknGJ50lJi3LM4RDdaISPEsCgpYjyfmn8OYC95J+oxrfGnWy6/DdPYUYI js/5Pvvtp9Qxhm2ayeNaA8S18Crqv8gmxrsYJ8L1Xce/lrd57QkVRxBX5NUHRzTNztY1 sYUg== 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=57GTQbkkoTIYsX8AsUQsI3kUtcdAazbeehTKAb0YI0U=; fh=g+V4MklwSpLhMjFKcCDgctB8fntbjNhH8glTcEU1zS0=; b=C5/ysUvP4X5Bpbpw7X9z3axrvKujM/HkMr4XsMxxfEgWl0WqImpTBkeaBQfkyUPtPI zDdNh99sgwbJWO4Zdc0jy1qH9Z1XTAlNq4Sug8YhoPEg/x8AhhSEybiuZ/z7p+pLOEGW pAeoWQ1hZL7hlZjU35BrwIp9PWqBeUf5mxhUzcaNMAEMYPoYaw/CwcnGPO+UkCdSdx6c FXwVb5bPZzRoUQy2QyK7x4XOwcansklD8rJ2bpWijUwwCg632P8vahE0+e3T6hjUNJnY YwAkAZRH77BtR1kXOfU/ZWpx4QUWc6ug77yPfAYUeAcfkyme7eKHwMgWraKoDsNu9dxA 3jVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WlRmXHRW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id bz39-20020a056a02062700b005c67e10f240si1212595pgb.312.2023.12.08.00.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 00:18:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=WlRmXHRW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 8384A810835C; Fri, 8 Dec 2023 00:18:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235752AbjLHISM (ORCPT + 99 others); Fri, 8 Dec 2023 03:18:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232974AbjLHISK (ORCPT ); Fri, 8 Dec 2023 03:18:10 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18095B5 for ; Fri, 8 Dec 2023 00:18:17 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2866951b6e0so1825074a91.2 for ; Fri, 08 Dec 2023 00:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702023496; x=1702628296; 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=57GTQbkkoTIYsX8AsUQsI3kUtcdAazbeehTKAb0YI0U=; b=WlRmXHRWyCxY6SBJS/B3JMPrx6TavSKtlX4DHcQuhjyK9HowKXYHjXPSIlsP/RhVXX ESNIW14g9N3M2YYbjagHONLq7pcxy3st6coCWQSMIKMCZEIwPA5J1sgHMdiY7je+d33r aSHrjy/hfp8Xxi6HKhuDuUb5xfMqv1+BcJworPYF+Z1pX+rrJsndfWBNQfuGR7Sb32v9 k8wDjUWKlviXUQHvGWXZiyLXu/1DOebcES/fdUB74QwiLefPl+d0hGhaZ7Su6kMvu5LF +jYuEEKkZd5OOHptN2YqxBOSEnRaSquoq2Rya/xpa/BVTu0lPQ0ZEUv0ir5Fmkla3eC9 9L/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702023496; x=1702628296; 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=57GTQbkkoTIYsX8AsUQsI3kUtcdAazbeehTKAb0YI0U=; b=qaEzv9azAk2ZqnoNYYJMA6KpVjs/zRBD/MaCHCi3InaQ2c8/bhy9wgrxVFl5Ji031r jeKnOUpbKtmB3FSHe69aMb2QcO7uC53C5PQtqtN4Hpcp0oepRI4w+ImNXtM8vbViz5Ew cr4HsIJa2eOD9uPWv1f3eXzevo88QrtsJ8IGZWlWxF/ri9XHtxQrEE1lGyqZ+5prgOMp pHBRjaVw3Weag0fVseVrQ53D3s4r9Xgjj5r2tFrzB919l+ygoXN2Jp2Th1LQDaC0oS5B /iQZ9D9l5ZPm+8Y62PKKQwX+DZMA/ApvUm89mmcJUjjVLxgvYXe5+4/VGNQzcxcJC5n/ jgmw== X-Gm-Message-State: AOJu0YyS8XEshoAHOCMJLS636shKRrfA1r5WzAtmzUdfNN9rR2/qoVXa XVmRXufQ/zdBmcOQecmss+LDy4wVwd5p9EeNpgw= X-Received: by 2002:a17:90a:780e:b0:286:ca3e:be8c with SMTP id w14-20020a17090a780e00b00286ca3ebe8cmr3855048pjk.90.1702023496234; Fri, 08 Dec 2023 00:18:16 -0800 (PST) MIME-Version: 1.0 References: <20230902115026.13460-1-qiang.zhang1211@gmail.com> In-Reply-To: From: Z qiang Date: Fri, 8 Dec 2023 16:18:04 +0800 Message-ID: Subject: Re: [PATCH] workqueue: Fix UAF report by KASAN in pwq_release_workfn() To: Xuewen Yan 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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 08 Dec 2023 00:18:28 -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= is 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_work= queue(). > > > > > > 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= are > > > installed and pwq_unbound_release_workfn() won't try to free the wq a= s the > > > pwq's don't have any reference on it. So, if you flush the pwq releas= e work > > > items, there can be no rcu_free_wq() in flight. Can you please try to= see > > > 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 k= ey, > and at the last of alloc_workqueue, it would also unregister_lockdep_key = twice. > For unbound wq, if apply_workqueue_attrs() return error, the link_pwq() w= ill not be invoked, that means will not insert pwq->pwqs_node to wq->pwqs list, that also means the is_last is false in pwq_release_workfn(). > 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 } free lockdep in rcu_free_wq(); Thanks Zqiang > > I would really appreciate it if you could help explain it. > > Thanks! > BR > > > > > > > Thanks > > Zqiang > > > > > > > > Thanks. > > > > > > -- > > > tejun