* [B.A.T.M.A.N.] [PATCHv2 maint] batman-adv: increase orig refcount when storing ref in gw_node
@ 2014-05-01 23:35 Antonio Quartulli
2014-05-04 16:21 ` Marek Lindner
0 siblings, 1 reply; 2+ messages in thread
From: Antonio Quartulli @ 2014-05-01 23:35 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Antonio Quartulli
From: Antonio Quartulli <antonio@open-mesh.com>
A pointer to the orig_node representing a bat-gateway is
stored in the gw_node->orig_node member, but the refcount
for such orig_node is never increased.
This leads to memory faults when gw_node->orig_node is accessed
and the originator has already been freed.
Fix this by increasing the refcount on gw_node creation
and decreasing it on gw_node free.
Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
---
Change since v1:
- properly release orig_node in case of gw_node allocation failure
gateway_client.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/gateway_client.c b/gateway_client.c
index d7fafc1..d5a40ab 100644
--- a/gateway_client.c
+++ b/gateway_client.c
@@ -42,8 +42,10 @@
static void batadv_gw_node_free_ref(struct batadv_gw_node *gw_node)
{
- if (atomic_dec_and_test(&gw_node->refcount))
+ if (atomic_dec_and_test(&gw_node->refcount)) {
+ batadv_orig_node_free_ref(gw_node->orig_node);
kfree_rcu(gw_node, rcu);
+ }
}
static struct batadv_gw_node *
@@ -406,9 +408,14 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
if (gateway->bandwidth_down == 0)
return;
+ if (!atomic_inc_not_zero(&orig_node->refcount))
+ return;
+
gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
- if (!gw_node)
+ if (!gw_node) {
+ batadv_orig_node_free_ref(orig_node);
return;
+ }
INIT_HLIST_NODE(&gw_node->list);
gw_node->orig_node = orig_node;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [B.A.T.M.A.N.] [PATCHv2 maint] batman-adv: increase orig refcount when storing ref in gw_node
2014-05-01 23:35 [B.A.T.M.A.N.] [PATCHv2 maint] batman-adv: increase orig refcount when storing ref in gw_node Antonio Quartulli
@ 2014-05-04 16:21 ` Marek Lindner
0 siblings, 0 replies; 2+ messages in thread
From: Marek Lindner @ 2014-05-04 16:21 UTC (permalink / raw)
To: b.a.t.m.a.n; +Cc: Antonio Quartulli, Antonio Quartulli
[-- Attachment #1: Type: text/plain, Size: 773 bytes --]
On Friday 02 May 2014 01:35:13 Antonio Quartulli wrote:
> From: Antonio Quartulli <antonio@open-mesh.com>
>
> A pointer to the orig_node representing a bat-gateway is
> stored in the gw_node->orig_node member, but the refcount
> for such orig_node is never increased.
> This leads to memory faults when gw_node->orig_node is accessed
> and the originator has already been freed.
>
> Fix this by increasing the refcount on gw_node creation
> and decreasing it on gw_node free.
>
> Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
> ---
>
> Change since v1:
> - properly release orig_node in case of gw_node allocation failure
>
> gateway_client.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
Applied in revision 8dbdee5.
Thanks,
Marek
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-04 16:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-01 23:35 [B.A.T.M.A.N.] [PATCHv2 maint] batman-adv: increase orig refcount when storing ref in gw_node Antonio Quartulli
2014-05-04 16:21 ` Marek Lindner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox