Skip to contentSkip to conversation

lightnvm: fix out-of-bounds write to array devices->info[]

PATCH Applied Colin King 2 participants 2 messages Oct 16, 2020

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 lightnvm: fix out-of-bounds write to array devices->info[]

From: Colin Ian King <[email protected]>

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")
---
 drivers/lightnvm/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/lightnvm/core.c +3 -2
index fe78bf0fdce5..f9f5dd38c697 100644
@@ -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;
 		}
 	}
Signature · 1 line
2.27.0
maintainer Applied
#1 lore raw
Quoted 6 lines · Colin King

From: Colin Ian King <[email protected]>

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.

Applied, thanks.

Signature · 1 line
Jens Axboe