Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2698885pxj; Mon, 31 May 2021 08:32:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3J1ycVB8CBQrrw88gz2mIc/nD5lBSgXziOnYtB6/JnUTs09hY2ykDzWuG1KopdPB++eAI X-Received: by 2002:a17:907:948c:: with SMTP id dm12mr7208098ejc.484.1622475130350; Mon, 31 May 2021 08:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622475130; cv=none; d=google.com; s=arc-20160816; b=Pv9JkoKbpqQCFec6Ofs+d1SNfawYZpLXURagVN5Nwt7iwGVKJtYo81JwFVUkKn6+1i PF+0cLWnBLxVxgvlz7VCv2qMLrtZ4yLWWEjO6/eO6umMuGUhGkEs5rUKvpxlIQ4vKj0D 4pxKg6Dclg08qQxnnzGmTcV5kNFI5z50u6DN9d8nU9RcsxQxayZhCF9WnvSlXBeW9CCw cS716SqyKsL30wnKtxOGD+ejO8xYvwDwfY7VbvLWx89Lqti1ewurDz7SJvxlHPcFHPz4 /jwH+FhgMWsg3jSG5wY8w2OOGJgJiC7WwugQG8XWnJMqWLeqvsW6OLN2Bk1QPlh3q6wo w3zw== 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=CtM5Az1tBhBW6bKpkHiJHyiSSXh/NeE5S/B6YmJymOs=; b=J6bbwuaPK/pZ4t4jqvvd8xGUuXssJt1wM5CnRD1hditE5mUECjbR+RUl6m33bmEqg9 6zzU7uUbtml0Z0229Tx+WmKSidBBFL4kpq25Armsl/fcfl4XPpuHzmJaGeTH5DxrZsnM 6P+rzN+MSvTnGdBoojs56xkS0seb3X/MKwsqcJ92Gp34Flz6wz+bo4GMCFe2r+RlwedY vyXRwviqzZiMf2B5LOZprC3D0KwWSXwaeoxvod3O6Bo96paJVO5OebeuNGhIuw8AM4uo wlwDUXHl4vqhWxI36aCrfZF2+ZOwrQH4UxEK4+tdmS+xkK5Tlhw5zhZvd7EBDMafASCV VqSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PhGfobfm; 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 h15si15395322ejq.124.2021.05.31.08.31.47; Mon, 31 May 2021 08:32:10 -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=PhGfobfm; 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 S234792AbhEaP3X (ORCPT + 99 others); Mon, 31 May 2021 11:29:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:46052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233478AbhEaOTH (ORCPT ); Mon, 31 May 2021 10:19:07 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0A00561493; Mon, 31 May 2021 13:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468651; bh=3Ni3jjMcqqxbHAMZygPQBjgxXpoqPMFRowJx8DM7sN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PhGfobfmirarNC5bKxwAGLqZV7XGiI+YLIBgWsL7Cg6ToqzvGTU2t32Ivmka/amfv zuyAdEwaTG6+X7AuIYhDD/6PkMu5jYz1z584knSe8dxYHD7qjfyCZZipvxveLSImOu Qed18FcmEU5PrPMA+6mW5LyrQECTsi+UieOE0nW8= 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.4 073/177] net/mlx5e: Fix nullptr in add_vlan_push_action() Date: Mon, 31 May 2021 15:13:50 +0200 Message-Id: <20210531130650.416982880@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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 @@ -3170,8 +3170,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);