Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4773585pxb; Tue, 25 Jan 2022 19:12:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBHAXb25ko/1ZP4V5yI4C3ftZ0TrOfJYTy5umyOkDjOHlleEfeuUBVylGkvGidGD/v+RMt X-Received: by 2002:a63:d156:: with SMTP id c22mr4700541pgj.570.1643166749278; Tue, 25 Jan 2022 19:12:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643166749; cv=none; d=google.com; s=arc-20160816; b=GpqpzFEc44BC/1Xh/uuhhXzeRBrsALVGtHBV/5BVszMjhGlN1PgQoXxbTWQPdfkMWh I18fzjn8Ofj8mUK3C0ArH7RXg2pv5xoTerBrXWb4msfKWO22NeKW98MQejiTy3jIfT2C T5dCJvlh8Y6RGNAzVmIZTIbOZ05JAJSPq7QeOs3wDvAAAG6KKXinAktrI2rK0a2u5A5y sYE0CKOFEDBwLQ9UB/962d4UPBLDu+iQTOPhUgRBvIQrHgthxrtpUBWxhmNT6itjlJ54 wck0UcvBYcFKMlAPb1TjCEj/w+Te9xNnRiQln9EKYrr72zq3T9pDx+Z/2O2U2uOPe12k w0bw== 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=pC+ACXA8gx778UyReOgvOKum2O2sCk8HUYunYh1ItQQ=; b=NWNQCfaY/AYW9CkEzI6u5HR1O8k77nKsGMsQeilzp6/fKrjI/B0fx9vJlou6jAw7ik HPE3p7uIPUImiViQ7V9CFkeWLve8M2GRvA2FgKEKeWTGYx/7dTdaH48n8QLijoR1EUN2 lUoQH+QPmmLXAT+MusU+AfyQVvdr1Lk+1Kak0D9Dj6eXQb37DpC+Lg7brzZJfPWcCgsQ opZrbugielLpAufwQRf7xRPnWq93OB35t1wqQU5NkykTJjLzEnMysXh0MNg6vMJZAIIg 5p6vlnalq8Ak5LJh4E5XMtzxx4XVKj1/OQ1qG8qmXKOnrevBOy6E7zK1E+M+SHkL/17M /RPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kfe3v9vI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si5832132plp.572.2022.01.25.19.12.17; Tue, 25 Jan 2022 19:12:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kfe3v9vI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347944AbiAYR4l (ORCPT + 99 others); Tue, 25 Jan 2022 12:56:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385185AbiAYRyu (ORCPT ); Tue, 25 Jan 2022 12:54:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2364C06175E; Tue, 25 Jan 2022 09:54:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7F05CB819DC; Tue, 25 Jan 2022 17:54:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BE27C340E0; Tue, 25 Jan 2022 17:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643133286; bh=e8RIDdHaka7BpYFM9Quoh+WQnHQ0tbZzk2YChopEt5k=; h=Date:From:To:Cc:Subject:From; b=kfe3v9vI/NVHnoFrPeCBhSyVHjQQDrMtFRj2FLGHhtonu4oVamFx2uaUDoex/ZPwl zAnO3bCTPb9q619jkKtp8C1pKJs+BkuizxhpCxMKjeiPV8PutwIkovgwe8m+mrFAMM 2HEC5/bm4WyeaEShCLHujXX1zoGLyVfDlZOEvGB6zvoypSLpPLnlheC948/vEtMNsN /fdY4pHAsSdnn3fHTGfUNrB0XxeSV1ybgzkbB/ohctVLAxpjqfQ05uUhAiSMJhSLRq 3rYxH/SCyAD0/K0KLdZnAVPnfzcfa4kBNlSjiA/QDbNGNDJwFRub/mtBKmXwTelMft NwUAu3eCvQhBQ== Date: Tue, 25 Jan 2022 12:01:31 -0600 From: "Gustavo A. R. Silva" To: "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc() Message-ID: <20220125180131.GA67746@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/hv/vmbus_drv.c:1132:31: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva --- drivers/hv/vmbus_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 17bf55fe3169..cd193456cd84 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1129,7 +1129,7 @@ void vmbus_on_msg_dpc(unsigned long data) } if (entry->handler_type == VMHT_BLOCKING) { - ctx = kmalloc(sizeof(*ctx) + payload_size, GFP_ATOMIC); + ctx = kmalloc(struct_size(ctx, msg.payload, payload_size), GFP_ATOMIC); if (ctx == NULL) return; -- 2.27.0