diff mbox series

[net-next] mac80211_hwsim: fix memory leak in hwsim_new_radio_nl

Message ID 20230515034712.2425489-1-shaozhengchao@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] mac80211_hwsim: fix memory leak in hwsim_new_radio_nl | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers fail 1 blamed authors not CCed: jaewan@google.com; 1 maintainers not CCed: jaewan@google.com
netdev/build_clang success Errors and warnings before: 10 this patch: 10
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

shaozhengchao May 15, 2023, 3:47 a.m. UTC
When parse_pmsr_capa failed in hwsim_new_radio_nl, the memory resources
applied for by pmsr_capa are not released. Add release processing to the
incorrect path.

Fixes: 92d13386ec55 ("mac80211_hwsim: add PMSR capability support")
Reported-by: syzbot+904ce6fbb38532d9795c@syzkaller.appspotmail.com
Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
---
 drivers/net/wireless/virtual/mac80211_hwsim.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Steen Hegelund May 15, 2023, 8:30 a.m. UTC | #1
Hi Shao,

On Mon, 2023-05-15 at 11:47 +0800, Zhengchao Shao wrote:
> [You don't often get email from shaozhengchao@huawei.com. Learn why this is
> important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> When parse_pmsr_capa failed in hwsim_new_radio_nl, the memory resources
> applied for by pmsr_capa are not released. Add release processing to the
> incorrect path.
> 
> Fixes: 92d13386ec55 ("mac80211_hwsim: add PMSR capability support")
> Reported-by: syzbot+904ce6fbb38532d9795c@syzkaller.appspotmail.com
> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
> ---
>  drivers/net/wireless/virtual/mac80211_hwsim.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/virtual/mac80211_hwsim.c
> b/drivers/net/wireless/virtual/mac80211_hwsim.c
> index 9a8faaf4c6b6..6a50858a5645 100644
> --- a/drivers/net/wireless/virtual/mac80211_hwsim.c
> +++ b/drivers/net/wireless/virtual/mac80211_hwsim.c
> @@ -5965,8 +5965,10 @@ static int hwsim_new_radio_nl(struct sk_buff *msg,
> struct genl_info *info)
>                         goto out_free;
>                 }
>                 ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT],
> pmsr_capa, info);
> -               if (ret)
> +               if (ret) {
> +                       kfree(pmsr_capa);

This should not be needed, see below.

>                         goto out_free;
> +               }
>                 param.pmsr_capa = pmsr_capa;


Why don't you just move this line up before the parse_pmsr_capa as there is
already a kfree(param.pmsr_capa) under the out_free label?

>         }
> 
> --
> 2.34.1
> 
> 

BR
Steen
shaozhengchao May 15, 2023, 9:07 a.m. UTC | #2
On 2023/5/15 16:30, Steen Hegelund wrote:
> Hi Shao,
> 
> On Mon, 2023-05-15 at 11:47 +0800, Zhengchao Shao wrote:
>> [You don't often get email from shaozhengchao@huawei.com. Learn why this is
>> important at https://aka.ms/LearnAboutSenderIdentification ]
>>
>> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
>> content is safe
>>
>> When parse_pmsr_capa failed in hwsim_new_radio_nl, the memory resources
>> applied for by pmsr_capa are not released. Add release processing to the
>> incorrect path.
>>
>> Fixes: 92d13386ec55 ("mac80211_hwsim: add PMSR capability support")
>> Reported-by: syzbot+904ce6fbb38532d9795c@syzkaller.appspotmail.com
>> Signed-off-by: Zhengchao Shao <shaozhengchao@huawei.com>
>> ---
>>   drivers/net/wireless/virtual/mac80211_hwsim.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/wireless/virtual/mac80211_hwsim.c
>> b/drivers/net/wireless/virtual/mac80211_hwsim.c
>> index 9a8faaf4c6b6..6a50858a5645 100644
>> --- a/drivers/net/wireless/virtual/mac80211_hwsim.c
>> +++ b/drivers/net/wireless/virtual/mac80211_hwsim.c
>> @@ -5965,8 +5965,10 @@ static int hwsim_new_radio_nl(struct sk_buff *msg,
>> struct genl_info *info)
>>                          goto out_free;
>>                  }
>>                  ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT],
>> pmsr_capa, info);
>> -               if (ret)
>> +               if (ret) {
>> +                       kfree(pmsr_capa);
> 
> This should not be needed, see below.
> 
>>                          goto out_free;
>> +               }
>>                  param.pmsr_capa = pmsr_capa;
> 
> 
> Why don't you just move this line up before the parse_pmsr_capa as there is
> already a kfree(param.pmsr_capa) under the out_free label?
> 

Hi Steen:
	Your suggestion looks good. I will send V2.

Zhengchao Shao

>>          }
>>
>> --
>> 2.34.1
>>
>>
> 
> BR
> Steen
diff mbox series

Patch

diff --git a/drivers/net/wireless/virtual/mac80211_hwsim.c b/drivers/net/wireless/virtual/mac80211_hwsim.c
index 9a8faaf4c6b6..6a50858a5645 100644
--- a/drivers/net/wireless/virtual/mac80211_hwsim.c
+++ b/drivers/net/wireless/virtual/mac80211_hwsim.c
@@ -5965,8 +5965,10 @@  static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
 			goto out_free;
 		}
 		ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT], pmsr_capa, info);
-		if (ret)
+		if (ret) {
+			kfree(pmsr_capa);
 			goto out_free;
+		}
 		param.pmsr_capa = pmsr_capa;
 	}