1
0
Fork 0

lightnvm: fix out-of-bounds write to array devices->info[]

[ Upstream commit a48faebe65 ]

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: cd9e9808d1 ("lightnvm: Support for Open-Channel SSDs")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
5.4-rM2-2.2.x-imx-squashed
Colin Ian King 2020-10-16 15:33:51 +01:00 committed by Greg Kroah-Hartman
parent b0b10fa454
commit d21b8c8fbf
1 changed files with 3 additions and 2 deletions

View File

@ -1316,8 +1316,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;
}
}