From 606babd474290e84e5a86f94480f62f4a5ff92ac Mon Sep 17 00:00:00 2001 From: Mahesh A Saptasagar Date: Tue, 27 Oct 2015 15:13:46 +0530 Subject: wlan: Validate ioctls for valid input length Return failure to applications if ioctl is invoked with arguments of improper length. Change-Id: I01589f37996510ee130485ef43e1f36811692e28 CRs-Fixed: 930542 --- CORE/HDD/src/wlan_hdd_hostapd.c | 60 ++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/CORE/HDD/src/wlan_hdd_hostapd.c b/CORE/HDD/src/wlan_hdd_hostapd.c index bdee270..dffcc05 100644 --- a/CORE/HDD/src/wlan_hdd_hostapd.c +++ b/CORE/HDD/src/wlan_hdd_hostapd.c @@ -3958,9 +3958,8 @@ static int __iw_softap_setwpsie(struct net_device *dev, case DOT11F_EID_WPA: if (wps_genie[1] < 2 + 4) { - vos_mem_free(pSap_WPSIe); - kfree(fwps_genie); - return -EINVAL; + ret = -EINVAL; + goto exit; } else if (memcmp(&wps_genie[2], "\x00\x50\xf2\x04", 4) == 0) { @@ -4018,6 +4017,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > sizeof(pSap_WPSIe->sapwpsie.sapWPSBeaconIE.UUID_E)) + { + ret = -EINVAL; + goto exit; + } vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSBeaconIE.UUID_E, pos, length); pSap_WPSIe->sapwpsie.sapWPSBeaconIE.FieldPresent |= WPS_BEACON_UUIDE_PRESENT; pos += length; @@ -4032,9 +4036,8 @@ static int __iw_softap_setwpsie(struct net_device *dev, default: hddLog (LOGW, "UNKNOWN TLV in WPS IE(%x)", (*pos<<8 | *(pos+1))); - vos_mem_free(pSap_WPSIe); - kfree(fwps_genie); - return -EINVAL; + ret = -EINVAL; + goto exit; } } } @@ -4046,9 +4049,8 @@ static int __iw_softap_setwpsie(struct net_device *dev, default: hddLog (LOGE, "%s Set UNKNOWN IE %X",__func__, wps_genie[0]); - vos_mem_free(pSap_WPSIe); - kfree(fwps_genie); - return 0; + ret = -EINVAL; + goto exit; } } else if( wps_genie[0] == eQC_WPS_PROBE_RSP_IE) @@ -4060,9 +4062,8 @@ static int __iw_softap_setwpsie(struct net_device *dev, case DOT11F_EID_WPA: if (wps_genie[1] < 2 + 4) { - vos_mem_free(pSap_WPSIe); - kfree(fwps_genie); - return -EINVAL; + ret = -EINVAL; + goto exit; } else if (memcmp(&wps_genie[2], "\x00\x50\xf2\x04", 4) == 0) { @@ -4126,6 +4127,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > (sizeof(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.UUID_E))) + { + ret = -EINVAL; + goto exit; + } vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.UUID_E, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_UUIDE_PRESENT; pos += length; @@ -4135,6 +4141,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > (sizeof(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Manufacture.name))) + { + ret = -EINVAL; + goto exit; + } pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Manufacture.num_name = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.Manufacture.name, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_MANUFACTURE_PRESENT; @@ -4145,6 +4156,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > (sizeof(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelName.text))) + { + ret = -EINVAL; + goto exit; + } pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelName.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelName.text, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_MODELNAME_PRESENT; @@ -4154,6 +4170,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > (sizeof(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelNumber.text))) + { + ret = -EINVAL; + goto exit; + } pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelNumber.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.ModelNumber.text, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_MODELNUMBER_PRESENT; @@ -4163,6 +4184,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > (sizeof(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SerialNumber.text))) + { + ret = -EINVAL; + goto exit; + } pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SerialNumber.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.SerialNumber.text, pos, length); pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.FieldPresent |= WPS_PROBRSP_SERIALNUMBER_PRESENT; @@ -4186,6 +4212,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, pos += 2; length = *pos<<8 | *(pos+1); pos += 2; + if (length > (sizeof(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceName.text))) + { + ret = -EINVAL; + goto exit; + } pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceName.num_text = length; vos_mem_copy(pSap_WPSIe->sapwpsie.sapWPSProbeRspIE.DeviceName.text, pos, length); pos += length; @@ -4217,6 +4248,8 @@ static int __iw_softap_setwpsie(struct net_device *dev, } // switch } halStatus = WLANSAP_Set_WpsIe(pVosContext, pSap_WPSIe); + if (halStatus != eHAL_STATUS_SUCCESS) + ret = -EINVAL; pHostapdState = WLAN_HDD_GET_HOSTAP_STATE_PTR(pHostapdAdapter); if( pHostapdState->bCommit && WPSIeType == eQC_WPS_PROBE_RSP_IE) { @@ -4225,10 +4258,11 @@ static int __iw_softap_setwpsie(struct net_device *dev, WLANSAP_Update_WpsIe ( pVosContext ); } +exit: vos_mem_free(pSap_WPSIe); kfree(fwps_genie); EXIT(); - return halStatus; + return ret; } static int iw_softap_setwpsie(struct net_device *dev, -- cgit v1.1