Message ID | 1457189627-8839-1-git-send-email-sven@narfation.org (mailing list archive) |
---|---|
State | Superseded, archived |
Delegated to: | Marek Lindner |
Headers |
Return-Path: <b.a.t.m.a.n-bounces@lists.open-mesh.org> X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [127.0.0.1]) by open-mesh.org (Postfix) with ESMTP id 42BBD82391; Sat, 5 Mar 2016 15:53:54 +0100 (CET) Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=W0/VSh6Z; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 1A82982390 for <b.a.t.m.a.n@lists.open-mesh.org>; Sat, 5 Mar 2016 15:53:51 +0100 (CET) Received: from sven-desktop.home.narfation.org (p200300C593C286FD0000000000002E16.dip0.t-ipconnect.de [IPv6:2003:c5:93c2:86fd::2e16]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 8A33C110103; Sat, 5 Mar 2016 15:53:51 +0100 (CET) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=20121; t=1457189631; bh=OixwhWSZpNAXDFOzqJYUOLfKScTaxl3rKaEBl5y1kEk=; h=From:To:Cc:Subject:Date:From; b=W0/VSh6ZtjSBV4wn+c/GlrxEZbNVe26J7RyJ3668v3wp23QTfilAomAxDyanOGyZO r2ZnjTIHIaf1auv+bybB1Pu8Ayig8lGIvXUb61BT9Ss944sQqfnKJW7aoVOyFeutpb tUpkBGtS3bNEYyiqnuNEA5SLUjRs86tLkb+sYDA8= From: Sven Eckelmann <sven@narfation.org> To: b.a.t.m.a.n@lists.open-mesh.org Date: Sat, 5 Mar 2016 15:53:47 +0100 Message-Id: <1457189627-8839-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.7.0 Subject: [B.A.T.M.A.N.] [PATCH maint] batman-adv: Reduce refcnt of removed router when updating route X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking <b.a.t.m.a.n.lists.open-mesh.org> List-Unsubscribe: <https://lists.open-mesh.org/mm/options/b.a.t.m.a.n>, <mailto:b.a.t.m.a.n-request@lists.open-mesh.org?subject=unsubscribe> List-Archive: <http://lists.open-mesh.org/pipermail/b.a.t.m.a.n/> List-Post: <mailto:b.a.t.m.a.n@lists.open-mesh.org> List-Help: <mailto:b.a.t.m.a.n-request@lists.open-mesh.org?subject=help> List-Subscribe: <https://lists.open-mesh.org/mm/listinfo/b.a.t.m.a.n>, <mailto:b.a.t.m.a.n-request@lists.open-mesh.org?subject=subscribe> Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking <b.a.t.m.a.n@lists.open-mesh.org> Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" <b.a.t.m.a.n-bounces@lists.open-mesh.org> |
Commit Message
Sven Eckelmann
March 5, 2016, 2:53 p.m. UTC
_batadv_update_route rcu_derefences orig_ifinfo->router outside of a
spinlock protected region to print some information messages to the debug
log. But this pointer is not checked again when the new pointer is assigned
in the spinlock protected region. Thus is can happen that the value of
orig_ifinfo->router changed in the meantime and thus the reference counter
of the wrong router gets reduced after the spinlock protected region.
Just rcu_dereferencing the value of orig_ifinfo->router inside the spinlock
protected region (which also set the new pointer) is enough to get the
correct old router object.
Fixes: d90ddb94423f ("batman-adv: Make orig_node->router an rcu protected pointer")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
net/batman-adv/routing.c | 2 ++
1 file changed, 2 insertions(+)
Comments
On Saturday, March 05, 2016 15:53:47 Sven Eckelmann wrote: > --- a/net/batman-adv/routing.c > +++ b/net/batman-adv/routing.c > @@ -104,6 +104,8 @@ static void _batadv_update_route(struct batadv_priv > *bat_priv, neigh_node = NULL; > > spin_lock_bh(&orig_node->neigh_list_lock); > + curr_router = rcu_dereference_protected(orig_ifinfo->router, true); > + > rcu_assign_pointer(orig_ifinfo->router, neigh_node); > spin_unlock_bh(&orig_node->neigh_list_lock); > batadv_orig_ifinfo_free_ref(orig_ifinfo); Don't we also need to check for curr_router->refcount > 0 to mimic the check above ? Maybe a negative refcount does not hurt or is it unsigned ? Cheers, Marek
On Sunday 20 March 2016 18:45:29 Marek Lindner wrote: > On Saturday, March 05, 2016 15:53:47 Sven Eckelmann wrote: > > --- a/net/batman-adv/routing.c > > +++ b/net/batman-adv/routing.c > > @@ -104,6 +104,8 @@ static void _batadv_update_route(struct batadv_priv > > *bat_priv, neigh_node = NULL; > > > > spin_lock_bh(&orig_node->neigh_list_lock); > > > > + curr_router = rcu_dereference_protected(orig_ifinfo->router, > > true); > > + > > > > rcu_assign_pointer(orig_ifinfo->router, neigh_node); > > spin_unlock_bh(&orig_node->neigh_list_lock); > > batadv_orig_ifinfo_free_ref(orig_ifinfo); > > Don't we also need to check for curr_router->refcount > 0 to mimic the check > above ? Maybe a negative refcount does not hurt or is it unsigned ? If this one gets negative then we would have a bug in a different place. The assignment only happens in this neigh_list_lock protected block. So the neigh_node behind orig_ifinfo->router must at least have a reference count of 1 or there was no valid reference (as in reference counter) for the pointer. The the kref_get_unless_zero before was only necessary because the curr_router was aquired inside a rcu_read_lock protected region which is not perfectly in sync with its writers. So it could happen that rcu_dereference returned a pointer to a neigh_node but this neigh_node will be free'd (reference counter == 0). And we cannot get a valid reference for an object which has refcount of 0. This function avoids this problem by assuming that orig_ifinfo->router is NULL. This is not perfectly correct but better than having a pointer to free'd memory. Kind regards, Sven
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 1fb1be3..61fdefe 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c @@ -104,6 +104,8 @@ static void _batadv_update_route(struct batadv_priv *bat_priv, neigh_node = NULL; spin_lock_bh(&orig_node->neigh_list_lock); + curr_router = rcu_dereference_protected(orig_ifinfo->router, true); + rcu_assign_pointer(orig_ifinfo->router, neigh_node); spin_unlock_bh(&orig_node->neigh_list_lock); batadv_orig_ifinfo_free_ref(orig_ifinfo);