2020-06-18 13:28:18

by Zheng Bin

[permalink] [raw]
Subject: [PATCH -next] macvlan: Fix memleak in macvlan_changelink_sources

macvlan_changelink_sources
if (addr)
ret = macvlan_hash_add_source(vlan, addr)
nla_for_each_attr(nla, head, len, rem)
ret = macvlan_hash_add_source(vlan, addr)
-->If fail, need to free previous malloc memory

Fixes: 79cf79abce71 ("macvlan: add source mode")
Signed-off-by: Zheng Bin <[email protected]>
---
drivers/net/macvlan.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 6a6cc9f75307..0017c5d28a27 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -1379,8 +1379,10 @@ static int macvlan_changelink_sources(struct macvlan_dev *vlan, u32 mode,

addr = nla_data(nla);
ret = macvlan_hash_add_source(vlan, addr);
- if (ret)
+ if (ret) {
+ macvlan_flush_sources(vlan->port, vlan);
return ret;
+ }
}
} else {
return -EINVAL;
--
2.25.4


2020-06-20 05:06:40

by David Miller

[permalink] [raw]
Subject: Re: [PATCH -next] macvlan: Fix memleak in macvlan_changelink_sources

From: Zheng Bin <[email protected]>
Date: Thu, 18 Jun 2020 21:26:29 +0800

> macvlan_changelink_sources
> if (addr)
> ret = macvlan_hash_add_source(vlan, addr)
> nla_for_each_attr(nla, head, len, rem)
> ret = macvlan_hash_add_source(vlan, addr)
> -->If fail, need to free previous malloc memory
>
> Fixes: 79cf79abce71 ("macvlan: add source mode")
> Signed-off-by: Zheng Bin <[email protected]>

Bug fixes should never be submitted against net-next.

They should instead be submitted against 'net'.

Thank you.