From patchwork Tue Feb 6 12:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501032dyb; Tue, 6 Feb 2024 04:26:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEd+YGlC+tUk6SJQzumQQkPakXHWnhPolhG4B+6hxSYVw7nMZ7S7pvVpeBv0MMzzsiVDTgS X-Received: by 2002:a05:6830:20c3:b0:6e1:4848:a41b with SMTP id z3-20020a05683020c300b006e14848a41bmr2398307otq.24.1707222408243; Tue, 06 Feb 2024 04:26:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222408; cv=pass; d=google.com; s=arc-20160816; b=Hzoc73ACLTcNz0zbku9ENMxnrx4bRgiDMsaxe5depgMrFgqJqeQPmW3qITeA2kCbDj yZIY4oYV6JZQJkUZVJ2jq7sq8XS2nXJ382S+uCZCdb15NIFCeCsCZ8Ve/VVeq3Yx+KlX Zsncumx3D9q4ELw9YYguzoXuf2dA/6+I9GikNehEHga1ym9vhygS+qXU5Fl5wSr6Xuju yIynEFmJqUjRpeJtnqi8pCDwa/MlImXhCNniquO+Cv1z/VE+7WiyWTNnxJ8xg5MBAhFt SflU2Z3z6ZfffKOxZo17/9wKRPhRgIcIfmhiCRczlC2ez3KVoZYQGiBog/WGfqoVq+ah ssFA== 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=aUi2o92H7na3AikfktCLJJ9nmgMtNj7gryPNIZhys9M=; b=Xi616iGV/7/bdZWsz84EccqqG1DUfIwxWQyyvujbb7PJQB6l7EhEZSCFkiM89PNUCb BysJ5FDvlQd+saWp+WJNnrXXE1Bkvs2VdA5ZF0GTKr0sw/u1U/EUmtplF6yzMjf8MsNc 9xXMuJKo5sSLvt3oaNJITcyz7fkKYiW52ZfUm18f6zwJYQvWM6F+TnfrvJPK3XophojU 5DdJQHuXFifETURGfjiQ4LQWWELEZYmu5BDKdZjC6S0VEaVPi0scdmrlC7inHFHuHoDg m38yMA+4uLibACqB9IwA0I7CbdDzniuwWNiOz/R8shtsqB2G6ZN/nTWcT46tKSqM72M4 Kqvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWGwTJNekNU7q9cDKZZfuFJ6N9ivqaAKgMbP/p8suJo1FB8gufwzfSeEZysK8Axi938ociIRtxR/JbbLdZ3OEuAZMv2yA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o8-20020a05622a138800b0042beee75f61si2170289qtk.568.2024.02.06.04.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54918-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 060591C24341 for ; Tue, 6 Feb 2024 12:26:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E215114FFBB; Tue, 6 Feb 2024 12:09:39 +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 4B5FD13AA4A; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=r1ltP/SvZZ15DLKT8fV1gWEG8LaQq6R6iI2u4xup0iz5/cjabiewHGkkCDoiZ5t5GY46SM6bS+ea5hDFFLdyjjtMqwA676fl745bgRMYm3gDRM4YHfnRdaaRlVmr4zVytbbkXzteUQnJsmLv32ZJkOaIloPKVpRywjkf8mU22lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=S927KE9dYG/Lzm2Z83o0zTy+NJITK2h/kIEZaYEod3o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=V/kCj25Pb1+KVftMfixVuA/b0Yf5U7JpCZhlZ+CgOQGp06IUbSS2iNIbqK6JX8aFrX/0r3Ruz2MglBlwMJLyOCe5q+0nT2yj7Z18YRmc9yhvZPORbc3460Gf+6c0nr7UOUUdtmTKQHVt3pjzhjbFMXvQXuRKV/YXupDgdc9y6dI= 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 32A8FC43141; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bNK-2spg; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.546131126@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:49 -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.6][PATCH 44/57] eventfs: Use kcalloc() instead of kzalloc() References: <20240206120905.570408983@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: 1790152444021776179 X-GMAIL-MSGID: 1790152444021776179 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; }