Skip to contentSkip to conversation

: mei bus fix type promotion bugs

PATCH New Tomas Winkler 1 participant 3 messages Jul 11, 2018

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 mei: bus: type promotion bug in mei_nfc_if_version()

In reply to Tomas Winkler

From: Dan Carpenter <[email protected]>

We accidentally removed the check for negative returns without considering the issue of type promotion.
The "if_version_length" variable is type size_t so if __mei_cl_recv() returns a negative then "bytes_recv" is type promoted
to a high positive value and treated as success.

Fixes 582ab27a063a ("mei: bus: fix received data size check in NFC fixup")

---
V2: rebase

 drivers/misc/mei/bus-fixup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/bus-fixup.c +1 -1
index e45fe826d87d..65e28be3c8cc 100644
@@ -341,7 +341,7 @@ static int mei_nfc_if_version(struct mei_cl *cl,
 
 	ret = 0;
 	bytes_recv = __mei_cl_recv(cl, (u8 *)reply, if_version_length, 0, 0);
-	if (bytes_recv < if_version_length) {
+	if (bytes_recv < 0 || bytes_recv < if_version_length) {
 		dev_err(bus->dev, "Could not read IF version\n");
 		ret = -EIO;
 		goto err;
Signature · 1 line
2.14.4
#2 lore raw

PATCH 2/2 mei: bus: type promotion bug in mei_fwver()

In reply to Tomas Winkler

if __mei_cl_recv() returns a negative then "bytes_recv" type is promoted to a high positive value in comparison with size_t evaluated by MKHI_FWVER_LEN(1). It results in error condition not to be detected.

Cc Dan Carpenter <[email protected]>
Fixes 9078ad92ef86 ("mei: expose fw version to sysfs")
---
 drivers/misc/mei/bus-fixup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/mei/bus-fixup.c +1 -1
index 65e28be3c8cc..4c232f0eae90 100644
@@ -181,7 +181,7 @@ static int mei_fwver(struct mei_cl_device *cldev)
 	ret = 0;
 	bytes_recv = __mei_cl_recv(cldev->cl, buf, sizeof(buf), 0,
 				   MKHI_RCV_TIMEOUT);
-	if (bytes_recv < MKHI_FWVER_LEN(1)) {
+	if (bytes_recv < 0 || bytes_recv < MKHI_FWVER_LEN(1)) {
 		/*
 		 * Should be at least one version block,
 		 * error out if nothing found
Signature · 1 line
2.14.4
#0 lore raw

cover : mei bus fix type promotion bugs

The first patch is a rebase of Dan's patch over misc-next version of the driver. It should go also to the stable.
Second one fixes a same issue introduced in next cycle:
"mei: expose fw version to sysfs"

Dan Carpenter (1):
mei: bus: type promotion bug in mei_nfc_if_version()

Tomas Winkler (1):
mei: bus: type promotion bug in mei_fwver()

 drivers/misc/mei/bus-fixup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.14.4