mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Paul <sean@poorly.run>
To: Chuhong Yuan <hslester96@gmail.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	Sean Paul <sean@poorly.run>, David Airlie <airlied@linux.ie>,
	Daniel Vetter <daniel@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/modes: Fix unterminated strncpy
Date: Tue, 30 Jul 2019 13:12:27 -0400	[thread overview]
Message-ID: <20190730171227.GS104440@art_vandelay> (raw)
In-Reply-To: <20190730084032.26428-1-hslester96@gmail.com>

On Tue, Jul 30, 2019 at 04:40:32PM +0800, Chuhong Yuan wrote:
> strncpy(dest, src, strlen(src)) leads to unterminated
> dest, which is dangerous.
> Fix it by using strscpy.
> 
> Signed-off-by: Chuhong Yuan <hslester96@gmail.com>
> ---
>  drivers/gpu/drm/drm_modes.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index 80fcd5dc1558..170fc24e0f31 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -1770,7 +1770,7 @@ bool drm_mode_parse_command_line_for_connector(const char *mode_option,
>  	}
>  
>  	if (named_mode) {
> -		strncpy(mode->name, name, mode_end);
> +		strscpy(mode->name, name, mode_end + 1);

Shouldn't you be checking that mode_end + 1 is not > than the size of mode->name
(ie: DRM_DISPLAY_MODE_LEN)? This still seems unsafe.

Sean

>  	} else {
>  		ret = drm_mode_parse_cmdline_res_mode(name, mode_end,
>  						      parse_extras,
> -- 
> 2.20.1
> 

-- 
Sean Paul, Software Engineer, Google / Chromium OS

      reply	other threads:[~2019-07-30 17:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-30  8:40 Chuhong Yuan
2019-07-30 17:12 ` Sean Paul [this message]

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=20190730171227.GS104440@art_vandelay \
    --to=sean@poorly.run \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hslester96@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=maxime.ripard@bootlin.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

Powered by JetHome