]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
lightnvm: fix out-of-bounds write to array devices->info[]
authorColin Ian King <colin.king@canonical.com>
Fri, 16 Oct 2020 14:33:51 +0000 (15:33 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:08:15 +0000 (10:08 +0100)
[ Upstream commit a48faebe65b0db55a73b9220c3d919eee849bb79 ]

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: cd9e9808d18f ("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>
drivers/lightnvm/core.c

index db38a68abb6c0317e4088fe4882bd84f15ffc317..a6f4ca438bca18f30fa85ac6efeea6b1e9e5896c 100644 (file)
@@ -1315,8 +1315,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;
                }
        }