linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: GOTO Masanori <gotom@debian.or.jp>
Cc: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>,
	"James E.J. Bottomley" <JBottomley@parallels.com>,
	linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [patch] [SCSI] nsp32: fix an off by one
Date: Thu, 3 Apr 2014 10:28:53 +0300	[thread overview]
Message-ID: <20140403072853.GC14286@mwanda> (raw)

This off by one bug will cause memory corruption when we use every
sglun.

The problem is that NSP32_SG_TABLE_SIZE is too small.  Here is how
it's caculated in the original code:

	sizeof(nsp32_sgtable) * NSP32_SG_SIZE * MAX_TARGET * MAX_LUN

But the problem is that the NSP32_SG_SIZE should be (NSP32_SG_SIZE + 1)
like this:

	sizeof(nsp32_sgtable) * (NSP32_SG_SIZE + 1) * MAX_TARGET * MAX_LUN

Or another more intuitive way to write it would be:

	sizeof(nsp32_sglun) * MAX_TARGET * MAX_LUN

We use NSP32_SG_TABLE_SIZE to allocate data->sg_list which is an array
of nsp32_sglun structs.  The array has MAX_TARGET * MAX_LUN elements.

MAX_TARGET (8) * MAX_LUN (8) = 64 elements.  The missing "+ 1" means
that we only allocate enough space for 63 elements.  In terms of bytes,
the old code allocated 65536 bytes and now it allocates 66048 bytes.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Static checker stuff.

diff --git a/drivers/scsi/nsp32.h b/drivers/scsi/nsp32.h
index c022182..d94f4cd 100644
--- a/drivers/scsi/nsp32.h
+++ b/drivers/scsi/nsp32.h
@@ -454,7 +454,7 @@ typedef struct _nsp32_sgtable {
 typedef struct _nsp32_sglun {
 	nsp32_sgtable sgt[NSP32_SG_SIZE+1];	/* SG table */
 } __attribute__ ((packed)) nsp32_sglun;
-#define NSP32_SG_TABLE_SIZE (sizeof(nsp32_sgtable) * NSP32_SG_SIZE * MAX_TARGET * MAX_LUN)
+#define NSP32_SG_TABLE_SIZE (sizeof(nsp32_sglun) * MAX_TARGET * MAX_LUN)
 
 /* Auto parameter mode memory map.   */
 /* All values must be little endian. */

                 reply	other threads:[~2014-04-03  7:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20140403072853.GC14286@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=JBottomley@parallels.com \
    --cc=gotom@debian.or.jp \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=yokota@netlab.is.tsukuba.ac.jp \
    /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;
as well as URLs for NNTP newsgroup(s).