Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3354682pxb; Wed, 13 Oct 2021 04:25:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJCNbUfbOU0FiRrMNMeSDLKaE7rTw7kDWsJ5k0QZaw616SU12cFGQ87WAmFW2dEn6CQ1dT X-Received: by 2002:a17:90a:6b4d:: with SMTP id x13mr12815252pjl.208.1634124339313; Wed, 13 Oct 2021 04:25:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634124339; cv=none; d=google.com; s=arc-20160816; b=zl8IeedjrRD3agEIbmzQc4vOwEiGuMUllO6+aVQ4fWOlsS+o34ZSoVxQ/EA6ncbJJ/ NQSGpskwdC8XmSWcNBRYSvu7pK+vYcEWTParhwqSgFrVUjB2y7jvoAXcGyWYDHTKafku xrUQMUFjcPMKLSptKXg5bueomMMtl0sVoMVI7pgIVWdmngpCE7FdJ7C+w8MHtLUFGGUH /XhGcyK8i43NZslCFFB7d5T44VzjMon/vzKyU0RhkC61tXLm6rHhGIfUSK2gtfMIdWJK 34fN36olD3EuHm7K2jIfkBoUa8D4OVre2epe2OFndFDKkU1FL1xg6V4VRUCutaE/7GMx YFFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from; bh=/RunbFgOPH1aXWvGKrotp6gtEvzd3AlshfymSRO/o8k=; b=CyZP75a7AahR4dcK+3A49zWhJ5Vz6TfOZoPP1nonMidA+5gDBBeyf2t0V2YuRu/Rav OCQ+33ws3kjfRwjruv5TKEndZX7MsvCeVmG4u1JZ9BMBEqW+ISY+Y7KT9SDo1I53jFNg 7gTQEixYWwbYPAlbyXE6wY19BzViGhpnxspBt4ogMG7f0BN6Iy6RxAioRVekqf8u54K0 ySjBpQC1J/Ic7zKJ5F7JwERgObzncfBrVvxxVJvtzXiYMFwOSMU9qthe/ErjuvP11t2i tJWB1g+6RDU5Hqacve1HrR2GtibDyXho/vXgsEhcgRnU8xuvtqZamFZKkZeO580BDsM0 i9wg== ARC-Authentication-Results: i=1; mx.google.com; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d11si6825128pjh.68.2021.10.13.04.25.25; Wed, 13 Oct 2021 04:25:39 -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; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbhJML0R (ORCPT + 99 others); Wed, 13 Oct 2021 07:26:17 -0400 Received: from mga04.intel.com ([192.55.52.120]:46880 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbhJML0R (ORCPT ); Wed, 13 Oct 2021 07:26:17 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10135"; a="226178099" X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="226178099" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 04:24:13 -0700 X-IronPort-AV: E=Sophos;i="5.85,370,1624345200"; d="scan'208";a="491417739" Received: from araghuw-mobl.gar.corp.intel.com (HELO localhost) ([10.251.208.234]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Oct 2021 04:24:08 -0700 From: Jani Nikula To: Len Baker , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter Cc: Len Baker , 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 In-Reply-To: <20211011092304.GA5790@titan> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20211003104258.18550-1-len.baker@gmx.com> <20211011092304.GA5790@titan> Date: Wed, 13 Oct 2021 14:24:05 +0300 Message-ID: <87k0ihxj56.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, 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. >> >> In this case these are not actually dynamic sizes: all the operands >> involved in the calculation are constant values. However it is better 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 flexible >> 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: > > == Series Details == > > 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. BR, Jani. [1] https://cgit.freedesktop.org/drm/drm-tip > > Regards, > Len -- Jani Nikula, Intel Open Source Graphics Center