From patchwork Fri Dec 15 13:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang.guang5@zte.com.cn X-Patchwork-Id: 179297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9289065dys; Fri, 15 Dec 2023 05:53:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHY1d8G6+2drMIKtOrJ7LRIMMFhmVivZqReUvUfzhU+5u6YiY7aKyqHMllByNrxwlaCRSxc X-Received: by 2002:a05:6358:2c93:b0:170:c41c:8107 with SMTP id l19-20020a0563582c9300b00170c41c8107mr12640880rwm.6.1702648408352; Fri, 15 Dec 2023 05:53:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702648408; cv=none; d=google.com; s=arc-20160816; b=oJoJfNu0hDBV0ZVaDiVm3yK2ewQeUVklUo8IB+Ty7Kj1kjIDHrakv3lpn2XxxYgUws d1pbEVFQhD8BNCVG/ulT6fc4iqXq6suTC9MhNvBxH4TfajcY6cTrSEMuOU0qGiq9Qexb hW+orzRzXLj+LzM8XPByzg72CIYAIWoPEWJ3TVrdm/V+dFNXWNLDNMJoSOKhCy8AD1Y1 IyRMd3XlgXeZH+An4zmm5zr2NPn1FzA0FhCchZqDMF1Vmf8m4cywtEmylJl7iXIKhVNL LJbC5ieu9F/tfBKwz9kT7W7OZYMzB9nphTKQGdbwx3E5yd2upOppV5FHLwO6kgXdI9qz Q0jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:cc:to:from:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date; bh=r+kHsb2bl+22v8qESmhzGMXMD6jxzz4nkVAt9YaAy00=; fh=T0X22gN0gNEhODgeYrqO5lU9+zN0mZqQ0rXhmYP/Og0=; b=kpOMN4QY14j1SVbWTW1sGcSWZRkaqiPDyMT++WxDEKCEd/x0A4bSnUmCWZFm80Gcxf KTMk5PqHRJpgWO2bQd3V8n4h/EQOxS+CNH6J4Nvg/M0heAClHI9wWJDI/VF3uD+iDyXw j2dkUWvK80sS+0aVpmC5kcctrMJ61F39WdyZOdC+EO2KjsupRJ7dDUrmuk4huSBCxfgW +sNTyPfK/PJtMpMyfLm1+e4+GtfRKUKy2bSnlTDuF7dS8acZxYYRjupSywYX5qBZALa6 0OM1btYplrwb371UO7tdMwGkwWoIfnqnw/gf8G10SZfRwpAN2iBWt/UQQzwCDgxz1LUE CmrQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1045-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a3-20020a631a43000000b005c6c9572a4esi12861618pgm.582.2023.12.15.05.53.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 05:53:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1045-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=zte.com.cn 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 1FA012821AA for ; Fri, 15 Dec 2023 13:53:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E31C92FE3E; Fri, 15 Dec 2023 13:53:11 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mxct.zte.com.cn (mxct.zte.com.cn [58.251.27.85]) (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 2A1452FE32; Fri, 15 Dec 2023 13:53:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mxde.zte.com.cn (unknown [10.35.20.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxct.zte.com.cn (FangMail) with ESMTPS id 4Ss9Qx64BrzW8Q; Fri, 15 Dec 2023 21:43:21 +0800 (CST) Received: from mxhk.zte.com.cn (unknown [192.168.250.137]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mxde.zte.com.cn (FangMail) with ESMTPS id 4Ss9Qn33byz76dgd; Fri, 15 Dec 2023 21:43:13 +0800 (CST) Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4Ss9QX2Y9pz8XrRC; Fri, 15 Dec 2023 21:43:00 +0800 (CST) Received: from xaxapp03.zte.com.cn ([10.88.97.17]) by mse-fl2.zte.com.cn with SMTP id 3BFDgxiw098749; Fri, 15 Dec 2023 21:42:59 +0800 (+08) (envelope-from yang.guang5@zte.com.cn) Received: from mapi (xaxapp01[null]) by mapi (Zmail) with MAPI id mid31; Fri, 15 Dec 2023 21:43:02 +0800 (CST) Date: Fri, 15 Dec 2023 21:43:02 +0800 (CST) X-Zmail-TransId: 2af9657c57e67a3-52481 X-Mailer: Zmail v1.0 Message-ID: <202312152143029891646@zte.com.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: Cc: , , , , , Subject: =?utf-8?q?=5BPATCH_linux-next=5D_ext4=3A_use_kcalloc_instead_of_ope?= =?utf-8?q?n_coded_arithmetic?= X-MAIL: mse-fl2.zte.com.cn 3BFDgxiw098749 X-Fangmail-Gw-Spam-Type: 0 X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 657C57F8.000/4Ss9Qx64BrzW8Q X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785356257314869458 X-GMAIL-MSGID: 1785356257314869458 From: Yang Guang 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 --- 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;