Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1775959pxp; Mon, 7 Mar 2022 02:03:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzD43/irNX85GMgu2/4Gi4TmA/XfXONX3gGxAL4UfGNrGx7cETBBv/z+kI91TrIwTTk5FMw X-Received: by 2002:aa7:d711:0:b0:416:11c2:55fa with SMTP id t17-20020aa7d711000000b0041611c255famr10492614edq.242.1646647388645; Mon, 07 Mar 2022 02:03:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647388; cv=none; d=google.com; s=arc-20160816; b=tKEcDrnq8MVK1gC4XCxTkAxFQ87GtmOAOFJSksdi2SbztPqEUC3Q95O5i4D1gExTWi pWfQseKgbQSUT3A1ZFfXZvjrKkoeayXX5tZbW4D96h6vqeuDVt39uVLX36D7w1ns1yo3 qIpLaFVMW0ITTiUAeNKetRJ6U6Ebsm9kD39/k3tL9AwyD/j5045Zq57Nfd7RTSrkLqVl rYNnrpOQU4hP1/ExO4UMiSrxgI7ZCV5qPTZFfPqQ2vEe1UP/2HEsWLXcikSvbyNg3WaZ HIfbfzZMXdm5lDBMZDusUHZ2L5D75mvafWLO27DPCgTtkdHrGhD7Q87FuTqA0/KiH2+K kHRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gykHQd2QnbwsxNBRtsg1BsYEBZl7hr4gMNiMlPrP9lY=; b=SHrYZEoWux0xfa/3bI9fX5CzxhMtgMjqX2xXBvF8OM5x2swoKRcXd5lxjfaARXL0d7 6QhNucma0hDKQ5cV0GlyuGqhC7QFlANQZYQ8MZV3irBDocmT+t28H1Hsqy1PVAxe6XAw DdUU65ixmIoV3W6ZuKm6RXDLQwsNei30+lojLu5fv623J3n9qtf/hItZjOBRnV8DAswn jPwK8AxOP8fr+MJEHGBYz0J5uhGL8mM+WqOtQi3eOmDMfPz9H6zxbfZqhVKATcoweLD/ yAzlyBnE9EZyNFgq/yKQDVgvf08wsfUpYD6ayerHiLk4j6jDe/tl2ADfgnwTQe4UiubG ovLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KSYa9elC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di9-20020a170906730900b006dad7f3e79fsi5488681ejc.368.2022.03.07.02.02.45; Mon, 07 Mar 2022 02:03:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KSYa9elC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236873AbiCGJ0m (ORCPT + 99 others); Mon, 7 Mar 2022 04:26:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237156AbiCGJX2 (ORCPT ); Mon, 7 Mar 2022 04:23:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D2FD66ADE; Mon, 7 Mar 2022 01:21:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E76A1B810C0; Mon, 7 Mar 2022 09:21:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3548EC340FC; Mon, 7 Mar 2022 09:21:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644915; bh=7CwRksKJml/9QpQn0cdYH6brkoQJtb4mCcNbBsPHmvw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KSYa9elC87gzUm5uKrw/S6N4DG60Z9zdX/19St3oyOe+qLmhmiThFktVuocxOkjC2 teP+DawSQy9fRDxmcJDggkv+MpkTBr7VnATcxEq4it6+DEhmRBBqCT8LD310fpQX9Z x289XK3BQ503hP3DiL1PQdn/wkkCHYeM1Yj6Sp6w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sven Eckelmann , Simon Wunderlich Subject: [PATCH 4.14 20/42] batman-adv: Request iflink once in batadv-on-batadv check Date: Mon, 7 Mar 2022 10:18:54 +0100 Message-Id: <20220307091636.738398248@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sven Eckelmann 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 Signed-off-by: Greg Kroah-Hartman --- net/batman-adv/hard-interface.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- 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(co struct net *net = dev_net(net_dev); struct net_device *parent_dev; 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");