wl12xx: Fix problems in nvs file parsing
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
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
@@ -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
PATCH 2/2 wl12xx: Check buffer bound when processing nvs data
In reply to Pontus FuchsAn 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
@@ -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
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 datadrivers/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.