Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17842083rwd; Tue, 27 Jun 2023 08:12:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6GohnjhTVRZTResy95AduUqgeaeDyruxcIS3JLUiYm2w16wzQqId4wMWNVGqrcRnW2kbOP X-Received: by 2002:a05:6402:12d3:b0:51d:988d:5ed8 with SMTP id k19-20020a05640212d300b0051d988d5ed8mr4571104edx.29.1687878735058; Tue, 27 Jun 2023 08:12:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878735; cv=none; d=google.com; s=arc-20160816; b=J4PQv6/IrHc8RW3NPG6qjOVAH5DvmY1CktLWeLlMA7EfIhz2kNE5ewT+WJCi53Ch2E Zu3sSwiefKdcQ2tQywapkpa4MjtXunD0slzzw+giICTw9AREQ/XcxYF1+13ZQK8ytccz t5iLUggkL4IZOLa96MPGcGXzJBVGmVxvuBtiT0zEAj1v6kK2XKabfggag3XQ58g8PM2Y UmPt1TBvgek6ZZxlTu6oF0bz5/YRmNAepv2LW9Q19yMZVcStOQZYOm6Hfc3BNbyhfAdZ 7OCpXU/GNlx5LSnsQsVrAl3b82NRYQqPRD9RSVPD8/1nJt2jDolNDv1Z5bJJfqnEY7Rd AtUw== 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=cW6FsUc372OgjCXWGlVTOpJDBn/sKhwbAV7MvUlsfDU=; fh=lH17MxD66mEZA0q9ApMflL6110os5JJlJCkBGCyBnjQ=; b=zaiIB/1P5wd0Wlh84PlF1twT2LhzXG/TLbx9IXgEtB6UoGhZRZSJcNGjtnEY0hmsTc hfT9PAwlof4L9cZasm9zn36gUp5FeHqvJTnDhdssOU12OlJFKD/1UmQT0V7ok87nE0bQ HhwWk9cksuKkyVxKW8QMD66WqrkjYQjVUq++zdmMOuXVDqIWh5adTt9gC01tflXUE8Na IC3i+Ea/E/qsnwBnqIKEKIPO9oaefIfikdtmdhCIuaQfCUVYZ/9DApgnxCQC4DLElL2h rcZMLfIeIihUkidQxNZ4IRp9oCJoq2V3P4d5C+VDjUN7aGAN27d7SlBnmHEX746tMBAn EUJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=jWt7EReJ; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s20-20020a056402165400b0051da6e381fcsi1191022edx.424.2023.06.27.08.11.49; Tue, 27 Jun 2023 08:12:15 -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=jWt7EReJ; 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 S231739AbjF0OpZ (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231684AbjF0Oop (ORCPT ); Tue, 27 Jun 2023 10:44:45 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7654F12C; Tue, 27 Jun 2023 07:44:12 -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=cW6FsUc372OgjCXWGlVTOpJDBn/sKhwbAV7MvUlsfDU=; b=jWt7EReJ5kDtaESX69GV8d4liYZONaNjYK6YwdVqiDhOrR+UO9w9kKRo +ywuVIwSPjmV/l3kagzTPaaXWEA08ystOtiHsidk5aXckj/9gzF9Rpoj3 I1ITEQ51Rbp6KM/FiTv0VHqRI8yNXSJ9Lc78ZzS16NIIda7XjaWrQUZT3 A=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936318" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: linux-kernel@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org Subject: [PATCH v2 01/24] lib/test_vmalloc.c: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:16 +0200 Message-Id: <20230627144339.144478-2-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. lib/test_vmalloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff -u -p a/lib/test_vmalloc.c b/lib/test_vmalloc.c --- 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(n, PAGE_SIZE); if (!p) return -1; @@ -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(junk_length, sizeof(void *)); if (!ptr) return rv; - junk_ptr = vmalloc(sizeof(void *) * junk_length); + junk_ptr = vmalloc_array(junk_length, sizeof(void *)); if (!junk_ptr) { vfree(ptr); return rv; @@ -271,7 +271,8 @@ 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(nr_pages > 0 ? nr_pages : 1, + PAGE_SIZE); if (!ptr) return -1;