From patchwork Sun Feb 4 01:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147847dyb; Sat, 3 Feb 2024 17:21:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfRqCHf17u3qbLWX5YTcrYsZ+E2f9IYZlNoeVHYXaRjztAD64Tz72s+zd9lpckHBMCmj/Z X-Received: by 2002:a2e:8518:0:b0:2d0:8b22:a79a with SMTP id j24-20020a2e8518000000b002d08b22a79amr3118660lji.23.1707009692523; Sat, 03 Feb 2024 17:21:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009692; cv=pass; d=google.com; s=arc-20160816; b=d0MeB/W7QzBb4MGg6Yi961wCeR2VAe4SnuW4B53/5QekVLcr5pbIEMqK6Aup+kj50/ jhxRFWk6/TbsDpJJAg6RsVQClGnmjaG+qY7oDKAtDuI1BNh+ZobEJLMvmuPCWzW83CFZ TxqnGFj/AY/ETf+2bIDXQ7WSSWY/SCHD5bqQiPVQrhjZRRH3JgSUyK/juO1nMKQAiYse 7xF5memzsmBzrAp1WZTyVpeGfPRkyOYqXpdqQbP/S7tfUD+8UY4o/oe3Bw2nYtmy4skB bOpJl85WxLHZjy9HbMDlhzB651GrbPZ2YD3jXudyJ7XE0dSQrEf20grDER2IZGd8zkoZ jzFw== 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=GPohKznXU2BNmlCVHYAj4MeIS3nZM5k3Ff/hCqQFXzA=; fh=JWv0HP5E9F6XTEPoiTwCevC6qTdvLCqdxf1Gn7FeNU0=; b=0LpFtK0Qn3gyXxqgmcqjTz8u/SQujJkV08iYKhyb4QV9kw+vsVCcw5UiP/E0nro8yn VyrFSM9mZ7ZlemqxHsgu8CMocD0951/fBUH8VRJ5JpZ6hL7oiykoFDi62PYLDCQkvwt9 9/uWQSONMIzriSfgqepFGnBNzN0bAgQwh/AffvNHf+MXKC+1gN2GCc0qG8U0anYqP0Sc u9nrYIlfRoWKelJYWEk3n1NLwwGp3ycOogMC1bYU8qMTdBg8rog6+4ohcs1TcSBp4dfe /+QT7d+9C0vgn3NRdEZ6OgSe5A4x4J3ct0RmwU5HRL+YNuOEUAZ506aAXf+Nzrlr6rpg Bsyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVHSgdLaU0FFzj6EUFvBBGALoYujYqr/oEoZRvVintLVPeM1MOcdwW+g0AyDC+9+Ne4PVQd5rW/xl2N0/vfx4lrhDFStg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id df23-20020a05640230b700b0056023d8f37dsi953794edb.653.2024.02.03.17.21.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:21:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51345-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2298A1F217D7 for ; Sun, 4 Feb 2024 01:21:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3784414273; Sun, 4 Feb 2024 01:18:10 +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 1DD226FB5; Sun, 4 Feb 2024 01:18:06 +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=1707009486; cv=none; b=FMCWZgOz79ZTiH5/hmTapw4Dcyup0xI6XNNxiPlCqq355Dt2c3OkZh+JcAq+KFs1LnyQEKIfwBNcU+/wbRd34yde2bxkriGF4Tk8N2ar7mQPIyTuxf16FfeG8aM4AXZ4T7PLMdx05jV96trUhqV/qvURjeGuzPxGCdnS7yvJ8iE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009486; c=relaxed/simple; bh=GD76TU70lFmz5imut84Og/YwBOUVo8vHQeAC83rp8IM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WBOoVIfQwaDjVCpet7mz0fKNmYG9ZLleHveUw6zTnrH6Vv8QTNwrWud97dFtPdGgf8oHkRFenaM1s48zSJV4r7Xl1JZ+v+GRGY/Ue1ptwELBD6ny+dqeD6a82cYRzsl/1kNl6kDAVL78oQphoukvBxoy3bHaHrdSZiaEfAWimmA= 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 03F68C433B1; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006OpL-2kK1; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.512011833@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:25 -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 , Andrew Morton , Erick Archer , "Gustavo A. R. Silva" Subject: [v6.7][PATCH 10/23] eventfs: Use kcalloc() instead of kzalloc() References: <20240204011615.703023949@goodmis.org> 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: 1789929395313724118 X-GMAIL-MSGID: 1789929395313724118 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) --- 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; }