Message ID | 20240828030321.20688-9-laoar.shao@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Improve the copy of task comm | expand |
Hi, On Wed, Aug 28, 2024 at 11:03:21AM GMT, Yafang Shao wrote: > To prevent erros from occurring when the src string is longer than the > dst string in strcpy(), we should use strscpy() instead. This > approach also facilitates future extensions to the task comm. > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> > Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> > Cc: Maxime Ripard <mripard@kernel.org> > Cc: Thomas Zimmermann <tzimmermann@suse.de> > Cc: David Airlie <airlied@gmail.com> > --- > drivers/gpu/drm/drm_framebuffer.c | 2 +- > drivers/gpu/drm/i915/i915_gpu_error.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c > index 888aadb6a4ac..2d6993539474 100644 > --- a/drivers/gpu/drm/drm_framebuffer.c > +++ b/drivers/gpu/drm/drm_framebuffer.c > @@ -868,7 +868,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, > INIT_LIST_HEAD(&fb->filp_head); > > fb->funcs = funcs; > - strcpy(fb->comm, current->comm); > + strscpy(fb->comm, current->comm); > > ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB, > false, drm_framebuffer_free); > diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c There are other strcpy() in this file but it seems all control paths to the copies themselves stem from string literals, so it is probably fine not to also change those ones. But, if a v9 is required and you're feeling up to it, we should probably replace them too, as per [1]. > index 96c6cafd5b9e..afa9dae39378 100644 > --- a/drivers/gpu/drm/i915/i915_gpu_error.c > +++ b/drivers/gpu/drm/i915/i915_gpu_error.c > @@ -1412,7 +1412,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); > e->pid = task->pid; > } > rcu_read_unlock(); > -- > 2.43.5 > > Reviewed-by: Justin Stitt <justinstitt@google.com> [1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy Thanks Justin
On Fri, Sep 13, 2024 at 5:28 AM Justin Stitt <justinstitt@google.com> wrote: > > Hi, > > On Wed, Aug 28, 2024 at 11:03:21AM GMT, Yafang Shao wrote: > > To prevent erros from occurring when the src string is longer than the > > dst string in strcpy(), we should use strscpy() instead. This > > approach also facilitates future extensions to the task comm. > > > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> > > Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> > > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> > > Cc: Maxime Ripard <mripard@kernel.org> > > Cc: Thomas Zimmermann <tzimmermann@suse.de> > > Cc: David Airlie <airlied@gmail.com> > > --- > > drivers/gpu/drm/drm_framebuffer.c | 2 +- > > drivers/gpu/drm/i915/i915_gpu_error.c | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c > > index 888aadb6a4ac..2d6993539474 100644 > > --- a/drivers/gpu/drm/drm_framebuffer.c > > +++ b/drivers/gpu/drm/drm_framebuffer.c > > @@ -868,7 +868,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, > > INIT_LIST_HEAD(&fb->filp_head); > > > > fb->funcs = funcs; > > - strcpy(fb->comm, current->comm); > > + strscpy(fb->comm, current->comm); > > > > ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB, > > false, drm_framebuffer_free); > > diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c > > There are other strcpy() in this file but it seems all control paths to > the copies themselves stem from string literals, so it is probably fine > not to also change those ones. But, if a v9 is required and you're > feeling up to it, we should probably replace them too, as per [1]. will change them in the next version. Thanks for your suggestion. > > > > index 96c6cafd5b9e..afa9dae39378 100644 > > --- a/drivers/gpu/drm/i915/i915_gpu_error.c > > +++ b/drivers/gpu/drm/i915/i915_gpu_error.c > > @@ -1412,7 +1412,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); > > e->pid = task->pid; > > } > > rcu_read_unlock(); > > -- > > 2.43.5 > > > > > > > Reviewed-by: Justin Stitt <justinstitt@google.com> > > [1]: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy > > Thanks > Justin
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 888aadb6a4ac..2d6993539474 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -868,7 +868,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, INIT_LIST_HEAD(&fb->filp_head); fb->funcs = funcs; - strcpy(fb->comm, current->comm); + strscpy(fb->comm, current->comm); ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB, false, drm_framebuffer_free); diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c index 96c6cafd5b9e..afa9dae39378 100644 --- a/drivers/gpu/drm/i915/i915_gpu_error.c +++ b/drivers/gpu/drm/i915/i915_gpu_error.c @@ -1412,7 +1412,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); e->pid = task->pid; } rcu_read_unlock();