From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 97D6735958; Mon, 23 Mar 2026 16:20:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774282805; cv=none; b=jk45XIpiJBOzibMCG6oQK9rJu3EaRMKWpHxn17R1XFBZ5bV0bT19DdM2siYIyR94XEU6/3Sa5PQbNemAuOMoqP0hbRWPMOMf0SxxsXFCQosJbBF7YFAsNPoyFbpMT7I5EiCZjfxHX+UQiPzBDht4tZf9cseeEnjA8miFveoz7xQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774282805; c=relaxed/simple; bh=/Yz5LKbFo9dibWtULSK0IwA0vIi4pP51hE7b8agedoY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N4dLlUN2SPsnx/FMYiK1aP6HJdyVBYoUerzI9tRKio4xQk7AheRiDywmkgS8UXryKNUq3u0T9V+xUhG2rU75RDafhbdhwPijZdM11wKZVluADgVyrhDPvcjU76yCeSlAHj8S1YQ0d6gVUmvvQpF92P76M4u6dVknowmzcTmlWO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ejcghrqB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ejcghrqB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFA08C4CEF7; Mon, 23 Mar 2026 16:20:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774282805; bh=/Yz5LKbFo9dibWtULSK0IwA0vIi4pP51hE7b8agedoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ejcghrqBfokKwhYEUowca8GgbCIatWeYKG/3FdxBrpikfwfd1oYe2TZkrGKYghwlX fkcL3/BsECgXh6RYjsvNpFpulvvEIXDXDYZx6yqGfRc9Wc6KVKPIqx1yxzTeNzPU+d j/Yp/6hNexXXeWSSrY8zIfPwgZcbozh5WltC36R8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Jander , Johan Hovold , Mark Brown Subject: [PATCH 6.1 293/481] spi: fix use-after-free on controller registration failure Date: Mon, 23 Mar 2026 14:44:35 +0100 Message-ID: <20260323134532.249809856@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134525.256603107@linuxfoundation.org> References: <20260323134525.256603107@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 8634e05b08ead636e926022f4a98416e13440df9 upstream. Make sure to deregister from driver core also in the unlikely event that per-cpu statistics allocation fails during controller registration to avoid use-after-free (of driver resources) and unclocked register accesses. Fixes: 6598b91b5ac3 ("spi: spi.c: Convert statistics to per-cpu u64_stats_t") Cc: stable@vger.kernel.org # 6.0 Cc: David Jander Signed-off-by: Johan Hovold Link: https://patch.msgid.link/20260312151817.32100-2-johan@kernel.org Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3212,10 +3212,8 @@ int spi_register_controller(struct spi_c dev_info(dev, "controller is unqueued, this is deprecated\n"); } else if (ctlr->transfer_one || ctlr->transfer_one_message) { status = spi_controller_initialize_queue(ctlr); - if (status) { - device_del(&ctlr->dev); - goto free_bus_id; - } + if (status) + goto del_ctrl; } /* Add statistics */ ctlr->pcpu_statistics = spi_alloc_pcpu_stats(dev); @@ -3238,6 +3236,8 @@ int spi_register_controller(struct spi_c destroy_queue: spi_destroy_queue(ctlr); +del_ctrl: + device_del(&ctlr->dev); free_bus_id: mutex_lock(&board_lock); idr_remove(&spi_master_idr, ctlr->bus_num);