* [PATCH] staging: rtl8723au: fix potential leak in update_bcn_wps_ie()
@ 2014-05-01 11:57 Christian Engelmayer
2014-05-01 12:22 ` Mateusz Guzik
0 siblings, 1 reply; 4+ messages in thread
From: Christian Engelmayer @ 2014-05-01 11:57 UTC (permalink / raw)
To: devel; +Cc: Larry.Finger, Jes.Sorensen, gregkh, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]
Fix a potential leak in the error path of function update_bcn_wps_ie().
Make sure that allocated memory for 'pbackup_remainder_ie' is freed
upon return. Detected by Coverity - CID 1077718.
Signed-off-by: Christian Engelmayer <cengelma@gmx.at>
---
Compile tested and applies against branch staging-next of tree
git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
---
drivers/staging/rtl8723au/core/rtw_ap.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/rtl8723au/core/rtw_ap.c b/drivers/staging/rtl8723au/core/rtw_ap.c
index 9b31412..f2c78a7 100644
--- a/drivers/staging/rtl8723au/core/rtw_ap.c
+++ b/drivers/staging/rtl8723au/core/rtw_ap.c
@@ -1276,7 +1276,7 @@ static void update_bcn_wps_ie(struct rtw_adapter *padapter)
pwps_ie_src = pmlmepriv->wps_beacon_ie;
if (pwps_ie_src == NULL)
- return;
+ goto exit;
wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
if ((wps_offset+wps_ielen+2+remainder_ielen)<= MAX_IE_SZ)
@@ -1291,8 +1291,8 @@ static void update_bcn_wps_ie(struct rtw_adapter *padapter)
pnetwork->IELength = wps_offset + (wps_ielen+2) + remainder_ielen;
}
- if (pbackup_remainder_ie)
- kfree(pbackup_remainder_ie);
+exit:
+ kfree(pbackup_remainder_ie);
}
static void update_bcn_p2p_ie(struct rtw_adapter *padapter)
--
1.9.1
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8723au: fix potential leak in update_bcn_wps_ie()
2014-05-01 11:57 [PATCH] staging: rtl8723au: fix potential leak in update_bcn_wps_ie() Christian Engelmayer
@ 2014-05-01 12:22 ` Mateusz Guzik
2014-05-01 20:16 ` Christian Engelmayer
0 siblings, 1 reply; 4+ messages in thread
From: Mateusz Guzik @ 2014-05-01 12:22 UTC (permalink / raw)
To: Christian Engelmayer
Cc: devel, Larry.Finger, Jes.Sorensen, gregkh, linux-kernel
On Thu, May 01, 2014 at 01:57:27PM +0200, Christian Engelmayer wrote:
> Fix a potential leak in the error path of function update_bcn_wps_ie().
> Make sure that allocated memory for 'pbackup_remainder_ie' is freed
> upon return. Detected by Coverity - CID 1077718.
>
if (remainder_ielen > 0) {
pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
if (pbackup_remainder_ie)
memcpy(pbackup_remainder_ie, premainder_ie,
remainder_ielen);
}
pwps_ie_src = pmlmepriv->wps_beacon_ie;
if (pwps_ie_src == NULL)
return;
Maybe just check pwps_ie_src earlier?
--
Mateusz Guzik
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8723au: fix potential leak in update_bcn_wps_ie()
2014-05-01 12:22 ` Mateusz Guzik
@ 2014-05-01 20:16 ` Christian Engelmayer
2014-05-01 21:46 ` Jes Sorensen
0 siblings, 1 reply; 4+ messages in thread
From: Christian Engelmayer @ 2014-05-01 20:16 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: devel, Larry.Finger, Jes.Sorensen, gregkh, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1852 bytes --]
On Thu, 1 May 2014 14:22:17 +0200, Mateusz Guzik <mguzik@redhat.com> wrote:
> On Thu, May 01, 2014 at 01:57:27PM +0200, Christian Engelmayer wrote:
> > Fix a potential leak in the error path of function update_bcn_wps_ie().
> > Make sure that allocated memory for 'pbackup_remainder_ie' is freed
> > upon return. Detected by Coverity - CID 1077718.
> >
>
> if (remainder_ielen > 0) {
> pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
> if (pbackup_remainder_ie)
> memcpy(pbackup_remainder_ie, premainder_ie,
> remainder_ielen);
> }
>
> pwps_ie_src = pmlmepriv->wps_beacon_ie;
> if (pwps_ie_src == NULL)
> return;
>
>
> Maybe just check pwps_ie_src earlier?
>
You are right, I see no reason why this cannot be done early in the function.
diff --git a/drivers/staging/rtl8723au/core/rtw_ap.c b/drivers/staging/rtl8723au/core/rtw_ap.c
index 9b31412..da028c535 100644
--- a/drivers/staging/rtl8723au/core/rtw_ap.c
+++ b/drivers/staging/rtl8723au/core/rtw_ap.c
@@ -1256,6 +1256,10 @@ static void update_bcn_wps_ie(struct rtw_adapter *padapter)
DBG_8723A("%s\n", __func__);
+ pwps_ie_src = pmlmepriv->wps_beacon_ie;
+ if (pwps_ie_src == NULL)
+ return;
+
pwps_ie = rtw_get_wps_ie23a(ie+_FIXED_IE_LENGTH_, ielen-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
if (pwps_ie == NULL || wps_ielen == 0)
@@ -1274,10 +1278,6 @@ static void update_bcn_wps_ie(struct rtw_adapter *padapter)
remainder_ielen);
}
- pwps_ie_src = pmlmepriv->wps_beacon_ie;
- if (pwps_ie_src == NULL)
- return;
-
wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
if ((wps_offset+wps_ielen+2+remainder_ielen)<= MAX_IE_SZ)
{
Regards,
Christian
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] staging: rtl8723au: fix potential leak in update_bcn_wps_ie()
2014-05-01 20:16 ` Christian Engelmayer
@ 2014-05-01 21:46 ` Jes Sorensen
0 siblings, 0 replies; 4+ messages in thread
From: Jes Sorensen @ 2014-05-01 21:46 UTC (permalink / raw)
To: Christian Engelmayer
Cc: Mateusz Guzik, devel, Larry.Finger, gregkh, linux-kernel
Christian Engelmayer <cengelma@gmx.at> writes:
> On Thu, 1 May 2014 14:22:17 +0200, Mateusz Guzik <mguzik@redhat.com> wrote:
>> On Thu, May 01, 2014 at 01:57:27PM +0200, Christian Engelmayer wrote:
>> > Fix a potential leak in the error path of function update_bcn_wps_ie().
>> > Make sure that allocated memory for 'pbackup_remainder_ie' is freed
>> > upon return. Detected by Coverity - CID 1077718.
>> >
>>
>> if (remainder_ielen > 0) {
>> pbackup_remainder_ie = kmalloc(remainder_ielen, GFP_ATOMIC);
>> if (pbackup_remainder_ie)
>> memcpy(pbackup_remainder_ie, premainder_ie,
>> remainder_ielen);
>> }
>>
>> pwps_ie_src = pmlmepriv->wps_beacon_ie;
>> if (pwps_ie_src == NULL)
>> return;
>>
>>
>> Maybe just check pwps_ie_src earlier?
>>
>
> You are right, I see no reason why this cannot be done early in the function.
Looks good to me - if you send me a patch with a commit message and a
Signed-off-by, I'll add it to the rtl8723au driver tree and push it to
Greg with my next set of changes.
Cheers,
Jes
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-01 21:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-01 11:57 [PATCH] staging: rtl8723au: fix potential leak in update_bcn_wps_ie() Christian Engelmayer
2014-05-01 12:22 ` Mateusz Guzik
2014-05-01 20:16 ` Christian Engelmayer
2014-05-01 21:46 ` Jes Sorensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).