Blob Blame History Raw
From ce042c183bcb94eb2919e8036473a1fc203420f9 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Wed, 20 Jun 2018 13:41:51 +0300
Subject: [PATCH] block: sed-opal: Fix a couple off by one bugs
Git-commit: ce042c183bcb94eb2919e8036473a1fc203420f9
Patch-mainline: v4.18-rc2
References: bsc#1099918

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")
Reviewed-by: Scott Bauer <scott.bauer@intel.com>
Tested-by: Scott Bauer <scott.bauer@intel.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Coly Li <colyli@suse.de>

---
 block/sed-opal.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/block/sed-opal.c
+++ b/block/sed-opal.c
@@ -887,7 +887,7 @@ static u64 response_get_u64(const struct
 		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;