From patchwork Tue Jun 27 14:43:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8252402vqr; Tue, 27 Jun 2023 07:46:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bd36Lljb2bVFTgT+UFLy7e8rVlRCIGAncPxZAnVtu25b5KZPfU31HqjkOYcIyCmrd/9J+ X-Received: by 2002:a17:90a:74c5:b0:262:e912:270f with SMTP id p5-20020a17090a74c500b00262e912270fmr6069455pjl.29.1687877160527; Tue, 27 Jun 2023 07:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877160; cv=none; d=google.com; s=arc-20160816; b=pPRmYHHovY7g2e27hUxWLVtZPMRQvBPOtPLORsUUOTh5TvjErdjyBRu9PFVUa8gd/t StquQWJGxGB7bsz+C0XRe1Xvu0ScQJSGwNbmV7PjiAq3n99sLxl4sjDrX21hPjoVDO4n a5LKwwuVAlH+hmg9Slojq7HChvcPX6R2E6ao54xsWwpBi1koDQDSoEfx5wqdLibGWG15 yBf/Sx+Q6UzSw1td6tvxs5jSTh7DS+PeUp/sPqhvHt9WPr96Q6lBSuWDvMgnvc0PbUUZ 5JD2A9fraoCBo4uiQSvaD+5NKpd6Hb9ogDK7mIDMkv+2oVoASZ2yZ8PmA7B3hAYj8nz/ aVyA== 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=cW6FsUc372OgjCXWGlVTOpJDBn/sKhwbAV7MvUlsfDU=; fh=lH17MxD66mEZA0q9ApMflL6110os5JJlJCkBGCyBnjQ=; b=zaiIB/1P5wd0Wlh84PlF1twT2LhzXG/TLbx9IXgEtB6UoGhZRZSJcNGjtnEY0hmsTc hfT9PAwlof4L9cZasm9zn36gUp5FeHqvJTnDhdssOU12OlJFKD/1UmQT0V7ok87nE0bQ HhwWk9cksuKkyVxKW8QMD66WqrkjYQjVUq++zdmMOuXVDqIWh5adTt9gC01tflXUE8Na IC3i+Ea/E/qsnwBnqIKEKIPO9oaefIfikdtmdhCIuaQfCUVYZ/9DApgnxCQC4DLElL2h rcZMLfIeIihUkidQxNZ4IRp9oCJoq2V3P4d5C+VDjUN7aGAN27d7SlBnmHEX746tMBAn EUJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=jWt7EReJ; 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 c14-20020a631c4e000000b00543ae703b97si7545769pgm.209.2023.06.27.07.45.47; Tue, 27 Jun 2023 07:46:00 -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=jWt7EReJ; 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 S231771AbjF0Op0 (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231684AbjF0Oop (ORCPT ); Tue, 27 Jun 2023 10:44:45 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7654F12C; Tue, 27 Jun 2023 07:44:12 -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=cW6FsUc372OgjCXWGlVTOpJDBn/sKhwbAV7MvUlsfDU=; b=jWt7EReJ5kDtaESX69GV8d4liYZONaNjYK6YwdVqiDhOrR+UO9w9kKRo +ywuVIwSPjmV/l3kagzTPaaXWEA08ystOtiHsidk5aXckj/9gzF9Rpoj3 I1ITEQ51Rbp6KM/FiTv0VHqRI8yNXSJ9Lc78ZzS16NIIda7XjaWrQUZT3 A=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936318" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: linux-kernel@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org Subject: [PATCH v2 01/24] lib/test_vmalloc.c: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:16 +0200 Message-Id: <20230627144339.144478-2-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769867481705279300?= X-GMAIL-MSGID: =?utf-8?q?1769867481705279300?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. lib/test_vmalloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff -u -p a/lib/test_vmalloc.c b/lib/test_vmalloc.c --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -156,7 +156,7 @@ static int random_size_alloc_test(void) for (i = 0; i < test_loop_count; i++) { n = get_random_u32_inclusive(1, 100); - p = vmalloc(n * PAGE_SIZE); + p = vmalloc_array(n, PAGE_SIZE); if (!p) return -1; @@ -221,11 +221,11 @@ static int full_fit_alloc_test(void) junk_length = fls(num_online_cpus()); junk_length *= (32 * 1024 * 1024 / PAGE_SIZE); - ptr = vmalloc(sizeof(void *) * junk_length); + ptr = vmalloc_array(junk_length, sizeof(void *)); if (!ptr) return rv; - junk_ptr = vmalloc(sizeof(void *) * junk_length); + junk_ptr = vmalloc_array(junk_length, sizeof(void *)); if (!junk_ptr) { vfree(ptr); return rv; @@ -271,7 +271,8 @@ static int fix_size_alloc_test(void) if (use_huge) ptr = vmalloc_huge((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE, GFP_KERNEL); else - ptr = vmalloc((nr_pages > 0 ? nr_pages:1) * PAGE_SIZE); + ptr = vmalloc_array(nr_pages > 0 ? nr_pages : 1, + PAGE_SIZE); if (!ptr) return -1; From patchwork Tue Jun 27 14:43:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8267306vqr; Tue, 27 Jun 2023 08:06:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GHjF6SBPaJWCZdOXYHHR0uyzfKtdU0hOtTmNKvbtu6FI9Z4+sCMxZxIsJhbDeIXWKT2N6 X-Received: by 2002:a17:903:1245:b0:1b4:5697:d991 with SMTP id u5-20020a170903124500b001b45697d991mr11342528plh.15.1687878398208; Tue, 27 Jun 2023 08:06:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878398; cv=none; d=google.com; s=arc-20160816; b=TeArQFxIdqdRc/r8ZlwYrUwsdcqrvprIpDnklCDtsh5BTPhmKlRzzrsneH5v7Eo3MX OKLQWFYl7izLc4CT4VNTCp1ybckbnSR2om+DB9R+RI0+2SmVlI03oqpETNYlaC2pm1jM 5i0Y0iXOw9o7vPI/8UN8oJmqKpEe5maSwkRcqMu1tjRoYLJcXFbyldC38eDvlmk+BJzS 5zEEfP7drjmxHLj+w1K4XzOW7wksPHh9I8yLaiG5fjSisWuDpcosvq7RiB2iKAQ6Pd4T yXMBE16HsAOoI20AYiLjzp8afCDXN0IV1DkpvDMCf2PryWiU0AlIUnKoeBhZ4b/ASI09 YTfg== 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=EVWsKZHA5sOX60HufObe+UOCTdtjhEjhk52tD7khaXk=; fh=eOmvIS7lT6UGkAkNGkrYPducpbNj1vRpvotfriH1k1c=; b=uYM7qzqnviuOjWFxIYTrQpy6kkuPge7gQ+anOYwJi5b3XbzATMkvNzsSGZUQhFTkdE jk2i5AfxHO7wTJKsiWr1pVD52hThUD2MtNUiwQWzvtbKVjHkyRoBfoojvOiHasxM0pmj hsTpgBEtpHSLTujvF34Li5yte+ickZ1V542UivYnENHcBkBVfuQS976Z92jK9cpEpkeo W1VH4amDd070XdqpMFTaSGhqvDhD9uOSWmGIEzsdFbu+myyYoSoABBA6PLw/1vqe8BKR rLwsRErsizqoZTiaPainlFd8W/h/7XTlzBzkXnb9EJrcSbrqQ5H6t0JJZzcHwXqQJi2J cvlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=YiBhSF6i; 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 o16-20020a170902d4d000b001b530ede2besi7748724plg.614.2023.06.27.08.05.36; Tue, 27 Jun 2023 08:06:38 -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=YiBhSF6i; 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 S231925AbjF0Op3 (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbjF0Ooy (ORCPT ); Tue, 27 Jun 2023 10:44:54 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E1730F9; Tue, 27 Jun 2023 07:44:31 -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=EVWsKZHA5sOX60HufObe+UOCTdtjhEjhk52tD7khaXk=; b=YiBhSF6iFx9Y7bUlk/oeZ9e9XBU2wtUjxdXzeaWAa04130mi7xMLwQ7/ D5clOwTGrRgCVQj0YszXht1xsutUj8JN6X+TOWF432vl0LvK2epGu++PW JSpcR1yhL2M21hPKmCNNbg74dczchrf+cqRoFMmR/AbJ/HrTa9At4AYdg U=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936319" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: Veerasenareddy Burru Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Abhijit Ayarekar , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/24] octeon_ep: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:17 +0200 Message-Id: <20230627144339.144478-3-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868779528645403?= X-GMAIL-MSGID: =?utf-8?q?1769868779528645403?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/net/ethernet/marvell/octeon_ep/octep_rx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c --- a/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_rx.c @@ -158,7 +158,7 @@ static int octep_setup_oq(struct octep_d goto desc_dma_alloc_err; } - oq->buff_info = vzalloc(oq->max_count * OCTEP_OQ_RECVBUF_SIZE); + oq->buff_info = vcalloc(oq->max_count, OCTEP_OQ_RECVBUF_SIZE); if (unlikely(!oq->buff_info)) { dev_err(&oct->pdev->dev, "Failed to allocate buffer info for OQ-%d\n", q_no); From patchwork Tue Jun 27 14:43:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113450 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8252694vqr; Tue, 27 Jun 2023 07:46:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6ZXJ4ISH1V6XARoV6Ru3rVZBZmBgZ42tlED9+hDvJiJukxtdwUbY9QSlFsm4vMRVJn9w5a X-Received: by 2002:a05:6a00:b4e:b0:67f:d5e7:4604 with SMTP id p14-20020a056a000b4e00b0067fd5e74604mr245351pfo.13.1687877187810; Tue, 27 Jun 2023 07:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877187; cv=none; d=google.com; s=arc-20160816; b=Jlhk4zYpB/KUfiPcslzx3lEqjvleNzkNHCPBrjr0Z2ohXpYnGMMzv47BcVZpm1NW+q 0G5dhxlMCNHAsg7xhIp/Uowa9oll0oGcN8eNvCn0EtAUZmQsIB15hu66yPxTS+nv/Mue 1M0W2b2PCjlbByIc7tCPM/ec/JfnF0VpOJPiQmWnZX/2D94Ffb7xJbXjW5wbKgZyPD+Q pcw/Ny6BITDABS8ozVeiTsAZVGh9qV2U9/2sY45WVh87Aq76LQkBDWT8jGsOFnhAXnU7 VWCanctcRQL6EKgRtn931fDZzlJPohi8k4pZWEY0zYqSzT1+zh5XaObLKByVDaNRu9Hd xF7w== 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=e/q9GJUjVjbhzGKibBqdfdyRa1uJDPYc59CeSzfnNk0=; fh=KDjSc6TiaTxYeTQgAIDgbheP2RhMXxXkYk4QBAdMl5w=; b=HoQVC/y0kBQAa85MifuXJcvmPWRcA0AfQjcX0QQRSmeAsUv3YKlB0X0U1WqP0Yvxru wxSSy8WjhoIFu3nWgtag7RB18v/MDqY2b74DCGEPY4UCXrAh0x9HVpa0EboAApLt06CN usv2vrnDbT75kcnTi2bKboiGEz6Dyk2Tl52hvKy8x2xf9rX80f3eP81OVw8m4ukKAans sUMnazD5aUC2DNHuSD842/PGh07bJiORhULcKnd+VlSFTPaRkPGepmgbbG6VUrlpc3YF 9MFGScESNWNswRnUy3yecqnl55NcysYLYNDBxRyyoETHgAKzI2TYd8yXJicBYO3RN0Rc /Ysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=LFjLqDcU; 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 y23-20020a056a001c9700b0066888630a21si7197675pfw.67.2023.06.27.07.46.15; Tue, 27 Jun 2023 07:46:27 -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=LFjLqDcU; 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 S231960AbjF0Opl (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232169AbjF0OpF (ORCPT ); Tue, 27 Jun 2023 10:45:05 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9313B2D69; Tue, 27 Jun 2023 07:44:46 -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=e/q9GJUjVjbhzGKibBqdfdyRa1uJDPYc59CeSzfnNk0=; b=LFjLqDcUJOS8QiGxmMwTJ1y4Iep+0HGsVtpDuCawBY5+SQrzARKEYY+e LpJ/2nlUx2u6cO9WYFeUn5ZI5IackFgqx7NrkFGfOUSrq5MH+vXpPKEWq 4rRq0ltEIc/oqu2mZbmlmaagNsebxFirot+mQAJKsleackI83o/NMh+pZ A=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936320" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: =?utf-8?q?Noralf_Tr=C3=B8nnes?= Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/24] drm/gud: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:18 +0200 Message-Id: <20230627144339.144478-4-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769867510138960889?= X-GMAIL-MSGID: =?utf-8?q?1769867510138960889?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall Reviewed-by: Thomas Zimmermann --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/gpu/drm/gud/gud_pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/gpu/drm/gud/gud_pipe.c b/drivers/gpu/drm/gud/gud_pipe.c --- a/drivers/gpu/drm/gud/gud_pipe.c +++ b/drivers/gpu/drm/gud/gud_pipe.c @@ -390,7 +390,7 @@ static int gud_fb_queue_damage(struct gu mutex_lock(&gdrm->damage_lock); if (!gdrm->shadow_buf) { - gdrm->shadow_buf = vzalloc(fb->pitches[0] * fb->height); + gdrm->shadow_buf = vcalloc(fb->pitches[0], fb->height); if (!gdrm->shadow_buf) { mutex_unlock(&gdrm->damage_lock); return -ENOMEM; From patchwork Tue Jun 27 14:43:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8270893vqr; Tue, 27 Jun 2023 08:10:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6RnqiVB+wXchoGzXAXwnpVmIYBS9TITq0xnTgkBmOPh/6OklFBXpkQa56Ccf9nlXFgfbct X-Received: by 2002:a17:903:2342:b0:1ad:f138:b2f6 with SMTP id c2-20020a170903234200b001adf138b2f6mr13145396plh.16.1687878632274; Tue, 27 Jun 2023 08:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878632; cv=none; d=google.com; s=arc-20160816; b=Kt/aa5PvTszcqr3O91KkjY51gNDmF4xqTew7vBGm74FaQ4NUP3HzuyRM0N/5bHZqQM x+jXLmxv5XFYjoRhIf62+KAoj08fm4By0HPAnPXSV+tLfbt07U+X5nlMFkeY61jmEo4s 7nT6ZqvNftY5peV0lmh1i/Ahjv8VVSbJQQsTRyhAcGm2sNAb6Hut94JmkYlRtiiww39c ExGmmnGk/H/GkN5P+YaXp2akv7ptRtL5e2BqViGzbTPji4eMKuiKD43KJPczmEOohibz xJb+S+w+Hjk2ZYZEKdBZ4C/m+C22ll8PzYE2ZYXalYrQp3HpdHhpAO0q304IFJyRklz2 BiCg== 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=9Uv1/3sMOK5WjHkwYctB4Lm1eQ43JKgqddzae9sDlAM=; fh=gLlWIf+O21ga8Sv1wgcsqEfUZdKyvaDY+SrmHgYl8iY=; b=tlFeV9pmvkzNL3OjuRXn5JfvT1mfRQ7g2lVaYS7LIVGBqRQVCdSWzLm+fSPDQrgARS NkG7O6EtfHg4iotUFU6qQ1osoBiidjmTUs/WyVqjSl/fqLyN2c8Cn041QkZCCrOfgHE0 UczWJhJL+lDTdvnxRaK7RyJyuglMgwqR4CtdOtME452qnjFpp9PHoDDAJQdct3SMyOWa o73WZ8CWrjem2lzoCGLNxeOK+A/qkRdf5eXp6DUrkfhPQ5Rr3FOLkbw0F9ojmJi9Mcb7 2ZNgk8ruSTVcDyk29jZ2oiHHWBspQ8h6pqFUDdCPwkyiVeHNAe2TgQxvYYbcoj3v7Ufd l1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=jFLOVyOS; 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 q4-20020a170902f34400b001b8096934c4si3568348ple.256.2023.06.27.08.10.18; Tue, 27 Jun 2023 08:10:32 -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=jFLOVyOS; 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 S231975AbjF0Opp (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232187AbjF0OpJ (ORCPT ); Tue, 27 Jun 2023 10:45:09 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19CB8FA; Tue, 27 Jun 2023 07:44:46 -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=9Uv1/3sMOK5WjHkwYctB4Lm1eQ43JKgqddzae9sDlAM=; b=jFLOVyOSfjgRFE1+axxBVSiw9elyDAC/qWd/c9+ZPqESIpXQlrmrruqO a88dlv1GtRFSBKP5PALtKNdYjjXSm2eb2PWOcLxcnVjyF4pP4+8m+6i68 yjU33agmfZ2rT3nr7Xxmjy1sw1hZZ8YTTnAmp2+CU9UGypaoT6x8oCkIg A=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936321" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: Jeroen de Borst Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Praveen Kaligineedi , Shailend Chand , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/24] gve: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:19 +0200 Message-Id: <20230627144339.144478-5-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769869024380645221?= X-GMAIL-MSGID: =?utf-8?q?1769869024380645221?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/net/ethernet/google/gve/gve_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/net/ethernet/google/gve/gve_tx.c b/drivers/net/ethernet/google/gve/gve_tx.c --- a/drivers/net/ethernet/google/gve/gve_tx.c +++ b/drivers/net/ethernet/google/gve/gve_tx.c @@ -248,7 +248,7 @@ static int gve_tx_alloc_ring(struct gve_ tx->mask = slots - 1; /* alloc metadata */ - tx->info = vzalloc(sizeof(*tx->info) * slots); + tx->info = vcalloc(slots, sizeof(*tx->info)); if (!tx->info) return -ENOMEM; From patchwork Tue Jun 27 14:43:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8271598vqr; Tue, 27 Jun 2023 08:11:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74n6LNdq1aQGCk238vgbwUFyz6wpTdbYSH39B/N9z0I3kKxuSFa5twI4mbGc6cYev/OqYw X-Received: by 2002:a05:6512:348e:b0:4fb:745e:dd01 with SMTP id v14-20020a056512348e00b004fb745edd01mr3564572lfr.45.1687878682121; Tue, 27 Jun 2023 08:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878682; cv=none; d=google.com; s=arc-20160816; b=oxbzd8mTL01cvNhOaqRJKjCPIDD8ynjP8tLAp84I3HP05IRdv7d+hg4LvIifI2LVkh ATH6/G5P7HKX5zLzffyoWGNEaLM6TwBEgXL4BrbUeoAO0cuD0WMuHDYOaeQpuuTKCD07 QZ9g9CDSE1tsOa00DlIh9qV1sVAJ6TnLM44vhIB7mdobgPIfi6lIPfrSUC7FLdljNiRN erIvC7ARuBVutiXJBscEs3vXNC5s82bWuKHm8Fsxf7N/kqtwPC0fBbiB/9aLZlNwJy5j QfcPfijFGJmyrkX3ShD6zzslmeHTfEF9FY9P++YQfzLUiEgtxB75rdwzOpsaE1luI/dT 1QNQ== 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=OHv2BAP3aRkKkSVfOQ7PNXJXXJkfxWmwjM1eG5qnd00=; fh=Ygz6F1xnF1zM4n1U3QukXT1v1FK1PfRfZlLDTSzpaMU=; b=wEkd2OLwO/hfuB+r+ySVavmeA/CJSDP4fK3NdU7sgVuY1q4q41biQWViAkTeJ3olSu HMT7fr6EfDHmGlLRQTXaZ+HVp+rDhb8PZ7G1oiGDfPu/OlP8zWrwxpFVNhKclQH4kpy5 O2r+fIVy1Ocv68M+CMKYvHpF5OtAmEWCWvCMlnIJZ9qWHNxOBLucCzVZOPDTrFcvs1d1 VV/xtG4eX+GQCXewvMYzbhzRRNa2lNB27Iq7K7LhZwEKeVgPmTEc+Z2EXi8iLzr+hVbb N80VOjuofok9fiVad5vit7O6HeS0Lsszk/JXe0f7MP3wVgYVKQj5+6FFdziYYdVidRiN cnCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=uWxagvqS; 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 d15-20020a056402000f00b005184a09e9basi3862147edu.601.2023.06.27.08.10.55; Tue, 27 Jun 2023 08:11:22 -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=uWxagvqS; 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 S231981AbjF0Opu (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232207AbjF0OpL (ORCPT ); Tue, 27 Jun 2023 10:45:11 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A67463593; Tue, 27 Jun 2023 07:44:47 -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=OHv2BAP3aRkKkSVfOQ7PNXJXXJkfxWmwjM1eG5qnd00=; b=uWxagvqScJ4P/eaWlwExiFn9fJPU7N64Zvsr7shHMa+4qAIIkcRXjsDK eOh6XoEpvq48Xf/zwXlYXqObrFaDd1vUTLpcpW1DabzmJuEMY/JqpRasu FjmjeNNt/ww0IQj/LKk3VC2H1IcYqjOTpYP+fvSDTIMkkqW1wJ61EbMFv Q=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936322" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: Cheng Xu Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Kai Shen , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/24] RDMA/erdma: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:20 +0200 Message-Id: <20230627144339.144478-6-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769869076622581369?= X-GMAIL-MSGID: =?utf-8?q?1769869076622581369?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/infiniband/hw/erdma/erdma_verbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/infiniband/hw/erdma/erdma_verbs.c b/drivers/infiniband/hw/erdma/erdma_verbs.c --- a/drivers/infiniband/hw/erdma/erdma_verbs.c +++ b/drivers/infiniband/hw/erdma/erdma_verbs.c @@ -481,8 +481,8 @@ static int init_kernel_qp(struct erdma_d 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(qp->attrs.sq_size, sizeof(u64)); + kqp->rwr_tbl = vmalloc_array(qp->attrs.rq_size, sizeof(u64)); if (!kqp->swr_tbl || !kqp->rwr_tbl) goto err_out; From patchwork Tue Jun 27 14:43:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113458 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8259425vqr; Tue, 27 Jun 2023 07:58:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4JGKeibn5h7GvCnJ9Nf6NItgJ1M0FKo8O2OxR8VhJxbzESA04KUNGNkj9WbHdy5R73oaB0 X-Received: by 2002:a9d:7408:0:b0:6b7:518a:1672 with SMTP id n8-20020a9d7408000000b006b7518a1672mr5206945otk.34.1687877886090; Tue, 27 Jun 2023 07:58:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877886; cv=none; d=google.com; s=arc-20160816; b=nSOEcX2j0UcGNnUl+dJvySyAfa1S/Gx+Ak+HC5qbHvQ8sWoQApjEBO2hxW/ABxeGvw w6nK+nt+Ral2A72L5rWnt9k32e7ij4G+bEb8QiWNbMNszI3Xc4/esTZeKGWWlXzYb2mJ /QVu/eq0CAEY5PY8JR6tPszG4qeL1/kaUWhyOKU91a4sWYBMDzw3zP177cNiWa6u30g0 yeYKfhkrEANOitm/wY9B61sQ8WYhhck9bwmiSpE7iTGqwTwz32EnP9winIa0F2AR+yaj IA5bl4gKdL/No3EAqyG2zn1OW4ZCAR5KZVHGCbEBpdZcUEhPjgP1Qqzkkr+AjQgdToZL 5RyA== 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=BSv2qibrxL39vitaWqz38N4RpcUIwxJv+1q57KgeapA=; fh=ZOby/FnckUC+VASmlT/H3idM9WGy/7LzfEft/Of1qNI=; b=jqIK59K7YtTyGT0hp67uJ7Ae/VVSN/nOdFWxGBAyZJme8pSsdIlyhxzYneGMKeRyCQ nCJm7ibpSEqr13JA2tdpjfbXq8f+ak+V18i5JzM5HDYo0wHwGhJ17Z9B0iJwSHDVJvC4 +aoh2z6qqBxXNTEOgzgpgidCOdEhp7eBo1PFd51UiYrag3FQG6JiZ6ABZXJTsCcmNRS+ gEUqx+Vwn6z3+2fu1NxC6twwQUjfuzgqNfr3RY59J2WeY6bxYjrSEkHtZlfRNp2/uPsz E0QVxi13vrp1Ho5E30SX9/xRIz4kKiab4TITZGLcKOvoyWehJ0SRJuqPv+lJAfyxt+Bw MGZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=orZaBSyF; 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 s2-20020a6550c2000000b00553d5cc2c8bsi7360649pgp.508.2023.06.27.07.57.52; Tue, 27 Jun 2023 07:58: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=orZaBSyF; 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 S231939AbjF0Op7 (ORCPT + 99 others); Tue, 27 Jun 2023 10:45:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232283AbjF0OpU (ORCPT ); Tue, 27 Jun 2023 10:45:20 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA8CB297D; Tue, 27 Jun 2023 07:45:00 -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=BSv2qibrxL39vitaWqz38N4RpcUIwxJv+1q57KgeapA=; b=orZaBSyF/DmIgjzGMdI3ecENh8T0Rpi5NjDgXjWmm0IiI0c/SJiqga6S Hm93XWBkr0orqShR+FhXfGY6HphUFavxbllc3ygUWsrJxZX7j+aOxBwD3 465HZncpUz2LekQrVlyX8y8k6UOL6NQ6pfoYCkY6Uk8+n9vBNWAKwLPt6 c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936323" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:51 +0200 From: Julia Lawall To: Sumit Semwal Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Benjamin Gaignard , Liam Mark , Laura Abbott , Brian Starkey , John Stultz , =?utf-8?q?Christian_K=C3=B6nig?= , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/24] dma-buf: system_heap: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:21 +0200 Message-Id: <20230627144339.144478-7-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868242360716155?= X-GMAIL-MSGID: =?utf-8?q?1769868242360716155?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall Acked-by: John Stultz --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/dma-buf/heaps/system_heap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -221,7 +221,7 @@ static void *system_heap_do_vmap(struct { struct sg_table *table = &buffer->sg_table; int npages = PAGE_ALIGN(buffer->len) / PAGE_SIZE; - struct page **pages = vmalloc(sizeof(struct page *) * npages); + struct page **pages = vmalloc_array(npages, sizeof(struct page *)); struct page **tmp = pages; struct sg_page_iter piter; void *vaddr; From patchwork Tue Jun 27 14:43:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8271379vqr; Tue, 27 Jun 2023 08:11:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7AMMaSPhlM9AVD7ORflAH6cPCQHL/8cuemKLqTtWIap7IvOS1MvrjRpIDQ7I/mFeAQ/qO5 X-Received: by 2002:a05:6a00:809:b0:66a:4a45:e017 with SMTP id m9-20020a056a00080900b0066a4a45e017mr18767145pfk.20.1687878665304; Tue, 27 Jun 2023 08:11:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878665; cv=none; d=google.com; s=arc-20160816; b=AVfn2BezGCcKmcuVgOOzF1YcCjqk5HD6uFXi2xqS6r79kPmUNRBWHaCifoCUX5vUoe aApWP6Gh3RH7arbgKIHuCYkmQYUXPIie2a7HPP3X9vrrb4g3DEZV+C874l4UGOgBeFvi +jc19XbF0xAYVkQm8cVSQfFRIYCBqhYI1ZiHkR/n72dNwG0UAVFKws0mW7nt8hfwNDhU qanTuzilaXJhpefZLUOChkAzrPDN80ebH8QMWFHT3B3GjTa22CgnM3Y4/+aentAIkq8I ZsuUye0va5EivolSzUOfqNPaYdKCjuxrcIEpX0z3jQNDBEoF+HWPWj6PYeys3TxGuKqB hCtA== 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=1tnGFewg2jR0iMP418C+xvB2RAhFZotb9IdUilMQXSs=; fh=plZTqtxM767CadgDJEMIJwoLy2otFn0Mka3ObEmb46A=; b=Z4CERN84DQTuqFQq8OdwRywvbN0R0wbcemwQwgzphj4TnHUkVUcy0rhnKHWKjJV3c1 1rY2TlPqQ/ZY0A7BGJY7UULUaqGWUwPzdMl9oxRRC88HK1BAgANNpfICsMoaKDrr7r+3 3RdMGyvyYCJUir69NU8wBG7LobEiSrGlezUE9dRdSSztu0sc1Femw36Iw3Mz0S4acLoL 1DQbF7Y1qhuKZ/UbxjvOS+pgXNcYeMyWXfqRlrrB2fDNjF/RKQVSx0JOErzAsoG9eG7i 2h9jdC0SBo1oZhgwMlJMlgB5PSBPwrnHU6ABX/3/A5hGo8wDhRZuBPGbEf4iFvkeBqXd 8j+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=t3l9LnZl; 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 g17-20020aa79f11000000b00678b9f5aa99si3774114pfr.66.2023.06.27.08.10.51; Tue, 27 Jun 2023 08:11:05 -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=t3l9LnZl; 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 S232043AbjF0OqD (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbjF0OpU (ORCPT ); Tue, 27 Jun 2023 10:45:20 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36E2F2D4A; Tue, 27 Jun 2023 07:45:02 -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=1tnGFewg2jR0iMP418C+xvB2RAhFZotb9IdUilMQXSs=; b=t3l9LnZl8E31zljbSHPAQNc818zyETs8RMV762Np9tk93rnpPSWcxAce TZQi4X52h0ikF+kYiol3tCeBK6JJsOV2esoYvTmI3RCoGk5b/TA/lljL0 SuoaPWdfYHhQXBVqBGGSUeEtEQFPzrf/VtcqN8eLC8l+glhRTE6hvHivX I=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936326" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Satish Kharat Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Sesidhar Baddela , Karan Tilak Kumar , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/24] scsi: fnic: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:22 +0200 Message-Id: <20230627144339.144478-8-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769869059456976821?= X-GMAIL-MSGID: =?utf-8?q?1769869059456976821?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/scsi/fnic/fnic_trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c --- a/drivers/scsi/fnic/fnic_trace.c +++ b/drivers/scsi/fnic/fnic_trace.c @@ -465,7 +465,7 @@ int fnic_trace_buf_init(void) fnic_max_trace_entries = (trace_max_pages * PAGE_SIZE)/ FNIC_ENTRY_SIZE_BYTES; - fnic_trace_buf_p = (unsigned long)vzalloc(trace_max_pages * PAGE_SIZE); + fnic_trace_buf_p = (unsigned long)vcalloc(trace_max_pages, PAGE_SIZE); if (!fnic_trace_buf_p) { printk(KERN_ERR PFX "Failed to allocate memory " "for fnic_trace_buf_p\n"); From patchwork Tue Jun 27 14:43:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113456 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8258567vqr; Tue, 27 Jun 2023 07:56:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68RjNRXHe8IIMQcp8qvswQNCkTUmbFzge7nPm8QqnsK6ch4n8T9XDtmYwTK31xjPjEFCRf X-Received: by 2002:a17:907:2cc5:b0:988:2a2f:91b9 with SMTP id hg5-20020a1709072cc500b009882a2f91b9mr28919613ejc.63.1687877789543; Tue, 27 Jun 2023 07:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877789; cv=none; d=google.com; s=arc-20160816; b=Viuy+Ok4sbHEORMAi51PPHJ2+2FBcloVfh6gJ9h3KND0ib+Om8JmAUJiBDa1gUPEAK TsBDibJcGMxAtTg0pYroCQ1cMgZwJ7mltQMdfdwuylz5uISIPpuSuGAChs5PMOoACnIY RlA60YVyOufKgWGLqvOcWx6hSkHpFJ+3/w62n/9cXK/wCbpvr4DbMaPG3lCJFjKF6rYn 6L750Tp9H77KJMYhdwNnUOd5d5FMyOZKcnU5dj4Y+tg3aJTj/kcanwkn4e09xPW1pEm2 GoJgQD1rH2gG6pae+r51ykUr43HVyqwhkWz2Gi1+6fd9LMUWyYANxE18ba0/BZipwsMG aAyQ== 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=N7AP+04mjhCGwoi8mZXHhSk+FSTzVi3y4B9SmymBm1U=; fh=NpAvJDIKFrONVSWH1MNdtvSMQD99BcTZxtEaAewZwLY=; b=vD8ZJ/y6fyYydn4EEIzD8pdRuEiTH4BpI3Ezn6Ftm2dRmQPgia8NldgBiz0rVG0a35 xeJLCFuUDdkQf3KYveq4sBjQjNEehPGgiiVLmIg7rSdV6QFv9vg7hT5M0xryFl48nF4E +XmxCOaUdOLgrTnYfXAv5qgaIah0swl/3+wooDh2an0dELcqr6HdOFM41eFdzEa+wE8b tF1kbG20SqAj0ja/d/oV6ARh/VCrfyJoGkZPmDReamzeg+UqEnemYjaiSxEfrgEbmeEX dDAzjzTHGdrSSxQt1/DADGpGGwmins4gry2fd9Cg8lg88BdDlMub8yiKzsPjAFEJlyAj SIag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=B5JvCzRE; 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 l24-20020a1709060e1800b009883df8c277si4196304eji.578.2023.06.27.07.56.04; Tue, 27 Jun 2023 07:56:29 -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=B5JvCzRE; 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 S231887AbjF0OqI (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232289AbjF0OpU (ORCPT ); Tue, 27 Jun 2023 10:45:20 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E4E2D4F; Tue, 27 Jun 2023 07:45:04 -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=N7AP+04mjhCGwoi8mZXHhSk+FSTzVi3y4B9SmymBm1U=; b=B5JvCzRENXTsKMxGoAGWDZconALS+TZ6d+BIM/Uj91ZMG/CjYrbSuZL5 cSjibfgl5W8ZARbYN8LLgUzgR9uC5N26eP6fq0BIhiA8Mq6iI72EjX8U/ LFjRMPW39Gxgve/rAjVifL1QL73pzu3CjjBc+AmlLQyO6/m7A4vyxOp/P A=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936327" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: David Hildenbrand Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/24] virtio-mem: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:23 +0200 Message-Id: <20230627144339.144478-9-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868140938015373?= X-GMAIL-MSGID: =?utf-8?q?1769868140938015373?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/virtio/virtio_mem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff -u -p a/drivers/virtio/virtio_mem.c b/drivers/virtio/virtio_mem.c --- a/drivers/virtio/virtio_mem.c +++ b/drivers/virtio/virtio_mem.c @@ -399,7 +399,7 @@ static int virtio_mem_bbm_bb_states_prep if (vm->bbm.bb_states && old_pages == new_pages) return 0; - new_array = vzalloc(new_pages * PAGE_SIZE); + new_array = vcalloc(new_pages, PAGE_SIZE); if (!new_array) return -ENOMEM; @@ -465,7 +465,7 @@ static int virtio_mem_sbm_mb_states_prep if (vm->sbm.mb_states && old_pages == new_pages) return 0; - new_array = vzalloc(new_pages * PAGE_SIZE); + new_array = vcalloc(new_pages, PAGE_SIZE); if (!new_array) return -ENOMEM; @@ -588,7 +588,7 @@ static int virtio_mem_sbm_sb_states_prep if (vm->sbm.sb_states && old_pages == new_pages) return 0; - new_bitmap = vzalloc(new_pages * PAGE_SIZE); + new_bitmap = vcalloc(new_pages, PAGE_SIZE); if (!new_bitmap) return -ENOMEM; From patchwork Tue Jun 27 14:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8264834vqr; Tue, 27 Jun 2023 08:04:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ45fblMISnDX2qHU0s+MF2fbLFJC7umpxYLNnv5/bY8TEesPJg1swWxx9Q+K97elmCKN8S0 X-Received: by 2002:a17:902:ead5:b0:1b8:2a96:6471 with SMTP id p21-20020a170902ead500b001b82a966471mr1011234pld.46.1687878247067; Tue, 27 Jun 2023 08:04:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878247; cv=none; d=google.com; s=arc-20160816; b=GiLSSNtSeRJEoF9p9dNX6lwZNz0hMNMF8lj7Auq0gI2Pj06eyQOtGnmRhSzU9dpuAw arhrOZUGK3hx8+DL6zX36iicQJgMyVnwRpLY119VWkVvsUu/JQcGJUXy+ECb35Cqcjpf s5v86Y4WoO6dqKnXH6XJ8TY+GoAd3Cz0Ts9cpoT7zMWN+0bOqv9IUkp/dQKE7zI+U/jX CJIWtUXRX474Wf6iwkqmtQmXLzbU+Gfir6yfnAgGRA65iD89vmdYvD672uNjhBDa80+O b/Wopni/X8upZMXB9vhf/mWeXuNFdSsRy+xeb6DepM3mrqni3G7UcQaiI0bpsu9sxAdi bmEQ== 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=fzSlg9RNv3R+3q3XKuXY+6o6TuoQBOkN0UNS+oRdi0g=; fh=uYoBPU9uLNfv2jsr/TuWKYWHj5pvtXo1hvKYeRwcxt4=; b=m0JDFAFY5r978vasyU6Ev8vK2huUBwxBpGldtjWBi3ToFPd9Z1pIQs+4apoDdXn/uB /S9LI/O7sOgLqkNfulMlpgr8oiGe8wJZzDpmKJ1iWZfS81tvpI9R5UdBNeBTb0ABBJC4 McqXz6rnLGUmTn4QzJkCe4L38RE35QK2+223Ksr2RDVoHVm9N3L++bb5bpPW3AYpshAp tM5vEiEucR919C3IKwxpTneRWNFtsD7iqdlVwHgjJHS8ODHFzbTLCABt3VQJXk9Dwsuc eMeBEOOVckQ4luMctZWluFyv98vvjjb2GwSkIJFXBEJqNYUK4I7sBT9+fc6Eh1Y8+umM x3uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=dpxRX6SK; 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 o16-20020a170902d4d000b001b530ede2besi7748724plg.614.2023.06.27.08.03.50; Tue, 27 Jun 2023 08:04:07 -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=dpxRX6SK; 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 S232085AbjF0OqR (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232334AbjF0OpY (ORCPT ); Tue, 27 Jun 2023 10:45:24 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F11230F1; Tue, 27 Jun 2023 07:45:13 -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=fzSlg9RNv3R+3q3XKuXY+6o6TuoQBOkN0UNS+oRdi0g=; b=dpxRX6SKkutCFKOYF4CwCciL+V9U5RgWhgmvlkclZlRvImw5QJ17O2LY M9nttluQAh/UNtlB4llXPA7Jwu+IR5YR2l36V97hbUU6lLQSksCae62fb VSdf3WEpvEHszDLULnIk7nnYz+Z0KY2ThObKD3MYXOgxPiP06rK8g0GSU c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936330" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Shannon Nelson Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Brett Creeley , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/24] pds_core: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:24 +0200 Message-Id: <20230627144339.144478-10-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868621038607914?= X-GMAIL-MSGID: =?utf-8?q?1769868621038607914?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/net/ethernet/amd/pds_core/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/net/ethernet/amd/pds_core/core.c b/drivers/net/ethernet/amd/pds_core/core.c --- a/drivers/net/ethernet/amd/pds_core/core.c +++ b/drivers/net/ethernet/amd/pds_core/core.c @@ -196,7 +196,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, un dma_addr_t q_base_pa; int err; - qcq->q.info = vzalloc(num_descs * sizeof(*qcq->q.info)); + qcq->q.info = vcalloc(num_descs, sizeof(*qcq->q.info)); if (!qcq->q.info) { err = -ENOMEM; goto err_out; @@ -219,7 +219,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, un if (err) goto err_out_free_q_info; - qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info)); + qcq->cq.info = vcalloc(num_descs, sizeof(*qcq->cq.info)); if (!qcq->cq.info) { err = -ENOMEM; goto err_out_free_irq; From patchwork Tue Jun 27 14:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8262716vqr; Tue, 27 Jun 2023 08:02:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55qaIWXL2nmPoDLTI+6sADV8H83uXq/sIp8O/elHk+TICmNrfyEwTet1Tg1gqJknHhwz+z X-Received: by 2002:a05:6a21:329e:b0:10b:cdb1:3563 with SMTP id yt30-20020a056a21329e00b0010bcdb13563mr41552833pzb.46.1687878128215; Tue, 27 Jun 2023 08:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878128; cv=none; d=google.com; s=arc-20160816; b=vIdpDSrbj2k96utbS+MNnY8+LDrXC99Wh60SwybFKLRt1RaIFTd5ergbgJYqbu5rgm QNjuB73GuCUn+tcLw8Rus5C1SvH1Gvp0yUhuBbZ+WkD3EDAd3Eza9JyL29BBYULCETRu 1X3oglGt3tGmIO0zIqMwEKIwpK6vCFrWJLLxkrmhiZBpHSOyvooSk+2ajkgtvtzzZLtd 4GSPWmrGUibToNZhvC6fezXPUh2bwpDTOqRzLo6zF0FvMdzqPLDSskYcGauTmJS9XP+G tGD8FpgjB+XYPCKDtIbRY0+yaFMJ15H/XmUgeGI48TX3+MVZGdGtwCoNA5izup03BRcm zTfw== 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=1d+HkOGv6OfyiMGAQyiABbRWZaDBVJgUU8HY/iw2H9I=; fh=i4XP3ebgau+VIgOC4KmKLKwKpAqWxsePKVnX8jeNB6M=; b=BR4yWvjfZXtMF8c0o/YfpsRD4CFlmH8eH0iOWwtJaoYr2JMgYdKyIc89jYHwdceB+3 5Md8dlNRokRVjmempmricJy9JnlGfazzp99W6wNxil76XHx1lsviQkVFzMrVUal3rct5 0kjwY+7eqaC6VHAFxKcHinMqi3hsxXo+x2Q6Wi8tJKtR6mjBZhYv+7Y6z7NKMs9iwCEM 5xhbPFrqtvuCRgUOBQ6TNvttFS/LhIT+hsNexSKjTqPMWss40XHGh9MvYc80TJ0ygkYt fnwkaEm4JJe+CnP2rEgQceQx4VaBzPfapqRw/jt9RoNgmfiLjwfNJTZvugAjfDPrnw/w 9K9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=Ty33xuSF; 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 a35-20020a056a001d2300b00666add78ca9si823315pfx.326.2023.06.27.08.01.50; Tue, 27 Jun 2023 08:02:08 -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=Ty33xuSF; 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 S231860AbjF0OqT (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232338AbjF0OpY (ORCPT ); Tue, 27 Jun 2023 10:45:24 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 540C930F8; Tue, 27 Jun 2023 07:45:13 -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=1d+HkOGv6OfyiMGAQyiABbRWZaDBVJgUU8HY/iw2H9I=; b=Ty33xuSF+5fsTS8p+4VvMrEzWuLgpkXQsVReiKGoz3LISCRhTIqyEyCP rXVJzOFlXdpZpyjlKo+Eo6Qna6ekj4qhIRNfqlHl6X6atXIUCfpwHbZxr +wuEWHVOpATOApen0xNEKF59d5u/1Xuqm5nxuzNsqKiS+1az5fwKG2qTv c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936331" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Manivannan Sadhasivam Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/24] bus: mhi: host: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:25 +0200 Message-Id: <20230627144339.144478-11-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868496362858816?= X-GMAIL-MSGID: =?utf-8?q?1769868496362858816?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall Reviewed-by: Jeffrey Hugo --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/bus/mhi/host/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/bus/mhi/host/init.c b/drivers/bus/mhi/host/init.c --- a/drivers/bus/mhi/host/init.c +++ b/drivers/bus/mhi/host/init.c @@ -759,7 +759,7 @@ static int parse_ch_cfg(struct mhi_contr * so to avoid any memory possible allocation failures, vzalloc is * used here */ - mhi_cntrl->mhi_chan = vzalloc(mhi_cntrl->max_chan * + mhi_cntrl->mhi_chan = vcalloc(mhi_cntrl->max_chan, sizeof(*mhi_cntrl->mhi_chan)); if (!mhi_cntrl->mhi_chan) return -ENOMEM; From patchwork Tue Jun 27 14:43:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113469 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8266604vqr; Tue, 27 Jun 2023 08:05:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4KhOSKU69xSiegKS/L2C+AWfNjXmI4hkbq57o3R+t/B4iA8D77dzPmiY6dO3MAT76ZSydk X-Received: by 2002:a05:6a20:6a1e:b0:119:5af7:7cef with SMTP id p30-20020a056a206a1e00b001195af77cefmr24381812pzk.56.1687878355623; Tue, 27 Jun 2023 08:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878355; cv=none; d=google.com; s=arc-20160816; b=ENR+r0Vsi2H25FXdE+Q2QKofO8fDZoH8c8ClVsYiYCzzlGuRdTyPjGGjjjm/TmNcc4 gF0hBxBBzCuexAlshlOhDJ5kO71aLsjQXPdzaAgJRO7bNQ265tVcDN+/LnA+T91n3rwz 6Q+2ip4BivcCyueyFYN8LkttKmyoHdhQhqnn4YYXkEYihtaI/lWKi9etOrRMdnZyYvL/ CMjrNMtMhrTPVnj+0Zy0ybAo8TLARCAOB8+aQFZzYiPvg5tyWczBGvg0fLByrK+MVS98 SV5sEsEVWBhpltlqhwYrItI/VQ5y6X+JlQbZdwgTsryKbsRJghgkmi7hrBoLv1Y42lq/ URdg== 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=YkMaWxPDeWDuwTCFlcObNyyTEnApvX0G2Mje4w+fbtU=; fh=8UFpjDLzrQW0pVp2Tsq8Gqt5uE7DW+OTepjfwpBuFE4=; b=zS1DwawNe4FLhsKKzP7GBdvvYeBQLodBenLx7HK4LITkCJY6p3gD8DMydjLGhGix0c xPf6ZKP6kXdkNFkPpSU0DhP+qhqX5q7RHpkRG+3aWUUdxaM03lHHFWEMfhcV6HSRv1Qu HuaSBGwNKEgKQkfagy0BAJMBtY6uZAXJoNRFK2zDFL8BQUdvpGMfMPTAe7u1mhtWvovu LYzQDOel3RS0/MM/KPzM/c3jFNWFeD7emCh1Kp0gb4FEfe+rXf57f/9V7UoS+jY5Bxh8 E0DAdRTH/gWxmRPzGps8DIJeozLC0C8U1IxJX5WRgQyZ1OW8f0peT+xbkxMwfX6vcCmS 34wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=lPX+7nYe; 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 z11-20020a6552cb000000b0054fe9faf30bsi7326830pgp.562.2023.06.27.08.05.26; Tue, 27 Jun 2023 08:05:55 -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=lPX+7nYe; 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 S232115AbjF0OqW (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbjF0OpZ (ORCPT ); Tue, 27 Jun 2023 10:45:25 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 950363584; Tue, 27 Jun 2023 07:45:14 -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=YkMaWxPDeWDuwTCFlcObNyyTEnApvX0G2Mje4w+fbtU=; b=lPX+7nYe2ZOHxz0U8/dk+DhD+wLKHgnLzJkbNkPJLIr3SePpUVgi6Skq Q+SJxt7nzTKIib54VI3UqWgjp2Ujv3MeddOvxrKuRUlHb7MKhVf12NvxB vTBapNghDQqBLKxRS6/K9ORo/2D4ZInye6vH9tidIFBk5UrzVe7gTYA8t w=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936332" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Shannon Nelson Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Brett Creeley , drivers@pensando.io, "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/24] ionic: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:26 +0200 Message-Id: <20230627144339.144478-12-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868734777605474?= X-GMAIL-MSGID: =?utf-8?q?1769868734777605474?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c @@ -561,7 +561,7 @@ static int ionic_qcq_alloc(struct ionic_ new->q.dev = dev; new->flags = flags; - new->q.info = vzalloc(num_descs * sizeof(*new->q.info)); + new->q.info = vcalloc(num_descs, sizeof(*new->q.info)); if (!new->q.info) { netdev_err(lif->netdev, "Cannot allocate queue info\n"); err = -ENOMEM; @@ -582,7 +582,7 @@ static int ionic_qcq_alloc(struct ionic_ if (err) goto err_out; - new->cq.info = vzalloc(num_descs * sizeof(*new->cq.info)); + new->cq.info = vcalloc(num_descs, sizeof(*new->cq.info)); if (!new->cq.info) { netdev_err(lif->netdev, "Cannot allocate completion queue info\n"); err = -ENOMEM; From patchwork Tue Jun 27 14:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8257612vqr; Tue, 27 Jun 2023 07:54:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OyRaP36juRDm9gx97Y4815XESnBB9oWWLyyYwzx0Uj+LtCbeVf8wqOSTH5WhlBqhlhST5 X-Received: by 2002:aa7:db4f:0:b0:51a:5ac3:4df8 with SMTP id n15-20020aa7db4f000000b0051a5ac34df8mr16507899edt.5.1687877688270; Tue, 27 Jun 2023 07:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877688; cv=none; d=google.com; s=arc-20160816; b=pvf1OSZoxen2dy/TvE0lp8FT9Vq0t55aFZzf+iMPVnKFripUzFQ3eOzgX6NBbb50b9 rMDkaXCgn9geUApfjaIL8iYvXGSqqAwVvc7MWrRjm8Ln57g34NC2gvJ/Z4FAbQoehJIp R8GydQXmOWu/g8vRN74MQHCnagykJN1uTVRVFQ2e4WFcghzNyYWwaJ7vsVHDw5PFZwQ0 xzNwwQ0CzmWcSJ+NBGElD6Qj/YKQU7Q8SuoPpjKFCd0b/HHMQL9DBdbI4UrHy5hQ5xq6 c2LRjfVcTfD0taBljbL1WBaHNiZZV9eJ/1bFgn+4OeKzgYDMibxYJwyEhNcC/arGCo92 Ftgg== 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=2mtRBGCOnnmq8owg9Z09zy3e8yDpPGmF5WIoD2SontQ=; fh=INSTs+KMEjXBQJLY4XLMumsk5AZsZlFf/93gHyvt3mw=; b=XtaFjPuCdLb0gIXoaVFEtJJErw9CxKpgezyWvmdncsoxSCv3UhcNVtdP4aDacaxa8+ de8Krsypa/E6/7c87G5aRvbZH2yOJU0G7IxKLJZ8sSG8sxk7qIvSPyQQkoW5FLogqFj0 1aqn8lHLlcx59/HC6TVwERijrS2SOmI60ngBPngVEVToog9P3waFy8kVDxsk5nE5R3ru 6+ttEBNIU+3LQ7bg3eC7+HnYROFA26KNIF157TVV9Q7aheiUas2yGKD3E0Gluf0E0l1/ CeL6IGrLoyYqlndCEdA420riWtJRcW4ebny7wLGJ9WjLC8J9mW5ObpOIIaQk7BLUzQ/I kp2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=OcPuxrmw; 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 b17-20020aa7d491000000b0051d88350109si3831043edr.328.2023.06.27.07.54.23; Tue, 27 Jun 2023 07:54:48 -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=OcPuxrmw; 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 S232130AbjF0Oq3 (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjF0Op2 (ORCPT ); Tue, 27 Jun 2023 10:45:28 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FBFA359E; Tue, 27 Jun 2023 07:45:19 -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=2mtRBGCOnnmq8owg9Z09zy3e8yDpPGmF5WIoD2SontQ=; b=OcPuxrmwn0aRonaE3elKZrFZuEyIeBl9WsoH87B97Do+eEB8eWsAZn3m Mp7IGkipazXYfiToh9tPy6Sbs1n//8Vov5hPoiHN59IzsQOpsXOz9RnUl iW5QAnDPa8qdtv9RCOwkIRsBlWDTBUZkQl25OewNifuJY1oBC2/d9V/4S M=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936333" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Chris Mason Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 12/24] btrfs: zoned: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:27 +0200 Message-Id: <20230627144339.144478-13-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868034815763888?= X-GMAIL-MSGID: =?utf-8?q?1769868034815763888?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. fs/btrfs/zoned.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c --- a/fs/btrfs/zoned.c +++ b/fs/btrfs/zoned.c @@ -465,8 +465,8 @@ int btrfs_get_dev_zone_info(struct btrfs * use the cache. */ if (populate_cache && bdev_is_zoned(device->bdev)) { - zone_info->zone_cache = vzalloc(sizeof(struct blk_zone) * - zone_info->nr_zones); + zone_info->zone_cache = vcalloc(zone_info->nr_zones, + sizeof(struct blk_zone)); if (!zone_info->zone_cache) { btrfs_err_in_rcu(device->fs_info, "zoned: failed to allocate zone cache for %s", From patchwork Tue Jun 27 14:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113460 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8260119vqr; Tue, 27 Jun 2023 07:59:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ne+KpSlIsuatG0WI+LR/5r6IEVeqEznib+vdQeMo0QXXuMnwttzypfD14xaXvJHYX4f4/ X-Received: by 2002:a05:6a00:2d02:b0:669:4481:1224 with SMTP id fa2-20020a056a002d0200b0066944811224mr24211013pfb.11.1687877962806; Tue, 27 Jun 2023 07:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877962; cv=none; d=google.com; s=arc-20160816; b=MfKSFxvJRkCTTnsG3ov6FMnYv+iPGQ7AV6HfTeVZxjeWqGJLh6u8C0vWgU3Dvc5TZq Gv6BJ+6NRr6S9URzJmXsYpiHKdV+mOTr2bMI1W3R+ccuYV3/rJKNf4+hcP81SRCiLu7T HVG7MCeY+kFoSn9qLjCaymr+qeG5R0BkY+Fl4Hs5G6ycIpIASxBKUuSIjpW5yh9XTYDU KLMSRBW9O0K2i0Sl1cO+6ivMc0qBk4V0o7hi9UGhqQ6Y6nikNX3CorCVkDreK/7GIAfb pVqtQ4Knf4Jo4rdHYI6+4nW3rtoDXvJQ6JwWsw/WEU9XVA+DdNZuMM7oogFKgeHXGzfu 9gNA== 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=1sXATaOQFUGiET/ojS3B/ZSG4Py8hHBuvNarEMw2KCM=; fh=Y5ktOfm+epNBEAFDp+eEinCy6k2ckTW696PJV0Ba5/s=; b=B4UEOWU78LUX8TqQL4tCAZy8FlHpysU3LIahkI0kfNKon9xOQmzYH6flZ0oRzdI90Y FX5XgIujNAQ8XSYOb+pfLYLiYRS8MK1G+ebzkSXLTTjLreiVl+WwnSZYGPATs552MsuB o+E9QUhfHZLeoENBR3XWyxYWczCUqj14jbub2reNYKBaeANoeIQv492s+3UJ//9shYYy cmeP2xQlBKQMFIGLReGFvbvKJ51dtecFB/guXb/wNKPFPXYQ3sSKwhQnJfJG6kkT3bfL DYZO5I9g3VuvUALYrRa/EmMKL8GBbwioo3saHU8YGfp/AcC2KMJvnNPaG9sT31rirP11 3tpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=KSr4HdSZ; 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 u62-20020a638541000000b0054869ad7424si7461688pgd.155.2023.06.27.07.59.09; Tue, 27 Jun 2023 07:59:22 -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=KSr4HdSZ; 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 S232124AbjF0Oq0 (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231882AbjF0Op1 (ORCPT ); Tue, 27 Jun 2023 10:45:27 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84C4935A2; Tue, 27 Jun 2023 07:45:19 -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=1sXATaOQFUGiET/ojS3B/ZSG4Py8hHBuvNarEMw2KCM=; b=KSr4HdSZCErHO2NZAduGYuYcXD6gUFYTrhSuLZkHDtlEbDCReV+1qTH6 N/LpPNb9lFET+P9TMPaAnaiy9H1tpVEMXMX1ed6lg38ZguvsDMgkw6YfQ 6PqahJ+o3rvCXo9GjaocbTbqJbf4DpBod97Uyhx6lp6JPmc41SpqnKXVD g=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936335" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Thierry Reding Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Krishna Reddy , Joerg Roedel , Will Deacon , Robin Murphy , Jonathan Hunter , linux-tegra@vger.kernel.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 13/24] iommu/tegra: gart: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:28 +0200 Message-Id: <20230627144339.144478-14-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868322699543908?= X-GMAIL-MSGID: =?utf-8?q?1769868322699543908?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/iommu/tegra-gart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/iommu/tegra-gart.c b/drivers/iommu/tegra-gart.c --- a/drivers/iommu/tegra-gart.c +++ b/drivers/iommu/tegra-gart.c @@ -348,8 +348,8 @@ struct gart_device *tegra_gart_probe(str if (err) goto remove_sysfs; - gart->savedata = vmalloc(resource_size(res) / GART_PAGE_SIZE * - sizeof(u32)); + gart->savedata = vmalloc_array(resource_size(res) / GART_PAGE_SIZE, + sizeof(u32)); if (!gart->savedata) { err = -ENOMEM; goto unregister_iommu; From patchwork Tue Jun 27 14:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8253458vqr; Tue, 27 Jun 2023 07:47:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NE/dHifPQgtkLkVBWyPrjjrolIQzDwAI08zpNgRDEu0wnWM+o28a2DbXsOky6pvw+0GDY X-Received: by 2002:a05:6402:1a29:b0:51d:b246:72e4 with SMTP id be9-20020a0564021a2900b0051db24672e4mr535023edb.5.1687877262106; Tue, 27 Jun 2023 07:47:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877262; cv=none; d=google.com; s=arc-20160816; b=jvLuQ0bhJYz39Fjt0ajyGig8KLo9z6Wwxxlzxk9S4ieQP88SlyECW/EJc1RYPPYxgH DdQWfNrJrtvViEy7fNcx2H1QYYG0FxWjw5OQCF4iOq6lD7etTF25ib+/OCxjY+v/AgOo pfikPz8XemZtkJE5p2KPWk0eq4h3N12mYpp/Et2fjY6JGBTIVQY7Py3kNIwO9+rAMp+K S1vbAlaY+VBR1bjbQq9UuCGgrAtzdl4O9ENbnFppMeSfljrNnKWmiCUItUjf1t50rDs9 2TdyfEw6ljW5oXecnTpQ6cM2Tc6S1DmaFrAFo3c9Ig/dDjYkqCRl/f9BR5EKxDIrhyz/ HlnQ== 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=RmZB8noDrpTEgQ34AyoMdB9Dp2s8sUTzrIorMQcMPuE=; fh=xUJ7o1lRdW8khgHzqT6aUleN84qcbXF0LDmqk1w4YYY=; b=Kxn1DXUbDnH0oxyy2mDL9gkYUQ+RUn/qGR9ScE6Spo9jf2uEOqkLQ5TczspziWTNcF IvaVkCj1UOvm6fu9BH5rzN+4PabOQtrzSBlwcPyeRTEHtR+Kl0Fzca+IHatirvl2ZLfa CBreVN8pTvldApAioYVJ3MhCyTW4g7/z1+XmxKFjjtYo24txYYnK6zreDofwBuUE59qX IoJKtcSBWUDH23bpJqo4CbmTqGLz6HGr+9MLY/zYiAWJvRUyhb98EYJ9Dp1u2T3a7vTH Oxdm8epwS9riDXS1/HtGohofmPzYcCR+3FXnPZ1yD76B4SkDsVuSzQGpSic/kKyrB2P0 Ysaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=GjCGi63W; 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 q25-20020a056402033900b0051a39411fd3si4163386edw.356.2023.06.27.07.47.18; Tue, 27 Jun 2023 07:47: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=GjCGi63W; 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 S232136AbjF0Oqc (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231902AbjF0Op2 (ORCPT ); Tue, 27 Jun 2023 10:45:28 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2484D3A96; Tue, 27 Jun 2023 07:45:19 -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=RmZB8noDrpTEgQ34AyoMdB9Dp2s8sUTzrIorMQcMPuE=; b=GjCGi63WWIhe+GQ1WuZtY7p1RpJ9Ss04/hj/GygcSrN0F8lf6k6MzF+b yzRzNlhLeIjc9mGf96UTSuog/GrBhy16Fk/+6wcK7vSpr21Me+u+A9MQg pxRZpNH8xzpyxzYNzf79A1Gii+do3IX74quXSmqOfuQCWgbDHugM5j40T M=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936337" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Bernard Metzler Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 14/24] RDMA/siw: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:29 +0200 Message-Id: <20230627144339.144478-15-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769867588183177981?= X-GMAIL-MSGID: =?utf-8?q?1769867588183177981?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/infiniband/sw/siw/siw_qp.c | 4 ++-- drivers/infiniband/sw/siw/siw_verbs.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff -u -p a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c --- 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, st if (udata) qp->sendq = vmalloc_user(num_sqe * sizeof(struct siw_sqe)); else - qp->sendq = vzalloc(num_sqe * sizeof(struct siw_sqe)); + qp->sendq = vcalloc(num_sqe, sizeof(struct siw_sqe)); if (qp->sendq == NULL) { rv = -ENOMEM; @@ -414,7 +414,7 @@ int siw_create_qp(struct ib_qp *ibqp, st qp->recvq = vmalloc_user(num_rqe * sizeof(struct siw_rqe)); else - qp->recvq = vzalloc(num_rqe * sizeof(struct siw_rqe)); + qp->recvq = vcalloc(num_rqe, sizeof(struct siw_rqe)); if (qp->recvq == NULL) { rv = -ENOMEM; @@ -1624,7 +1624,7 @@ int siw_create_srq(struct ib_srq *base_s srq->recvq = vmalloc_user(srq->num_rqe * sizeof(struct siw_rqe)); else - srq->recvq = vzalloc(srq->num_rqe * sizeof(struct siw_rqe)); + srq->recvq = vcalloc(srq->num_rqe, sizeof(struct siw_rqe)); if (srq->recvq == NULL) { rv = -ENOMEM; diff -u -p a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c --- 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_ { if (irq_size) { irq_size = roundup_pow_of_two(irq_size); - qp->irq = vzalloc(irq_size * sizeof(struct siw_sqe)); + qp->irq = vcalloc(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_ } if (orq_size) { orq_size = roundup_pow_of_two(orq_size); - qp->orq = vzalloc(orq_size * sizeof(struct siw_sqe)); + qp->orq = vcalloc(orq_size, sizeof(struct siw_sqe)); if (!qp->orq) { qp->attrs.orq_size = 0; qp->attrs.irq_size = 0; From patchwork Tue Jun 27 14:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8253500vqr; Tue, 27 Jun 2023 07:47:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6CZLf50g951RVKXchQ/ZNWQsEMoWJ9PEMwz91JZAns0CGnawg8IlezT68LHLLLl8t1esJg X-Received: by 2002:a17:906:ef0e:b0:978:adad:fe18 with SMTP id f14-20020a170906ef0e00b00978adadfe18mr25942449ejs.21.1687877268394; Tue, 27 Jun 2023 07:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877268; cv=none; d=google.com; s=arc-20160816; b=fWpoTllVd2U4+pH8qe0tbsDO4VLcq1GTSobgXfUDJUMdlVb73eES5DUcYj/ZgxYDFe egJHeIewo8UGJHAAtnsfNj2S9KXoyozbuND3fxRxlErtWuJyLkDpxQzpr5S93bROWfQY JoHzA/jvzpfGKxxvMupC/eqoyzjd1AnaR56xAsyUfO3z6bGu63nk76PpyxbEpeMxB79Z AvyZVjnIb9fmECtdSBxhYtSxHwtHPIib8q09jNnElqdjh84uPG/ZQ7QRP59iEuyZHsJQ N4Y0LB+V9oGoqHvRVVMyNMQoJOTeEkuFE6QZ5bpJD+6wtAx0YkjAzJTjKXTd2SS56F61 knQw== 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=uOCXLaXRiomt/H0q8utpd2M3e4T7ehi0Ry85QhvtitQ=; fh=YiRS5rzdLZXIlkyjL3mbSS6v6M5b2k1K/zpT8DZ/zIw=; b=QkSrLjBdF7cjoC4DGPH0PFdJrWam+UKNJWzY6sZXOkVG1YVvD9oezvKlJNmcHROhoS Uy+k8896gm7WmttC3mqyi7lH8FG0bJ7AwS6NWtoCyoOtJwfmdpjPOPimMyGol4IDfONi aD2oPKA3ohA17XY3f7YqKu7ohN+23T4HbXWNtUXr7WG9j9IbhLd5slVZ9SAhDOykmbfn KajhIB0mYDxapaf7YILnMBUUy7g+Wx8lH1ZzY0dZTg3B7+tWEmYBM46MqGOeDohOf2J3 XgtoRQunntycPK9OryU2hcPGJoLtJj9uOtrY6wL1F+XECG+ftZ4fN3XlUlvpV0U5R3Uv vWlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=hZkO1dGI; 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 sb22-20020a170906edd600b00988afd7e58asi4428921ejb.350.2023.06.27.07.47.24; Tue, 27 Jun 2023 07:47:48 -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=hZkO1dGI; 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 S232147AbjF0Oqf (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231929AbjF0Op3 (ORCPT ); Tue, 27 Jun 2023 10:45:29 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88ED3A9B; Tue, 27 Jun 2023 07:45:21 -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=uOCXLaXRiomt/H0q8utpd2M3e4T7ehi0Ry85QhvtitQ=; b=hZkO1dGIGwuuQTtoKxGsqKTtjf8AmCS3lBjekTBtliF+28pj2YYjyv+d pQuTHMXb9pFINDBs+NiWxzAYZfemeDyybBg1ldmHXdGRE64q83ScGKiPN G4UR3nYmAPZhzU/eZeV1XKOTnDpIYYn37BXMGwHkzCRcoxCLjOYD+NAh6 c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936338" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Oded Gabbay Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 15/24] habanalabs: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:30 +0200 Message-Id: <20230627144339.144478-16-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769867594621895930?= X-GMAIL-MSGID: =?utf-8?q?1769867594621895930?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall Reviewed-by: Oded Gabbay --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/accel/habanalabs/common/device.c | 3 ++- drivers/accel/habanalabs/common/state_dump.c | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff -u -p a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c --- a/drivers/accel/habanalabs/common/device.c +++ b/drivers/accel/habanalabs/common/device.c @@ -2594,7 +2594,8 @@ static void hl_capture_user_mappings(str */ vfree(pgf_info->user_mappings); pgf_info->user_mappings = - vzalloc(pgf_info->num_of_user_mappings * sizeof(struct hl_user_mapping)); + vcalloc(pgf_info->num_of_user_mappings, + sizeof(struct hl_user_mapping)); if (!pgf_info->user_mappings) { pgf_info->num_of_user_mappings = 0; goto finish; diff -u -p a/drivers/accel/habanalabs/common/state_dump.c b/drivers/accel/habanalabs/common/state_dump.c --- a/drivers/accel/habanalabs/common/state_dump.c +++ b/drivers/accel/habanalabs/common/state_dump.c @@ -272,7 +272,8 @@ static u32 *hl_state_dump_read_sync_obje base_addr = sds->props[SP_SYNC_OBJ_BASE_ADDR] + sds->props[SP_NEXT_SYNC_OBJ_ADDR] * index; - sync_objects = vmalloc(sds->props[SP_SYNC_OBJ_AMOUNT] * sizeof(u32)); + sync_objects = vmalloc_array(sds->props[SP_SYNC_OBJ_AMOUNT], + sizeof(u32)); if (!sync_objects) return NULL; @@ -453,8 +454,8 @@ hl_state_dump_alloc_read_sm_block_monito s64 base_addr; /* Base addr can be negative */ int i; - monitors = vmalloc(sds->props[SP_MONITORS_AMOUNT] * - sizeof(struct hl_mon_state_dump)); + monitors = vmalloc_array(sds->props[SP_MONITORS_AMOUNT], + sizeof(struct hl_mon_state_dump)); if (!monitors) return NULL; From patchwork Tue Jun 27 14:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8268835vqr; Tue, 27 Jun 2023 08:08:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VKNt32m+VcLSZX8m1ld7lig3cKgSAQ2T5tGHY8F3Pmy9G68Ph78dWyIL+tn7QWiohy5BA X-Received: by 2002:a17:907:97c2:b0:988:8a02:457b with SMTP id js2-20020a17090797c200b009888a02457bmr24722902ejc.15.1687878492656; Tue, 27 Jun 2023 08:08:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878492; cv=none; d=google.com; s=arc-20160816; b=bxCb3e/gfa/U5wZsuWv1VzDz9uLkP/J1I7UUGcOly2poKkzGaN42+XjemsMVeiy8M2 sOL6chqI7+Cnb9trLM4FesSVlygKADQ8xhTHXwQDeyVbMstY/btuEMhsyKca84BwSPSW rfX2cJCwrF7gJcdonTzDJZfYfO8ULtC9UluoelvZ2nu9dWsCcVt+FIrvpvnKzHXlL7mr s+aIY9QUZCS40g1ZJITKdh8qfB4LMRfZo6AjVUH2VQDkQb5DqP80o7Pswu0/geVmBSkx ht7jIfJPZy1klaDDhXc9hDH7I/byhd2rYQAJX56QV5PrX9V3szm0SJzTZ4/1JVfNlENs hNUw== 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=7lnPTkCHesLh89B4y204QnH5Kjltfl8JZirnUVZstTQ=; fh=SvOmmDmTQMV797LqhFJ/WzXzyouS7qHdx7RZXWMwi+Y=; b=LXGsmNkpmImoNng+LaV/5iNWS5AqhsM7JfZ1zkHXM3F9avrGdWou0tHB5jIkp/tOjk DJZgmxslgGgnEBpeh1JNlRTVwqnpDlbBkHBXeBKTEorwznZns18ayKjjTnTLMd0MK7pM cMCzrhqKVctHrGril+KDdimtti9wwfhSVvs7g1aVhppgOouZWej4X6+9za3q9gLdqHZn G/TZaaGqKpIr+Go6HrcZM26l8A1+JWB672zsOLr1wZ4ACY0LIwf62YW/5eNdLFkw2lsh lbcaqPBvBHAN7Mrb32wrC/pSuajVi/BAPSLm/qX+vThC/yvpCVBRwozbbENvUE5XGEQr qNvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=D48xdhBp; 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 z23-20020a1709064e1700b0098b0feb8935si4348155eju.1035.2023.06.27.08.07.34; Tue, 27 Jun 2023 08:08:12 -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=D48xdhBp; 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 S232157AbjF0Oqj (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231933AbjF0Op3 (ORCPT ); Tue, 27 Jun 2023 10:45:29 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15FD23A9C; Tue, 27 Jun 2023 07:45:21 -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=7lnPTkCHesLh89B4y204QnH5Kjltfl8JZirnUVZstTQ=; b=D48xdhBpfwiIgnA2AZQwT7G8kGdQLMyeE/bNp4/G1WWDhqy1NQswa8ef 9kJySCxs4j0zEvi1o43L6LZHm9SXMOsqjIMXYSNhk/lLG0nKoysVZDATI LGnDCLIO1XSogZ+Tufk5B4mBrsaoHdTlFIQeH85shSvKwrjilzllcylk0 U=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936339" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Zhenyu Wang Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Zhi Wang , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 16/24] drm/i915/gvt: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:31 +0200 Message-Id: <20230627144339.144478-17-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868878155931041?= X-GMAIL-MSGID: =?utf-8?q?1769868878155931041?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/gpu/drm/i915/gvt/gtt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff -u -p a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c --- a/drivers/gpu/drm/i915/gvt/gtt.c +++ b/drivers/gpu/drm/i915/gvt/gtt.c @@ -1969,14 +1969,16 @@ static struct intel_vgpu_mm *intel_vgpu_ return ERR_PTR(-ENOMEM); } - mm->ggtt_mm.host_ggtt_aperture = vzalloc((vgpu_aperture_sz(vgpu) >> PAGE_SHIFT) * sizeof(u64)); + mm->ggtt_mm.host_ggtt_aperture = vcalloc(vgpu_aperture_sz(vgpu) >> PAGE_SHIFT, + sizeof(u64)); if (!mm->ggtt_mm.host_ggtt_aperture) { vfree(mm->ggtt_mm.virtual_ggtt); vgpu_free_mm(mm); return ERR_PTR(-ENOMEM); } - mm->ggtt_mm.host_ggtt_hidden = vzalloc((vgpu_hidden_sz(vgpu) >> PAGE_SHIFT) * sizeof(u64)); + mm->ggtt_mm.host_ggtt_hidden = vcalloc(vgpu_hidden_sz(vgpu) >> PAGE_SHIFT, + sizeof(u64)); if (!mm->ggtt_mm.host_ggtt_hidden) { vfree(mm->ggtt_mm.host_ggtt_aperture); vfree(mm->ggtt_mm.virtual_ggtt); From patchwork Tue Jun 27 14:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113475 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8268728vqr; Tue, 27 Jun 2023 08:08:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tIP9oOfVYHL+sY8Mxrco4gS4oSNdgbB6L1OAprqNRzYDXl0HQxXpokmQNuLPmzQNyuoAq X-Received: by 2002:a05:6a21:999c:b0:126:5ffd:c5b7 with SMTP id ve28-20020a056a21999c00b001265ffdc5b7mr14073450pzb.22.1687878485928; Tue, 27 Jun 2023 08:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878485; cv=none; d=google.com; s=arc-20160816; b=z+mjej6Wduh3QggOl1RR92UeHKO5GuBAieucNNZ36IOTyfPaTByJ8WhiGGrirGuRCd 69L+yR9nY5+EB0JEXIs3fuxKimEh6Du9bK38c7HCfoWK8ssmImSePtkKzu4kSYL6BjTp djjnUoKa3MAJUUztW4GH03hD6s7wNFFzY0IDF02TWVzHM7v3E+rMEmd1lXQrxMukJ9oh oeVXS6e9FvAMVPVs6jWZHQmZ/CZfJuhQXfbtNkd529o1diQ2rR83qm81pseTlXBPFpYV H7n+eru0XRyu6WuznE13wFSxnDeEHK20gt1P94SMwi5srvgGYs6LYg/joMFkycRLrV9N SbHA== 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=tzdHyO2WkZ+/4hPd1oFud1vh1gFsmlhbwd5pOc3CStU=; fh=0KXxUBdGdTZUREAi7vY5lmM/NYX8UoMHfo6Q4BbR6pg=; b=Q+eJuHJLyL4QW6Cn0qbK2laPnLySqJ3byva3No4UHXMfQWaFyiugPzukmQ1h/UO0D5 fqVOm7doJI6shKVkDpGzojFUMp4zm/ZTnrevqAjnfDPNGiozzSz3NqHoLrwM9Dm6Fi4z fzsH/7pQr57XOpgdMyJ9IOF/4kHlxF6OgZNi94V399WYgpeqvXm5+P+63nDOuwQa7utx PcQsc/qyMSdBiUAEJHE1fvwcu0nbXLrAk5hDDVHlvBi0Q5aft3oirUml4gOoU9sbN7LA Qi6Vgwjw/cnIGJkHh+R4GkN/xxKUV5kWRECCtCGJ1OJmauo4zWk4sGZYBh8ZGUDbAKY+ qclQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=YFRO9acw; 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 q1-20020a056a00150100b00666631f7ed9si7341197pfu.82.2023.06.27.08.07.52; Tue, 27 Jun 2023 08:08:05 -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=YFRO9acw; 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 S231985AbjF0Oqp (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231968AbjF0Opn (ORCPT ); Tue, 27 Jun 2023 10:45:43 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19721273C; Tue, 27 Jun 2023 07:45:22 -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=tzdHyO2WkZ+/4hPd1oFud1vh1gFsmlhbwd5pOc3CStU=; b=YFRO9acwySrxiS5SFbzoT1YrVzANqJrEedC6LESFP2q+N87wGaSsp+K8 coUUn8YtjsqjzxyiuVIzB57myohVF0rG/rM8ldUD8f745mtj2AO2ZIJGm 4Qdc3b6VAAKdCtQOCew/H5rCzZWc5hA4nQXETwpclVpOEGprtGSC06u5a Y=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936340" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Dmitry Vyukov Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Andrey Konovalov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 17/24] kcov: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:32 +0200 Message-Id: <20230627144339.144478-18-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868871077681037?= X-GMAIL-MSGID: =?utf-8?q?1769868871077681037?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. kernel/kcov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/kernel/kcov.c b/kernel/kcov.c --- a/kernel/kcov.c +++ b/kernel/kcov.c @@ -901,7 +901,7 @@ void kcov_remote_start(u64 handle) /* Can only happen when in_task(). */ if (!area) { local_unlock_irqrestore(&kcov_percpu_data.lock, flags); - area = vmalloc(size * sizeof(unsigned long)); + area = vmalloc_array(size, sizeof(unsigned long)); if (!area) { kcov_put(kcov); return; From patchwork Tue Jun 27 14:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113470 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8266824vqr; Tue, 27 Jun 2023 08:06:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55128kXvZx95pv93DpeBjo4Nagm/FDK0iinEdOq5rJO5xfcM9vxuHUfcjHcx2sagH/drl/ X-Received: by 2002:a05:6a20:7d9c:b0:126:8b2d:4462 with SMTP id v28-20020a056a207d9c00b001268b2d4462mr11432707pzj.24.1687878368739; Tue, 27 Jun 2023 08:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878368; cv=none; d=google.com; s=arc-20160816; b=gFoU4jGlOkWf7Gh5CeDP/6ed0xbn/LqPk+AJyHKbPy8AWJNGgg9Kvk3Zw7g+HxOB5x XPWVqTrNeGjB1jm1TnDLDQcq6lxq+GEF6xKEDmQvnzU7nq4yjZD2K2U09tQpIWwLA8lo SsPz2vf7z4c4Q/Me9Aqxji7A0MT6UtArHlql/pEeKqlRZ7HLOJ8HUtKoGB9lZywNGhUd tbng7TeL+X2tnf2/G4A9EyJgyF2xwOUGEXvLeMKif97LGivAIhHB3dDLBx8StktrhMJM aCysJzXq4WOnG/WDv2tJyz4MWFWX1jwCLDcD3qOqg2h3/5Wghlg537r0zh+dA1iu0gLY fOag== 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=15aAN7iRIzM2PQnXvJBcm1gB/dKFeQxYgsMIxD38BXs=; fh=oBkuyY0guxuTnpyOiiOENkf35Ym1ZBwApLjSBSeb1do=; b=cTBjOfu30PlRLU2dLKAF1k6FNRianZNsbGJxN9JkYKJvS0P5wZjbNoOu69K0fytOyd 09v+lb3vX4qMJsACZ4AEMnFTLHkUclwJE3PVEDA7Kc4jN8Vyc5wRoj9tV4M4i+6KOh2L /kJVQcWyArMzlgKaUWKLPp1OGo7U0S3lDSTriMLIkc1D5TPEPn8Bd2ipkQHdyrXEwrH/ M8vEzsUwbwLq8HUsjSPjfikiKyi8KQtCPjvtxgzEOb2ANMV9/iB0kEsnXBAfOKyOMp+0 AA90JJVxuuC7QZYKo1dpb7XcDacsYsYo5UteEyr95w8VLJ7fHoDS9bbV6/KoobzNoVnj KfZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=ig3FVSP0; 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 f28-20020a631f1c000000b0052c8234a858si7551109pgf.168.2023.06.27.08.05.43; Tue, 27 Jun 2023 08:06:08 -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=ig3FVSP0; 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 S232203AbjF0Oqs (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231726AbjF0Opo (ORCPT ); Tue, 27 Jun 2023 10:45:44 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C70D530DF; Tue, 27 Jun 2023 07:45: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=15aAN7iRIzM2PQnXvJBcm1gB/dKFeQxYgsMIxD38BXs=; b=ig3FVSP0tAKQyeuBH3vlirUPjrltMfU0GOMhVPqQ5WN3DfvpLzYobNB6 U2LPadL/tt9g+aj/Kk4AooQeQjjtACA4irPnGUwrKbGAZq7IzSlOEfR4m kPXxOICFaXOIBapdcSnR7+BOcCB/kmTT7WOW2aUo7dUnRJU3LFcGKAwCE A=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936341" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Claudiu Manoil Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Vladimir Oltean , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 18/24] net: enetc: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:33 +0200 Message-Id: <20230627144339.144478-19-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868748091352697?= X-GMAIL-MSGID: =?utf-8?q?1769868748091352697?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/net/ethernet/freescale/enetc/enetc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1789,7 +1789,7 @@ static int enetc_alloc_tx_resource(struc res->bd_count = bd_count; res->bd_size = sizeof(union enetc_tx_bd); - res->tx_swbd = vzalloc(bd_count * sizeof(*res->tx_swbd)); + res->tx_swbd = vcalloc(bd_count, sizeof(*res->tx_swbd)); if (!res->tx_swbd) return -ENOMEM; @@ -1877,7 +1877,7 @@ static int enetc_alloc_rx_resource(struc if (extended) res->bd_size *= 2; - res->rx_swbd = vzalloc(bd_count * sizeof(struct enetc_rx_swbd)); + res->rx_swbd = vcalloc(bd_count, sizeof(struct enetc_rx_swbd)); if (!res->rx_swbd) return -ENOMEM; From patchwork Tue Jun 27 14:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113459 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8259650vqr; Tue, 27 Jun 2023 07:58:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48FPx6X9s5dkstBkpQArA5t2t57LZXDYyu/UjFWKVNsZjTZkzzLsZWAgs4Si6n5XHAGNMC X-Received: by 2002:a17:906:6a0f:b0:992:4723:fc81 with SMTP id qw15-20020a1709066a0f00b009924723fc81mr863900ejc.17.1687877910158; Tue, 27 Jun 2023 07:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877910; cv=none; d=google.com; s=arc-20160816; b=eoFfsDTF/J2aMxBARBb7uQ6Bq6v81OsvnFYyGypauW2ovB4FV+5hxn0lBUbDrrNbGV BHnjeCfrD+byn3RwSqorEINY96tTiXjHE0gsbn1H2mfWZiqrN9Nd7MHLvKSioE8isRhK l7AO7zaQveR+sTo8HOsy0SnmIN6LrkYOX23w6bJdad02XlfB9UDCqb1FgptaCGCfPHJZ ElhJGZUQw8PKzNubesgNt2xzilkk091rDmHIjvSIcOcbq9BMLBs4S+LlXSvrEgYA9k7W CnUhB2/bEKE/SsYfjwVtRCLcsAZAebwSHB+G8EE6Yyg27bD8AykMOvVBZriVkbTGjiAM GLJQ== 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=pZdndxQjXQo3BjDH5lsbs+qaO6vkvVK0DG4Lv8xJQDg=; fh=bVjJAQz6jHpcyOBTs1Cc2Y/Lw+Oc5oJ0H2Q56vrqsEU=; b=uYqHKzH79CFP+A9/2QF0V2OxePCx1JgMzF1SkBTJpOU2IYYIyidjw/5RhYAvsh06YC Dh/23ZNKAG73gCP3gUrIBHsqjW+WRe+nxemNopWSHJLwHGtabom1PRspEqBqhryhM2o0 LMVmyo22cf7b5Pqf5qbAln1mQnZjQS5rEdOV+jsJM/h52nD4dRs+gsvIQt7Kxa7G9W34 jw8tc0d2Uz9HFp8FcUDoax1nOrIwbXZ0pZCsLK+ZjPbuZlqTx+dLL82kn8RLAKR7ekMh pHUxSWtQbMZBXDNHEGKDNkRPgVhh/ZIb82ExSVhUih8mP/yfFRv4AHwFXAynwo/7kdfG JrHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=g8uRt1mM; 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 oy17-20020a170907105100b009924806cd01si310488ejb.386.2023.06.27.07.58.05; Tue, 27 Jun 2023 07:58:30 -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=g8uRt1mM; 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 S232213AbjF0Oqy (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230405AbjF0Opz (ORCPT ); Tue, 27 Jun 2023 10:45:55 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03F8635A4; Tue, 27 Jun 2023 07:45: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=pZdndxQjXQo3BjDH5lsbs+qaO6vkvVK0DG4Lv8xJQDg=; b=g8uRt1mM441oG8JVpko4SPSsBHoBBFNgc9h+XNADjURwzgbxiF4pOxxw rpfubCYGNo2a7MOBMZHsQ5NqmOwXA/WELw6L0eotmQyDA3gTbvDHCM72i BK1nd4nWtLzc1fcFRMbFdp8G8mGEkpNIzyClpIYE/itJvBkxQW1F7CwPs E=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936342" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Selvin Xavier Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 19/24] RDMA/bnxt_re: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:34 +0200 Message-Id: <20230627144339.144478-20-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868267795678146?= X-GMAIL-MSGID: =?utf-8?q?1769868267795678146?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/infiniband/hw/bnxt_re/qplib_res.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/infiniband/hw/bnxt_re/qplib_res.c b/drivers/infiniband/hw/bnxt_re/qplib_res.c --- 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 else pages = sginfo->npages; /* page ptr arrays */ - pbl->pg_arr = vmalloc(pages * sizeof(void *)); + pbl->pg_arr = vmalloc_array(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(pages, sizeof(dma_addr_t)); if (!pbl->pg_map_arr) { vfree(pbl->pg_arr); pbl->pg_arr = NULL; From patchwork Tue Jun 27 14:43:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8268572vqr; Tue, 27 Jun 2023 08:07:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+qLsurYRW1chutvJ0ggq9aaPGkGXZplVXrsEJjY0eooYi84WUU9vFEgHIXHxNAmdo/C8d X-Received: by 2002:a17:906:64db:b0:98d:5ae2:f1c with SMTP id p27-20020a17090664db00b0098d5ae20f1cmr11369372ejn.34.1687878476869; Tue, 27 Jun 2023 08:07:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878476; cv=none; d=google.com; s=arc-20160816; b=L6zwzDGHfu6ogTF+D0pReWZOozUy1DpvdksmnM/g1C44v6Yu+v14VgcKtGySrQXQFs uyh4okFrSrtB+Xb2ehkyLTMgM5WfHyayLDCEE4r/2H7vRbV7Sj6KzPP+rbN0HuvEz53I WR05TlRFCjc57M8aSVGUpEnQBRkR/h6U105Adf7GV0JYbIjOg//q56iDfQXedT63a+BJ NbmWsfCzr4iebvTL9gtb6OdPP57Bpn8TFPGudjn2WikiCG9OCFLcWell6JvnnutRjBwC YJ/xKHIN7IaJ3vZZ86piWrRaDaF8ApRpB8CSMtPWTLfFcfushIXbkdsr9dGCKTG+RxhQ 6/0w== 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=VbQwbhgrDYedmuD3Y7RCVQ57pP4c57YQ3unyPj5Q6N4=; fh=xG++Ct94g/YGAS8zVkboMlT523ejGRcTzzsL3xuTrg4=; b=ZGIDeYu+4m52E7z5SWAoMnhPMScIy0KFWTnujaOYq6OhsHafpmv4MHTl8JnAKuPo3C ge2TXUIsgcR3q/dgiDg+/R5FybVGjffwUOFf0Dxm6+Y6EGGJY/fIyMdDCF9p7+WQwpsS V/FQ9SrEcNOM/yhBLZt7TBafq0mc1QMZqkxVJuIXXI9ywle2IcjcVtwu5Co3FXWRxuCf Xi+Cxf6SYa1acibdsKIVTHVQ8tfUaScdn7zZfmnjdwjsGNpayw2Hh7ozIBk4EuLTtOnY cgN1yBTxUpxToHJc6vGQQCOzKaRwSM68Zwt/gsU0uzN0aVmO9ldSmZTBYSU/PDgWwBa4 I2SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=nMz70TxR; 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 m19-20020a1709066d1300b00988a13c6a90si4202136ejr.601.2023.06.27.08.07.15; Tue, 27 Jun 2023 08:07:56 -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=nMz70TxR; 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 S232224AbjF0Oq6 (ORCPT + 99 others); Tue, 27 Jun 2023 10:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbjF0Op4 (ORCPT ); Tue, 27 Jun 2023 10:45:56 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A5F41A2; Tue, 27 Jun 2023 07:45:25 -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=VbQwbhgrDYedmuD3Y7RCVQ57pP4c57YQ3unyPj5Q6N4=; b=nMz70TxR38nwlO049zqy5wzxY7CBD7tWCsU5Sn6Y6MlVDUptwIcjVDE5 p6BL4QWGL3Ag4tQzyaC7hjRzFtGLZRTZymYhHQTTx2ihXgi3j+8n0iMOR bFTgYsROCO8yKBSy3R85gXtUQz94fVgblUf+B/eGNjmAxR9FgkimEm8r1 c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936343" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:52 +0200 From: Julia Lawall To: Ian Abbott Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, H Hartley Sweeten , linux-kernel@vger.kernel.org Subject: [PATCH v2 20/24] comedi: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:35 +0200 Message-Id: <20230627144339.144478-21-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868862189629662?= X-GMAIL-MSGID: =?utf-8?q?1769868862189629662?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT)) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. The position of this patch in the series changed accordingly. drivers/comedi/comedi_buf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/comedi/comedi_buf.c b/drivers/comedi/comedi_buf.c --- a/drivers/comedi/comedi_buf.c +++ b/drivers/comedi/comedi_buf.c @@ -89,7 +89,7 @@ comedi_buf_map_alloc(struct comedi_devic bm->dma_hw_dev = get_device(dev->hw_dev); } - bm->page_list = vzalloc(sizeof(*buf) * n_pages); + bm->page_list = vcalloc(n_pages, sizeof(*buf)); if (!bm->page_list) goto err; @@ -169,7 +169,7 @@ static void __comedi_buf_alloc(struct co buf = &bm->page_list[0]; async->prealloc_buf = buf->virt_addr; } else { - pages = vmalloc(sizeof(struct page *) * n_pages); + pages = vmalloc_array(n_pages, sizeof(struct page *)); if (!pages) return; From patchwork Tue Jun 27 14:43: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: 113465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8263875vqr; Tue, 27 Jun 2023 08:03:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6K8jVgrQ9SNoOfiRwzfSlWXO60WbQWHnx/0WpyKjonuyZCq7DmgJ/AZTQD20TgtwtUsfJI X-Received: by 2002:a17:902:dac7:b0:1b0:3ab6:5143 with SMTP id q7-20020a170902dac700b001b03ab65143mr6329833plx.68.1687878192941; Tue, 27 Jun 2023 08:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878192; cv=none; d=google.com; s=arc-20160816; b=t1uac0KWKhhOKSaiPWqf9WAKZkHmmMrewKAPJYdwuHMEqIQEiYptO80dGIFKWUz4Zq x0fP4SeRAEVKQl80J482Dc7ZPFzTVjtwtEdXWG1hvw7JeLQtP0YrKkv42NsAjuvVPYIb 8SLLwJNUCWC+ujIsGhJ2gd1W8LyG1EQUrfKXe2xwzfPruUHA+8qFwW+ubC1+54JGJHA5 2z4/JkD5F47y5TXB0n8Gzn+KtrPHGgmP6IZ6NLa66uzUmQIqqld6si12b0UwhU5LdPYl sBO0afxDK3YJ5YGEXqHJfnXkydRIsMgc8JFF+2AMck2Qu6EX3lfykutwvdX51NfLHPG8 wdQA== 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=fwBApC6jUrjlR2TIvGLbzPMAAmAGjDhOLjgURNPzPzY=; fh=s2znx5y9PkrupoBVYpjXEyh2OcIIRwmeyfdKzbiZ+kM=; b=omgP5lQY7dewi416Qh9RZk/60UhAEiXMDdXOySvE1SO8HFul5r2jo12gDzEdqwgqw8 S3FCBSKWr7hfjSGa4xItSCXYmZEGREJVKQyHBnQuVxruhpx8/uW8LCgr44EQCMR2v989 8XMaIjQwPWycEdrdmZNd4XM4ufb+X02Ko4PGAyavCTPnpLTTYriMN/8XhiguFEEI6TK6 ISx+PReXXMB9Ez5tJ2rpDi6x8Zd8elq0NmCqEwmcEPdplIomO2Bcs2e6TkONOSk3PpbB 29jwYhvz3kWkm1ewiDoPeUP/zuYfUZ5wuv1xUFEvDeeshpCPZZHxghY1HJzpSspUfjvl HYnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=BHgadewr; 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 w10-20020a17090a8a0a00b0025653dc2881si10169223pjn.23.2023.06.27.08.02.54; Tue, 27 Jun 2023 08:03:12 -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=BHgadewr; 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 S232035AbjF0OrC (ORCPT + 99 others); Tue, 27 Jun 2023 10:47:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231989AbjF0Op5 (ORCPT ); Tue, 27 Jun 2023 10:45:57 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94BC72D69; Tue, 27 Jun 2023 07:45:25 -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=fwBApC6jUrjlR2TIvGLbzPMAAmAGjDhOLjgURNPzPzY=; b=BHgadewrKiM5wnoPnQZAWH8o6p5BCcSHwzkn5yYPbk0N0IP7/9sSeR7N sqE5B+1PHNUwj6GGrZBBO0y0feNdNGhOCNhIeNH3u8ZyMFbrOUfyOJO54 B0p1GvJMIraCE0QjixXzsjSnRtyRFnT16pIhfE20xApj+YjoQ+3KwB0vz c=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936344" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:53 +0200 From: Julia Lawall To: Jarkko Sakkinen Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Dave Hansen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 21/24] x86/sgx: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:36 +0200 Message-Id: <20230627144339.144478-22-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868564000114205?= X-GMAIL-MSGID: =?utf-8?q?1769868564000114205?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. arch/x86/kernel/cpu/sgx/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c --- a/arch/x86/kernel/cpu/sgx/main.c +++ b/arch/x86/kernel/cpu/sgx/main.c @@ -628,7 +628,7 @@ static bool __init sgx_setup_epc_section if (!section->virt_addr) return false; - section->pages = vmalloc(nr_pages * sizeof(struct sgx_epc_page)); + section->pages = vmalloc_array(nr_pages, sizeof(struct sgx_epc_page)); if (!section->pages) { memunmap(section->virt_addr); return false; From patchwork Tue Jun 27 14:43:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8258990vqr; Tue, 27 Jun 2023 07:57:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7vPvlKOcd3OqU5zC3hwwL0hKozYTlVLYtAh1hqB6cKCYu8OOEdGz8gzLh9EJA9k+oX6vaJ X-Received: by 2002:a17:902:d302:b0:1b8:28f4:f259 with SMTP id b2-20020a170902d30200b001b828f4f259mr754589plc.69.1687877835594; Tue, 27 Jun 2023 07:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877835; cv=none; d=google.com; s=arc-20160816; b=Qdwm6WPT4ADNCQG+V9E1OdGo9pP/oS91HWj0KzLT+6FREg2VOroI+3qhXtB9XkLs+5 LOKuZYLHIrVTA6y3+iYzvGbgHGNPc/7LQBGt4aSv0gPQmnnjbTElK7A7wY1LpRA6ii4N Ajrqt26EFh07jUAzhJOqptZnk+BpB78s7jnQ+PtmJBzV190vLopym1O1GEEMDqqZcpbL jB+WTUups/SV+xZPIC6LbAiocUS1me0My/hEp55PvQYLIA7fzuFNDk3AVQesgl/Vhbl4 jWZD/IwjaXug2DpO5N4nHsvX+wB+CpOuHgAWcyLW9X5f5lBsosP2ETYutSwMh39Ffyy4 hm/Q== 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=rUzmkjTakIf1l5Hdr1TLtSGZWZezFJIK9Clkpx3VPN4=; fh=zS3ETOVGQKdstzmg6EDw4r42S54ZBNLJAWXxgACdMsc=; b=VarAMJL2sEsGUTsRDBen7Piuq/tckz24o1iyjvIctt8sS5+VO08Ika6fGRBRAUP0cF +9ssGgq4qDxdnoBOQP+6GhfdcQPyr2jvkJkMA5g7K2I1E9koGYQ7pQPiw3wH9IEYo9yj sKaaazbCIQ9ZnhKmNSEBVfuyc9cSjwmjkzPT9EntTxzSZVVUiwpwEBFotCFF0zow7gXV JpIn/LutzGoD9R1K7PdI/fNmtto67DjUrVZZyZou4hYPHgd7ktkSBtJjMmUH8XMf+T/p RtqaTndm/XO02t2d118TzbKFAha6UvLygOWq4dXqZ5ew6rJLR1a28hJFjoYY2cJBXDnT iOpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=YU2muZyA; 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 lg13-20020a170902fb8d00b001b829a32f36si569130plb.637.2023.06.27.07.57.02; Tue, 27 Jun 2023 07:57:15 -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=YU2muZyA; 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 S232237AbjF0OrG (ORCPT + 99 others); Tue, 27 Jun 2023 10:47:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231990AbjF0Op6 (ORCPT ); Tue, 27 Jun 2023 10:45:58 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1548835A6; Tue, 27 Jun 2023 07:45:25 -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=rUzmkjTakIf1l5Hdr1TLtSGZWZezFJIK9Clkpx3VPN4=; b=YU2muZyAimuOaNCN/40I/rQBJ4UKO7cZzX4Ns4xfMNxcNtf60stG8vLV OUQT7SM9PQDqEiNQb+GJRV7tsNdaMhbSut5FfSyOzxaZDsiUfbnN8/yiX zL2fR+ESjZuSBV6CTlVOC54xtEJBTZW28IAqKnqEDsce1t7x/6m+mZ0e+ k=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936345" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:53 +0200 From: Julia Lawall To: "K. Y. Srinivasan" Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Haiyang Zhang , Wei Liu , Dexuan Cui , "David S. Miller" , Eric Dumazet , Paolo Abeni , linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 22/24] net: mana: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:37 +0200 Message-Id: <20230627144339.144478-23-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868189021413865?= X-GMAIL-MSGID: =?utf-8?q?1769868189021413865?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/net/ethernet/microsoft/mana/hw_channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c @@ -627,7 +627,7 @@ static int mana_hwc_establish_channel(st if (WARN_ON(cq->id >= gc->max_num_cqs)) return -EPROTO; - gc->cq_table = vzalloc(gc->max_num_cqs * sizeof(struct gdma_queue *)); + gc->cq_table = vcalloc(gc->max_num_cqs, sizeof(struct gdma_queue *)); if (!gc->cq_table) return -ENOMEM; From patchwork Tue Jun 27 14:43:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113453 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8254771vqr; Tue, 27 Jun 2023 07:49:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5a3krKG6eoVEUNhAVwxLVChpaF/OYzU/sfs7nqF/wj328UZC+Dx1iXvi08H2LcHdG4GpPv X-Received: by 2002:a17:906:eec9:b0:96b:e93:3aa8 with SMTP id wu9-20020a170906eec900b0096b0e933aa8mr27444281ejb.21.1687877392653; Tue, 27 Jun 2023 07:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687877392; cv=none; d=google.com; s=arc-20160816; b=PbhUUl+FBqvYl4EWSu5UAfiYdd2GFzXtnt5g3EECWU1+GlSgKDOh4Oj5g5MkPWHVD0 DR7ROHWN8dqX2h/NPvnkXETNs1CqZ1mHxc/L8uZCHTFW9uqtgmpmiO+7gd0H7CYy6cTt r/vppNblyeGOJL0K645lUmKaoAgT52t0kQEjePueQTFan6qrSyrL/a8WCIj5b1fxiD+v +CYlTHOOtWl00tpAG+jhh9JFM9nWnrSqf+COx6L4rHuZ0DftOLHoFVwjAVQ4d6UtPTBA NSo5nMyWmquHto08VjbT4JvrTrS/28Tvsql02fMffUHfhIK0+RdAn3JZICrbRR4pwi1K KFZg== 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=1fuBHkuVCLvBAw8MSaPz0+UJaQZjfgmRVP18IwyNeDQ=; fh=8ZAmWz3KuL4uniLkQvxSfAdIbL4KHtMaoLSgn3cQUic=; b=0pUWJijNcQ7D5D2tE7ruNpScnsv9wyu7Won1h04GBDhAFj+vBW+2sPA2t/tUGGhpyl MlYLs+v231PFI9gIqkIjJjX//UJKUOH9cg0CnQfUt27KN6cFX7NWsP1Me8kOmRVXPpke vLuxQc1tKK2myqnUsZzR0UqC3QPJB2QSw9nSFpjIzz/3bZBwTkIJz/GFiGhWt7PYe4Hr 0OtI0ygiYRJFKb1TFBd2IZRI4fkVa48f+weCkblegUIK4ygB4gI5Ru7+fEKugC3LXAqJ 756iq28UoSrG+53ggo2yj3anq3cqQXzR5o04em3xQVaLXtFXkm8bilhvcQQ+Tm5TcRR9 MaIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=OThXz5HO; 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 rh22-20020a17090720f600b0098e19ebc8fcsi3868940ejb.679.2023.06.27.07.49.28; Tue, 27 Jun 2023 07:49:52 -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=OThXz5HO; 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 S231696AbjF0OrL (ORCPT + 99 others); Tue, 27 Jun 2023 10:47:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbjF0Op5 (ORCPT ); Tue, 27 Jun 2023 10:45:57 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 391013593; Tue, 27 Jun 2023 07:45:27 -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=1fuBHkuVCLvBAw8MSaPz0+UJaQZjfgmRVP18IwyNeDQ=; b=OThXz5HOfGeTx9GD1nvtvqYG/QJvKBhAtvHz62cnidSYuUWImbYlLedV QyDiCsD4jvF4TDB040IrOhHB/CSeZG4H1P4v4+Zu6HW/zl+fwnSIwGIYT nJ93hxVqPqxEW9Mu1JxrZeFxmha8G4U9oBr7c2HOjcOaDb2Po5/neaAlT Y=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936346" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:53 +0200 From: Julia Lawall To: "Michael S. Tsirkin" Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, Jason Wang , Xuan Zhuo , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 23/24] vduse: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:38 +0200 Message-Id: <20230627144339.144478-24-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769867724674984745?= X-GMAIL-MSGID: =?utf-8?q?1769867724674984745?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT)) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. The position of this patch in the series changed accordingly. drivers/vdpa/vdpa_user/iova_domain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c --- a/drivers/vdpa/vdpa_user/iova_domain.c +++ b/drivers/vdpa/vdpa_user/iova_domain.c @@ -571,8 +571,8 @@ vduse_domain_create(unsigned long iova_l 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 = vcalloc(bounce_pfns, + sizeof(struct vduse_bounce_map)); if (!domain->bounce_maps) goto err_map; From patchwork Tue Jun 27 14:43:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 113477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8269646vqr; Tue, 27 Jun 2023 08:08:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jI12fWLTSazeZhrZVhDkFNhDESLrngReiZ4iANUrnWxwDkype/BNP4UqgFja8hiMgHeGU X-Received: by 2002:a17:902:ecc5:b0:1b7:f98d:5567 with SMTP id a5-20020a170902ecc500b001b7f98d5567mr8334567plh.68.1687878539158; Tue, 27 Jun 2023 08:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687878539; cv=none; d=google.com; s=arc-20160816; b=kzzsjwFKq3+HkiSryI6h48GlcMThyoYcmt1MhgtlTiOoBQRXIfjEPGyID9JHs+qVGC 3d8PMpLJYI9bjSbcvz2vuKvpnO24VWEcjaO+4sC13GNHFkfo8ojpESuEY9Smxh9uD/71 Ke3xOVXDpow2rifZ5gZG3UBMeZs29jX+pGQomkgH0Y8hH4cyIY7H06U++0UZSVX2dEQD nyEWL+l0kY/2e5MjdF+a0m1dMcDFLIAr2fOwxdJh8ygx1GOLV4964dJMEhWilSYB3uNH MbxtTJR1w15rcozIb1sQDwehiNY/OrQaJTJ+puffLaay/pNMLaIUVzSrhuYSt3wrSSVk KzpQ== 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=Z82TQ5gJtsAQsS8pQEGxb7cmdrfE0splW6XwEm1/6wU=; fh=I6SiokgE0vc3hBxxKQwokIrt5VG73lyQvGV134hluyQ=; b=vwNG315eWD/HUofaVP2KEE3qcEK0lt6IPyK6zw4aUgRTe/jS2A/aXPiGZqgWkqe6m+ ZQZ6H0eVOfvEbBb88FRlyvcMTTohWUkZAJ4Xfs00PKwI+pPbfHlxCIItxTIw61wOHYFT GbBzN3Ih/ly1D/7M0ze/wPXFaVZV6FE4L044sUrcaWJrERyyGCORIKsoc5asG9XUNjJh maPK5t57kAftJXZRhAWkV5BLHtnqnyStzb8qFniCpX7kGZpayjl1jkHeI5zpY9SnxCBL 8hnh3DQrtn/Tc4qi7mx/l9kAwMuUmw4aChkOWCAoiIkHEEqXK4y4VzUWLpgmTNBCjS1I GV5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=iHdVPjsd; 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 u5-20020a170902e80500b001b53c41c138si8231412plg.26.2023.06.27.08.08.39; Tue, 27 Jun 2023 08:08:59 -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=iHdVPjsd; 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 S232248AbjF0OrP (ORCPT + 99 others); Tue, 27 Jun 2023 10:47:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231993AbjF0Op6 (ORCPT ); Tue, 27 Jun 2023 10:45:58 -0400 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A02EF30E5; Tue, 27 Jun 2023 07:45:27 -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=Z82TQ5gJtsAQsS8pQEGxb7cmdrfE0splW6XwEm1/6wU=; b=iHdVPjsdGYPUTWXu4Ea7YwNhgAHax/50Ctdon4mH6O9Lm0GAA6tq10Hq qpugFsfftNxOqg1ePJ9wS48K0v0nTQ2yH8JsF6EyFw8CUraY+BkP6Lr0a 8faRDg0zoYpPt6Zw8zxx/r+fj+B0Y/oAEVT8RP7qie5okcXB+89hhiW// E=; Authentication-Results: mail2-relais-roc.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,162,1684792800"; d="scan'208";a="114936347" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2023 16:43:53 +0200 From: Julia Lawall To: Nilesh Javali Cc: kernel-janitors@vger.kernel.org, keescook@chromium.org, christophe.jaillet@wanadoo.fr, kuba@kernel.org, GR-QLogic-Storage-Upstream@marvell.com, "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 24/24] scsi: qla2xxx: use vmalloc_array and vcalloc Date: Tue, 27 Jun 2023 16:43:39 +0200 Message-Id: <20230627144339.144478-25-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230627144339.144478-1-Julia.Lawall@inria.fr> References: <20230627144339.144478-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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?1769868927166869048?= X-GMAIL-MSGID: =?utf-8?q?1769868927166869048?= Use vmalloc_array and vcalloc to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @initialize:ocaml@ @@ let rename alloc = match alloc with "vmalloc" -> "vmalloc_array" | "vzalloc" -> "vcalloc" | _ -> failwith "unknown" @@ size_t e1,e2; constant C1, C2; expression E1, E2, COUNT, x1, x2, x3; typedef u8; typedef __u8; type t = {u8,__u8,char,unsigned char}; identifier alloc = {vmalloc,vzalloc}; fresh identifier realloc = script:ocaml(alloc) { rename alloc }; @@ ( alloc(x1*x2*x3) | alloc(C1 * C2) | alloc((sizeof(t)) * (COUNT), ...) | - alloc((e1) * (e2)) + realloc(e1, e2) | - alloc((e1) * (COUNT)) + realloc(COUNT, e1) | - alloc((E1) * (E2)) + realloc(E1, E2) ) // Signed-off-by: Julia Lawall --- v2: Use vmalloc_array and vcalloc instead of array_size. This also leaves a multiplication of a constant by a sizeof as is. Two patches are thus dropped from the series. drivers/scsi/qla2xxx/qla_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff -u -p a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c @@ -8434,7 +8434,7 @@ qla24xx_load_risc_flash(scsi_qla_host_t ql_dbg(ql_dbg_init, vha, 0x0163, "-> fwdt%u template allocate template %#x words...\n", j, risc_size); - fwdt->template = vmalloc(risc_size * sizeof(*dcode)); + fwdt->template = vmalloc_array(risc_size, sizeof(*dcode)); if (!fwdt->template) { ql_log(ql_log_warn, vha, 0x0164, "-> fwdt%u failed allocate template.\n", j); @@ -8689,7 +8689,7 @@ qla24xx_load_risc_blob(scsi_qla_host_t * ql_dbg(ql_dbg_init, vha, 0x0173, "-> fwdt%u template allocate template %#x words...\n", j, risc_size); - fwdt->template = vmalloc(risc_size * sizeof(*dcode)); + fwdt->template = vmalloc_array(risc_size, sizeof(*dcode)); if (!fwdt->template) { ql_log(ql_log_warn, vha, 0x0174, "-> fwdt%u failed allocate template.\n", j);