Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2574154pxb; Thu, 3 Feb 2022 09:21:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxDPErd53C5WI2OvCvJYiwqeECXKyhc2iUOzDPHY96lPGdt9e7KcdwchIS7iS+vkV/2pjf X-Received: by 2002:a17:903:1250:: with SMTP id u16mr36191254plh.126.1643908915475; Thu, 03 Feb 2022 09:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643908915; cv=none; d=google.com; s=arc-20160816; b=Q7xag1i8Rm49vRWYolhos8RrEcvTG+GRRBo7MXqENVSNq7YcPkXfYxwAjZSG3v7gDw 8qWqcEFWdV9B+r1muHKWb2pVqQWBgYlFlAiqYum/SC62SrWL41mD+3bSa06URLz+E5gv DUPBs1H+MnF4Yly8CNjN3YW7hz9c+wd1f2mZQUWNvCaHFHs7wfAiURTEj0LTNK1sHgal sBAMd7YbRk7Qo37JnMdvdRpOxhKJ9N//qLVCUjv64TJX14iDZqfjeDwcHv3NR0Kb6PbG 4unZEO/Xa6nfoN7MW0vJhEOKmyaWWjoiXLe8ZCb+hMgEt60FMpOkKliK+0AQbgvolnVh Uj0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=x5SP6wBXIEPK1p3rvS9+DT/uhtMpldQ/pITLaalWzLw=; b=gheFjQdLSXmxas9GtJ7RrI9kTmLcO31XATyn1P2JHFMhX+qgsvN+aIUAizuqEK/gNY JQuHKYN5KuO31hnu0FPEGG5A8uCdNdIwQiz5pwwG6mLSScjJXvzUJpOwdLgUb7VDF0X3 2CjwlPFegVwFfr0fUHBmNF9GtDzSFJWa3HY5rpIYoAYj77CqPwML3iaEdiwdvqZq1pd2 3ZG8yLt+bVYUybUQArefCJpoJZ+dJPk1kdo0hYjI3MHJ8eGaUvTI8aE7i7L2F8g/RRNj h9HMPl8F4m0nw1ZR5qUlY7XNEDgO4ZFeJPWl8/VyHN8lyEf27mbJ+nvDuhv9cmcEydMY 2D1A== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm12si4535837pjb.106.2022.02.03.09.21.43; Thu, 03 Feb 2022 09:21:55 -0800 (PST) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350585AbiBCMm6 (ORCPT + 99 others); Thu, 3 Feb 2022 07:42:58 -0500 Received: from mail-wm1-f44.google.com ([209.85.128.44]:41815 "EHLO mail-wm1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350577AbiBCMm5 (ORCPT ); Thu, 3 Feb 2022 07:42:57 -0500 Received: by mail-wm1-f44.google.com with SMTP id bg21-20020a05600c3c9500b0035283e7a012so1761885wmb.0; Thu, 03 Feb 2022 04:42:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=x5SP6wBXIEPK1p3rvS9+DT/uhtMpldQ/pITLaalWzLw=; b=BkpFmJqwJz2ysee2aWBOvg5aYAdb4B2kyqZ75ITDC0pELnyr0Inc0/Ad5oThqyQa3V Zpx1PBm9uPNogd30kux2cg3+SOvc/fenVulaad2ED8imb80jEDkS0TAykntmobrVxZ4b s/ret2/ISqUvnRtPl2ca+7hdY4u8DagxJgXRr3B/biggRy//JgKnuvE3T/r1uD43iwJ3 q3/if4dTHIxgGFxZAeBQHQchGSeQZPrKMCUl+VY9d1HsyWSu+wvmvjJpSVkufSPPOGWa OYXmUqimvQeD/gYqMT75ySKAVrnRKCke/cmbTN8mUUeiZDY+BUj9OS5sA6YzTW4ufyNC 5fUA== X-Gm-Message-State: AOAM532l+edQ3sP4y2pYpmxoIhqx6S+ynqzAtGgAEhRptP8Nml7M9W/h shVcmauGXbRmUJ/nwNmIKGE= X-Received: by 2002:a05:600c:2741:: with SMTP id 1mr10407655wmw.50.1643892176074; Thu, 03 Feb 2022 04:42:56 -0800 (PST) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id p7sm7421259wmq.20.2022.02.03.04.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Feb 2022 04:42:54 -0800 (PST) Date: Thu, 3 Feb 2022 12:42:53 +0000 From: Wei Liu To: "Michael Kelley (LINUX)" Cc: "Gustavo A. R. Silva" , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-hardening@vger.kernel.org" Subject: Re: [PATCH][next] Drivers: hv: vmbus: Use struct_size() helper in kmalloc() Message-ID: <20220203124253.h33oehbhninoadca@liuwe-devbox-debian-v2> References: <20220125180131.GA67746@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 27, 2022 at 04:01:28PM +0000, Michael Kelley (LINUX) wrote: > From: Gustavo A. R. Silva Sent: Tuesday, January 25, 2022 10:02 AM > > > > 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 > > --- > > 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 > > Reviewed-by: Michael Kelley > Applied to hyperv-next. Thanks.