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 AF904267B89; Tue, 8 Apr 2025 11:55: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=1744113305; cv=none; b=fu6Z5q3qAt/M2ck6HJqBTyrFxb/J6zMIsOWJVDSjllOHs5dOgQMNpjfgBoWR3psFIMHGvBifI1RXM2ZzmVJwmAgk3vaCFn8EZYdBgy/VlgklYjxdK9C3bpr4lkdDEVRYbq7uAO9ebX7jpfFa16RqPCGCPFW35kep6lPlGMlPrbc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744113305; c=relaxed/simple; bh=0NUXfvtP/zXfHO2KzwG23FNKyb+2VPKpybMTFfy/UZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZoOPM9vJvzLrqbvIyU3tuPW7VZpdQZSy/6YOlQUXOBnC6GpPLuTc0UXH9jp10MKDqLuSX9j3F+GX1WorC51P1IiVVVm6ea3SX3FJxBGGgLwQUvoZUAn/Ycalc0lw5s0n7kOvC8fQ6oqyixpfq8IbavwAJahoBb04xINkaEMFTZg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PRTaUYV/; 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="PRTaUYV/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 420A5C4CEE5; Tue, 8 Apr 2025 11:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744113305; bh=0NUXfvtP/zXfHO2KzwG23FNKyb+2VPKpybMTFfy/UZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PRTaUYV/Q/hjydOBgujZv8RR6duzts80YD0o0LNxN2gTARa7z7sV0qUMG1ofWgPyK gTj0pmxsJNXfLhh8LXe+ZurtpnP4xjBBNhNUwK8TMlJSZxKmX1RB1mXx0dV97dBURS Qe7tz+wyA9CUhkYKkL9qVXMO/IzgAyeJdpyWFlX4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Will McVicker , Krzysztof Kozlowski , Sasha Levin Subject: [PATCH 6.6 071/268] clk: samsung: Fix UBSAN panic in samsung_clk_init() Date: Tue, 8 Apr 2025 12:48:02 +0200 Message-ID: <20250408104830.410534405@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104828.499967190@linuxfoundation.org> References: <20250408104828.499967190@linuxfoundation.org> User-Agent: quilt/0.68 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.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will McVicker [ Upstream commit d19d7345a7bcdb083b65568a11b11adffe0687af ] With UBSAN_ARRAY_BOUNDS=y, I'm hitting the below panic due to dereferencing `ctx->clk_data.hws` before setting `ctx->clk_data.num = nr_clks`. Move that up to fix the crash. UBSAN: array index out of bounds: 00000000f2005512 [#1] PREEMPT SMP Call trace: samsung_clk_init+0x110/0x124 (P) samsung_clk_init+0x48/0x124 (L) samsung_cmu_register_one+0x3c/0xa0 exynos_arm64_register_cmu+0x54/0x64 __gs101_cmu_top_of_clk_init_declare+0x28/0x60 ... Fixes: e620a1e061c4 ("drivers/clk: convert VL struct to struct_size") Signed-off-by: Will McVicker Link: https://lore.kernel.org/r/20250212183253.509771-1-willmcvicker@google.com Signed-off-by: Krzysztof Kozlowski Signed-off-by: Sasha Levin --- drivers/clk/samsung/clk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c index b6701905f2546..fa5bdf6b3a929 100644 --- a/drivers/clk/samsung/clk.c +++ b/drivers/clk/samsung/clk.c @@ -74,12 +74,12 @@ struct samsung_clk_provider * __init samsung_clk_init(struct device *dev, if (!ctx) panic("could not allocate clock provider context.\n"); + ctx->clk_data.num = nr_clks; for (i = 0; i < nr_clks; ++i) ctx->clk_data.hws[i] = ERR_PTR(-ENOENT); ctx->dev = dev; ctx->reg_base = base; - ctx->clk_data.num = nr_clks; spin_lock_init(&ctx->lock); return ctx; -- 2.39.5