Skip to content

Commit

Permalink
lightnvm: fix out-of-bounds write to array devices->info[]
Browse files Browse the repository at this point in the history
[ Upstream commit a48faeb ]

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: cd9e980 ("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>
  • Loading branch information
Colin Ian King authored and gregkh committed Oct 29, 2020
1 parent 3c967d1 commit 0db50a0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/lightnvm/core.c
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 0db50a0

Please sign in to comment.