Skip to content

Commit 9363558

Browse files
Colin Ian Kingsmb49
authored andcommitted
lightnvm: fix out-of-bounds write to array devices->info[]
BugLink: https://bugs.launchpad.net/bugs/1902137 [ 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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Ian May <[email protected]>
1 parent 26cf856 commit 9363558

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/lightnvm/core.c

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

1318-
if (i > 31) {
1319-
pr_err("max 31 devices can be reported.\n");
1318+
if (i >= ARRAY_SIZE(devices->info)) {
1319+
pr_err("max %zd devices can be reported.\n",
1320+
ARRAY_SIZE(devices->info));
13201321
break;
13211322
}
13221323
}

0 commit comments

Comments
 (0)