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; From patchwork Fri Dec 8 20:46:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 176029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5710683vqy; Fri, 8 Dec 2023 12:47:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IHD9Fc177SjE6AWANmhDL2bTLjuVEIW9aBWxaIjkWrrtiqYl91iRhr9M7MpuYVs1ThD0ULG X-Received: by 2002:a05:6a21:3298:b0:18f:97c:6149 with SMTP id yt24-20020a056a21329800b0018f097c6149mr664636pzb.70.1702068424765; Fri, 08 Dec 2023 12:47:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702068424; cv=none; d=google.com; s=arc-20160816; b=AJ74B2ttCB3ryJZ+0+lDZFWgw47WxRi4mKHEsOehfsbtMN98/TRfAQ5EWd/3cZ8PXM IjDz+G4vpx/pbYmnThhGv0xKYSkfZ8z8KYeUB8V5WXY+gNj6vVD2sRZ7KuZEucQArPJr qYbMibTZALdEYt1ElkXG/N/hgdYm1VnJoYj+0f8CZxXjrKzhXHgIwGtbTw4ZNok1Fp29 F2vEQWtMP/KVuLKP8QxwVg5TiXPA0yBW/XbJDjWs6t8DpfEuPXHe9xCN5OISWUKLI24g 3la4XrEOkdjSGI5fyq33GoXUhZw6FWt8wfyeRMekuw3S0m8v1XY+Drh2xJ3JxLfPffsM 8ekw== 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=OUm2hzTidMbVdw5ax/yHOZYECAzHPDWlYlnEDUQbJ6E=; fh=3wOtCVUcvBrsL51U+yUhlochyUa73CpX1FOSR+cseNE=; b=eVpz44gOvuMrtLn1UQ/e8JJ+bvb3pFBlc+nMU5U6k5jYo9QqTQqycEKMbryBJRaWUk mZY6AZDtI1YgjRB1puUGV2xOHoezqOrXyp0XKNUdwDpMOCYmAoEo74dUkEdXOOrAkH41 tCpl97fnh0dVAYorVY+lb69DG6hUXUo3MXmvg4I1Gz0C3WrWgairaBMyN5skfBdc0vT4 tqnkAS0XQgJm+UaRnl526gn2rUSoQgPYwGFe0dQLYgDAku8rq4POwe7yTKhkepIXVKR2 uqQGhq2PlpwrAUrCJjYcFXVMHYzcfG3DId+w+6s0EhLBd67VTueaKa4xOuz7QRkenFPX iWLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=eDRVITlZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id v7-20020a655687000000b00589884fef91si2020271pgs.740.2023.12.08.12.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 12:47:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=eDRVITlZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id C8BF880E6F9B; Fri, 8 Dec 2023 12:47:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574757AbjLHUqW (ORCPT + 99 others); Fri, 8 Dec 2023 15:46:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235943AbjLHUqS (ORCPT ); Fri, 8 Dec 2023 15:46:18 -0500 Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 349F119A3 for ; Fri, 8 Dec 2023 12:46:24 -0800 (PST) Received: from pop-os.home ([92.140.202.140]) by smtp.orange.fr with ESMTPA id BhjkrXIBfToaHBhjrr2fhc; Fri, 08 Dec 2023 21:46:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1702068384; bh=OUm2hzTidMbVdw5ax/yHOZYECAzHPDWlYlnEDUQbJ6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eDRVITlZravmpDCqVEtKjoVG/CMGGLp20GLTLwVo/LflmiG3NNaPOOQlAGfd29KCP wgg8XW//4KTUZVX0hVOcxlorSgosDdTLSuvmDIgpAEB7BoZ2rZHQowvuGfCEObI/vm f0Nw4O9zwclo1iVHjfeUYWKqFl1UwiM9tOhF5cVHRUUBcibJW7wVipBdIfNDPg9sTz 8JSFq3LaLDdsi4HBpFOnlFo6Xv9ptREmVJuZDHOaxI+HCxDCx5icQwjkA7yf/KeNAD al34aO70NpNPYuUUkmdOgk2P98Vzfdwu8RZ1J1btEqLIHqMZ/GfqSDej9fs7j9ujBI fTdnw4DoPdM4g== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 08 Dec 2023 21:46:24 +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 2/2] VMCI: Remove VMCI_HANDLE_ARRAY_HEADER_SIZE and VMCI_HANDLE_ARRAY_MAX_CAPACITY Date: Fri, 8 Dec 2023 21:46:10 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: 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=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 08 Dec 2023 12:47:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784748100753339953 X-GMAIL-MSGID: 1784748100753339953 Remove VMCI_HANDLE_ARRAY_HEADER_SIZE and VMCI_HANDLE_ARRAY_MAX_CAPACITY that are unused. Suggested-by: Kees Cook Signed-off-by: Christophe JAILLET Reviewed-by: Kees Cook --- drivers/misc/vmw_vmci/vmci_handle_array.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_handle_array.h b/drivers/misc/vmw_vmci/vmci_handle_array.h index b0e6b1956014..27a38b97e8a8 100644 --- a/drivers/misc/vmw_vmci/vmci_handle_array.h +++ b/drivers/misc/vmw_vmci/vmci_handle_array.h @@ -20,14 +20,8 @@ struct vmci_handle_arr { struct vmci_handle entries[] __counted_by(capacity); }; -#define VMCI_HANDLE_ARRAY_HEADER_SIZE \ - offsetof(struct vmci_handle_arr, entries) /* Select a default capacity that results in a 64 byte sized array */ #define VMCI_HANDLE_ARRAY_DEFAULT_CAPACITY 6 -/* Make sure that the max array size can be expressed by a u32 */ -#define VMCI_HANDLE_ARRAY_MAX_CAPACITY \ - ((U32_MAX - VMCI_HANDLE_ARRAY_HEADER_SIZE - 1) / \ - sizeof(struct vmci_handle)) struct vmci_handle_arr *vmci_handle_arr_create(u32 capacity, u32 max_capacity); void vmci_handle_arr_destroy(struct vmci_handle_arr *array);