diff options
| author | Colin Ian King <colin.king@canonical.com> | 2020-10-16 15:33:51 +0100 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-10-29 09:58:00 +0100 |
| commit | d21b8c8fbf89195e7d55e8182daff95e86d1c43c (patch) | |
| tree | 27029948a9c17626c6d2ef08104b4c1e1795c49f /drivers/lightnvm | |
| parent | b0b10fa454eab242b583c2b1b92793fd3875b627 (diff) | |
| download | linux-d21b8c8fbf89195e7d55e8182daff95e86d1c43c.tar.gz linux-d21b8c8fbf89195e7d55e8182daff95e86d1c43c.tar.bz2 linux-d21b8c8fbf89195e7d55e8182daff95e86d1c43c.zip | |
lightnvm: fix out-of-bounds write to array devices->info[]
[ 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>
Diffstat (limited to 'drivers/lightnvm')
| -rw-r--r-- | drivers/lightnvm/core.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 7543e395a2c6..a2ebc75af8c7 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -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; } } |
