From: <yang.guang5@zte.com.cn>
To: <tytso@mit.edu>
Cc: <jiang.xuexin@zte.com.cn>, <chen.haonan2@zte.com.cn>,
<cgel.zte@gmail.com>, <adilger.kernel@dilger.ca>,
<linux-ext4@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH linux-next] ext4: use kcalloc instead of open coded arithmetic
Date: Fri, 15 Dec 2023 21:43:02 +0800 (CST) [thread overview]
Message-ID: <202312152143029891646@zte.com.cn> (raw)
From: Yang Guang <yang.guang5@zte.com.cn>
Dynamic 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.
Signed-off-by: Chen Haonan <chen.haonan2@zte.com.cn>
---
fs/ext4/hash.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
index deabe29da7fb..7a9afac1597c 100644
--- a/fs/ext4/hash.c
+++ b/fs/ext4/hash.c
@@ -302,7 +302,7 @@ int ext4fs_dirhash(const struct inode *dir, const char *name, int len,
if (len && IS_CASEFOLDED(dir) &&
(!IS_ENCRYPTED(dir) || fscrypt_has_encryption_key(dir))) {
- buff = kzalloc(sizeof(char) * PATH_MAX, GFP_KERNEL);
+ buff = kcalloc(PATH_MAX, sizeof(char), GFP_KERNEL);
if (!buff)
return -ENOMEM;
--
2.25.1
reply other threads:[~2023-12-15 13:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202312152143029891646@zte.com.cn \
--to=yang.guang5@zte.com.cn \
--cc=adilger.kernel@dilger.ca \
--cc=cgel.zte@gmail.com \
--cc=chen.haonan2@zte.com.cn \
--cc=jiang.xuexin@zte.com.cn \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox