Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2657815pxj; Mon, 31 May 2021 07:34:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYkgdPRMki+V1OQMCr45he/xIu9qGEPv1DfUmWn25v017E87HcXbhPt+myVhsw9fBUwxYr X-Received: by 2002:a92:1901:: with SMTP id 1mr17681153ilz.237.1622471679836; Mon, 31 May 2021 07:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622471679; cv=none; d=google.com; s=arc-20160816; b=RnCCnjOAc+4lSZL27/8oKcF1IIh2mYh6uFdcntGDxmoen0GrBNehXDNXaES4O/kxIY 25m1csnGF1F7kmF7FCE5nbs/alWdRf+VlJeAhd8xN2GD6iKLjKR1bE9GQ1+09q1jDdwd gP8BO7zsnvRqFFQ2C3zkm6REeS2VLJAq7edi7dqfwq00yXJC/KTxKgwdgvVYHJscJ/f9 7hvDrueV3l8u0mrhxVRUg6XYwbdv6wAOrH/pfCRKKazCAtw1pAIQD2hTnin9ToYzkE4L r0mQUD2Z3r/LVwiylN4bmTmVK+gVuDW0u042z2PGivv7e5OMqqPFrkE4Ruro5fW4jB2v wuyA== 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=K700gP+bOFsyjJW1B7MQwNsAIeJz1FNixgOmrVCgvpQ=; b=BSzz8cgS5QkucwcgonvK54j4FAQlWEujXbUAHbuutoIk802HKIRfVebJtv69B5asYX WGeTzwYiuyoeyl3bziF3azi4NPPGJcY6Vog8m3h9gKz2bUEvoSNsXaZ7KlGhAzDqpvM+ kcXMuyPizPRa9f1fpC+eY2lKcfvXua1+gk0WbnRgzDb8VmR9bKDQZqZ8pOffJyfM/utg hIFBVwXcEQq58OxMuelArU2sskf7Q5T38gbC9bXsK5b3nGIKO7XZW//4fvQQdo96kYCX SM5JHpFfabSjYAsZFD9NXfliewGiK3L1BINfLwErJZJzxMwINwU3bfPbzOT1Q8HC+RHc wWpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J8cTEpTk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si4139424jad.28.2021.05.31.07.34.27; Mon, 31 May 2021 07:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J8cTEpTk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S233412AbhEaOff (ORCPT + 99 others); Mon, 31 May 2021 10:35:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231843AbhEaNzb (ORCPT ); Mon, 31 May 2021 09:55:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3323461438; Mon, 31 May 2021 13:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468059; bh=QNIFF73Sw1QWHUeB332tv0d14bDPDTq2zZcpI4cWW+E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J8cTEpTkoN3MJLOUki+cypTmjKY8TONOxHONN5XYKShweJYUkFSWCq6n4XF1gQ/C8 s4pMGq9+xNsTEYUYu6sYlivLUu91OwQ/kO3ekkw1n2dNBcKvE7+efi6pSt1KaHcwPs GUK3Tuv6rl5HlQgEzUtIrv17BEF7ZXk/i8BEU3Ks= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dima Chumak , Vlad Buslov , Saeed Mahameed Subject: [PATCH 5.10 101/252] net/mlx5e: Fix nullptr in add_vlan_push_action() Date: Mon, 31 May 2021 15:12:46 +0200 Message-Id: <20210531130701.428616818@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dima Chumak commit dca59f4a791960ec73fa15803faa0abe0f92ece2 upstream. The result of dev_get_by_index_rcu() is not checked for NULL and then gets dereferenced immediately. Also, the RCU lock must be held by the caller of dev_get_by_index_rcu(), which isn't satisfied by the call stack. Fix by handling nullptr return value when iflink device is not found. Add RCU locking around dev_get_by_index_rcu() to avoid possible adverse effects while iterating over the net_device's hlist. It is safe not to increment reference count of the net_device pointer in case of a successful lookup, because it's already handled by VLAN code during VLAN device registration (see register_vlan_dev and netdev_upper_dev_link). Fixes: 278748a95aa3 ("net/mlx5e: Offload TC e-switch rules with egress VLAN device") Addresses-Coverity: ("Dereference null return value") Signed-off-by: Dima Chumak Reviewed-by: Vlad Buslov Signed-off-by: Saeed Mahameed Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c @@ -4025,8 +4025,12 @@ static int add_vlan_push_action(struct m if (err) return err; - *out_dev = dev_get_by_index_rcu(dev_net(vlan_dev), - dev_get_iflink(vlan_dev)); + rcu_read_lock(); + *out_dev = dev_get_by_index_rcu(dev_net(vlan_dev), dev_get_iflink(vlan_dev)); + rcu_read_unlock(); + if (!*out_dev) + return -ENODEV; + if (is_vlan_dev(*out_dev)) err = add_vlan_push_action(priv, attr, out_dev, action);