From patchwork Wed Mar 9 16:45:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18481 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 9470D82837; Wed, 9 Mar 2022 17:46:14 +0100 (CET) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 93B5E82837 for ; Wed, 9 Mar 2022 17:46:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1646844370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I9LT95Zfk+rYqKuti6LG5WksKN8jujhcd8v0/tR98hA=; b=1NDXs2YkNozfJH6XDRcrzQ0aps5sq9tz9S3AiXKUQqXNgeJBAUF1XYfYEcV1xX228/2nM9 nPY8rcxZCmLDnN/rm1xRRA7SfoN3DIVPS5h/uOc9AOkXuQKYW7O4L442SGC2CwGYgwke9h xXM1aUBqJLi4sXpgLcQTfqWPCQHjA/U= From: Sven Eckelmann To: stable@vger.kernel.org Subject: [PATCH 4.9 1/2] batman-adv: Request iflink once in batadv-on-batadv check Date: Wed, 9 Mar 2022 17:45:41 +0100 Message-Id: <20220309164542.408824-2-sven@narfation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220309164542.408824-1-sven@narfation.org> References: <20220309164542.408824-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1646844370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=I9LT95Zfk+rYqKuti6LG5WksKN8jujhcd8v0/tR98hA=; b=wyU9tV2n0PLmN001HB8V51rnCE7RP8zgheTBJNHJSUV9Vq7+Ti+PXH14rLmAGmWVzshAl3 gWjxE61DOrq2kM5dL2kgJcw+juXu8auOPouBmcwxueREKxb57vpGCNQs3vf0p7Pwmy3lur Dlb9UIAl7I6Eo9RspiR0aBL9jfWrbCc= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=1NDXs2Yk; dmarc=pass (policy=none) header.from=narfation.org; spf=pass (diktynna.open-mesh.org: domain of sven@narfation.org designates 2a00:17d8:100::8b1 as permitted sender) smtp.mailfrom=sven@narfation.org ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1646844370; a=rsa-sha256; cv=none; b=YwMwkL9GUYTWYk/PY8m39SoC5uf6w9oQiBlG1evD/w3m+JUn8FY7zoh3bjDeYZstqU/69p UjkdaiqZgckyajMZpsQ7kn/owAtt4atfnn9NKOhjJqv/ATXff5bnvDFLDqu62m/KWmU8E5 nfwdV6NJxtgyLdP/i+/DDIlPr3RnSWc= Message-ID-Hash: A5FNU32OST5GL7PX7WUT4S7QDKYVWOFS X-Message-ID-Hash: A5FNU32OST5GL7PX7WUT4S7QDKYVWOFS X-MailFrom: sven@narfation.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 3.2.1 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: commit 690bb6fb64f5dc7437317153902573ecad67593d upstream. There is no need to call dev_get_iflink multiple times for the same net_device in batadv_is_on_batman_iface. And since some of the .ndo_get_iflink callbacks are dynamic (for example via RCUs like in vxcan_get_iflink), it could easily happen that the returned values are not stable. The pre-checks before __dev_get_by_index are then of course bogus. Fixes: b7eddd0b3950 ("batman-adv: prevent using any virtual device created on batman-adv as hard-interface") Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich [ bp: 4.9 backported: adjust context. ] Signed-off-by: Sven Eckelmann --- net/batman-adv/hard-interface.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 4f384abb4ced..64cf9cd3be4d 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -155,22 +155,23 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) struct net *net = dev_net(net_dev); struct net_device *parent_dev; const struct net *parent_net; + int iflink; bool ret; /* check if this is a batman-adv mesh interface */ if (batadv_softif_is_valid(net_dev)) return true; + iflink = dev_get_iflink(net_dev); + /* no more parents..stop recursion */ - if (dev_get_iflink(net_dev) == 0 || - dev_get_iflink(net_dev) == net_dev->ifindex) + if (iflink == 0 || iflink == net_dev->ifindex) return false; parent_net = batadv_getlink_net(net_dev, net); /* recurse over the parent device */ - parent_dev = __dev_get_by_index((struct net *)parent_net, - dev_get_iflink(net_dev)); + parent_dev = __dev_get_by_index((struct net *)parent_net, iflink); /* if we got a NULL parent_dev there is something broken.. */ if (!parent_dev) { pr_err("Cannot find parent device\n"); From patchwork Wed Mar 9 16:45:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18482 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 78BB58449B; Wed, 9 Mar 2022 17:46:17 +0100 (CET) Received: from dvalin.narfation.org (dvalin.narfation.org [213.160.73.56]) by diktynna.open-mesh.org (Postfix) with ESMTPS id ECBDA8447A for ; Wed, 9 Mar 2022 17:46:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1646844373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZwpCCR3j0fJP68u+mjeOcu9cn7tpGvSxapemqPWCvhE=; b=cqlYL+8mTLRxIvZN3ZFnaSBUkDE/9cMvb4YWqnMz4PyYCzxgAhSf61mmqd//2yGITuBDTA IuYuBMaIP7FFOLqcoXVSHuer4XXwb8ObZHkFKNDDc+B5znfl2cL3AFxVV2pbEJf4rL+var IEiyttfUcJ6Yj2SMuF+HCxAzuHU3Jj4= From: Sven Eckelmann To: stable@vger.kernel.org Subject: [PATCH 4.9 2/2] batman-adv: Don't expect inter-netns unique iflink indices Date: Wed, 9 Mar 2022 17:45:42 +0100 Message-Id: <20220309164542.408824-3-sven@narfation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220309164542.408824-1-sven@narfation.org> References: <20220309164542.408824-1-sven@narfation.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1646844374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZwpCCR3j0fJP68u+mjeOcu9cn7tpGvSxapemqPWCvhE=; b=ItDwqi4PVB2aHZMdwg2smT3smTJNH7BZHgHWbmyGXuKHEM8cwrbJpMO7bHipEsZpo6bGQ0 P5yXjmzDdek0mvzjG7qQZ4zl0NJc4XJL03Angs4hM4ZwIx56h7e23o2X37YaOIjx6/1z8H OtVcglWP5YGseP5OsL+OKoTqcGRoJFY= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=cqlYL+8m; dmarc=pass (policy=none) header.from=narfation.org; spf=pass (diktynna.open-mesh.org: domain of sven@narfation.org designates 213.160.73.56 as permitted sender) smtp.mailfrom=sven@narfation.org ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1646844374; a=rsa-sha256; cv=none; b=maS6K3ncYvpHb73p7Ot1qfofNzwoQYE9S81+KkDbXI9LK0EfB9Y3GwE+pQl3KjbLGQ8wXR eWdGHHWH7ZoUEx91CkaWnsIZah4Vb9v+bPJGokybqEUjoPnpAKR/kvViHeSQjgvj8D+3+Z qtP0nBziRyWMFAIB6zgk+qUA07mTSkI= Message-ID-Hash: V4W7V6LJUEO3MJ7YO2TOA4WN7ZE47XZ5 X-Message-ID-Hash: V4W7V6LJUEO3MJ7YO2TOA4WN7ZE47XZ5 X-MailFrom: sven@narfation.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: b.a.t.m.a.n@lists.open-mesh.org, Sabrina Dubroca X-Mailman-Version: 3.2.1 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: commit 6c1f41afc1dbe59d9d3c8bb0d80b749c119aa334 upstream. The ifindex doesn't have to be unique for multiple network namespaces on the same machine. $ ip netns add test1 $ ip -net test1 link add dummy1 type dummy $ ip netns add test2 $ ip -net test2 link add dummy2 type dummy $ ip -net test1 link show dev dummy1 6: dummy1: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 96:81:55:1e:dd:85 brd ff:ff:ff:ff:ff:ff $ ip -net test2 link show dev dummy2 6: dummy2: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 5a:3c:af:35:07:c3 brd ff:ff:ff:ff:ff:ff But the batman-adv code to walk through the various layers of virtual interfaces uses this assumption because dev_get_iflink handles it internally and doesn't return the actual netns of the iflink. And dev_get_iflink only documents the situation where ifindex == iflink for physical devices. But only checking for dev->netdev_ops->ndo_get_iflink is also not an option because ipoib_get_iflink implements it even when it sometimes returns an iflink != ifindex and sometimes iflink == ifindex. The caller must therefore make sure itself to check both netns and iflink + ifindex for equality. Only when they are equal, a "physical" interface was detected which should stop the traversal. On the other hand, vxcan_get_iflink can also return 0 in case there was currently no valid peer. In this case, it is still necessary to stop. Fixes: b7eddd0b3950 ("batman-adv: prevent using any virtual device created on batman-adv as hard-interface") Fixes: 5ed4a460a1d3 ("batman-adv: additional checks for virtual interfaces on top of WiFi") Reported-by: Sabrina Dubroca Signed-off-by: Sven Eckelmann Signed-off-by: Simon Wunderlich [ bp: 4.9 backported: drop modification of non-existing batadv_get_real_netdevice. ] Signed-off-by: Sven Eckelmann --- net/batman-adv/hard-interface.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 64cf9cd3be4d..eaf0a483211a 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c @@ -163,13 +163,15 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) return true; iflink = dev_get_iflink(net_dev); - - /* no more parents..stop recursion */ - if (iflink == 0 || iflink == net_dev->ifindex) + if (iflink == 0) return false; parent_net = batadv_getlink_net(net_dev, net); + /* iflink to itself, most likely physical device */ + if (net == parent_net && iflink == net_dev->ifindex) + return false; + /* recurse over the parent device */ parent_dev = __dev_get_by_index((struct net *)parent_net, iflink); /* if we got a NULL parent_dev there is something broken.. */