From patchwork Sat Jan 20 13:34:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erick Archer X-Patchwork-Id: 13524379 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (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 CC869F4E2; Sat, 20 Jan 2024 13:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705757705; cv=none; b=YUtZAHOGdGEFhuZRRF4Gv+gyhJzwpcH50D+zcJxxNJaCTFVHeomuJ3LbMXFV5Y+Is+H+sLXigpARTzGdeQOrC9OPBfvxnzGbVMT1FW72pqd5wsYrNXSm5NbqXjZU80edSfrC2rkcT6ZZ8CRrH9Oh99QI7U5JnrPBRzEfv96g2Pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705757705; c=relaxed/simple; bh=HSEmP7fhfhYJi7q8y21JZnQX6pvDCIMAR2srytoMCDk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oj68e26KD9eSFwSZG2ip5fuZAJmMxr+u1rLoMmUNRcpJ3bot35dUEWeg3NKJyKshgDDCbhehswAx/6ChkIuq/lx1nqBfUJNE9tEpVIdZINJFhdxmwajoRYn0zZKoQLqqyoLr3lqeS7tq0VvmD8ws1p4xEMt6MCwdwEZX/8ylZBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com; spf=pass smtp.mailfrom=gmx.com; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b=p6QpFoD3; arc=none smtp.client-ip=212.227.15.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b="p6QpFoD3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.com; s=s31663417; t=1705757695; x=1706362495; i=erick.archer@gmx.com; bh=HSEmP7fhfhYJi7q8y21JZnQX6pvDCIMAR2srytoMCDk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=p6QpFoD3XTH9wTkgyZW04NKN4CfYTn1T0impi1JHePIDWbFxOXykMy68D88EKdy0 4apZu40PRCbiVUqKib1t93/uMiLXpRev4xP/vVe61X5dx1YJZFQNC9pTOnPuVL6yM j3XAMjw1KneXxsyVtDrYPHxvJzszAaWY12EPx+VuyVoZoO38EvQNf/msY4SIMx9WY RQ1+zFDvl+0/GTAY7QMh18IF3Eff74SqfClv+DY+qsi29+BvETPUumehEvVgqZhEL Csi5GoL85OeOvwRhKLt2m4LlLPtROzFnVV81E+B+B8lpcgosGFnU5F+1s4Z2Orko0 6UUFV1CwbGXcD1AUqw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([79.157.194.183]) by mail.gmx.net (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M1poA-1rOyZT21jk-002KVY; Sat, 20 Jan 2024 14:34:55 +0100 From: Erick Archer To: Thomas Bogendoerfer , "Gustavo A. R. Silva" Cc: Erick Archer , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] MIPS: Alchemy: Use kcalloc() instead of kzalloc() Date: Sat, 20 Jan 2024 14:34:43 +0100 Message-Id: <20240120133443.4237-1-erick.archer@gmx.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags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iq5QILs0EikGZ1A+sZ0ijoduhh/ He4fSPgBGmrv2fCIjfWKOlBwo1nMMUHr1gOyLaNarYIR/YGapnVNtKpFcigiAw/Lpq4WgfIuc 4aK3bdsI0UwvzawrodOnLHwBxSRaFF0k3YIK4r4Fn3KbJ0uh675g09Dxc05+0pBaXa2rdvWnf 1H+hbiwj36cpW7z+ZWwf8DNKuyQ= As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, use the purpose specific kcalloc() function instead of the argument size * count in the kzalloc() function. Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] Link: https://github.com/KSPP/linux/issues/162 Signed-off-by: Erick Archer Reviewed-by: Gustavo A. R. Silva --- arch/mips/alchemy/common/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.25.1 diff --git a/arch/mips/alchemy/common/clock.c b/arch/mips/alchemy/common/clock.c index c01be8c45271..6c8996e20a7d 100644 --- a/arch/mips/alchemy/common/clock.c +++ b/arch/mips/alchemy/common/clock.c @@ -771,7 +771,7 @@ static int __init alchemy_clk_init_fgens(int ctype) } id.flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE; - a = kzalloc((sizeof(*a)) * 6, GFP_KERNEL); + a = kcalloc(6, sizeof(*a), GFP_KERNEL); if (!a) return -ENOMEM;