From patchwork Fri Sep 15 18:17:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 140607 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1237860vqi; Fri, 15 Sep 2023 11:19:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4JTMQjvwbgCf2e8hoDiG8atbQjOGfTKyMZNUrX62XBLJBY0JEuC0tbvCJuVt9Bl0IuhQF X-Received: by 2002:a05:6300:8089:b0:14c:4deb:7189 with SMTP id ap9-20020a056300808900b0014c4deb7189mr2678776pzc.26.1694801977936; Fri, 15 Sep 2023 11:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694801977; cv=none; d=google.com; s=arc-20160816; b=JvwLS95RjoGR7YZqgOp2A1U5wXJLN+/mv84aJSY7hzjRRI6OCIqiG2fzRHFVDSNeK3 FmxlTds0xtO56KDn6sIqSGUFGHuACjv/IqMwHwiLo5uylQxxOWgF8FouDIgciJscJzK0 yVoX+L0zWWJQdp7hgd3PyLrpQCt516AldoOinR4sjyHz5sB+FmCZDDF2yNn7MynebtZU KYozl49MIKlCGWeWLct6qzqtH+FCzvG6aPZhvc+8/cHDaj/sF1F78wfjWrimAtXV9CqH NwRw1zCmEp4zlgMi4f+g4AL073B4oqtJM9Zy2YHy+bhVnWpVHjCK+PFmOGTOCFAAoTHv hfrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=kjrTLyqmQYWQmaj3xgiSN2NFrH2lc7h8bix/58MQ7SI=; fh=QIIsnf0kr6DKk6Iw9fqpc5EmBCSjKc7PtOk/F9ZCaAE=; b=J3QeZZ4t7aPvf4CjLkwqQwFPObihV6pQzwxVwNMzluEHkArMNnVN3shFtmY0fep00F Ce/TOTeoOAPw/QTAyTO62IJcMcdmPYRU3dNHnVkY5ZkdgpiUW/fUrm4e+MV6lpy2Sflj +YWqoVUg98UhcA2O/XJ1vsCM8PKqdM7bxVOAqa+ZjAtUq2eJbg21ZIzKbhyfqIyPI9op ArLPjaGNvzC0Q0l4RTapbb26yHhXKquQ8O71TUIbvO59fIGmTi+Osop8lSZmU0fQNcgR tlV8Oo+jfRZ6SWW2Q3mHJT078T6kPciFOJdNG6Sx0If2rp2Q8zCwuFUdC+VXIsczS5Uj D4dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yq79jB3G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id l24-20020a637018000000b0056af922fdc9si3567817pgc.852.2023.09.15.11.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 11:19:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Yq79jB3G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 958D682E47DE; Fri, 15 Sep 2023 11:18:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236369AbjIOSR2 (ORCPT + 30 others); Fri, 15 Sep 2023 14:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236363AbjIOSRA (ORCPT ); Fri, 15 Sep 2023 14:17:00 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79071FCC; Fri, 15 Sep 2023 11:16:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CC75C433C7; Fri, 15 Sep 2023 18:16:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694801815; bh=QQqUp4XKgQyXwHPRMB+70AKUDzS82qjfk8gBWWVgGI4=; h=Date:From:To:Cc:Subject:From; b=Yq79jB3G8IBEwWWnWZobdn6Dv325x+kOyUwQrhwpzktHSyJ6HHrnRXQHYvmOYWOPh gT0e2oKdogaJYnAlSYqFv5zYbSKiPsiSftkYHjSjGR+pjxGaNk7hZKn56zH3bOCSFx JSEh05iC5fyiG4U1VIs7g7UMiazvSKY+Vyf4Ax2XMU5/IZPk03/phNT7y+qEvMjTmH yT8AEElu4D1porsU9LKGu82QC3nQEL/EYaqMnvQPmRoqBhWKP/293HMA/nYqQqRnaV Lq6hPhMYaIGNt04csavSvpsgSl505s4DlcNVdiVeR1n7j6s2fIwFuOB9CpyRMFpWKI XtKv0BUO7E/xQ== Date: Fri, 15 Sep 2023 12:17:49 -0600 From: "Gustavo A. R. Silva" To: Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] gve: Use size_add() in call to struct_size() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 15 Sep 2023 11:18:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777128678973161270 X-GMAIL-MSGID: 1777128678973161270 If, for any reason, `tx_stats_num + rx_stats_num` wraps around, the protection that struct_size() adds against potential integer overflows is defeated. Fix this by hardening call to struct_size() with size_add(). Fixes: 691f4077d560 ("gve: Replace zero-length array with flexible-array member") Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/net/ethernet/google/gve/gve_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/google/gve/gve_main.c b/drivers/net/ethernet/google/gve/gve_main.c index 5704b5f57cd0..83b09dcfafc4 100644 --- a/drivers/net/ethernet/google/gve/gve_main.c +++ b/drivers/net/ethernet/google/gve/gve_main.c @@ -190,7 +190,7 @@ static int gve_alloc_stats_report(struct gve_priv *priv) rx_stats_num = (GVE_RX_STATS_REPORT_NUM + NIC_RX_STATS_REPORT_NUM) * priv->rx_cfg.num_queues; priv->stats_report_len = struct_size(priv->stats_report, stats, - tx_stats_num + rx_stats_num); + size_add(tx_stats_num, rx_stats_num)); priv->stats_report = dma_alloc_coherent(&priv->pdev->dev, priv->stats_report_len, &priv->stats_report_bus, GFP_KERNEL);