From patchwork Tue Feb 6 11:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481101dyb; Tue, 6 Feb 2024 03:49:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMMVXCjCF6nI1VyO1Wb5mRdWjG18mw8smQ32/L3qGi3HbS7vk+O3SFBmUA1cODCu7kB+yp X-Received: by 2002:a05:6870:d107:b0:219:442b:abd0 with SMTP id e7-20020a056870d10700b00219442babd0mr2536972oac.49.1707220175005; Tue, 06 Feb 2024 03:49:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220174; cv=pass; d=google.com; s=arc-20160816; b=CQnf0o+TdeJfXLd023OLiYBZByPWQtTD9PfJYJrG6n3/RQrT44g33qnRva/7TlYTyg 9WO55DyCmHB3lOMKRY/V1dyDp+loeJXEyvxF5++BX2yjhxBmrnlAb53NPSoR/+1O745F iVASH0n7pFd1xXO8l2sO0fCixJMS67xSldvs86MmJcjYXEmkO60cXzHKt8O0l92e4Pne rlBS3WOaTAksErYcVJxFEiP6hvTsST0gWpb9621B9sXJPN5eZ3KloA4ETmGX1z41I+q2 j+B8sFAdDwbPG97troejj3i1Kr/753P8DkgMPzSN/HlWUzrZ5NMsdEESN7M6dhfYs+BH wLvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=lR6au0kG3WFsHJQwGXzt6iecpuPnXQli3iId+Lo3sbw=; fh=/Teh1vuF58PkzZmpoz/B5X9cN9rS7nQNBXDuw3yKtMs=; b=lGuAlUdlhSPQyaMLNcUtXB5/EC3qfWlAcwW7GQICq4QfobArJ5hDoIZRRMdIq7sLFj GjIc2KoE7ThcpNV7F6WlA06RlgCdJyWiRt7env3th3MTDd095+swQmmadod3CSbSjo9E 4C0pZjM0gaoaSX7owjqC3awtXQc0tXUSJoS+4yVUCTa8TBgYnd1cmiitGzlMcOiRcbt0 3+d06pAr7G4II1m75pURf0I0E1DGtH6WBS5Pt5XdeNRAF3iXAt+gt26rAubTgCX6LOLn QcS9XMCV/jUMM+oNCMDEJ1nZga8PHJ3ylqmX5Y7zpEfGK0pbArkOVgYW1cry28qNF3Zi 8Z0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXClOkMkDqtbDQ8zUKdb9tUfi15M1Pxik/9n9hcUKRpLjhdlMKiy/00ekoZqkoI2ga7I/hhBJoXIdybfBG7yLdHaKXZRg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 187-20020a6301c4000000b005d8e3a180cbsi1578390pgb.841.2024.02.06.03.49.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:49:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.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 11AAF288550 for ; Tue, 6 Feb 2024 11:49:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C09131369B1; Tue, 6 Feb 2024 11:33:36 +0000 (UTC) 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 8B65C1339A6; Tue, 6 Feb 2024 11:33:31 +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=1707219211; cv=none; b=an8vO7GRstKip+ehyZT2mx3nrI9R2XUM2NP7KJA+PetsvXACkCn8HUeRjBnRDMzLFn0qdydQs1XGSGdH7ObW77WFHDsDVfNWyR+hdyVT294+cO/1k4ji9vgQ2nXF6WTv4x/8aSyDfqLNS8kE1RVqMCMLOtF+MmOCnd61xeBCE54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=S927KE9dYG/Lzm2Z83o0zTy+NJITK2h/kIEZaYEod3o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sCqYJT54z6FIHdc24IaW/wC9caSfmOuXrghXEbSjRwXecVCSz4S2zeT6j6VJ8Cb+lNLnU1Wt1KSZ6Kq5qpfPjXhqCfgHkW65Lquee75xAz9tQlVgZCBVOScCF3y0KedZu14hClkth3flYysQBIL5O89UD4oN+l/iT476YyVE+ac= 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 71994C3278F; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aLJ-3ZBf; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.716264689@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:08 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Erick Archer , "Gustavo A. R. Silva" Subject: [v6.7][PATCH v2 10/23] eventfs: Use kcalloc() instead of kzalloc() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150102275186632 X-GMAIL-MSGID: 1790150102275186632 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-erick.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) (cherry picked from commit 1057066009c4325bb1d8430c9274894d0860e7c3) --- 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, struct dentry *dentry, /* Preallocate the children mode array if necessary */ if (!(dentry->d_inode->i_mode & S_IFDIR)) { if (!ei->entry_attrs) { - ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, + ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs), GFP_NOFS); if (!ei->entry_attrs) { ret = -ENOMEM; @@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode } if (size) { - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children = 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 char *name, struct dentry goto fail; if (size) { - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) goto fail; }