Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1776102pxp; Mon, 7 Mar 2022 02:03:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlGGc5oWDM62DnpKFiftbjoke/qo9pm3WiR05N1Frgk32L00SZejdfel9dm9p8xlEgF34O X-Received: by 2002:a63:8749:0:b0:37f:f8e1:1877 with SMTP id i70-20020a638749000000b0037ff8e11877mr8582044pge.529.1646647399890; Mon, 07 Mar 2022 02:03:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647399; cv=none; d=google.com; s=arc-20160816; b=odGP84Z0tbQFRq75G/JKFMPr5gmj/Iju+XbJmfLbJ4hk5H6/irx//Z6mLW8bLYAJHV ReV1K37aiHPOOQwDvRXe9Oic3BHhAucuy4533XpPw4TBbIDjnTA8sfl7tyLOEJoNQMlQ E+eQ4/oK4veqf2kLyXqJLyd+jfLUEaO7mTuhwbOa9ahXxxcRUPiZ5jilLGq4vAUkxzIH MjFf9X1gvpSC2fNyfqfCdGsqaEbwBoU8UwdumdUYnc5QUBDTiERpAX/GijUNCJ71fnmz SSycirTzKv9+q3Djsa+L6pYtUD7snM0hXGkJiwg35GuBUBjgSDcyyb7MJmQ2J8TAYV0R b97A== 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=5hEQU9jqRlQO8xUC2x3PiTwSdiUEzML3/+N2vWMmFjU=; b=zmXXdX2qRqSWvORQZHh6CzSgBt6d9GM3JZVtC3QPiItO84mqAnqecx8nge3rOg5mIl wuSyTgTmcXGXqGuQIly5dRx/ppmwTTsprTAsGlNfx8iblcDH6jrQ7/Q0eQhXssC5rMJA LlnQsr8yftPaAqAy30u83AylDEmUf37Ssl9TJKgHXGbeOMYqNOCV2TOK0of4ZgnyDtY7 Ojjft6yd/A5NOhkxKeMYuQ+v4jmKJ8epb2imnCR2tkCch8nD3k0nxck5MjjM6m28EFSq Hhuh+DsIS4/x6zsC73rUmrLOcTm/tphZ+QtjBi/1UJSOanW/0vCvYo7RPD9lB+fhkFW0 +nmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UQTKCXhp; 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 u3-20020a056a00158300b004cc3db186cesi12996442pfk.338.2022.03.07.02.03.05; Mon, 07 Mar 2022 02:03:19 -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=UQTKCXhp; 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 S236987AbiCGJ1d (ORCPT + 99 others); Mon, 7 Mar 2022 04:27:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236715AbiCGJYZ (ORCPT ); Mon, 7 Mar 2022 04:24:25 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C4A58E63; Mon, 7 Mar 2022 01:23:27 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 880F66113A; Mon, 7 Mar 2022 09:23:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93F6BC340E9; Mon, 7 Mar 2022 09:23:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645007; bh=DIaHoi5DTOYTWJey/z9WUzcDdY/AoO2Svz+OcqnU0/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UQTKCXhpRWE6LjSFLxzeWVZ9FvL2PwFC1fz4lbD7H0b1yIUbmLlhftNh1ZAZX8kTL z+UvUs/lBQlI7Gzi+FTq6SbRehEH3D9qrlaegyaut58PKOoPxKesJOwAElbD1oq9aP qe+PxoWtJPPCV13Xp1v+nBamBWXQEPtmUnQP1IEo= 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 21/42] batman-adv: Request iflink once in batadv_get_real_netdevice Date: Mon, 7 Mar 2022 10:18:55 +0100 Message-Id: <20220307091636.766654593@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 6116ba09423f7d140f0460be6a1644dceaad00da upstream. There is no need to call dev_get_iflink multiple times for the same net_device in batadv_get_real_netdevice. 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: 5ed4a460a1d3 ("batman-adv: additional checks for virtual interfaces on top of WiFi") 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 @@ -221,14 +221,16 @@ static struct net_device *batadv_get_rea struct net_device *real_netdev = NULL; struct net *real_net; struct net *net; - int ifindex; + int iflink; ASSERT_RTNL(); if (!netdev) return NULL; - if (netdev->ifindex == dev_get_iflink(netdev)) { + iflink = dev_get_iflink(netdev); + + if (netdev->ifindex == iflink) { dev_hold(netdev); return netdev; } @@ -238,9 +240,8 @@ static struct net_device *batadv_get_rea goto out; net = dev_net(hard_iface->soft_iface); - ifindex = dev_get_iflink(netdev); real_net = batadv_getlink_net(netdev, net); - real_netdev = dev_get_by_index(real_net, ifindex); + real_netdev = dev_get_by_index(real_net, iflink); out: if (hard_iface)