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 DE79841836D; Fri, 7 Aug 2026 15:05:21 +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=1786115123; cv=none; b=MIALChneRAZIhQkVOXzAehyfY961xBnKz7FeRsI58mzwhlz0tTQl99TuudjAxlfWVmHwelIDF/2bC28LiDJXwLRzobQUmeFMpsJff+jDwzPVQeW3GSBfklHD6fHNoAOfhXeHJ2UF8cbAp4pAXNggj6KH9DiwExusGqs4+2P09Us= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786115123; c=relaxed/simple; bh=VhrcryUVu8DT7ISbzVFJbJR9gk6e3N4cZ2rDGG8V5D4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WeIXvN22L843ad0gxxKB/b5VD30JKmqSSqXgMvX5bZiJl+c8uDLtSRdZdzE+rTEdYbioCuABuRV/UDiZ4is/qssFud81kK7TqN4z+Q75j0twOGTTuvMrtPCHEdvWtwVTWIfZnVdFj3ENnMsOzz6O9JXMrW/VMKvXhlHc8bhCXIs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0JFrWvlT; 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="0JFrWvlT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30A341F000E9; Fri, 7 Aug 2026 15:05:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786115121; bh=UWTgMet0g6w9lUTljfAUbUXgv6Ms+ixpzOH5BBSADQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0JFrWvlT/KKUF/1Cu7GcHyRJERX5ybtVjjLR3cKBdXBrYdDCU5rBMIIy/eKt7FvWD mVM37B5kI3pMcBorwYtkMpIleE2QW7AnS5m3k88YzacsnIa5AtE9L0neF4yJoxSJPG FashZ5hoL8E+t+Z2wSU00cIUmy4iduNvgJ1r049o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Karl Mehltretter , Linus Walleij Subject: [PATCH 6.18 165/396] pinctrl: devicetree: dont free uninitialized dev_name on error path Date: Fri, 7 Aug 2026 16:35:25 +0200 Message-ID: <20260807143427.861890312@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143424.272339768@linuxfoundation.org> References: <20260807143424.272339768@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: Karl Mehltretter commit 015b5bcbcb622b32317642be91a7f79aa5413649 upstream. dt_remember_or_free_map() duplicates dev_name for each map entry. If kstrdup_const() fails, dt_free_map() frees dev_name in all num_maps entries, including entries that have not been initialized. Some pinctrl drivers, including pinctrl-imx, allocate the map with kmalloc() and leave dev_name for the core to initialize. The untouched entries therefore contain uninitialized data which is passed to kfree_const(). Reproduced on qemu's mcimx6ul-evk (pinctrl-imx) with failslab injection while binding the pinctrl-consuming device, under KASAN: BUG: KASAN: double-free in dt_free_map+0x34/0xa4 Free of addr c425a900 by task init/1 kfree from dt_free_map+0x34/0xa4 dt_free_map from dt_remember_or_free_map+0x184/0x198 dt_remember_or_free_map from pinctrl_dt_to_map+0x33c/0x4c8 pinctrl_dt_to_map from create_pinctrl+0x9c/0x5c0 Initialize all dev_name fields to NULL before duplicating the device name, making the full-map cleanup safe after a partial failure. Fixes: be4c60b563ed ("pinctrl: devicetree: Avoid taking direct reference to device name string") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-fable-5 Signed-off-by: Karl Mehltretter Signed-off-by: Linus Walleij Signed-off-by: Greg Kroah-Hartman --- drivers/pinctrl/devicetree.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/pinctrl/devicetree.c +++ b/drivers/pinctrl/devicetree.c @@ -69,6 +69,10 @@ static int dt_remember_or_free_map(struc int i; struct pinctrl_dt_map *dt_map; + /* Initialize dev_name before any allocation can fail */ + for (i = 0; i < num_maps; i++) + map[i].dev_name = NULL; + /* Initialize common mapping table entry fields */ for (i = 0; i < num_maps; i++) { const char *devname;