From: Antonio Quartulli <a@unstable.cc>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
Antonio Quartulli <a@unstable.cc>,
Marek Lindner <mareklindner@neomailbox.ch>
Subject: [B.A.T.M.A.N.] [PATCH 14/17] batman-adv: Use kref_get for _batadv_update_route
Date: Wed, 11 May 2016 03:30:02 +0800 [thread overview]
Message-ID: <1462908605-27412-15-git-send-email-a@unstable.cc> (raw)
In-Reply-To: <1462908605-27412-1-git-send-email-a@unstable.cc>
From: Sven Eckelmann <sven@narfation.org>
_batadv_update_route requires that the caller already has a valid reference
for neigh_node. It is therefore not possible that it has an reference
counter of 0 and was still given to this function
The kref_get function instead WARNs (with debug information) when the
reference counter would still be 0. This makes a bug in batman-adv better
visible because kref_get_unless_zero would have ignored this problem.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
net/batman-adv/routing.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index 2ecfca246be4..b494e435686f 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -100,10 +100,6 @@ static void _batadv_update_route(struct batadv_priv *bat_priv,
if (curr_router)
batadv_neigh_node_put(curr_router);
- /* increase refcount of new best neighbor */
- if (neigh_node && !kref_get_unless_zero(&neigh_node->refcount))
- neigh_node = NULL;
-
spin_lock_bh(&orig_node->neigh_list_lock);
/* curr_router used earlier may not be the current orig_ifinfo->router
* anymore because it was dereferenced outside of the neigh_list_lock
@@ -114,6 +110,10 @@ static void _batadv_update_route(struct batadv_priv *bat_priv,
*/
curr_router = rcu_dereference_protected(orig_ifinfo->router, true);
+ /* increase refcount of new best neighbor */
+ if (neigh_node)
+ kref_get(&neigh_node->refcount);
+
rcu_assign_pointer(orig_ifinfo->router, neigh_node);
spin_unlock_bh(&orig_node->neigh_list_lock);
batadv_orig_ifinfo_put(orig_ifinfo);
--
2.8.2
next prev parent reply other threads:[~2016-05-10 19:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 19:29 [B.A.T.M.A.N.] pull request: batman-adv 20160511 Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 01/17] batman-adv: Remove unused parameter recv_if of batadv_interface_rx Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 02/17] batman-adv: Remove hdr_size skb size check in batadv_interface_rx Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 03/17] batman-adv: NETIF_F_NETNS_LOCAL feature to prevent netns moves Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 04/17] batman-adv: Create batman soft interfaces within correct netns Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 05/17] batman-adv: add detection for complex bridge loops Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 06/17] batman-adv: Check hard_iface refcnt before calling function Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 07/17] batman-adv: Check hard_iface refcnt when receiving skb Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 08/17] batman-adv: Increase hard_iface refcnt for ptype Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 09/17] batman-adv: Use kref_get for batadv_tvlv_container_get Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 10/17] batman-adv: Use kref_get for batadv_nc_get_nc_node Antonio Quartulli
2016-05-10 19:29 ` [B.A.T.M.A.N.] [PATCH 11/17] batman-adv: Use kref_get for batadv_gw_select Antonio Quartulli
2016-05-10 19:30 ` [B.A.T.M.A.N.] [PATCH 12/17] batman-adv: Use kref_get for batadv_gw_node_add Antonio Quartulli
2016-05-10 19:30 ` [B.A.T.M.A.N.] [PATCH 13/17] batman-adv: Use kref_get for hard_iface subfunctions Antonio Quartulli
2016-05-10 19:30 ` Antonio Quartulli [this message]
2016-05-10 19:30 ` [B.A.T.M.A.N.] [PATCH 15/17] batman-adv: Use bool as return type for boolean functions Antonio Quartulli
2016-05-10 19:30 ` [B.A.T.M.A.N.] [PATCH 16/17] batman-adv: replace ethertype variable with ETH_P_BATMAN for readability Antonio Quartulli
2016-05-10 19:30 ` [B.A.T.M.A.N.] [PATCH 17/17] batman-adv: use batadv_compare_eth when possible Antonio Quartulli
2016-05-11 3:36 ` [B.A.T.M.A.N.] pull request: batman-adv 20160511 David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462908605-27412-15-git-send-email-a@unstable.cc \
--to=a@unstable.cc \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=mareklindner@neomailbox.ch \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox