From mboxrd@z Thu Jan 1 00:00:00 1970 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 31A2C2DF9F; Tue, 20 Feb 2024 21:35:51 +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=1708464951; cv=none; b=KShotPg+67ZK71+GDQAsWtrFO1/fezDuSaqcnxTTjzc6Ajkz8vo4AwLhh9YpK1gGlfcKsRIcX3wF2+uTf/BAHRcuu/Rn32V6/iDDBJRmyH30tJbkzf+0LMgKFgjrukzULz3SE5MbDCB105BbVMo0EJV29nl440GORwKJfClMzZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708464951; c=relaxed/simple; bh=+wgeC6gxUne5iIsZrHBLIzco0LQLai8B363XM+FhUI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XEsOL3c/5h8wWJ7Z8xYkoi3Ef0zc2qKoreHDnpweigtZSx1S6vgoFWyGTEAnTR+slFwLUyotqgA7eXOgFJDxmfsyyhmeC1XNrakwNFaJ/JyORakpYfaxc46tlGAMEEVgkyi67Oe7vikgT1efo4ISQ+BvxaaWDMabZRqoZAWxCbA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PKeDgbGD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PKeDgbGD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C355C433C7; Tue, 20 Feb 2024 21:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708464951; bh=+wgeC6gxUne5iIsZrHBLIzco0LQLai8B363XM+FhUI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PKeDgbGDyGXo3FeRAJA3uVQJ4rN6IjHcsKdPRyYTyXoqKB1ze2DjRfTOfr5+/Hchf lyTpNpGkjW1kD2uvHEi3kjwiJhvFIein4DFTmlai1BlJC6bcHUCtqpkkudoi4/Y2JQ wUZFSpxzW4+W0S3WiS61K8XuxPvLHQdhuGxQgvEs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Masami Hiramatsu , Mathieu Desnoyers , Mark Rutland , Erick Archer , "Gustavo A. R. Silva" , "Steven Rostedt (Google)" Subject: [PATCH 6.7 187/309] eventfs: Use kcalloc() instead of kzalloc() Date: Tue, 20 Feb 2024 21:55:46 +0100 Message-ID: <20240220205639.005826212@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240220205633.096363225@linuxfoundation.org> References: <20240220205633.096363225@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Erick Archer commit 1057066009c4325bb1d8430c9274894d0860e7c3 upstream. 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) Signed-off-by: Greg Kroah-Hartman --- fs/tracefs/event_inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -97,7 +97,7 @@ static int eventfs_set_attr(struct mnt_i /* 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; @@ -836,7 +836,7 @@ struct eventfs_inode *eventfs_create_dir } 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); @@ -903,7 +903,7 @@ struct eventfs_inode *eventfs_create_eve 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; }