From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 850B4C433F5 for ; Wed, 20 Oct 2021 23:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D445611C7 for ; Wed, 20 Oct 2021 23:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229998AbhJTXaJ (ORCPT ); Wed, 20 Oct 2021 19:30:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:60510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229702AbhJTXaJ (ORCPT ); Wed, 20 Oct 2021 19:30:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4FBB660F57; Wed, 20 Oct 2021 23:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634772474; bh=vvRfwlxU8SZoTOlb+tOlX8/u84LD6FdEwl6WBQOZ+Tc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Dxe/2mw2u998213c2OEBsM+rmgFmeySkb1AN7HPknwuv/VV80nKAP2ufhmV6lBq+M 3PIQO/YXQrRM45BFEfCKzFpHlYamtnEuKk/kn/4TdrFapzUtiX/XN8Krt+4XQ9aDjf 3KxkOC3Q6cIUp3JQdWnZt228t5jHvMto3m3x94gRP8pedSm7l72CVAImRnmPIJ+xCQ uGPbHGZHvDwbp8IOcHhElGCcgAjXayJ80KWLJ/o1tX3gYjT906BiODqr89ZOsKdPSl /o9MLlNfGH0OaORrwMs6/2672EDzHDX+yTZ3Buant1Ts8fdmfJNzEropurEqGx2swU +rkGKPKYTAqzQ== Date: Wed, 20 Oct 2021 18:32:33 -0500 From: "Gustavo A. R. Silva" To: "Gustavo A. R. Silva" Cc: Len Baker , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Vinod Koul , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dmaengine: pxa_dma: Prefer struct_size over open coded arithmetic Message-ID: <20211020233233.GA1320242@embeddedor> References: <20210918104055.8444-1-len.baker@gmx.com> 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-hardening@vger.kernel.org On Mon, Sep 20, 2021 at 07:00:58PM -0500, Gustavo A. R. Silva wrote: > > > On 9/18/21 05:40, Len Baker wrote: > > As noted in the "Deprecated Interfaces, Language Features, Attributes, > > and Conventions" documentation [1], size calculations (especially > > multiplication) should not be performed in memory allocator (or similar) > > function arguments due to the risk of them overflowing. This could lead > > to values wrapping around and a smaller allocation being made than the > > caller was expecting. Using those allocations could lead to linear > > overflows of heap memory and other misbehaviors. > > > > So, use the struct_size() helper to do the arithmetic instead of the > > argument "size + count * size" in the kzalloc() function. > > > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments > > > > Signed-off-by: Len Baker > > Reviewed-by: Gustavo A. R. Silva I'm taking this in my -next tree. Thanks -- Gustavo