Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2257909pxb; Fri, 17 Sep 2021 06:02:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxagLZdC34/G4TwgvUcQAkN3xLb6BcNOqyRrbX+mfEqBGvRuqVDD8hVGuUglgICuakutHR3 X-Received: by 2002:a5d:8d06:: with SMTP id p6mr8481727ioj.7.1631883768500; Fri, 17 Sep 2021 06:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631883768; cv=none; d=google.com; s=arc-20160816; b=uw7E8H3ak3cmKc4YHTM1N0ZSdWXipNIl3PeToLeV9CveNAO57m6JY5tepla8ecfrnY wLPj87nnA1v+ouC/zs1NC1m6FHHvq8Qj1NrLqr//puIIEjE0HxEPCxqEHuD6Sf8RkX+L oR0d5oAlCrpHnxo34f2q0pXupppMbnlxpoYJ3KZg6Xu0tuJdfUhoZOBx2buLoxXpXVLQ UwJOgKSkeng9H0VOiT6d/8ZtcQi0wLsR0YaZeb5Li3AovVAyZ9PcCmyrLV345cpPt7+b wuOEy6gEdfiSpQ9g1G5ZNvV4OQYdKq2lf6ZV0g4beSpqNFZlGACjN64Xax6iJ2UBhtEB cY/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject; bh=UiQ3xOlKfZ3gp9cBa/Ww9F3kO6+tWlpmVW/e4mFBIfw=; b=xmzarr0N6oLO3MLMOBzMPku/9U7qaK4JGFahPEWGuXhYVmFhi8j1zbo36xev0Ui4dW f2+ASluahdUXlknKSxeJuUyYugy04Ycp3AEHu7qRZ3FF9Y7pH96WinXveS796NDX3Niq /iU6g9DhDH7OPi8IW/VUClCBV87cTvfS66v7nHJwmFd3WJzB/ef2Om7Nj/km+b22Nk1K hoKz6d6rkukESlcdI2y/vEVAikqKlT4iDIYut9lKN9/1+yf1vT4kGVrP0h67L3yUSy3X eb++My8QCqobDLRaLzjUMQOwKhSJrw/dbDItJzKSyznYuJUChka+J9+arbhk6GnSz9lq cQoA== 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 n2si6941233jaj.35.2021.09.17.06.02.18; Fri, 17 Sep 2021 06:02:48 -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 S241255AbhIQHit (ORCPT + 99 others); Fri, 17 Sep 2021 03:38:49 -0400 Received: from mga14.intel.com ([192.55.52.115]:63016 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241229AbhIQHir (ORCPT ); Fri, 17 Sep 2021 03:38:47 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10109"; a="222402244" X-IronPort-AV: E=Sophos;i="5.85,300,1624345200"; d="scan'208";a="222402244" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2021 00:37:24 -0700 X-IronPort-AV: E=Sophos;i="5.85,300,1624345200"; d="scan'208";a="554499884" Received: from shettiar-mobl2.ger.corp.intel.com (HELO [10.213.243.199]) ([10.213.243.199]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Sep 2021 00:37:22 -0700 Subject: Re: [Intel-gfx] [PATCH v2] drm/i915: use strscpy() to avoid buffer overrun To: Tim Gardner , intel-gfx@lists.freedesktop.org Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20210916122649.12691-1-tim.gardner@canonical.com> From: Tvrtko Ursulin Organization: Intel Corporation UK Plc Message-ID: <77c6c991-b7b4-0362-63ca-17a801187f7a@linux.intel.com> Date: Fri, 17 Sep 2021 08:37:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210916122649.12691-1-tim.gardner@canonical.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/09/2021 13:26, 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 strscpy() which guarantees NULL termination. > > Also correct 2 other strcpy() call sites with the same potential for Coverity > warnings or overruns. > > v2 - Change $SUBJECT from "drm/i915: zero fill vma name buffer" > Use strscpy() instead of strncpy(). Its a much simpler change. > > Cc: Jani Nikula > Cc: Joonas Lahtinen > Cc: Rodrigo Vivi > Cc: David Airlie > Cc: Daniel Vetter > Cc: intel-gfx@lists.freedesktop.org > Cc: dri-devel@lists.freedesktop.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Tim Gardner > --- > drivers/gpu/drm/i915/i915_gpu_error.c | 6 +++--- > 1 file changed, 3 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..7f246f51959d 100644 > --- a/drivers/gpu/drm/i915/i915_gpu_error.c > +++ b/drivers/gpu/drm/i915/i915_gpu_error.c > @@ -1015,7 +1015,7 @@ i915_vma_coredump_create(const struct intel_gt *gt, > return NULL; > } > > - strcpy(dst->name, name); > + strscpy(dst->name, name, sizeof(dst->name)); > dst->next = NULL; > > dst->gtt_offset = vma->node.start; > @@ -1279,7 +1279,7 @@ static bool record_context(struct i915_gem_context_coredump *e, > rcu_read_lock(); > task = pid_task(ctx->pid, PIDTYPE_PID); > if (task) { > - strcpy(e->comm, task->comm); > + strscpy(e->comm, task->comm, sizeof(e->comm)); > e->pid = task->pid; > } > rcu_read_unlock(); > @@ -1323,7 +1323,7 @@ capture_vma(struct intel_engine_capture_vma *next, > return next; > } > > - strcpy(c->name, name); > + strscpy(c->name, name, sizeof(c->name)); > c->vma = vma; /* reference held while active */ > > c->next = next; > Reviewed-by: Tvrtko Ursulin Regards, Tvrtko