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 C61051BDEC; Wed, 3 Jan 2024 17:09:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="oh1Ms3CS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C7C6C433C7; Wed, 3 Jan 2024 17:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1704301762; bh=gMSNqnY+Oetu4fiDGGSpF9/cJkzcXgJFFNE/jZ9n5As=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oh1Ms3CS+eYQhuBkvqV9lmgxXtFgmtYR11gEcKibKxkUps/LUrSjkMZkfIVR1qRmB VnlNd3mAYBgO76cZkV1tbyk/ZurRanRYFbFMI7GLzQTiEwVwiFdVywrZwIddLhyJvi xh/uua9Arco49HLQlBGbgqASlwZvqQ5Vqr+M5dkg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Geert Uytterhoeven , Philipp Zabel , Sasha Levin Subject: [PATCH 5.10 04/75] reset: Fix crash when freeing non-existent optional resets Date: Wed, 3 Jan 2024 17:54:45 +0100 Message-ID: <20240103164843.633212603@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240103164842.953224409@linuxfoundation.org> References: <20240103164842.953224409@linuxfoundation.org> User-Agent: quilt/0.67 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven [ Upstream commit 4a6756f56bcf8e64c87144a626ce53aea4899c0e ] When obtaining one or more optional resets, non-existent resets are stored as NULL pointers, and all related error and cleanup paths need to take this into account. Currently only reset_control_put() and reset_control_bulk_put() get this right. All of __reset_control_bulk_get(), of_reset_control_array_get(), and reset_control_array_put() lack the proper checking, causing NULL pointer dereferences on failure or release. Fix this by moving the existing check from reset_control_bulk_put() to __reset_control_put_internal(), so it applies to all callers. The double check in reset_control_put() doesn't hurt. Fixes: 17c82e206d2a3cd8 ("reset: Add APIs to manage array of resets") Fixes: 48d71395896d54ee ("reset: Add reset_control_bulk API") Signed-off-by: Geert Uytterhoeven Link: https://lore.kernel.org/r/2440edae7ca8534628cdbaf559ded288f2998178.1701276806.git.geert+renesas@glider.be Signed-off-by: Philipp Zabel Signed-off-by: Sasha Levin --- drivers/reset/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/reset/core.c b/drivers/reset/core.c index f93388b9a4a1f..662867435fbe8 100644 --- a/drivers/reset/core.c +++ b/drivers/reset/core.c @@ -599,6 +599,9 @@ static void __reset_control_put_internal(struct reset_control *rstc) { lockdep_assert_held(&reset_list_mutex); + if (IS_ERR_OR_NULL(rstc)) + return; + kref_put(&rstc->refcnt, __reset_control_release); } -- 2.43.0