From patchwork Fri Jun 23 21:14:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6048658vqr; Fri, 23 Jun 2023 14:24:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5BX9w8aMrajbz68XuO9/KCVOsDcVkjNc+2d3J5CNX6IDYootWu9Kt3bjOjzESDfNDjOg5m X-Received: by 2002:a05:6808:1450:b0:3a0:34c2:646d with SMTP id x16-20020a056808145000b003a034c2646dmr16084102oiv.21.1687555480448; 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=Ee4p2VRs7nmjA8a5/iIxVlxJFCY11LbhRNR8F8rb6G5vnGR/kWVqPwXX3TL7hSTCcA StGplH/UINzA4Vxo1EjLB94nEYXGDmtjBjxek11E2zelRnxdXjRUkEkLwoztWv37wrt7 UEkGGA/dYrKIemNBjpVXqhwnseM5OOzGFPQYHVx/giND1x8nS4Tc0Eo8L9aosquHTVLN Wx1PkDrI+LjwpUrhfp3dNwTszKFIFzGdCMXv+H5VL/ojoWkAcDReKj8icNiED3BqkDfp Jjg6NfodAx5eN2tO8M+C26/9AaFL9H1yUsneZXAS3VhgKDKvJB8xlUwL60TI9R3MaGb4 aYsw== 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=QVL85YxfC9lZXDIeZBFhc354vgfWwHTzh6yW0KOYvK4=; fh=/dLKWv2g+MHt+9pGlXbIrGjHgmTrgFG7i3FAhq3mKZ4=; b=eTOmQ64dFaLl6pJ/9ZormK5hJtP5IebahJ47tv7isYcGOLzxJG+s5c8RnYb5q9dzT5 JCBFigsnTTh8iLfJOLqDZ9yOua9VHoBYiSAadOo5CikT3ri0fgmEG5J83iaQt1ymBD4S Vx6oHdMvg8qRCHELVBE2/Kgddga8MRYS/A9jebce817Xn0KPTCQ9r5UoOqgUpjN58spE MoKsUd8ddg1HQifCXoAWepPuHgyQWbDMQ+aREnwXKNsi6WDFeTDogvjQiTvK3r/oCiME oQQOUVWrteAdbFAzcKaIMj5b7LdLzVsqIgOlGB4nvcsImo4YetdmXEL9XbGxrW8OsVhD JDzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=obHoEbEA; 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 b10-20020a17090a8c8a00b0025337db9e19si314474pjo.156.2023.06.23.14.24.25; 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=obHoEbEA; 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 S232866AbjFWVQs (ORCPT + 99 others); Fri, 23 Jun 2023 17:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232906AbjFWVQD (ORCPT ); Fri, 23 Jun 2023 17:16:03 -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 1FA682D5E; Fri, 23 Jun 2023 14:15:30 -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=QVL85YxfC9lZXDIeZBFhc354vgfWwHTzh6yW0KOYvK4=; b=obHoEbEAs4Vxarjwie+EudxVXCEWB7n46ogAeNxZlsEWVoPQcxhx87vy b7lBQ22cD+VaMR23Nr7nQhnTC89WV184JirgVc3PcqN9bz2XA4WUXm5aW WjUCZtT+syctXB+oE0Kfp1AGf0HqfpKHdjFpSt0B28IJckRav0i1qufKi 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="59686189" 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:15 +0200 From: Julia Lawall To: "Michael S. Tsirkin" Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Jason Wang , Xuan Zhuo , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 25/26] vduse: use array_size Date: Fri, 23 Jun 2023 23:14:56 +0200 Message-Id: <20230623211457.102544-26-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?1769530175486048160?= X-GMAIL-MSGID: =?utf-8?q?1769530175486048160?= 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 --- drivers/vdpa/vdpa_user/iova_domain.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c index 5e4a77b9bae6..ee395e013086 100644 --- a/drivers/vdpa/vdpa_user/iova_domain.c +++ b/drivers/vdpa/vdpa_user/iova_domain.c @@ -571,8 +571,9 @@ vduse_domain_create(unsigned long iova_limit, size_t bounce_size) domain->iova_limit = iova_limit; domain->bounce_size = PAGE_ALIGN(bounce_size); - domain->bounce_maps = vzalloc(bounce_pfns * - sizeof(struct vduse_bounce_map)); + domain->bounce_maps = + vzalloc(array_size(bounce_pfns, + sizeof(struct vduse_bounce_map))); if (!domain->bounce_maps) goto err_map;