* [PATCH] net: bridge: fix a memory leak in __vlan_add
@ 2018-10-14 3:21 ` Li RongQing
0 siblings, 0 replies; 6+ messages in thread
From: Li RongQing @ 2018-10-14 3:21 UTC (permalink / raw)
To: netdev; +Cc: nikolay, bridge
After per-port vlan stats, vlan stats should be released
when fail to add vlan
Fixes: 9163a0fc1f0c0 ("net: bridge: add support for per-port vlan stats")
cc: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
net/bridge/br_vlan.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 9b707234e4ae..e08e269041dd 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -305,6 +305,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
if (masterv) {
br_vlan_put_master(masterv);
v->brvlan = NULL;
+
+ if (masterv->stats != v->stats && v->stats)
+ free_percpu(v->stats);
+ v->stats = NULL;
}
} else {
br_switchdev_port_vlan_del(dev, v->vid);
--
2.16.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Bridge] [PATCH] net: bridge: fix a memory leak in __vlan_add
@ 2018-10-14 3:21 ` Li RongQing
0 siblings, 0 replies; 6+ messages in thread
From: Li RongQing @ 2018-10-14 3:21 UTC (permalink / raw)
To: netdev; +Cc: nikolay, bridge
After per-port vlan stats, vlan stats should be released
when fail to add vlan
Fixes: 9163a0fc1f0c0 ("net: bridge: add support for per-port vlan stats")
cc: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
net/bridge/br_vlan.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index 9b707234e4ae..e08e269041dd 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -305,6 +305,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
if (masterv) {
br_vlan_put_master(masterv);
v->brvlan = NULL;
+
+ if (masterv->stats != v->stats && v->stats)
+ free_percpu(v->stats);
+ v->stats = NULL;
}
} else {
br_switchdev_port_vlan_del(dev, v->vid);
--
2.16.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] net: bridge: fix a memory leak in __vlan_add
2018-10-14 3:21 ` [Bridge] " Li RongQing
@ 2018-10-14 15:33 ` Nikolay Aleksandrov
-1 siblings, 0 replies; 6+ messages in thread
From: Nikolay Aleksandrov @ 2018-10-14 15:33 UTC (permalink / raw)
To: Li RongQing, netdev; +Cc: Roopa Prabhu, bridge
On 14/10/2018 06:21, Li RongQing wrote:
> After per-port vlan stats, vlan stats should be released
> when fail to add vlan
>
> Fixes: 9163a0fc1f0c0 ("net: bridge: add support for per-port vlan stats")
> cc: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> net/bridge/br_vlan.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
> index 9b707234e4ae..e08e269041dd 100644
> --- a/net/bridge/br_vlan.c
> +++ b/net/bridge/br_vlan.c
> @@ -305,6 +305,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
> if (masterv) {
> br_vlan_put_master(masterv);
> v->brvlan = NULL;
> +
> + if (masterv->stats != v->stats && v->stats)
> + free_percpu(v->stats);
> + v->stats = NULL;
> }
> } else {
> br_switchdev_port_vlan_del(dev, v->vid);
>
Hi,
Good catch, but the patch doesn't fix the bug entirely. The problem is that masterv can be
created just for this vlan and the br_vlan_put_master() above can free it, so we can
check a pointer that's not really up-to-date (and thus again leak memory).
You should move the new code above the br_vlan_put_master() call.
Also please tag the proper branch, this is for net-next, and CC all bridge
maintainers (added Roopa).
Thank you,
Nik
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bridge] [PATCH] net: bridge: fix a memory leak in __vlan_add
@ 2018-10-14 15:33 ` Nikolay Aleksandrov
0 siblings, 0 replies; 6+ messages in thread
From: Nikolay Aleksandrov @ 2018-10-14 15:33 UTC (permalink / raw)
To: Li RongQing, netdev; +Cc: Roopa Prabhu, bridge
On 14/10/2018 06:21, Li RongQing wrote:
> After per-port vlan stats, vlan stats should be released
> when fail to add vlan
>
> Fixes: 9163a0fc1f0c0 ("net: bridge: add support for per-port vlan stats")
> cc: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
> Signed-off-by: Li RongQing <lirongqing@baidu.com>
> ---
> net/bridge/br_vlan.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
> index 9b707234e4ae..e08e269041dd 100644
> --- a/net/bridge/br_vlan.c
> +++ b/net/bridge/br_vlan.c
> @@ -305,6 +305,10 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
> if (masterv) {
> br_vlan_put_master(masterv);
> v->brvlan = NULL;
> +
> + if (masterv->stats != v->stats && v->stats)
> + free_percpu(v->stats);
> + v->stats = NULL;
> }
> } else {
> br_switchdev_port_vlan_del(dev, v->vid);
>
Hi,
Good catch, but the patch doesn't fix the bug entirely. The problem is that masterv can be
created just for this vlan and the br_vlan_put_master() above can free it, so we can
check a pointer that's not really up-to-date (and thus again leak memory).
You should move the new code above the br_vlan_put_master() call.
Also please tag the proper branch, this is for net-next, and CC all bridge
maintainers (added Roopa).
Thank you,
Nik
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] net: bridge: fix a memory leak in __vlan_add
2018-10-14 15:33 ` [Bridge] " Nikolay Aleksandrov
@ 2018-10-15 8:31 ` Li RongQing
-1 siblings, 0 replies; 6+ messages in thread
From: Li RongQing @ 2018-10-15 8:31 UTC (permalink / raw)
To: nikolay; +Cc: Li RongQing, netdev, bridge, roopa
> >
>
> Hi,
> Good catch, but the patch doesn't fix the bug entirely. The problem is that masterv can be
> created just for this vlan and the br_vlan_put_master() above can free it, so we can
> check a pointer that's not really up-to-date (and thus again leak memory).
> You should move the new code above the br_vlan_put_master() call.
>
> Also please tag the proper branch, this is for net-next, and CC all bridge
> maintainers (added Roopa).
>
Ok, thanks, I will send v2
-RongQing
> Thank you,
> Nik
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Bridge] [PATCH] net: bridge: fix a memory leak in __vlan_add
@ 2018-10-15 8:31 ` Li RongQing
0 siblings, 0 replies; 6+ messages in thread
From: Li RongQing @ 2018-10-15 8:31 UTC (permalink / raw)
To: nikolay; +Cc: netdev, roopa, bridge, Li RongQing
> >
>
> Hi,
> Good catch, but the patch doesn't fix the bug entirely. The problem is that masterv can be
> created just for this vlan and the br_vlan_put_master() above can free it, so we can
> check a pointer that's not really up-to-date (and thus again leak memory).
> You should move the new code above the br_vlan_put_master() call.
>
> Also please tag the proper branch, this is for net-next, and CC all bridge
> maintainers (added Roopa).
>
Ok, thanks, I will send v2
-RongQing
> Thank you,
> Nik
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-10-15 16:15 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-14 3:21 [PATCH] net: bridge: fix a memory leak in __vlan_add Li RongQing
2018-10-14 3:21 ` [Bridge] " Li RongQing
2018-10-14 15:33 ` Nikolay Aleksandrov
2018-10-14 15:33 ` [Bridge] " Nikolay Aleksandrov
2018-10-15 8:31 ` Li RongQing
2018-10-15 8:31 ` [Bridge] " Li RongQing
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.