From: Dan Carpenter <dan.carpenter@oracle.com>
To: Scott Bauer <scott.bauer@intel.com>
Cc: Jonathan Derrick <jonathan.derrick@intel.com>,
Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH] block: sed-opal: Fix a couple off by one bugs
Date: Wed, 20 Jun 2018 13:41:51 +0300 [thread overview]
Message-ID: <20180620104151.yhvcgbcbkkwj4cuk@kili.mountain> (raw)
resp->num is the number of tokens in resp->tok[]. It gets set in
response_parse(). So if n == resp->num then we're reading beyond the
end of the data.
Fixes: 455a7b238cd6 ("block: Add Sed-opal library")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Static analysis. Not tested. This matches the checking in
response_get_token().
My other concern is that there isn't checking in response_parse() to
ensure that we don't go over MAX_TOKS (64) entries. If the firmware
is buggy we're probably very screwed already, so it doesn't necessarily
make a lot of difference at runtime but it might make static analysis
easier if we knew the value of resp->num was in the 1-64 range.
diff --git a/block/sed-opal.c b/block/sed-opal.c
index 945f4b8610e0..e0de4dd448b3 100644
--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -877,7 +877,7 @@ static size_t response_get_string(const struct parsed_resp *resp, int n,
return 0;
}
- if (n > resp->num) {
+ if (n >= resp->num) {
pr_debug("Response has %d tokens. Can't access %d\n",
resp->num, n);
return 0;
@@ -916,7 +916,7 @@ static u64 response_get_u64(const struct parsed_resp *resp, int n)
return 0;
}
- if (n > resp->num) {
+ if (n >= resp->num) {
pr_debug("Response has %d tokens. Can't access %d\n",
resp->num, n);
return 0;
next reply other threads:[~2018-06-20 10:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-20 10:41 Dan Carpenter [this message]
2018-06-20 17:28 ` [PATCH] block: sed-opal: Fix a couple off by one bugs Scott Bauer
2018-06-20 18:04 ` Jens Axboe
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=20180620104151.yhvcgbcbkkwj4cuk@kili.mountain \
--to=dan.carpenter@oracle.com \
--cc=axboe@kernel.dk \
--cc=jonathan.derrick@intel.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=scott.bauer@intel.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