Skip to contentSkip to conversation

wl12xx: Fix problems in nvs file parsing

PATCH In review Pontus Fuchs 2 participants 4 messages Oct 18, 2011 – Dec 1, 2011 Networking drivers (wireless)

lore
Share & tools
lore
#0 lore raw

cover wl12xx: Fix problems in nvs file parsing

A crafted nvs file could trick the driver into reading and writing beyond end of buffers.

Pontus Fuchs (2):
wl12xx: Validate FEM index from ini file and FW
wl12xx: Check buffer bound when processing nvs data

 drivers/net/wireless/wl12xx/boot.c |   14 ++++++++++++++
 drivers/net/wireless/wl12xx/cmd.c  |   22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/2 wl12xx: Validate FEM index from ini file and FW

Check for out of bound FEM index to prevent reading beyond ini memory end.

---
 drivers/net/wireless/wl12xx/cmd.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
drivers/net/wireless/wl12xx/cmd.c +22 -0
index 2413c43..38a21a3 100644
@@ -121,6 +121,11 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
 	if (!wl->nvs)
 		return -ENODEV;
 
+	if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+		wl1271_warning("FEM index from INI out of bounds");
+		return -EINVAL;
+	}
+
 	gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
 	if (!gen_parms)
 		return -ENOMEM;
@@ -144,6 +149,12 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
 	gp->tx_bip_fem_manufacturer =
 		gen_parms->general_params.tx_bip_fem_manufacturer;
 
+	if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+		wl1271_warning("FEM index from FW out of bounds");
+		ret = -EINVAL;
+		goto out;
+	}
+
 	wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
 		     answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
 
@@ -163,6 +174,11 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
 	if (!wl->nvs)
 		return -ENODEV;
 
+	if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+		wl1271_warning("FEM index from ini out of bounds");
+		return -EINVAL;
+	}
+
 	gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
 	if (!gen_parms)
 		return -ENOMEM;
@@ -187,6 +203,12 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
 	gp->tx_bip_fem_manufacturer =
 		gen_parms->general_params.tx_bip_fem_manufacturer;
 
+	if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+		wl1271_warning("FEM index from FW out of bounds");
+		ret = -EINVAL;
+		goto out;
+	}
+
 	wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
 		     answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
 
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/2 wl12xx: Check buffer bound when processing nvs data

In reply to Pontus Fuchs

An nvs with malformed contents could cause the processing of the calibration data to read beyond the end of the buffer. Prevent this from happening by adding bound checking.

---
 drivers/net/wireless/wl12xx/boot.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
drivers/net/wireless/wl12xx/boot.c +14 -0
index 4ce634b..c9c8b69 100644
@@ -347,6 +347,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
 		nvs_ptr += 3;
 
 		for (i = 0; i < burst_len; i++) {
+			if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
+				goto out_badnvs;
+
 			val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
 			       | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
 
@@ -358,6 +361,9 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
 			nvs_ptr += 4;
 			dest_addr += 4;
 		}
+
+		if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
+			goto out_badnvs;
 	}
 
 	/*
@@ -369,6 +375,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
 	 */
 	nvs_ptr = (u8 *)wl->nvs +
 			ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
+
+	if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
+		goto out_badnvs;
+
 	nvs_len -= nvs_ptr - (u8 *)wl->nvs;
 
 	/* Now we must set the partition correctly */
@@ -384,6 +394,10 @@ static int wl1271_boot_upload_nvs(struct wl1271 *wl)
 
 	kfree(nvs_aligned);
 	return 0;
+
+out_badnvs:
+	wl1271_error("nvs data is malformed");
+	return -EILSEQ;
 }
 
 static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
Signature · 1 line
1.7.4.1
#3 lore raw
In reply to Pontus Fuchs
Quoted 10 lines · Pontus Fuchs

A crafted nvs file could trick the driver into reading and writing beyond end of buffers.

Pontus Fuchs (2):
wl12xx: Validate FEM index from ini file and FW
wl12xx: Check buffer bound when processing nvs data

 drivers/net/wireless/wl12xx/boot.c |   14 ++++++++++++++
 drivers/net/wireless/wl12xx/cmd.c  |   22 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

Applied both, tack!

Signature · 2 lines
Cheers,
Luca.