Message ID | 20230623211457.102544-9-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 k13csp6055342vqr; Fri, 23 Jun 2023 14:42:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6W8/WHnc0VK5ylSYkRV8rItHm9/g9TzPt7DPo6kPN/x7Xv3lsEwRpNhSv/LaEGh/gSh1pY X-Received: by 2002:a05:6a20:6a23:b0:117:1ffb:a14 with SMTP id p35-20020a056a206a2300b001171ffb0a14mr29387162pzk.13.1687556526418; Fri, 23 Jun 2023 14:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556526; cv=none; d=google.com; s=arc-20160816; b=hycQ0zHqY3eVRVDXQ1UOUU4O0FCFDUTe2pGtEmSfG3xFK/c7a6HYWWjezWje3tCneu JBaUM/whpcgDuoeJRvdqMmMz8zhqWEqJpmoRI+e5YZjX4G6XcuC34TTFC2PQ41AXTVu5 lekK9+cExYxOLmLTZAGYze80dvOgb7bVEyIEX2ci8MiNfVhx2A2ZaxL/3EbZyraNbHNz eRDjswcpV0SGV1l8pEm5kMurWxqDkGp+npteYnzCK0kfWgBBIW5zxb33Tw3aumWFaGfS O2uZtA4ptL3Ur1Nb9F61rMKCATE03L/rsybKG1/+C980Q6m4ZUeqUF8td0WtwckaN0+A vUjA== 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=8WWGDy69qrtzavSblwBRgHQbwXA80r1Q53C16BTDHPg=; fh=le6LjByZ/GLn71+30CM/IrfFLROZ2UJGH4hDLIguZ6U=; b=FV0ZCDl4ROAQSPHNHCUWfg5pbKntrdaJO0N75pqrvkcQT13o1FNk3TIN5Q+DAzfSbR H1EF26sFNAdjuMfzaTmEziL7V1BIaebfmPuFp0Vy8l21j+A77J/TtPOnSVfrOaP1lCeX 3eHyxE8uz2GqXyJuINQReAp/2XnDlaxEfRmdojo4uB4FRaXvZGrKPX1tCEzJIQy6XXVi ZPD3iyVnxOmlHQZTO5hZP/KrZ5Dz7n7NTvQ4btpcBUEAKdowMmfiZc3D9wHpPp5w2cCo YKOHkG9544l5Pb3YeU1tVNFjEfTAzuQmVl5ien/KYw1y2rQfUQ7uEouEUWjWzjHeY6rk 6dRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b="Nf2/PyVP"; 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 w136-20020a627b8e000000b006689f89b186si41985pfc.208.2023.06.23.14.41.53; Fri, 23 Jun 2023 14:42:06 -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="Nf2/PyVP"; 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 S231911AbjFWVPd (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Fri, 23 Jun 2023 17:15:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232392AbjFWVPR (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 23 Jun 2023 17:15:17 -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 40E57189; Fri, 23 Jun 2023 14:15:15 -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=8WWGDy69qrtzavSblwBRgHQbwXA80r1Q53C16BTDHPg=; b=Nf2/PyVP65m4zS14KRN+iZPPDLs/1MtgDOLaD5cMvJhgt0f/01EceRnR jgPoDPxYGosXJu/ZTArJNQFAaCz5QS5fBWEzE7SX5MXsWerfQlC0Ssb1x C5j6BWtq+9VXv9wmH8wzYLLYHbEQB/XuYhxgc+ye2WpqAzpvKugTAcvbM 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="59686166" 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:11 +0200 From: Julia Lawall <Julia.Lawall@inria.fr> To: David Hildenbrand <david@redhat.com> Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Xuan Zhuo <xuanzhuo@linux.alibaba.com>, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/26] virtio-mem: use array_size Date: Fri, 23 Jun 2023 23:14:39 +0200 Message-Id: <20230623211457.102544-9-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?1769531272328061410?= X-GMAIL-MSGID: =?utf-8?q?1769531272328061410?= |
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>
---
drivers/virtio/virtio_mem.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Fri, 23 Jun 2023 23:14:39 +0200, Julia Lawall <Julia.Lawall@inria.fr> 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> Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> > > --- > drivers/virtio/virtio_mem.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c > index 835f6cc2fb66..a4dfe7aab288 100644 > --- a/drivers/virtio/virtio_mem.c > +++ b/drivers/virtio/virtio_mem.c > @@ -399,7 +399,7 @@ static int virtio_mem_bbm_bb_states_prepare_next_bb(struct virtio_mem *vm) > if (vm->bbm.bb_states && old_pages == new_pages) > return 0; > > - new_array = vzalloc(new_pages * PAGE_SIZE); > + new_array = vzalloc(array_size(new_pages, PAGE_SIZE)); > if (!new_array) > return -ENOMEM; > > @@ -465,7 +465,7 @@ static int virtio_mem_sbm_mb_states_prepare_next_mb(struct virtio_mem *vm) > if (vm->sbm.mb_states && old_pages == new_pages) > return 0; > > - new_array = vzalloc(new_pages * PAGE_SIZE); > + new_array = vzalloc(array_size(new_pages, PAGE_SIZE)); > if (!new_array) > return -ENOMEM; > > @@ -588,7 +588,7 @@ static int virtio_mem_sbm_sb_states_prepare_next_mb(struct virtio_mem *vm) > if (vm->sbm.sb_states && old_pages == new_pages) > return 0; > > - new_bitmap = vzalloc(new_pages * PAGE_SIZE); > + new_bitmap = vzalloc(array_size(new_pages, PAGE_SIZE)); > if (!new_bitmap) > return -ENOMEM; > >
On 23.06.23 23:14, 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> > > --- > drivers/virtio/virtio_mem.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Reviewed-by: David Hildenbrand <david@redhat.com>
On Fri, Jun 23, 2023 at 11:14:39PM +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> > > --- > drivers/virtio/virtio_mem.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) can't hurt I guess. Acked-by: Michael S. Tsirkin <mst@redhat.com> > diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c > index 835f6cc2fb66..a4dfe7aab288 100644 > --- a/drivers/virtio/virtio_mem.c > +++ b/drivers/virtio/virtio_mem.c > @@ -399,7 +399,7 @@ static int virtio_mem_bbm_bb_states_prepare_next_bb(struct virtio_mem *vm) > if (vm->bbm.bb_states && old_pages == new_pages) > return 0; > > - new_array = vzalloc(new_pages * PAGE_SIZE); > + new_array = vzalloc(array_size(new_pages, PAGE_SIZE)); > if (!new_array) > return -ENOMEM; > > @@ -465,7 +465,7 @@ static int virtio_mem_sbm_mb_states_prepare_next_mb(struct virtio_mem *vm) > if (vm->sbm.mb_states && old_pages == new_pages) > return 0; > > - new_array = vzalloc(new_pages * PAGE_SIZE); > + new_array = vzalloc(array_size(new_pages, PAGE_SIZE)); > if (!new_array) > return -ENOMEM; > > @@ -588,7 +588,7 @@ static int virtio_mem_sbm_sb_states_prepare_next_mb(struct virtio_mem *vm) > if (vm->sbm.sb_states && old_pages == new_pages) > return 0; > > - new_bitmap = vzalloc(new_pages * PAGE_SIZE); > + new_bitmap = vzalloc(array_size(new_pages, PAGE_SIZE)); > if (!new_bitmap) > return -ENOMEM; >
diff --git a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c index 835f6cc2fb66..a4dfe7aab288 100644 --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -399,7 +399,7 @@ static int virtio_mem_bbm_bb_states_prepare_next_bb(struct virtio_mem *vm) if (vm->bbm.bb_states && old_pages == new_pages) return 0; - new_array = vzalloc(new_pages * PAGE_SIZE); + new_array = vzalloc(array_size(new_pages, PAGE_SIZE)); if (!new_array) return -ENOMEM; @@ -465,7 +465,7 @@ static int virtio_mem_sbm_mb_states_prepare_next_mb(struct virtio_mem *vm) if (vm->sbm.mb_states && old_pages == new_pages) return 0; - new_array = vzalloc(new_pages * PAGE_SIZE); + new_array = vzalloc(array_size(new_pages, PAGE_SIZE)); if (!new_array) return -ENOMEM; @@ -588,7 +588,7 @@ static int virtio_mem_sbm_sb_states_prepare_next_mb(struct virtio_mem *vm) if (vm->sbm.sb_states && old_pages == new_pages) return 0; - new_bitmap = vzalloc(new_pages * PAGE_SIZE); + new_bitmap = vzalloc(array_size(new_pages, PAGE_SIZE)); if (!new_bitmap) return -ENOMEM;