From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D1B9369D75; Wed, 20 May 2026 17:55:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779299730; cv=none; b=stnHXIEqOB9PQzgDzdh1UwxH0WXCW6jaPqYlZNhVNV0+IpnwJMJSPiDCBzOzoQVL2UPreZmhc8UY/9n7qlpOQ9ZqcQ5zs/nAcPAIonyc7Unv+BD1LyveBkGWcLjLIWsh3grQkjNYujNUi7AaC3Qv6RAkv69a05x1jfDTtCo2nDY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779299730; c=relaxed/simple; bh=AT2EJvtHSaFNUjhahKoDVdrEShXfID7rWIaFc0fqge8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K4I7839ISevSlC6p40FqvSCLej/b25CgV8Y5nc3Zf3zMZeOqlC3ZNkWoYOQTWdq0mu9PDsfXQ0G/g8ZwFS8q2v2MUWXhpVK33OQ+kvyFnAXDNqAhMb3NXmqsNNjBQtCijrMb8UM/HOD33PdjYpsa8NmvQ07UWaqlNV6j4PR9HAc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N9bj5SmQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="N9bj5SmQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FCA61F000E9; Wed, 20 May 2026 17:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779299729; bh=A8LUZm7SHI52DBzYegpp1xkO46vpFLg+TJYyv6NdzJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N9bj5SmQoNq6VpH0fxKlxem8M2HmYzt7rJlF5elZeG/HGMMfQ2jBxMejzbNZg7TE8 fX2I3aFuh4UpgjdYcMM/5+n0HhIINgqOMzPDbOwEs+95QpHfXT6MhMQ19NNmazqSwC aexxycJ+ebU0vzFP5bk4xsNacXgZL9OWMlYVDGYE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable@kernel.org, Breno Leitao , Tejun Heo Subject: [PATCH 6.18 881/957] workqueue: Fix wq->cpu_pwq leak in alloc_and_link_pwqs() WQ_UNBOUND path Date: Wed, 20 May 2026 18:22:44 +0200 Message-ID: <20260520162153.672073039@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162134.554764788@linuxfoundation.org> References: <20260520162134.554764788@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Breno Leitao commit 0143033dc22cdff912cfc13419f5db92fea3b4cb upstream. For WQ_UNBOUND workqueues, alloc_and_link_pwqs() allocates wq->cpu_pwq via alloc_percpu() and then calls apply_workqueue_attrs_locked(). On failure it returns the error directly, bypassing the enomem: label which holds the only free_percpu(wq->cpu_pwq) in this function. The caller's error path kfree()s wq without touching wq->cpu_pwq, leaking one percpu pointer table (nr_cpu_ids * sizeof(void *) bytes) per failed call. If kmemleak is enabled, we can see: unreferenced object (percpu) 0xc0fffa5b121048 (size 8): comm "insmod", pid 776, jiffies 4294682844 backtrace (crc 0): pcpu_alloc_noprof+0x665/0xac0 __alloc_workqueue+0x33f/0xa20 alloc_workqueue_noprof+0x60/0x100 Route the error through the existing enomem: cleanup and any error before this one. Cc: stable@kernel.org Fixes: 636b927eba5b ("workqueue: Make unbound workqueues to use per-cpu pool_workqueues") Signed-off-by: Breno Leitao Signed-off-by: Tejun Heo Signed-off-by: Greg Kroah-Hartman --- kernel/workqueue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -5619,7 +5619,9 @@ static int alloc_and_link_pwqs(struct wo ret = apply_workqueue_attrs_locked(wq, unbound_std_wq_attrs[highpri]); } - return ret; + if (ret) + goto enomem; + return 0; enomem: if (wq->cpu_pwq) {