From patchwork Fri Jun 23 21:14:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6048661vqr; Fri, 23 Jun 2023 14:24:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4B7VnMs51OzG3w0YHHbaH/cHuG702Ve4F5IEM5v5y9OxPAZLP3fAa43xF01KcjzxqlkzQJ X-Received: by 2002:a05:6359:6398:b0:132:7a28:e13a with SMTP id sg24-20020a056359639800b001327a28e13amr7067849rwb.17.1687555480846; Fri, 23 Jun 2023 14:24:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555480; cv=none; d=google.com; s=arc-20160816; b=V5utMzZqgHbBYhxjxtxE4hYPemWWxZQ2XC5j3BM5rPyWqeVN4sPcqjQNIhfaMrvWBx WLqsJ4eYkBVdYIFCWcK6yPZq+09DM7Cp+OIXzpGay/woyXLIK8P6XRQBscmp+hPvV86e S7TDRtsdkI0tH0OFBLKGc44jR9+RUp6QLs/7ZqYG+RzKvExn7AW+RCgl+JWt49ko54pH TcmBiBxbfONeYz+A9+ikMvQjO7Bx6XP0CQKNevPTJtxBrIJKN4UL/OcvqR1iL/yNiBvO T0Uj6QvBKx8EEiQqRegCvLS1Hlz0TSnnvhGTNzHki6rEygSNdFQtH9hFPCSNLaAhy/eD Xn6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jd3h5W+nQqo5i0Obf5JwrqgVHs0D/GmiD6Eb1h7EYkk=; fh=hEHkW6PU5jJ8R0snCKvrzcRObo/hxfkg/Lt0qbve9mY=; b=hEPG1S2LxII/K5HysA2+BcxRHrfldieT8wnEikqCfPOC8ZI9MR5yq6Y0BTvLOKvuew 4YIW1F/4IoAKzxhFClpcCOgjDHWQd7NALt4xgMMoh1h2ukPXlA2NLL3b4/Fzaf6V/Ax1 SeC7rExhzS1JZpwY3+h7qwmwqjNixdD2Ovpy1gA2SPo2hxE3robkC7aOGUiESCpv2ZVe DE5Mtn+/cgfqsCBAep2ZkHtQ1B/QfikBvuKvVZvXscF2QbaUaoAcF/IWGGlPXXgefZBY ymDDNQRod6OBYMaTpIWxt0WZnzo/UuWt29N0asVXXS0IZxnBeZHvXkyZudCXYwXLttIj EtRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=o2bPTbjy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k26-20020a635a5a000000b005534371608dsi212225pgm.849.2023.06.23.14.24.26; Fri, 23 Jun 2023 14:24:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=o2bPTbjy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231843AbjFWVPP (ORCPT + 99 others); Fri, 23 Jun 2023 17:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbjFWVPN (ORCPT ); Fri, 23 Jun 2023 17:15:13 -0400 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 669CC189; Fri, 23 Jun 2023 14:15:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jd3h5W+nQqo5i0Obf5JwrqgVHs0D/GmiD6Eb1h7EYkk=; b=o2bPTbjyvGhNakcmvltIzFi/S0dJfu9Nh1VS5e0zg/1JS++mceceIzEZ O7PNODtaLw2mJg4i9aMMzB7XRGoym9HrXS1pKqYtQ7Vsg2bbwPMfmlTgt dxCKI7WizKNgfJ8IyzurReMpwe4ujwBPvCygX56mzwX70LBSaRsT9N9j4 I=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Julia.Lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.01,153,1684792800"; d="scan'208";a="59686159" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2023 23:15:10 +0200 From: Julia Lawall To: linux-kernel@vger.kernel.org Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org Subject: [PATCH 01/26] lib/test_vmalloc.c: use array_size Date: Fri, 23 Jun 2023 23:14:32 +0200 Message-Id: <20230623211457.102544-2-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230623211457.102544-1-Julia.Lawall@inria.fr> References: <20230623211457.102544-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769530175715665884?= X-GMAIL-MSGID: =?utf-8?q?1769530175715665884?= Use array_size to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @@ size_t e1,e2; expression COUNT; identifier alloc = {vmalloc,vzalloc,kvmalloc,kvzalloc}; @@ ( alloc( - (e1) * (e2) + array_size(e1, e2) ,...) | alloc( - (e1) * (COUNT) + array_size(COUNT, e1) ,...) ) @@ expression E1, E2; constant C1, C2; identifier alloc = {vmalloc,vzalloc}; @@ ( alloc(C1 * C2,...) | alloc( - (E1) * (E2) + array_size(E1, E2) ,...) ) // Signed-off-by: Julia Lawall --- lib/test_vmalloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index 3718d9886407..d02a47e0a72b 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -156,7 +156,7 @@ static int random_size_alloc_test(void) for (i = 0; i < test_loop_count; i++) { n = get_random_u32_inclusive(1, 100); - p = vmalloc(n * PAGE_SIZE); + p = vmalloc(array_size(n, PAGE_SIZE)); if (!p) return -1; @@ -175,7 +175,7 @@ static int long_busy_list_alloc_test(void) int rv = -1; int i; - ptr = vmalloc(sizeof(void *) * 15000); + ptr = vmalloc(array_size(15000, sizeof(void *))); if (!ptr) return rv; @@ -221,11 +221,11 @@ static int full_fit_alloc_test(void) junk_length = fls(num_online_cpus()); junk_length *= (32 * 1024 * 1024 / PAGE_SIZE); - ptr = vmalloc(sizeof(void *) * junk_length); + ptr = vmalloc(array_size(junk_length, sizeof(void *))); if (!ptr) return rv; - junk_ptr = vmalloc(sizeof(void *) * junk_length); + junk_ptr = vmalloc(array_size(junk_length, sizeof(void *))); if (!junk_ptr) { vfree(ptr); return rv; @@ -271,7 +271,7 @@ static int fix_size_alloc_test(void) if (use_huge) ptr = vmalloc_huge((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE, GFP_KERNEL); else - ptr = vmalloc((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE); + ptr = vmalloc(array_size(nr_pages > 0 ? nr_pages : 1, PAGE_SIZE)); if (!ptr) return -1; @@ -293,7 +293,7 @@ pcpu_alloc_test(void) size_t size, align; int i; - pcpu = vmalloc(sizeof(void __percpu *) * 35000); + pcpu = vmalloc(array_size(35000, sizeof(void __percpu *))); if (!pcpu) return -1;