From patchwork Sun Jun 26 22:55:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16398 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 65ACB81D43; Mon, 27 Jun 2016 00:55:28 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=narfation.org Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=Y0KiJeN/; 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 61DC981D3D for ; Mon, 27 Jun 2016 00:55:25 +0200 (CEST) Received: from sven-desktop.home.narfation.org (p200300C593D02DF90000000000002E16.dip0.t-ipconnect.de [IPv6:2003:c5:93d0:2df9::2e16]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id C766A1C8001; Mon, 27 Jun 2016 00:55:24 +0200 (CEST) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=narfation.org; s=20121; t=1466981725; bh=t63ISG/uAa5WHpSmDLQMMhbfGSkTlwZUZfZWf0zDc4o=; h=From:To:Cc:Subject:Date:From; b=Y0KiJeN/70zGfmtCvHBE5y/+pIOKLC9Q+MZGRYjmYflSnnVkm6Zbl3DUDdd/axaxF Q0VYhBRHu+Ep7bqGDgjtuKLQ3GGWPlUTpAYRUiboFxLXC/wpB8b+UOU5mWnIfaEFz1 eJHipWcmFXNm5cfvxjQs3va3uywjHUvS24WGOIcU= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Mon, 27 Jun 2016 00:55:21 +0200 Message-Id: <1466981721-3202-1-git-send-email-sven@narfation.org> X-Mailer: git-send-email 2.8.1 Subject: [B.A.T.M.A.N.] [PATCH maint] batman-adv: Remove orig_node reference handling from send_skb_unicast 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The function batadv_send_skb_unicast is not acquiring a reference for an orig_node nor removing it from any datastructure. It still reduces the reference counter for an object which is still in the hands of the caller. This is confusing and can lead to problems in the reference handling in the caller function. This breaks for example the reference counting in batadv_interface_tx when an DHCP packet (BATADV_DHCP_TO_SERVER) is detected in a multicast (not broadcast) packet which is later detected by the multicast code as BATADV_FORW_SINGLE. The multicast code then assumes that it will send it and acquires the originator to the destination. But in reality, the DHCP forwarding code takes precedence and as result the reference counter is not decreased anymore. Fixes: 405cc1e5a81e ("batman-adv: Modified forwarding behaviour for multicast packets") Signed-off-by: Sven Eckelmann --- net/batman-adv/send.c | 22 ++++++++++++++++------ net/batman-adv/soft-interface.c | 3 +++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c index 729deec..44be408 100644 --- a/net/batman-adv/send.c +++ b/net/batman-adv/send.c @@ -362,8 +362,6 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv, ret = NET_XMIT_SUCCESS; out: - if (orig_node) - batadv_orig_node_put(orig_node); if (ret == NET_XMIT_DROP) kfree_skb(skb); return ret; @@ -395,6 +393,7 @@ int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv, struct ethhdr *ethhdr = (struct ethhdr *)skb->data; struct batadv_orig_node *orig_node; u8 *src, *dst; + int ret; src = ethhdr->h_source; dst = ethhdr->h_dest; @@ -406,8 +405,13 @@ int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv, } orig_node = batadv_transtable_search(bat_priv, src, dst, vid); - return batadv_send_skb_unicast(bat_priv, skb, packet_type, - packet_subtype, orig_node, vid); + ret = batadv_send_skb_unicast(bat_priv, skb, packet_type, + packet_subtype, orig_node, vid); + + if (orig_node) + batadv_orig_node_put(orig_node); + + return ret; } /** @@ -425,10 +429,16 @@ int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb, unsigned short vid) { struct batadv_orig_node *orig_node; + int ret; orig_node = batadv_gw_get_selected_orig(bat_priv); - return batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST, 0, - orig_node, vid); + ret = batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST, 0, + orig_node, vid); + + if (orig_node) + batadv_orig_node_put(orig_node); + + return ret; } void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet) diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c index 216ac03..e508bf5 100644 --- a/net/batman-adv/soft-interface.c +++ b/net/batman-adv/soft-interface.c @@ -57,6 +57,7 @@ #include "hard-interface.h" #include "multicast.h" #include "network-coding.h" +#include "originator.h" #include "packet.h" #include "send.h" #include "sysfs.h" @@ -377,6 +378,8 @@ dropped: dropped_freed: batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED); end: + if (mcast_single_orig) + batadv_orig_node_put(mcast_single_orig); if (primary_if) batadv_hardif_put(primary_if); return NETDEV_TX_OK;