Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13028044rwd; Fri, 23 Jun 2023 14:33:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5EifpcYILB0r4fP3RXe9ij46zTmifocXqha45u1mOV50Q8BDeODdsGipKXbfBqMb0sp+d1 X-Received: by 2002:a17:902:db10:b0:1b5:cd6:8246 with SMTP id m16-20020a170902db1000b001b50cd68246mr581565plx.2.1687556039312; Fri, 23 Jun 2023 14:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556039; cv=none; d=google.com; s=arc-20160816; b=Oy4wPfSxKGZg6hzO9IyFyBkvpD3NWX3x1EpLLR6RP9BLowXf6Sqi9wqJflgfHpgoVL bkP52gOIWsbeOGostxOlYxisjKia2r27oV1L+3GrAVC2B7x6k3ic+PCtp71GEZZJi7PD mtRAQv5c8Dk8cN1BwXf2yg0U08R7J0kt1lYAPCX8RTuzAjGiJoUnvT3QkF81A9gIi2g8 arqzEjtNORJ2wVnC0FJq+9JD7VFgMSzvdWb3MERO0ZD2tCOG15l99p7AiVHJVShI4ZcE 7FYkP43aXaiVY0VeGja0fxj5hsfUk7vGbyP4pVYtSZaAUg4M8ddr9Npnehi0S0DW6fbZ RzRQ== 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=qV5G73GxtezcE7jW6SYetBuixStXGKiX50k7hlLQiPI=; fh=1WfTt7ZQ2PCyDexWEgjrvClpa/X0h2q3omZne/wztD4=; b=Y63OcYCRVy1zpAhhu/lv9IHrKLPTB3rXCYwXkQ3lEqf5upJQ+6H8CcfedhJ6WrI8GL Uhud/ruW8K7rauygmWqSd6UfOhuE7s8eTnDhPDsnlYoaR8I9Ig/OxeHDkB7ity3QPArb rqLWA6rPcdfp00CXyGKk7vNdaM3VaLgXRTGQa4Hr2JzZNvwN+kgCdRrp6hbAp440FxEe n+riz8QFRX+yFoecoiOSXQWFX8F/BIV7akWvURl9iJ0/6SQ6htgqHYwZc+eY/keRgll5 xeSez4cTE2OKhDCN7r/VNiNmTaCKntIskWrTh71D8HeOpiAjNVlsRqILcUyqmsFq1hPD /izg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=D51bNxx3; 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 t18-20020a170902e85200b001b3dff53359si55307plg.467.2023.06.23.14.33.47; Fri, 23 Jun 2023 14:33:59 -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=D51bNxx3; 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 S232932AbjFWVQ0 (ORCPT + 99 others); Fri, 23 Jun 2023 17:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232775AbjFWVPo (ORCPT ); Fri, 23 Jun 2023 17:15:44 -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 34EAD2728; Fri, 23 Jun 2023 14:15:23 -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=qV5G73GxtezcE7jW6SYetBuixStXGKiX50k7hlLQiPI=; b=D51bNxx3+NCOjAzU8GhU1cIyLUhkDHrYSC94pyiQyblzcGfm6MHi5CUK TvZc5kxyOIspVbl2ClJqlsUb8ZKRt14bc0NfiU4O9w/U7pvI5eLxNyOWn 22WDtlFdhPqTCvxDq0AwaJhrNmHKRupFifZlpHJ6E4mIZJz7yDpQt9k6Z 8=; 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="59686179" 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:14 +0200 From: Julia Lawall To: Jarkko Sakkinen Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 21/26] x86/sgx: use array_size Date: Fri, 23 Jun 2023 23:14:52 +0200 Message-Id: <20230623211457.102544-22-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: 8bit 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 Use array_size to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @@ 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 --- arch/x86/kernel/cpu/sgx/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c index 166692f2d501..3a234942c586 100644 --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -628,7 +628,8 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, if (!section->virt_addr) return false; - section->pages = vmalloc(nr_pages * sizeof(struct sgx_epc_page)); + section->pages = vmalloc(array_size(nr_pages, + sizeof(struct sgx_epc_page))); if (!section->pages) { memunmap(section->virt_addr); return false;