Message ID | 20230623211457.102544-22-Julia.Lawall@inria.fr |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6048690vqr; Fri, 23 Jun 2023 14:24:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OKIXog5x8ObYCP1sCB8Omyseh6V9fHghQ0ZTEKQRzKJWVGVb2XB71OmyNggmh2y/Kas90 X-Received: by 2002:a05:6a20:1609:b0:105:2e9e:b13a with SMTP id l9-20020a056a20160900b001052e9eb13amr25299023pzj.8.1687555485169; Fri, 23 Jun 2023 14:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555485; cv=none; d=google.com; s=arc-20160816; b=QxlPjl2TZ6ThhDLC9vSqSSyGDxZIKSqmv20aAD4DySPF/StaWmVmFC9lUNOpmjBMWe EGKUUge7LrQTzPhXvcLrMxciTypbqvgHnlChb3Og0sOpj32UFxEL/xTfUAuXPLl7uIvH P5ATz8Kq+9BCPrjy3R7+DlMH8RCtGd9zmisFmx9hRIUKMaWtHGz2g6cvwC5lmeuEhuvo qVsj+ctqxAETx/vXOWiTD7Ds0PLxHZ39RLvQj3FOkbnufDsGwB4fpWLK/bfSqFyMTxqn S1rDHAUe3FeyGk4KhICwgT+qTty4dVtDyrtZaAK5RFYtIT3hnsIF5GRkKo2RjmLm4eMJ DgCw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx15-20020a056a00428f00b0066a48cbde7asi28053pfb.190.2023.06.23.14.24.31; Fri, 23 Jun 2023 14:24:45 -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 S232938AbjFWVQ1 (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Fri, 23 Jun 2023 17:16:27 -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 <rfc822;linux-kernel@vger.kernel.org>); 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 <Julia.Lawall@inria.fr> To: Jarkko Sakkinen <jarkko@kernel.org> Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Dave Hansen <dave.hansen@linux.intel.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769530180284973927?= X-GMAIL-MSGID: =?utf-8?q?1769530180284973927?= |
Series |
use array_size
|
|
Commit Message
Julia Lawall
June 23, 2023, 9:14 p.m. UTC
Use array_size to protect against multiplication overflows.
The changes were done using the following Coccinelle semantic patch:
// <smpl>
@@
expression E1, E2;
constant C1, C2;
identifier alloc = {vmalloc,vzalloc};
@@
(
alloc(C1 * C2,...)
|
alloc(
- (E1) * (E2)
+ array_size(E1, E2)
,...)
)
// </smpl>
Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
---
arch/x86/kernel/cpu/sgx/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On Fri, 2023-06-23 at 23:14 +0200, Julia Lawall wrote: > Use array_size to protect against multiplication overflows. > > The changes were done using the following Coccinelle semantic patch: > > // <smpl> > @@ > expression E1, E2; > constant C1, C2; > identifier alloc = {vmalloc,vzalloc}; > @@ > > ( > alloc(C1 * C2,...) > > > alloc( > - (E1) * (E2) > + array_size(E1, E2) > ,...) > ) > // </smpl> > > Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> > > --- > 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; > Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> BR, Jarkko
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;