Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13035993rwd; Fri, 23 Jun 2023 14:43:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4kJKpwfuthkxo5ADZTNF6fTcxQ+f80uytnlY4/zNFce811dniE5SGcVFEWvMd71REcP1t5 X-Received: by 2002:a17:90b:3881:b0:25e:f133:41cb with SMTP id mu1-20020a17090b388100b0025ef13341cbmr17290322pjb.21.1687556622237; Fri, 23 Jun 2023 14:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556622; cv=none; d=google.com; s=arc-20160816; b=bQjhiEXU7nF23EwVZhri5vLbWQhEqyol8npLsQcYKiodK+ZjtQ8BSKH0nVDeSf+k6+ ZETRYC/MvI1nplofM/bHUa12lWEIfP3SnWTORmPYyNccfD/zBfbPi2q+NkTRr2MEUMCR HsgWG9Qlb5LEwW5lxk/1ALu+JSV0iXN5imxYHO/QOkwJGw/pr6cupiYok2j3g0dKPbxk OAOvi+IGER6SY5X44qlmNoLZz4CZDWCMkXncaNPyBvT5eVmstzij97/eAXS+GmYiZL3b YGcK6IbVkcxNWLlwl2Uu/8qleCWfCSjlbeQF5BpWOetynaCJ3nyunh9FjrfmuwS6WB3H Twcg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cl21-20020a17090af69500b00253326d4e5bsi375489pjb.57.2023.06.23.14.43.30; Fri, 23 Jun 2023 14:43:42 -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 S232917AbjFWVQs (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 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 --- 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;