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 F33514BEE32; Sat, 12 Sep 2026 12:51:03 +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=1789217465; cv=none; b=mDNBN4Q5mfAiSehNccTlqaNgEYxSMJ5wdtVMao2Fq7dqbG5RcR5LJ2C/z79E0LjNJgjtJw48mziAKT5FyIFSzPEyXcA/kIaPDHEHNTFZmFeD3zaDzFi6xT3o6DwqaxCwR71KlMyxeYqi3KLMUH3bNOOekqVwDarHe4TIHkI6spk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789217465; c=relaxed/simple; bh=hdaWUOmDLk08wCuXa23UGoul+c9Ow6Swd1SHTJDNtPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cw5fanbnKmiDk32fWA1PeeQpESe7ikdgyrNUY30L2FdVXT4eTbIboV3spUneUvbx4J8oULlZNlUx6wGQ7bm1s8XURjz1vrZl9dpDcBAQA1v1JxAfVP8+WjnQ6s9YfzQicES2G0QfgZhKj40apRYgEVq+RDuRGodwpoDK/R4Oiwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YksIhaZV; 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="YksIhaZV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD07B1F000FF; Sat, 12 Sep 2026 12:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789217463; bh=Gys9NTkABF9jxXK/IgfJsCbdpDsII3ozOaQ6snvHl+o=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YksIhaZVs17aY837iBx/5CbNDUHoAyJQtQAPjD5jjOUcLY0c8+o998z+07N176YJI 5kTUqSORPya6Os1XU0ASEYlY3h/XcrG2kKXIq8e3Gk/ZXxvVc4zVO9c3bOehKF3pm2 +TP95CdFBFMUuv0eKIIaqb8Vb2Nb0m57UA1jhddg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mukesh Ojha , Danilo Krummrich , Sasha Levin Subject: [PATCH 6.12 0946/1376] firmware_loader: do not queue completed sysfs fallback requests Date: Sat, 12 Sep 2026 08:56:12 +0200 Message-ID: <20260912065628.645285076@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065607.535295758@linuxfoundation.org> References: <20260912065607.535295758@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mukesh Ojha [ Upstream commit b48373c901951fad1a26bd7c33ad91172b3945b5 ] fw_load_sysfs_fallback() calls device_add() before adding the fw_priv to pending_fw_head. device_add() publishes the fallback loading interface, so a userspace helper which discovers the device by scanning sysfs can write 0 to the loading attribute and complete the request before it is queued as pending. In that interleaving firmware_loading_store() calls fw_state_done() while pending_list still points to itself, so it cannot remove an entry from pending_fw_head. The subsequent unconditional list_add() then queues an already-completed fw_priv. Once the request is released, pending_fw_head can retain a pointer to freed memory and the next fallback request can fault while validating the list. Only in-flight fallback requests need suspend or reboot abort handling. If the request is already DONE after device_add(), return success from the fallback path without sending another uevent, waiting again, or queueing it as pending. This preserves the invariant that pending_fw_head contains only active fallback requests. Fixes: 75d95e2e39b2 ("firmware_loader: fix use-after-free in firmware_fallback_sysfs") Signed-off-by: Mukesh Ojha Link: https://patch.msgid.link/20260716081601.1674470-1-mukesh.ojha@oss.qualcomm.com Signed-off-by: Danilo Krummrich Signed-off-by: Sasha Levin --- drivers/base/firmware_loader/fallback.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c index 3ef0b312ae719..00d6b6e594616 100644 --- a/drivers/base/firmware_loader/fallback.c +++ b/drivers/base/firmware_loader/fallback.c @@ -95,6 +95,16 @@ static int fw_load_sysfs_fallback(struct fw_sysfs *fw_sysfs, long timeout) retval = -EINTR; goto out; } + + /* + * device_add() exposes the loading interface before pending_list is + * linked into pending_fw_head, so fw_state_done() may run first. + */ + if (fw_state_is_done(fw_priv)) { + mutex_unlock(&fw_lock); + goto out; + } + list_add(&fw_priv->pending_list, &pending_fw_head); mutex_unlock(&fw_lock); -- 2.53.0