From nobody Thu Dec 25 12:13:49 2025 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 750BD20B35 for ; Wed, 17 Jan 2024 14:36:54 +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=1705502214; cv=none; b=rByHLMiISWrTqzOqKfBnSOESQkJa5oVs2MF5+al2QJGanJLGysG/3focToT0S6T7rOI4q1W9O72imtFcpbksblxUOb+uMILsDtpw+naBNIAvIDp49ulT5TTsKaYkMM9y8cBjaQCHjeh//iXFfaQqH7nmlyJ2/J1rIKAvB63ZFos= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705502214; c=relaxed/simple; bh=GD76TU70lFmz5imut84Og/YwBOUVo8vHQeAC83rp8IM=; h=Received:Received:Message-ID:User-Agent:Date:From:To:Cc:Subject: References:MIME-Version:Content-Type; b=Qp1rqwTqHRhsa2b1GT2qd4bc0r0UFnciQhEV2fJyP1IKHBe4y38DopnMeh2+Bb8bb8bH6N6hcZVRoWlEiRFkK/63FAjrUNLCg7ByIr0R+Bg1VJByKx2ncMXg+oKWsioq13JGrMi+xDLxeY7CUp8R8vvWXX5WbXK4R3PJxDucWh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09B2EC433C7; Wed, 17 Jan 2024 14:36:54 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rQ73S-00000001XZ3-49ps; Wed, 17 Jan 2024 09:38:10 -0500 Message-ID: <20240117143810.857039986@goodmis.org> User-Agent: quilt/0.67 Date: Wed, 17 Jan 2024 09:35:51 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Erick Archer , "Gustavo A. R. Silva" Subject: [for-linus][PATCH 3/3] eventfs: Use kcalloc() instead of kzalloc() References: <20240117143548.595884070@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Erick Archer 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. [1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded= -arithmetic-in-allocator-arguments Link: https://lore.kernel.org/linux-trace-kernel/20240115181658.4562-1-eric= k.archer@gmx.com Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Mark Rutland Link: https://github.com/KSPP/linux/issues/162 Signed-off-by: Erick Archer Reviewed-by: Gustavo A. R. Silva Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 10580d6b5012..6795fda2af19 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -97,7 +97,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, stru= ct dentry *dentry, /* Preallocate the children mode array if necessary */ if (!(dentry->d_inode->i_mode & S_IFDIR)) { if (!ei->entry_attrs) { - ei->entry_attrs =3D kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, + ei->entry_attrs =3D kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs), GFP_NOFS); if (!ei->entry_attrs) { ret =3D -ENOMEM; @@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *na= me, struct eventfs_inode } =20 if (size) { - ei->d_children =3D kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children =3D kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) { kfree_const(ei->name); kfree(ei); @@ -941,7 +941,7 @@ struct eventfs_inode *eventfs_create_events_dir(const c= har *name, struct dentry goto fail; =20 if (size) { - ei->d_children =3D kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children =3D kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) goto fail; } --=20 2.43.0