Skip to content

Commit a48faeb

Browse files
Colin Ian Kingaxboe
authored andcommitted
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: 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>
1 parent 87aac3a commit a48faeb

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/lightnvm/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,8 +1311,9 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
13111311
strlcpy(info->bmname, "gennvm", sizeof(info->bmname));
13121312
i++;
13131313

1314-
if (i > 31) {
1315-
pr_err("max 31 devices can be reported.\n");
1314+
if (i >= ARRAY_SIZE(devices->info)) {
1315+
pr_err("max %zd devices can be reported.\n",
1316+
ARRAY_SIZE(devices->info));
13161317
break;
13171318
}
13181319
}

0 commit comments

Comments
 (0)