Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2394876lqp; Sun, 24 Mar 2024 17:35:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUnuSS32rikeEBroySxdBB+A13jMWPnDQxCdRPg8xgzSrQJZISFMm6YS6WlSTHvtI4h2RfYmSlsgZa8fD2xW/0MQM3EVekxHdx5iJwieg== X-Google-Smtp-Source: AGHT+IFk6g8n5ip8ImJ8pMMT54pyZMu3J51rHVWmIbCcLrKkXWMKwxRhBZ2rUEzqqS8oLNG3O1sW X-Received: by 2002:a05:6808:608b:b0:3c2:174d:489d with SMTP id de11-20020a056808608b00b003c2174d489dmr5081262oib.31.1711326910397; Sun, 24 Mar 2024 17:35:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711326910; cv=pass; d=google.com; s=arc-20160816; b=SaVFsk+3S/Kkm9gLBwFdrIh5z+DS1vvAxw4SDW/l4f1cFm9Xzv1WxYgSjJlGyY+6MK WcVfL1hZbnOhFN8TvBLEHkmkYPLMs2I4c1Oq0xiTFFU60gl6Q78qs5TXIThUgss6K8DO h7oNrosCpd7N20wxaWY9snVvQmIK8/6dVtAiDnGcPVN2pEjz5avUSh3MUYtROWAt3fid opPck3DDFdTot77W7Oe8U0MEWbs+s+4PvyA+0Z5yIG/DvgaagpWLpv557YR1B7W8D9t7 73TFa4fd8HMdTxLCsY04wsW4PRJg9BSs3NgHARu4NXnwBS89BvX11hMgwe5vSDuS1gLS 94Ww== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ozV5uZINkrhxWYodVet3JJP16qJMmMvCrlDD7YBGIBk=; fh=KgNp+pExLxhj/p6Ia7SuKy80oWZUC2+PEawxAXmyhws=; b=XTn0cShuN37JJU7UUYleK0Z0gDxff4EDPcPCTozRQ6Y18gPCW5IBoebZapDe/wSVd/ ehKdLA+FOeZZCtxGXOg8K4+ioUnyFamy8w53Fv90nrM+QvIaV+9Tuze0NNg4EFYxGbdF 2iaB8Gy+ls70ewZetwgV/bkbPRSzU6bNbPhdTMROGsqZ7EuOIRew7m/+dlj6j10ZApGW RIsHemO7xnv1bpw8QUIwgCZPFa+64xCtCnTP/Y9deSK1DRxrBFqRTKysU2Gk5eH7PGLE xQhtWQmVnNbpVA6rOhSkHpZ4ImYZ7ge6GFGWIR2euEZYhuhY5AbU+DDnmTHlG9ZwwcNx rDMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Han6rqnj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113426-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u36-20020a634724000000b005cdf9923679si6574376pga.727.2024.03.24.17.35.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:35:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Han6rqnj; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113426-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113426-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 22C37283FD7 for ; Mon, 25 Mar 2024 00:33:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4772F1A9934; Sun, 24 Mar 2024 22:43:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Han6rqnj" 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 5B0111A9269; Sun, 24 Mar 2024 22:43:48 +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=1711320228; cv=none; b=m7ATTIE9IQp/vi3bckg5+3GUUQTyLVvnSqbOE5euJ11jIBTWI2IU+NEGTyY1ZBnHgGmb20k118Fn6lqZE3W/bkhjzfWl6r+V33P3simwE0qkYWNdaCqaVx+9h+8wrKMlZkarwsLlkl3iU6COv1igna1XmBx4WJmVZbmjMMJgZLg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320228; c=relaxed/simple; bh=yndw88zz5hL38S4CIm5fOYrwYgVggB3WZzDKWBTNnLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QFzM8sLZhlFid8JQbeucU1fa9hgebGlBv3egymL2gQ6J8ibjBI1W1wF1QHDNLP0/FxCLS9vR06M3Bb95lX9vO094wSi7LZf/YNUr5kvrBqmuCULMO4I69KnZhsBAkhDSNlgNhQneuEFCQ1iRk/sV/KHI5USSqs30bB3TPVtOwXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Han6rqnj; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8379CC433B1; Sun, 24 Mar 2024 22:43:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320228; bh=yndw88zz5hL38S4CIm5fOYrwYgVggB3WZzDKWBTNnLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Han6rqnjIsTF9p777G3HoVujWP3ZtQ5tPJaCVLjAV3mqWDjxXDlZcrKDRlyXm6x1v LeZwW52/3cfiaPHRzmFUW3nX2HkD31KQcGuHk+Wv16s9rTV6sMA7vYcv3vwMH0hE2Q gBqDj1kkqjsJL6z/ZwAopQT+noIXql+uG42VE3rASLRVimfPYWTcKC4VfA7kCjPf7t +N7SoQ/CFjk4fP9HJOPDeRLnmf8Lb9012viDMrsJ0T64RPQzgy8M2WluMOjQpE9zyw olQYrn+QFOXD0qNgXj6JCxx3iCrkPUB/JBwVErOgp7KrpXLPkEhjDE7PqBWHnKeHm8 CXlA8r2/6ZVWQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Duoming Zhou , Michal Simek , Stephen Boyd , Sasha Levin Subject: [PATCH 6.8 535/715] clk: zynq: Prevent null pointer dereference caused by kmalloc failure Date: Sun, 24 Mar 2024 18:31:54 -0400 Message-ID: <20240324223455.1342824-536-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Duoming Zhou [ Upstream commit 7938e9ce39d6779d2f85d822cc930f73420e54a6 ] The kmalloc() in zynq_clk_setup() will return null if the physical memory has run out. As a result, if we use snprintf() to write data to the null address, the null pointer dereference bug will happen. This patch uses a stack variable to replace the kmalloc(). Fixes: 0ee52b157b8e ("clk: zynq: Add clock controller driver") Suggested-by: Michal Simek Suggested-by: Stephen Boyd Signed-off-by: Duoming Zhou Link: https://lore.kernel.org/r/20240301084437.16084-1-duoming@zju.edu.cn Acked-by: Michal Simek Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- drivers/clk/zynq/clkc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/clk/zynq/clkc.c b/drivers/clk/zynq/clkc.c index 7bdeaff2bfd68..c28d3dacf0fb2 100644 --- a/drivers/clk/zynq/clkc.c +++ b/drivers/clk/zynq/clkc.c @@ -42,6 +42,7 @@ static void __iomem *zynq_clkc_base; #define SLCR_SWDT_CLK_SEL (zynq_clkc_base + 0x204) #define NUM_MIO_PINS 54 +#define CLK_NAME_LEN 16 #define DBG_CLK_CTRL_CLKACT_TRC BIT(0) #define DBG_CLK_CTRL_CPU_1XCLKACT BIT(1) @@ -215,7 +216,7 @@ static void __init zynq_clk_setup(struct device_node *np) int i; u32 tmp; int ret; - char *clk_name; + char clk_name[CLK_NAME_LEN]; unsigned int fclk_enable = 0; const char *clk_output_name[clk_max]; const char *cpu_parents[4]; @@ -426,12 +427,10 @@ static void __init zynq_clk_setup(struct device_node *np) "gem1_emio_mux", CLK_SET_RATE_PARENT, SLCR_GEM1_CLK_CTRL, 0, 0, &gem1clk_lock); - tmp = strlen("mio_clk_00x"); - clk_name = kmalloc(tmp, GFP_KERNEL); for (i = 0; i < NUM_MIO_PINS; i++) { int idx; - snprintf(clk_name, tmp, "mio_clk_%2.2d", i); + snprintf(clk_name, CLK_NAME_LEN, "mio_clk_%2.2d", i); idx = of_property_match_string(np, "clock-names", clk_name); if (idx >= 0) can_mio_mux_parents[i] = of_clk_get_parent_name(np, @@ -439,7 +438,6 @@ static void __init zynq_clk_setup(struct device_node *np) else can_mio_mux_parents[i] = dummy_nm; } - kfree(clk_name); clk_register_mux(NULL, "can_mux", periph_parents, 4, CLK_SET_RATE_NO_REPARENT, SLCR_CAN_CLK_CTRL, 4, 2, 0, &canclk_lock); -- 2.43.0