summaryrefslogtreecommitdiffstats
path: root/drivers/lightnvm
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2020-10-16 16:33:51 +0200
committerJens Axboe <axboe@kernel.dk>2020-10-16 17:28:45 +0200
commita48faebe65b0db55a73b9220c3d919eee849bb79 (patch)
tree0cfe505940239ea23f57eca478376dd0ec3b9f72 /drivers/lightnvm
parentnbd: make the config put is called before the notifying the waiter (diff)
downloadlinux-a48faebe65b0db55a73b9220c3d919eee849bb79.tar.xz
linux-a48faebe65b0db55a73b9220c3d919eee849bb79.zip
lightnvm: fix out-of-bounds write to array devices->info[]
There is an off-by-one array check that can lead to a out-of-bounds write to devices->info[i]. Fix this by checking by using >= rather than > for the size check. Also replace hard-coded array size limit with ARRAY_SIZE on the array. Addresses-Coverity: ("Out-of-bounds write") Fixes: cd9e9808d18f ("lightnvm: Support for Open-Channel SSDs") Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/lightnvm')
-rw-r--r--drivers/lightnvm/core.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index fe78bf0fdce5..c1bcac71008c 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -1311,8 +1311,9 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
strlcpy(info->bmname, "gennvm", sizeof(info->bmname));
i++;
- if (i > 31) {
- pr_err("max 31 devices can be reported.\n");
+ if (i >= ARRAY_SIZE(devices->info)) {
+ pr_err("max %zd devices can be reported.\n",
+ ARRAY_SIZE(devices->info));
break;
}
}