Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2615061pxb; Sun, 17 Oct 2021 20:34:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhB7b0Wco976cNbtKh+KzUa5R9sbdRZ9j21htC586390B9LaeXE3soU2zH2uxF2F7q/rR0 X-Received: by 2002:a17:902:7e01:b0:13f:7f2e:753e with SMTP id b1-20020a1709027e0100b0013f7f2e753emr22883973plm.88.1634528090111; Sun, 17 Oct 2021 20:34:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528090; cv=none; d=google.com; s=arc-20160816; b=CdY48BNg/9pymoRNWt3P6keRpmnqoT+moSEBD6f/fFjaB9ZpXx1taRmNNB1CJw+P1Y cZMTjzdExZ4eMPISEF9GryELVKKOVgbQUYruz5q+QZ75HrqatgOihSNXAGObcew2ujYt v/1Rt4ES2jqzdAzJjPW9OX9Ik36VvIszOuL+w46/WC83x00qCB14YqkMHDgkkY2fdPcC PotKClx/nt4/jznrpEbuO/PfmuXHhqC3i0VuN7+1daWfjKlDOCbekhqLBf0Q4gyvBiRc lSFvD8bK7lQpI8MBbKuH4BU0r01DipdKJvjqxvR0mPt1vNIq4zl9qknT4WcaQTClBrlu scpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gcmS576EfDzUaSp481Qnp04QjUDiM5K40EMMBslSFnQ=; b=dSaU2K4+r+LQi2HXUJeaIvE/zTolRErigJKehFkcaBan/WURQNv/s0veBuGQFse5nZ /1IEw+DIU1x3/Y74sC2GJplYOc1PPuvV5Y4jawuGRGi/gJ3WoDTss79vRBsNs/glEiks 5gwzQIvlzMZxME5imQ1dWgrURQcm4CwUoXZo6Rz0Lincvo+fFTJbX9t5AI3urve1zWqt oSD3xqJKpHmYXpsV9foxJWeKpRsu2XTx6vqQQHqZWBEvng15GRrCbl7WV/hdwWHJfdjf /lm2Ju7AcWgoEyePVYOaqW0w6TyIV0FJRbCS+kw/VJQq/MUFMjJZsILr/xBDLnH+tEOD p1dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=gZKhnmBO; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si16634236pgj.581.2021.10.17.20.34.38; Sun, 17 Oct 2021 20:34:50 -0700 (PDT) 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=@gmx.net header.s=badeba3b8450 header.b=gZKhnmBO; 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=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244261AbhJPLSf (ORCPT + 98 others); Sat, 16 Oct 2021 07:18:35 -0400 Received: from mout.gmx.net ([212.227.15.19]:33795 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236029AbhJPLSf (ORCPT ); Sat, 16 Oct 2021 07:18:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1634382974; bh=Mhw02uk6pyAcd09twynYEmpbbHs67NvOvVZTeh65TQ4=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=gZKhnmBON9Gg/8BxGCv+oJ0/ws3frGh32IR7U1a57EisAnv8FCzFeeJTFTx3MWZM/ 2sH7hqesKMUlxkAcOudVEHnoPMis1JirRIEzbJV3Q8mBb7FYtKKz4ffG7UdhZ7MAza +hbJES3Y107oPh93XQzE9fpAcLZMaVIjaWJAPt/w= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from titan ([79.150.72.99]) by mail.gmx.net (mrgmx004 [212.227.17.184]) with ESMTPSA (Nemesis) id 1M59C2-1mcnbF3JzA-001B53; Sat, 16 Oct 2021 13:16:14 +0200 Date: Sat, 16 Oct 2021 13:16:02 +0200 From: Len Baker To: Daniel Vetter , Jani Nikula Cc: Len Baker , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Kees Cook , "Gustavo A. R. Silva" , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] drm/i915: Prefer struct_size over open coded arithmetic Message-ID: <20211016111602.GA1996@titan> References: <20211003104258.18550-1-len.baker@gmx.com> <20211011092304.GA5790@titan> <87k0ihxj56.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V03:K1:1BclTLkTU4amNua8fYN+IZPFm5F/GQXpWS5ysQ60YisVJ8xWdDC /wVNME45XYCO+L/RtZkhQg+PaCqrNbdrnQk4MkAVhNTVKSgB5ks64M+aOQgyg6YJn8xsTzx JPiLFzk4L4VDgWJj5ALAUEwzp9ZEFhM7SuKklT5w+M0uQztnaqPmNSb/sOJdVJGGvGv3JJg m0Vmj7TgIZV0yRFK77RsQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:LRQAcnKjBVU=:CUIE1tkUtt8DmHc2DvoXn6 CfLCNr20xEgnmwtw/fouwwD9ZLjaaJ4wI5EmfE09iOZ/JrfiNmIOw4uHDWU4vQ9Dxj0ypcI32 f2hdSYmXl+i7l824ntWiRLjoFDXR5dot5yqquTPykvH/vJcpSZAmrh0MDsaRHqD6YPd52qJVN izixixj4LjseACXWnd63uhDkIH0sqEqwr4/YII0+J9iBy6RehHRuEwLNTBSh1k7uyCpWKFrBP aZ+pVc3/biTOFiabHA4a80KFCFFPukHPRN6n4KdJXhhVpuASYVDQ1UYKX7pAjJcwR2I7t7THu GLyqdKYrX+q6MZMfQFPwHxqxQBRXkMOhIa9gVxThhWD8A8jY56q5mIjidg45soCI69P1hverj RzQSRVlrCbJpcEvgtDTh4c5B0/ihZp66scW2EkFWcGU+IV7q/MuoQNfrA1GDazKcP7tJ4+ket ZVDM74wwlBNIvyX+xr2sYlV8b08X7dmV64J7fPCm19qk37ak2k5AOA1/fX2wOOWZIcAk5CqrV UGWwFLH2G8vHYFY83YD8goXQJQy6uGM5jCJncxaVSDNEwfd7my6QWLPxM092RSsKZWH+n97Zs aThhPzumI/2XtV5zMqkUER3AU4W9NoQc5YlZ5LAfENHyUXDQGwUPFdKFDT63plQHQUe0xghd2 gKYivo+p1wzDtKggurJbRN79ZfzfKH0f2QS/aY2KOn8DJ3u60ONFt8pMg0Xp++Bsfz8qQ35j5 x+A3DBhXI9l979SF46JtLVczOih6ojMF+RRzNc3txb/bihWfy8Kk4UPJIeN0aEt7TowXfVckL jW0AxF7EJXTtd5v/rFCVq9f3SOpTS6G10G0c49WiEqVmEn6ELYR78ohT+DYriDQ++SI99dBNM 0Q067/K0q0FFLPwtfiBUPk8tfcgjkNHSjnQ66K2BcAX9QMboYyEyKCJJHehdu6qGHecghJuJG xYVrSymPAVB+xZ5tfS7y6pOBB2U9zQNPp5IYmSvbj5IX+r+u/tfzNpOen9LOqf10avjZDZesv 1JHQneqHXsgZbBLIoAdkpRzuEYOncjmzTxdTl22TnAUBBkzhJXcH5JS0Z0lzA+aZ4m/4ZESkK 1+MBTEdSQVCW1k= Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel and Jani, On Wed, Oct 13, 2021 at 01:51:30PM +0200, Daniel Vetter wrote: > On Wed, Oct 13, 2021 at 02:24:05PM +0300, Jani Nikula wrote: > > On Mon, 11 Oct 2021, Len Baker wrote: > > > Hi, > > > > > > On Sun, Oct 03, 2021 at 12:42:58PM +0200, Len Baker wrote: > > >> As noted in the "Deprecated Interfaces, Language Features, Attribut= es, > > >> and Conventions" documentation [1], size calculations (especially > > >> multiplication) should not be performed in memory allocator (or sim= ilar) > > >> 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. > > >> > > >> In this case these are not actually dynamic sizes: all the operands > > >> involved in the calculation are constant values. However it is bett= er to > > >> refactor them anyway, just to keep the open-coded math idiom out of > > >> code. > > >> > > >> So, add at the end of the struct i915_syncmap a union with two flex= ible > > >> array members (these arrays share the same memory layout). This is > > >> possible using the new DECLARE_FLEX_ARRAY macro. And then, use the > > >> struct_size() helper to do the arithmetic instead of the argument > > >> "size + count * size" in the kmalloc and kzalloc() functions. > > >> > > >> Also, take the opportunity to refactor the __sync_seqno and __sync_= child > > >> making them more readable. > > >> > > >> This code was detected with the help of Coccinelle and audited and = fixed > > >> manually. > > >> > > >> [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#= open-coded-arithmetic-in-allocator-arguments > > >> > > >> Signed-off-by: Len Baker > > >> --- > > >> drivers/gpu/drm/i915/i915_syncmap.c | 12 ++++++++---- > > >> 1 file changed, 8 insertions(+), 4 deletions(-) > > > > > > I received a mail telling that this patch doesn't build: > > > > > > =3D=3D Series Details =3D=3D > > > > > > Series: drm/i915: Prefer struct_size over open coded arithmetic > > > URL : https://patchwork.freedesktop.org/series/95408/ > > > State : failure > > > > > > But it builds without error against linux-next (tag next-20211001). = Against > > > which tree and branch do I need to build? > > > > drm-tip [1]. It's a sort of linux-next for graphics. I think there are > > still some branches that don't feed to linux-next. > > Yeah we need to get gt-next in linux-next asap. Joonas promised to send > out his patch to make that happen in dim. > -Daniel Is there a possibility that you give an "Acked-by" tag? And then this patc= h goes to the mainline through the Kees' tree or Gustavo's tree? Or is it better to wait for drm-tip to update? Regards, Len > > > > > BR, > > Jani. > > > > > > [1] https://cgit.freedesktop.org/drm/drm-tip > > > > > > > > > > Regards, > > > Len > > > > -- > > Jani Nikula, Intel Open Source Graphics Center > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch