From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 B27D337BE66 for ; Mon, 27 Apr 2026 17:51:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777312289; cv=none; b=opZkE6zze5wHD8Rx2LT1znXNejU9HEn6pFWAphDEHVrK3/htUiV0oAVPPGPsfhcR/tnOjqIT5nFgVjpDkSKaFZISKTrrTTRgY75E0Z8LQFFuhJEu7DWwJQOAaD2RUIgBHeexWd/wiDHbAyeymU099rnbvOwVLlOWmS2zxEpuNOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777312289; c=relaxed/simple; bh=nvBAoetNf10E2DcsREoKaqUC6Ij4g+nCkGJfGoG0dkU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eQ3jy+bkJZiqD1ReCDuGAhLobNwo/F2WLnnosDiMS3x9UG2Sijn88WxDQWgrE3vLfxrx7FwDL1J+bmUOGzEPoEBvxfNYUbNzacIn0NIMaS2ecsCGuF1EtNw8F2mzc3s8CmbYGpFdfFxQRdMcBMydxTs9XCJRsxqnqQ9aaaxOFOs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CK0Xfb59; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CK0Xfb59" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777312287; x=1808848287; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=nvBAoetNf10E2DcsREoKaqUC6Ij4g+nCkGJfGoG0dkU=; b=CK0Xfb59/kI5uCLgVn+ffQAexmeMNgE9MlZQyt+f+xNXnknTmXw03+D1 OZXsInsgy4o/41ZbeQhl50sZy6g96URPhv1Y6yGG1DWnqL08PHUfKPRSj 7nTiG7aEuhHCI2rzUBFyl86qNXpg+PD8E1u8gTlbuPr8iPED8OQzpLwbU kdhxf43uHs10CWl5wgVXHuLnBHyU63UL8nni3UwXyweL2L/8cfyAHqCYV k0sApDVO18FGGgA+U9vmJNy5t5OBl6q0JBeXOEiHLsYIkgsZ/NLlQcOMw 97r+toMZHJv4wqAUk81jDxXPBLm1+p9N8n43nrO4ciDwDoxaOX/oUZMad w==; X-CSE-ConnectionGUID: yM4QXSFtTdmiVsSj0RjFwg== X-CSE-MsgGUID: JGF3PoTNTACLZN6HfTi4rQ== X-IronPort-AV: E=McAfee;i="6800,10657,11769"; a="103670787" X-IronPort-AV: E=Sophos;i="6.23,202,1770624000"; d="scan'208";a="103670787" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2026 10:51:27 -0700 X-CSE-ConnectionGUID: 4oo98l6cTCiocbp0zOKtgQ== X-CSE-MsgGUID: rQBDRHP8S2C7YtOLqfeAHw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,202,1770624000"; d="scan'208";a="257236456" Received: from fpallare-mobl4.ger.corp.intel.com (HELO localhost) ([10.245.244.2]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2026 10:51:25 -0700 Date: Mon, 27 Apr 2026 20:51:22 +0300 From: Andy Shevchenko To: Breno Leitao Cc: Tejun Heo , Lai Jiangshan , Krzysztof Kozlowski , clm@fb.com, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: Re: [PATCH] workqueue: fix devm_alloc_workqueue() va_list misuse Message-ID: References: <20260427-wq_fix_chris-v1-1-988649834b79@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260427-wq_fix_chris-v1-1-988649834b79@debian.org> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Mon, Apr 27, 2026 at 09:47:44AM -0700, Breno Leitao wrote: > devm_alloc_workqueue() builds a va_list from its own variadic > arguments and then passes that va_list as a single positional > argument to the variadic alloc_workqueue() macro: > > va_start(args, max_active); > wq = alloc_workqueue(fmt, flags, max_active, args); > va_end(args); > > alloc_workqueue() expands to alloc_workqueue_noprof(), which > performs its own va_start() over its ... parameters. The inner > vsnprintf(wq->name, sizeof(wq->name), fmt, args) inside > __alloc_workqueue() therefore receives the outer va_list object > as the first variadic slot, not the caller's actual format > arguments. On x86-64 SysV a "%s" conversion dereferences the > pointer inside that va_list as a char * and copies arbitrary > stack bytes from devm_alloc_workqueue()'s register-save area > into wq->name. The write is bounded by WQ_NAME_LEN but the > read is not, so this is an out-of-bounds stack read whose result > also surfaces via show_all_workqueues(), print_worker_info(), > the WQ_NAME_LEN pr_warn_once(), and lockdep lock names. > > C does not allow forwarding a va_list through a ... parameter; > a v-style entry point is required. __alloc_workqueue() is > exactly that and is already used by alloc_workqueue_noprof(). > Split devm_alloc_workqueue() into devm_alloc_workqueue_noprof() > plus an alloc_hooks() macro wrapper, mirroring the > alloc_workqueue / alloc_workqueue_noprof split. The _noprof > function calls __alloc_workqueue() directly with the va_list we > already hold, and runs wq_init_lockdep(wq) afterwards to mirror > alloc_workqueue_noprof() (otherwise wq->lockdep_map stays NULL > and __flush_workqueue()'s on-stack > COMPLETION_INITIALIZER_ONSTACK_MAP would NULL-deref it). > > Keeping the alloc_hooks() wrapper preserves memory allocation > profiling attribution under CONFIG_MEM_ALLOC_PROFILING=y: the > kzalloc_noprof() and alloc_workqueue_attrs_noprof() inside > __alloc_workqueue() are charged to the driver call site rather > than to a single line in kernel/workqueue.c. > > No caller changes are required. Drivers continue to write > devm_alloc_workqueue() and devm_alloc_ordered_workqueue() as > before; the new macro forwards through alloc_hooks() into the > renamed _noprof function transparently. Out-of-tree modules > need only be recompiled against the updated header to pick up > the renamed export, mirroring the precedent set by the existing > alloc_workqueue / alloc_workqueue_noprof split. > > devm_alloc_ordered_workqueue() in include/linux/workqueue.h is > a macro that forwards to devm_alloc_workqueue(), so it inherits > this fix automatically. Two in-tree callers actively trigger > the broken path on every probe: > > drivers/power/supply/mt6370-charger.c:889 > drivers/power/supply/max77705_charger.c:649 > > both of which use devm_alloc_ordered_workqueue(dev, "%s", 0, > dev_name(dev)). > > A standalone reproducer module is available at[1]: > > Link: https://github.com/leitao/debug/blob/main/workqueue/valist/wq_va_test.c [1] > There shouldn't be blank line(s) in the tag block. > Fixes: 1dfc9d60a69e ("workqueue: devres: Add device-managed allocate workqueue") > Signed-off-by: Breno Leitao Otherwise second Tejun's "nice catch"! -- With Best Regards, Andy Shevchenko