Commit a48faebe authored by Colin Ian King's avatar Colin Ian King Committed by Jens Axboe

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: cd9e9808 ("lightnvm: Support for Open-Channel SSDs")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 87aac3a8
...@@ -1311,8 +1311,9 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg) ...@@ -1311,8 +1311,9 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
strlcpy(info->bmname, "gennvm", sizeof(info->bmname)); strlcpy(info->bmname, "gennvm", sizeof(info->bmname));
i++; i++;
if (i > 31) { if (i >= ARRAY_SIZE(devices->info)) {
pr_err("max 31 devices can be reported.\n"); pr_err("max %zd devices can be reported.\n",
ARRAY_SIZE(devices->info));
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment