mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Matthew R. Ochs" <mrochs@linux.vnet.ibm.com>
To: Insu Yun <wuninsu@gmail.com>
Cc: brking@us.ibm.com, JBottomley@odin.com,
	martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org, taesoo@gatech.edu,
	yeongjin.jang@gatech.edu, insu@gatech.edu, changwoo@gatech.edu
Subject: Re: [PATCH v2] ipr: fix out-of-bounds null overwrite
Date: Wed, 6 Jan 2016 11:26:06 -0600	[thread overview]
Message-ID: <85F2590B-6F13-4713-9D8A-440A332A993B@linux.vnet.ibm.com> (raw)
In-Reply-To: <1452088409-78304-1-git-send-email-wuninsu@gmail.com>

On Jan 6, 2016, at 7:53 AM, Insu Yun <wuninsu@gmail.com> wrote:
> 
> Return value of snprintf is not bound by size value, 2nd argument.
> (https://www.kernel.org/doc/htmldocs/kernel-api/API-snprintf.html).
> Return value is number of printed chars, can be larger than 2nd argument.
> Therefore, it can write null byte out of bounds ofbuffer.
> Since snprintf puts null, it does not need to put additional null byte.
> 
> Signed-off-by: Insu Yun <wuninsu@gmail.com>
> ---
> drivers/scsi/ipr.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
> index 536cd5a..caf63f9 100644
> --- a/drivers/scsi/ipr.c
> +++ b/drivers/scsi/ipr.c
> @@ -4003,13 +4003,12 @@ static ssize_t ipr_store_update_fw(struct device *dev,
> 	struct ipr_sglist *sglist;
> 	char fname[100];
> 	char *src;
> -	int len, result, dnld_size;
> +	int result, dnld_size;
> 
> 	if (!capable(CAP_SYS_ADMIN))
> 		return -EACCES;
> 
> -	len = snprintf(fname, 99, "%s", buf);
> -	fname[len-1] = '\0';
> +	snprintf(fname, 99, "%s", buf);

Changing the 99 to sizeof(fname) as part of this change would also
make for cleaner code in my opinion. Will leave it up to you if you'd
like to do a v3.

Reviewed-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com> 

      reply	other threads:[~2016-01-06 17:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-06 13:53 Insu Yun
2016-01-06 17:26 ` Matthew R. Ochs [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=85F2590B-6F13-4713-9D8A-440A332A993B@linux.vnet.ibm.com \
    --to=mrochs@linux.vnet.ibm.com \
    --cc=JBottomley@odin.com \
    --cc=brking@us.ibm.com \
    --cc=changwoo@gatech.edu \
    --cc=insu@gatech.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=taesoo@gatech.edu \
    --cc=wuninsu@gmail.com \
    --cc=yeongjin.jang@gatech.edu \
    /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®