From: Dan Carpenter <dan.carpenter@oracle.com>
To: "James E.J. Bottomley" <JBottomley@odin.com>
Cc: linux-scsi@vger.kernel.org,
"程君(成淼)" <chengmiao.cj@alibaba-inc.com>,
throber3 <throber3@gmail.com>,
security@kernel.org
Subject: [patch] ses: tighten range checks in ses_intf_add()
Date: Mon, 19 Oct 2015 16:48:20 +0300 [thread overview]
Message-ID: <20151019134820.GA28752@mwanda> (raw)
In-Reply-To: <----An------QYmAn$10b010ca-f710-44aa-8ea3-3b65a3c21286@alibaba-inc.com>
We test that "type_ptr" is within the buffer but then we read from
"type_ptr[3]" so we could be reading beyond the end of the buffer.
Reported-by: "Berry Cheng 程君(成淼)" <chengmiao.cj@alibaba-inc.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This isn't a complete fix because we still need more range checking in
all the other places which use type_ptr like ses_get_page2_descriptor().
We record len as page1_len but we don't use it anywhere...
I wonder if someone knew the expected format we could make reject too
short lengths earlier.
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index dcb0d76..39f69b0 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -641,7 +641,7 @@ static int ses_intf_add(struct device *cdev,
/* begin at the enclosure descriptor */
type_ptr = buf + 8;
/* skip all the enclosure descriptors */
- for (i = 0; i < num_enclosures && type_ptr < buf + len; i++) {
+ for (i = 0; i < num_enclosures && type_ptr + 4 < buf + len; i++) {
types += type_ptr[2];
type_ptr += type_ptr[3] + 4;
}
@@ -649,7 +649,7 @@ static int ses_intf_add(struct device *cdev,
ses_dev->page1_types = type_ptr;
ses_dev->page1_num_types = types;
- for (i = 0; i < types && type_ptr < buf + len; i++, type_ptr += 4) {
+ for (i = 0; i < types && type_ptr + 2 < buf + len; i++, type_ptr += 4) {
if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE)
components += type_ptr[1];
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next parent reply other threads:[~2015-10-19 13:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <----An------QYmAn$10b010ca-f710-44aa-8ea3-3b65a3c21286@alibaba-inc.com>
2015-10-19 13:48 ` Dan Carpenter [this message]
2015-10-20 6:38 ` [patch] ses: tighten range checks in ses_intf_add() Willy Tarreau
2015-11-05 21:52 ` Dan Carpenter
2015-11-05 22:01 ` James Bottomley
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=20151019134820.GA28752@mwanda \
--to=dan.carpenter@oracle.com \
--cc=JBottomley@odin.com \
--cc=chengmiao.cj@alibaba-inc.com \
--cc=linux-scsi@vger.kernel.org \
--cc=security@kernel.org \
--cc=throber3@gmail.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