From nobody Tue Feb 10 11:24:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD6DAC001B0 for ; Fri, 23 Jun 2023 21:15:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbjFWVPQ (ORCPT ); Fri, 23 Jun 2023 17:15:16 -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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 =3D {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 =3D {vmalloc,vzalloc}; @@ =20 ( 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) =20 for (i =3D 0; i < test_loop_count; i++) { n =3D get_random_u32_inclusive(1, 100); - p =3D vmalloc(n * PAGE_SIZE); + p =3D vmalloc(array_size(n, PAGE_SIZE)); =20 if (!p) return -1; @@ -175,7 +175,7 @@ static int long_busy_list_alloc_test(void) int rv =3D -1; int i; =20 - ptr =3D vmalloc(sizeof(void *) * 15000); + ptr =3D vmalloc(array_size(15000, sizeof(void *))); if (!ptr) return rv; =20 @@ -221,11 +221,11 @@ static int full_fit_alloc_test(void) junk_length =3D fls(num_online_cpus()); junk_length *=3D (32 * 1024 * 1024 / PAGE_SIZE); =20 - ptr =3D vmalloc(sizeof(void *) * junk_length); + ptr =3D vmalloc(array_size(junk_length, sizeof(void *))); if (!ptr) return rv; =20 - junk_ptr =3D vmalloc(sizeof(void *) * junk_length); + junk_ptr =3D 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 =3D vmalloc_huge((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE, GFP_KERNE= L); else - ptr =3D vmalloc((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE); + ptr =3D vmalloc(array_size(nr_pages > 0 ? nr_pages : 1, PAGE_SIZE)); =20 if (!ptr) return -1; @@ -293,7 +293,7 @@ pcpu_alloc_test(void) size_t size, align; int i; =20 - pcpu =3D vmalloc(sizeof(void __percpu *) * 35000); + pcpu =3D vmalloc(array_size(35000, sizeof(void __percpu *))); if (!pcpu) return -1;