mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Gardner <tim.gardner@canonical.com>
To: Jani Nikula <jani.nikula@linux.intel.com>,
	Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
	linux-kernel@vger.kernel.org
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [Intel-gfx] [PATCH] drm/i915: zero fill vma name buffer
Date: Thu, 16 Sep 2021 05:37:47 -0600	[thread overview]
Message-ID: <dc88e195-949c-bb46-b7d3-18e90df9b064@canonical.com> (raw)
In-Reply-To: <87ee9ox0kv.fsf@intel.com>



On 9/16/21 4:43 AM, Jani Nikula wrote:
> On Thu, 16 Sep 2021, Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> wrote:
>> On 15/09/2021 20:23, Tim Gardner wrote:
>>> In capture_vma() Coverity complains of a possible buffer overrun. Even
>>> though this is a static function where all call sites can be checked,
>>> limiting the copy length could save some future grief.
>>>
>>> CID 93300 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW)
>>> 4. fixed_size_dest: You might overrun the 16-character fixed-size string c->name
>>>      by copying name without checking the length.
>>> 5. parameter_as_source: Note: This defect has an elevated risk because the
>>>      source argument is a parameter of the current function.
>>> 1326        strcpy(c->name, name);
>>>
>>> Fix any possible overflows by using strncpy(). Zero fill the name buffer to
>>> guarantee ASCII string NULL termination.
>>>
>>> Cc: Jani Nikula <jani.nikula@linux.intel.com>
>>> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
>>> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
>>> Cc: David Airlie <airlied@linux.ie>
>>> Cc: Daniel Vetter <daniel@ffwll.ch>
>>> Cc: intel-gfx@lists.freedesktop.org
>>> Cc: dri-devel@lists.freedesktop.org
>>> Cc: linux-kernel@vger.kernel.org
>>> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
>>> ---
>>>    drivers/gpu/drm/i915/i915_gpu_error.c | 7 ++++---
>>>    1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c
>>> index 9cf6ac575de1..154df174e2d7 100644
>>> --- a/drivers/gpu/drm/i915/i915_gpu_error.c
>>> +++ b/drivers/gpu/drm/i915/i915_gpu_error.c
>>> @@ -1297,10 +1297,11 @@ static bool record_context(struct i915_gem_context_coredump *e,
>>>    	return simulated;
>>>    }
>>>    
>>> +#define VMA_NAME_LEN 16
>>>    struct intel_engine_capture_vma {
>>>    	struct intel_engine_capture_vma *next;
>>>    	struct i915_vma *vma;
>>> -	char name[16];
>>> +	char name[VMA_NAME_LEN];
>>>    };
>>>    
>>>    static struct intel_engine_capture_vma *
>>> @@ -1314,7 +1315,7 @@ capture_vma(struct intel_engine_capture_vma *next,
>>>    	if (!vma)
>>>    		return next;
>>>    
>>> -	c = kmalloc(sizeof(*c), gfp);
>>> +	c = kzalloc(sizeof(*c), gfp);
>>>    	if (!c)
>>>    		return next;
>>>    
>>> @@ -1323,7 +1324,7 @@ capture_vma(struct intel_engine_capture_vma *next,
>>>    		return next;
>>>    	}
>>>    
>>> -	strcpy(c->name, name);
>>> +	strncpy(c->name, name, VMA_NAME_LEN-1);
>>
>> GCC is supposed to catch any problems here as you say in the commit message.
>>
>> But to fix I suggest a single line change to strlcpy(c->name, name,
>> sizeof(c->name)) which always null terminates as bonus.
> 
> strscpy() is preferred over both strncpy() and strlcpy(). :)
> 
> BR,
> Jani.
> 

Good call. v2 on the way.

rtg

>>
>> Probably same in i915_vma_coredump_create() which with strncpy would
>> have a theoretical chance of attempting to copy over a
>> non-null-terminated string.
>>
>> Regards,
>>
>> Tvrtko
>>
>>>    	c->vma = vma; /* reference held while active */
>>>    
>>>    	c->next = next;
>>>
> 

-- 
-----------
Tim Gardner
Canonical, Inc

  reply	other threads:[~2021-09-16 11:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15 19:23 Tim Gardner
2021-09-16  8:23 ` [Intel-gfx] " Tvrtko Ursulin
2021-09-16 10:43   ` Jani Nikula
2021-09-16 11:37     ` Tim Gardner [this message]
2021-09-16 12:26       ` [PATCH v2] drm/i915: use strscpy() to avoid buffer overrun Tim Gardner
2021-09-17  7:37         ` [Intel-gfx] " Tvrtko Ursulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dc88e195-949c-bb46-b7d3-18e90df9b064@canonical.com \
    --to=tim.gardner@canonical.com \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rodrigo.vivi@intel.com \
    --cc=tvrtko.ursulin@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®