From patchwork Fri Dec 8 20:46:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 176028 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5710475vqy; Fri, 8 Dec 2023 12:46:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHc2HgM1EjeWIzRgt8T9dkRu1/lcF1Et8Ae5ceX3x+Bs39LBuSbf1hKW9mS87EsYDhBo2ST X-Received: by 2002:a05:6a20:cea4:b0:18d:b43:78e8 with SMTP id if36-20020a056a20cea400b0018d0b4378e8mr596802pzb.32.1702068392218; Fri, 08 Dec 2023 12:46:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702068392; cv=none; d=google.com; s=arc-20160816; b=eFE6v3Nv/VL2sf9qg+U747KFC16HVEnkitMoIg4xc93WsRtaS1xAizCkkjjsc3ApMZ AUovsXOzrVLUEIalg7UwjMN8KXE1diqi3oT4TDv2IUq8VCo04jgL4NoOUiGlLcurGmbm QtPNFi6GrqNiczAw6hlGLP1d4+5HxvQgSzgec15XUaAvUPw8neBTQs3cEARvBZdpYWyh ebbm63HALFnu3QPFkdpKBdzA4PxqlhiBTiDNmATbffVG9qUrBWkDlF/FmSCNIOF1AHnN K+hXI62maWt8gWcCvtNc9+OKvmilMqmLHeoCeVqoql9FZ92uzYrlKRfR/bE/8R2SB6gJ N0LQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=c7yN6XYmPkSmYh2d3ai7nF5rpx6ZA/0115qJPRMOJ2Q=; fh=3wOtCVUcvBrsL51U+yUhlochyUa73CpX1FOSR+cseNE=; b=INFJxTbSd8xLCfq+cuwpvmAegSoU90Dy7sx9z85RiPmSyvNzGCqZUaDmKIQhApOMk2 mLqU9e4t0J0wj3TVq3E7qoDocbMePm/i6TjSXT0PWeSdxsSH4Kb6Yx+CPFzYix73epSl GFIoEiCXI20bu5cwOC3ZkjjfHv/D15GQJeWMHyoragCTkRreymqQbBI2vn8vyshUck51 FTLDTPlfalFGSiPwPEBV61qz2latf+6tYuLZqGJ52Jb55DafWb4kmuuOFeSJoNyjQm/y RfR6oClUo1dUh7ghm9Q/swmk+eyxKB3OTVfwpgcp3K0/FKlFdiflqFejaGewnHuSWXVp +tdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=t+pSJO4x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id o65-20020a634144000000b005be264316d6si1946926pga.598.2023.12.08.12.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 12:46:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=t+pSJO4x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CC20F8087230; Fri, 8 Dec 2023 12:46:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574745AbjLHUqU (ORCPT + 99 others); Fri, 8 Dec 2023 15:46:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233919AbjLHUqP (ORCPT ); Fri, 8 Dec 2023 15:46:15 -0500 Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198C21995 for ; Fri, 8 Dec 2023 12:46:20 -0800 (PST) Received: from pop-os.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id BhjkrXIBfToaHBhjkr2fgx; Fri, 08 Dec 2023 21:46:18 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1702068378; bh=c7yN6XYmPkSmYh2d3ai7nF5rpx6ZA/0115qJPRMOJ2Q=; h=From:To:Cc:Subject:Date; b=t+pSJO4x/EZmGcAEdRrc6oukLmyBQhaRLPhPdh4WTYVNlpMHBvWHw2lwi98ggOEU0 dBIjGStSWPZ8YQuDdKuJu/0uURu/swVSxKrR+f3KpGsQHeIYWpvclddjl6KLLrOOYD bhZuXSyRGC1yCgIK9DI4QxXamkJ7YilG+1phzyTYSD8Fe2ahI6H0AiM1V3Ofs8BmLM pgok+pd0j9jnzX3Zmp9go7DIpd2KIWzJ6+Y5KuZDSkTBT3c2+UmeDUFLoRkx2blMUb 5TtTMEOmxS/Bx30r6zJFsmRZVzUqX5jBUqHSIEJ93n8+USicxGa33ZebtPaW8kbWsO VFTFYsXtiOc6Q== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 08 Dec 2023 21:46:18 +0100 X-ME-IP: 92.140.202.140 From: Christophe JAILLET To: Bryan Tan , Vishnu Dasa , VMware PV-Drivers Reviewers , Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , Kees Cook Subject: [PATCH 1/2] VMCI: Remove handle_arr_calc_size() Date: Fri, 8 Dec 2023 21:46:09 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 08 Dec 2023 12:46:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784748066522609909 X-GMAIL-MSGID: 1784748066522609909 Use struct_size() instead of handle_arr_calc_size(). This is much more conventionnal. Suggested-by: Kees Cook Signed-off-by: Christophe JAILLET Reviewed-by: Kees Cook --- drivers/misc/vmw_vmci/vmci_handle_array.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_handle_array.c b/drivers/misc/vmw_vmci/vmci_handle_array.c index de7fee7ead1b..56d48d42736b 100644 --- a/drivers/misc/vmw_vmci/vmci_handle_array.c +++ b/drivers/misc/vmw_vmci/vmci_handle_array.c @@ -8,12 +8,6 @@ #include #include "vmci_handle_array.h" -static size_t handle_arr_calc_size(u32 capacity) -{ - return VMCI_HANDLE_ARRAY_HEADER_SIZE + - capacity * sizeof(struct vmci_handle); -} - struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity) { struct vmci_handle_arr *array; @@ -25,7 +19,7 @@ struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity) capacity = min((u32)VMCI_HANDLE_ARRAY_DEFAULT_CAPACITY, max_capacity); - array = kmalloc(handle_arr_calc_size(capacity), GFP_ATOMIC); + array = kmalloc(struct_size(array, entries, capacity), GFP_ATOMIC); if (!array) return NULL; @@ -51,8 +45,8 @@ int vmci_handle_arr_append_entry(struct vmci_handle_arr **array_ptr, struct vmci_handle_arr *new_array; u32 capacity_bump = min(array->max_capacity - array->capacity, array->capacity); - size_t new_size = handle_arr_calc_size(array->capacity + - capacity_bump); + size_t new_size = struct_size(array, entries, + array->capacity + capacity_bump); if (array->size >= array->max_capacity) return VMCI_ERROR_NO_MEM;