From patchwork Fri Jun 23 21:14:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 13291311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 668E8C001DD for ; Fri, 23 Jun 2023 21:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231682AbjFWVUB (ORCPT ); Fri, 23 Jun 2023 17:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232841AbjFWVTm (ORCPT ); Fri, 23 Jun 2023 17:19:42 -0400 X-Greylist: delayed 214 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 23 Jun 2023 14:18:49 PDT 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 719CC3AA4 for ; Fri, 23 Jun 2023 14:18:49 -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=8o1B2LX7Hh8TNSfFwUWyg0VffJUQJIzGAe2D6u+TlYM=; b=W3acjQz81RgrW6TdUMeb4r5oVbvfBcJvglLvPyOomZw/Gz8zv3C2ybyt AQ/zZDn6VqQdCUL//CFztcf75hpwVKw2+UgTxjLTK+AnY3+yTDXwXfmru sa5l3mQ45KeFeCJR8op6gb0OOs7TVWJiQ+Tivrh+kEULUahwlkii+ThaU E=; 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="59686163" 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:10 +0200 From: Julia Lawall To: Cheng Xu Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Kai Shen , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/26] RDMA/erdma: use array_size Date: Fri, 23 Jun 2023 23:14:36 +0200 Message-Id: <20230623211457.102544-6-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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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 Acked-by: Cheng Xu --- drivers/infiniband/hw/erdma/erdma_verbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c index 83e1b0d55977..c49160f6ff27 100644 --- a/drivers/infiniband/hw/erdma/erdma_verbs.c +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c @@ -462,8 +462,8 @@ static int init_kernel_qp(struct erdma_dev *dev, struct erdma_qp *qp, dev->func_bar + (ERDMA_SDB_SHARED_PAGE_INDEX << PAGE_SHIFT); kqp->hw_rq_db = dev->func_bar + ERDMA_BAR_RQDB_SPACE_OFFSET; - kqp->swr_tbl = vmalloc(qp->attrs.sq_size * sizeof(u64)); - kqp->rwr_tbl = vmalloc(qp->attrs.rq_size * sizeof(u64)); + kqp->swr_tbl = vmalloc(array_size(qp->attrs.sq_size, sizeof(u64))); + kqp->rwr_tbl = vmalloc(array_size(qp->attrs.rq_size, sizeof(u64))); if (!kqp->swr_tbl || !kqp->rwr_tbl) goto err_out; From patchwork Fri Jun 23 21:14:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 13291338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22AB3C001B1 for ; Fri, 23 Jun 2023 21:21:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232204AbjFWVVZ (ORCPT ); Fri, 23 Jun 2023 17:21:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232955AbjFWVVJ (ORCPT ); Fri, 23 Jun 2023 17:21:09 -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 A6E6630F3 for ; Fri, 23 Jun 2023 14:19:49 -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=BOvAIPV5b2s9XXgIiUCDYijQMWfGXsngYuXLkntqOho=; b=oBORICMjMDk+FYpoVEcjGxoLDyziR5NvwJoDKLiolbwFfa3Z4eFHZSHL 3pG0TVOrluOqz7J/IM5bq1h1zIS7MSBXvaH4CZLEPk5H/3YJyn9/lUOID kTMHVnE51EZb+5cjH5miFKu9o0CoNvS2Z/vQfu4QQczhF8KbVHXdbHf5t w=; 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="59686172" 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:12 +0200 From: Julia Lawall To: Bernard Metzler Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 14/26] RDMA/siw: use array_size Date: Fri, 23 Jun 2023 23:14:45 +0200 Message-Id: <20230623211457.102544-15-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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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 Reviewed-by: Bernard Metzler --- drivers/infiniband/sw/siw/siw_qp.c | 4 ++-- drivers/infiniband/sw/siw/siw_verbs.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c index 81e9bbd9ebda..32ec85af0314 100644 --- a/drivers/infiniband/sw/siw/siw_qp.c +++ b/drivers/infiniband/sw/siw/siw_qp.c @@ -204,7 +204,7 @@ static int siw_qp_readq_init(struct siw_qp *qp, int irq_size, int orq_size) { if (irq_size) { irq_size = roundup_pow_of_two(irq_size); - qp->irq = vzalloc(irq_size * sizeof(struct siw_sqe)); + qp->irq = vzalloc(array_size(irq_size, sizeof(struct siw_sqe))); if (!qp->irq) { qp->attrs.irq_size = 0; return -ENOMEM; @@ -212,7 +212,7 @@ static int siw_qp_readq_init(struct siw_qp *qp, int irq_size, int orq_size) } if (orq_size) { orq_size = roundup_pow_of_two(orq_size); - qp->orq = vzalloc(orq_size * sizeof(struct siw_sqe)); + qp->orq = vzalloc(array_size(orq_size, sizeof(struct siw_sqe))); if (!qp->orq) { qp->attrs.orq_size = 0; qp->attrs.irq_size = 0; diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c index 398ec13db624..ddf83b638cb0 100644 --- a/drivers/infiniband/sw/siw/siw_verbs.c +++ b/drivers/infiniband/sw/siw/siw_verbs.c @@ -381,7 +381,7 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs, if (udata) qp->sendq = vmalloc_user(num_sqe * sizeof(struct siw_sqe)); else - qp->sendq = vzalloc(num_sqe * sizeof(struct siw_sqe)); + qp->sendq = vzalloc(array_size(num_sqe, sizeof(struct siw_sqe))); if (qp->sendq == NULL) { rv = -ENOMEM; @@ -414,7 +414,7 @@ int siw_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attrs, qp->recvq = vmalloc_user(num_rqe * sizeof(struct siw_rqe)); else - qp->recvq = vzalloc(num_rqe * sizeof(struct siw_rqe)); + qp->recvq = vzalloc(array_size(num_rqe, sizeof(struct siw_rqe))); if (qp->recvq == NULL) { rv = -ENOMEM; @@ -1624,7 +1624,7 @@ int siw_create_srq(struct ib_srq *base_srq, srq->recvq = vmalloc_user(srq->num_rqe * sizeof(struct siw_rqe)); else - srq->recvq = vzalloc(srq->num_rqe * sizeof(struct siw_rqe)); + srq->recvq = vzalloc(array_size(srq->num_rqe, sizeof(struct siw_rqe))); if (srq->recvq == NULL) { rv = -ENOMEM; From patchwork Fri Jun 23 21:14:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 13291339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF59AC04FE1 for ; Fri, 23 Jun 2023 21:21:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbjFWVV3 (ORCPT ); Fri, 23 Jun 2023 17:21:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231728AbjFWVVO (ORCPT ); Fri, 23 Jun 2023 17:21:14 -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 8D408359E for ; Fri, 23 Jun 2023 14:20:01 -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=8RgN37sI7dQZ+yBNJgvV+FVERbz2KA6A4JGbVoPo1D8=; b=ZLSOgmbfYoFK1LfswZnkAko5w1qaeuRTBPVtfsuJhYufYAShfc08lrY5 GfmwSRRDmk+b4IYZGmpWxgs4LgkYSVKQuaZq7LE+mHoJVN5ZQicrxpb1d qwR/n8FqYT1ATKyZe3Ay1Bz27c81Fou59W2Zj2TESMWOmR77CEA5urk0P s=; 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="59686177" 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:13 +0200 From: Julia Lawall To: Selvin Xavier Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 19/26] RDMA/bnxt_re: use array_size Date: Fri, 23 Jun 2023 23:14:50 +0200 Message-Id: <20230623211457.102544-20-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 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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/infiniband/hw/bnxt_re/qplib_res.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/bnxt_re/qplib_res.c b/drivers/infiniband/hw/bnxt_re/qplib_res.c index 81b0c5e879f9..f049b627e734 100644 --- a/drivers/infiniband/hw/bnxt_re/qplib_res.c +++ b/drivers/infiniband/hw/bnxt_re/qplib_res.c @@ -118,11 +118,11 @@ static int __alloc_pbl(struct bnxt_qplib_res *res, else pages = sginfo->npages; /* page ptr arrays */ - pbl->pg_arr = vmalloc(pages * sizeof(void *)); + pbl->pg_arr = vmalloc(array_size(pages, sizeof(void *))); if (!pbl->pg_arr) return -ENOMEM; - pbl->pg_map_arr = vmalloc(pages * sizeof(dma_addr_t)); + pbl->pg_map_arr = vmalloc(array_size(pages, sizeof(dma_addr_t))); if (!pbl->pg_map_arr) { vfree(pbl->pg_arr); pbl->pg_arr = NULL;