Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5477112pxb; Wed, 26 Jan 2022 12:58:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxfbLoh3y5vRIf79hRIav4BY5ZBXSG7Hdy0vqmDFB+zaHgja9p80kNSeTL+LKAWd/oz+VN/ X-Received: by 2002:a62:e304:: with SMTP id g4mr574059pfh.61.1643230710051; Wed, 26 Jan 2022 12:58:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643230710; cv=none; d=google.com; s=arc-20160816; b=LZiA1KdNlKL/npf69K51h/LYPgqIPnArQs+vhUYnoWnPpk3kZLC8KKyPmSpuaGc/un Db3MgkaP9OgVvgljWY4vVcjTZTdUpl0T/jo5zTYUJErfpuThXDeer3yJoRFovlmxAWnb SZX/zaNSOsNxTeXoSBU2cI6trmKkhCvGUWRgLNmsnGwpIfS9mU95MvXUo3Ycul3cAxiY kGvLTRA+MoufPIgcTPJxvkg8RJT3Atul9eo9YHKJfUeeVLS3ikxvGcX5K8uqMuWQr5dL UHPsWVAUfP0zz++xxOMwd1bwa3PsTl7WjYXtPPcbBWxu/vPnJudFCci/RjezBe8FOONy 2YuQ== 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 :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=8C9Zn+BmCoso/ZkC0MGcNy2k6ho4NFMSSVTPKWW4qnk=; b=GmMtb6lSPtGFp1xhwSsMapQaHu4KUKKuR4vbu0lC7UhB4ZmY9dJfF4KjW2Gj+zOtil QCKkEZ9IGYMLJl1E0Dvy2xUyxtFTZItIdaeloq2V7x9wni5JQ6PgAuEoIYJ8nncAT3Wm 6refH+pKZvR6UWBgHxesYfLxb5sybP8NhoulsLosVJtVe3zAmGj+ajfr/tW0hBeLwt9J cU3Hc3kX8lbKgzQk0Hr9e0ggAIh1HmW2E7vAPB9/4HBqGvhOpVm++DLx8qEEn6yFUxkz 7m6Safq+J0wIggyDanz3/ZXrjuWT5dig+3i4eO0x0hXPPN7kOrEGaDmMFpthOqzKMsaI O8Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ODNemuJ2; 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=pass (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 s14si231213plg.205.2022.01.26.12.58.17; Wed, 26 Jan 2022 12:58:30 -0800 (PST) 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=@intel.com header.s=Intel header.b=ODNemuJ2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239633AbiAZKIl (ORCPT + 99 others); Wed, 26 Jan 2022 05:08:41 -0500 Received: from mga12.intel.com ([192.55.52.136]:11913 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232002AbiAZKIk (ORCPT ); Wed, 26 Jan 2022 05:08:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643191720; x=1674727720; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=9DdtvZ7yMVpfqtYl7aRfb2H95FdCk00oZ2LfZcvlals=; b=ODNemuJ2HaVLkN5DsuGz2TDK9EM7wr4IoT87cDhvwu/KL13tOvYB/qwS qE2wembYwZt+eRnEV5yjNe0Fj/q+EN5BsVsnkihA7Zc7Mb54EbgnUWcTg GejotZmNN5bUrvIsLQkA3wlFT2XJzjvWTpAjCe4m5VPSh6S0f7YQ51vUe LOrHe2lu71Vf4Vx+tc6YaHuiB5hRbblpDQbeCZldzEb1GB9bsrx1Z0amu AavbSXttPU/Jx4FCDQ+wkvGyctQSzM7KkWn2a0tal9EjgTojQzMQxwIAo PSQ/wAyrk5GbMAgMpsWtbQgruQYnVcypQVdoojPYfaRUdcEJft/VLFvj7 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10238"; a="226496171" X-IronPort-AV: E=Sophos;i="5.88,317,1635231600"; d="scan'208";a="226496171" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2022 02:08:39 -0800 X-IronPort-AV: E=Sophos;i="5.88,317,1635231600"; d="scan'208";a="581061617" Received: from mburchar-mobl.amr.corp.intel.com (HELO [10.212.54.252]) ([10.212.54.252]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2022 02:08:37 -0800 Message-ID: Date: Wed, 26 Jan 2022 10:08:36 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.1 Subject: Re: [PATCH][next] drm/i915/guc: Use struct_size() helper in kmalloc() Content-Language: en-US To: "Gustavo A. R. Silva" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20220125180726.GA68646@embeddedor> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc In-Reply-To: <20220125180726.GA68646@embeddedor> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/01/2022 18:07, Gustavo A. R. Silva wrote: > 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/gpu/drm/i915/gt/uc/intel_guc_ct.c:792:23: warning: using sizeof on a flexible structure > > Link: https://github.com/KSPP/linux/issues/174 > Signed-off-by: Gustavo A. R. Silva > --- > drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c > index aa6dd6415202..e352a1aad228 100644 > --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c > +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c > @@ -789,7 +789,7 @@ static struct ct_incoming_msg *ct_alloc_msg(u32 num_dwords) > { > struct ct_incoming_msg *msg; > > - msg = kmalloc(sizeof(*msg) + sizeof(u32) * num_dwords, GFP_ATOMIC); > + msg = kmalloc(struct_size(msg, msg, num_dwords), GFP_ATOMIC); > if (msg) > msg->size = num_dwords; > return msg; > Reviewed-by: Tvrtko Ursulin Thanks for the patch, will merge shortly. Regards, Tvrtko