* [PATCH] drivers: vxlan: vnifilter: free percpu vni stats on error path
@ 2023-08-03 19:38 Fedor Pchelkin
2023-08-04 13:24 ` Ido Schimmel
0 siblings, 1 reply; 4+ messages in thread
From: Fedor Pchelkin @ 2023-08-03 19:38 UTC (permalink / raw)
To: Roopa Prabhu
Cc: Fedor Pchelkin, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Nikolay Aleksandrov, netdev, linux-kernel,
Alexey Khoroshilov, lvc-project
In case rhashtable_lookup_insert_fast() fails inside vxlan_vni_add(), the
allocated percpu vni stats are not freed on the error path.
Free them on the rhashtable_lookup_insert_fast() error path in
vxlan_vni_add().
Found by Linux Verification Center (linuxtesting.org).
Fixes: 4095e0e1328a ("drivers: vxlan: vnifilter: per vni stats")
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
---
drivers/net/vxlan/vxlan_vnifilter.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c
index a3de081cda5e..321cd0b450cc 100644
--- a/drivers/net/vxlan/vxlan_vnifilter.c
+++ b/drivers/net/vxlan/vxlan_vnifilter.c
@@ -740,6 +740,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan,
&vninode->vnode,
vxlan_vni_rht_params);
if (err) {
+ free_percpu(vninode->stats);
kfree(vninode);
return err;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] drivers: vxlan: vnifilter: free percpu vni stats on error path 2023-08-03 19:38 [PATCH] drivers: vxlan: vnifilter: free percpu vni stats on error path Fedor Pchelkin @ 2023-08-04 13:24 ` Ido Schimmel 2023-08-04 15:53 ` [PATCH net v2] " Fedor Pchelkin 0 siblings, 1 reply; 4+ messages in thread From: Ido Schimmel @ 2023-08-04 13:24 UTC (permalink / raw) To: Fedor Pchelkin Cc: Roopa Prabhu, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nikolay Aleksandrov, netdev, linux-kernel, Alexey Khoroshilov, lvc-project Prefix should be "PATCH net". See: https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html On Thu, Aug 03, 2023 at 10:38:32PM +0300, Fedor Pchelkin wrote: > In case rhashtable_lookup_insert_fast() fails inside vxlan_vni_add(), the > allocated percpu vni stats are not freed on the error path. > > Free them on the rhashtable_lookup_insert_fast() error path in > vxlan_vni_add(). > > Found by Linux Verification Center (linuxtesting.org). > > Fixes: 4095e0e1328a ("drivers: vxlan: vnifilter: per vni stats") > Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru> > --- > drivers/net/vxlan/vxlan_vnifilter.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c > index a3de081cda5e..321cd0b450cc 100644 > --- a/drivers/net/vxlan/vxlan_vnifilter.c > +++ b/drivers/net/vxlan/vxlan_vnifilter.c > @@ -740,6 +740,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, > &vninode->vnode, > vxlan_vni_rht_params); > if (err) { > + free_percpu(vninode->stats); This oversight (and future ones) wouldn't have happened if vxlan_vni_alloc() had a corresponding vxlan_vni_free(). I suggest something like [1]. BTW, I think the GFP_ATOMIC in vxlan_vni_alloc() should be GFP_KERNEL. I will take care of it in net-next. > kfree(vninode); > return err; > } > -- > 2.41.0 [1] diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index a3de081cda5e..c3ff30ab782e 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -713,6 +713,12 @@ static struct vxlan_vni_node *vxlan_vni_alloc(struct vxlan_dev *vxlan, return vninode; } +static void vxlan_vni_free(struct vxlan_vni_node *vninode) +{ + free_percpu(vninode->stats); + kfree(vninode); +} + static int vxlan_vni_add(struct vxlan_dev *vxlan, struct vxlan_vni_group *vg, u32 vni, union vxlan_addr *group, @@ -740,7 +746,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, &vninode->vnode, vxlan_vni_rht_params); if (err) { - kfree(vninode); + vxlan_vni_free(vninode); return err; } @@ -763,8 +769,7 @@ static void vxlan_vni_node_rcu_free(struct rcu_head *rcu) struct vxlan_vni_node *v; v = container_of(rcu, struct vxlan_vni_node, rcu); - free_percpu(v->stats); - kfree(v); + vxlan_vni_free(v); } static int vxlan_vni_del(struct vxlan_dev *vxlan, ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net v2] drivers: vxlan: vnifilter: free percpu vni stats on error path 2023-08-04 13:24 ` Ido Schimmel @ 2023-08-04 15:53 ` Fedor Pchelkin 2023-08-06 15:50 ` patchwork-bot+netdevbpf 0 siblings, 1 reply; 4+ messages in thread From: Fedor Pchelkin @ 2023-08-04 15:53 UTC (permalink / raw) To: Ido Schimmel Cc: Fedor Pchelkin, David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni, Nikolay Aleksandrov, Roopa Prabhu, netdev, linux-kernel, Alexey Khoroshilov, lvc-project In case rhashtable_lookup_insert_fast() fails inside vxlan_vni_add(), the allocated percpu vni stats are not freed on the error path. Introduce vxlan_vni_free() which would work as a nice wrapper to free vxlan_vni_node resources properly. Found by Linux Verification Center (linuxtesting.org). Fixes: 4095e0e1328a ("drivers: vxlan: vnifilter: per vni stats") Suggested-by: Ido Schimmel <idosch@idosch.org> Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru> --- v1->v2: per Ido Schimmel's suggestion, extract freeing vninode resources into a separate function vxlan_vni_free() and tag the patch as for 'net' drivers/net/vxlan/vxlan_vnifilter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/net/vxlan/vxlan_vnifilter.c b/drivers/net/vxlan/vxlan_vnifilter.c index a3de081cda5e..c3ff30ab782e 100644 --- a/drivers/net/vxlan/vxlan_vnifilter.c +++ b/drivers/net/vxlan/vxlan_vnifilter.c @@ -713,6 +713,12 @@ static struct vxlan_vni_node *vxlan_vni_alloc(struct vxlan_dev *vxlan, return vninode; } +static void vxlan_vni_free(struct vxlan_vni_node *vninode) +{ + free_percpu(vninode->stats); + kfree(vninode); +} + static int vxlan_vni_add(struct vxlan_dev *vxlan, struct vxlan_vni_group *vg, u32 vni, union vxlan_addr *group, @@ -740,7 +746,7 @@ static int vxlan_vni_add(struct vxlan_dev *vxlan, &vninode->vnode, vxlan_vni_rht_params); if (err) { - kfree(vninode); + vxlan_vni_free(vninode); return err; } @@ -763,8 +769,7 @@ static void vxlan_vni_node_rcu_free(struct rcu_head *rcu) struct vxlan_vni_node *v; v = container_of(rcu, struct vxlan_vni_node, rcu); - free_percpu(v->stats); - kfree(v); + vxlan_vni_free(v); } static int vxlan_vni_del(struct vxlan_dev *vxlan, -- 2.41.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] drivers: vxlan: vnifilter: free percpu vni stats on error path 2023-08-04 15:53 ` [PATCH net v2] " Fedor Pchelkin @ 2023-08-06 15:50 ` patchwork-bot+netdevbpf 0 siblings, 0 replies; 4+ messages in thread From: patchwork-bot+netdevbpf @ 2023-08-06 15:50 UTC (permalink / raw) To: Fedor Pchelkin Cc: idosch, davem, edumazet, kuba, pabeni, razor, roopa, netdev, linux-kernel, khoroshilov, lvc-project Hello: This patch was applied to netdev/net.git (main) by David S. Miller <davem@davemloft.net>: On Fri, 4 Aug 2023 18:53:36 +0300 you wrote: > In case rhashtable_lookup_insert_fast() fails inside vxlan_vni_add(), the > allocated percpu vni stats are not freed on the error path. > > Introduce vxlan_vni_free() which would work as a nice wrapper to free > vxlan_vni_node resources properly. > > Found by Linux Verification Center (linuxtesting.org). > > [...] Here is the summary with links: - [net,v2] drivers: vxlan: vnifilter: free percpu vni stats on error path https://git.kernel.org/netdev/net/c/b1c936e9af5d You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-06 15:51 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-08-03 19:38 [PATCH] drivers: vxlan: vnifilter: free percpu vni stats on error path Fedor Pchelkin 2023-08-04 13:24 ` Ido Schimmel 2023-08-04 15:53 ` [PATCH net v2] " Fedor Pchelkin 2023-08-06 15:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox