From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Subject: Re: [PATCH] iwlwifi: d3: use struct_size() in kzalloc() Date: Thu, 23 Aug 2018 21:33:19 -0700 Message-ID: References: <20180824011540.GA25716@embeddedor.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Cc: Johannes Berg , Emmanuel Grumbach , Luca Coelho , Intel Linux Wireless , Kalle Valo , "David S. Miller" , linux-wireless , Network Development , LKML To: Kees Cook , "Gustavo A. R. Silva" Return-path: In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Thu, 2018-08-23 at 20:03 -0700, Kees Cook wrote: > On Thu, Aug 23, 2018 at 6:15 PM, Gustavo A. R. Silva > wrote: > > One of the more common cases of allocation size calculations is finding > > the size of a structure that has a zero-sized array at the end, along > > with memory for some number of elements for that array. For example: > > > > struct foo { > > int stuff; > > void *entry[]; > > }; Question for Gustavo. Did you find any existing instances that are miscalculated? I believe there are some cases like: size = sizeof(struct foo) + count * sizeof(something); ptr = kmalloc(size); memset(ptr + sizeof(struct foo), 0, size - sizeof(struct foo)); where something could go wrong and not be detected.