From patchwork Mon Aug 3 12:18:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266919 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C8A8C433DF for ; Mon, 3 Aug 2020 12:24:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E737B20738 for ; Mon, 3 Aug 2020 12:24:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457459; bh=ahdMLEdPqINOYkePbEv2vrNcKY0K7lgexArhC/5J5+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WW+zoJe+XbchaDb3cJVUXHXouMeZ6GZDnlTAW2gxlDTyI3bsBRpm413r25tOAoXV1 /NMh0BEPDInKUd56xrl+uVRhyBZ2xp90IQFm1Loy/5CePctOyKKW3623Zx/VIQ/G46 FmfdpdgV/eFGiutgUfw4Ctq4if3eWf4RDpcfbx+c= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727955AbgHCMYS (ORCPT ); Mon, 3 Aug 2020 08:24:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:48446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727889AbgHCMYL (ORCPT ); Mon, 3 Aug 2020 08:24:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AA30720738; Mon, 3 Aug 2020 12:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457447; bh=ahdMLEdPqINOYkePbEv2vrNcKY0K7lgexArhC/5J5+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WNwbLtJQvdlB1arlxizRauDddf+ZGq8YgeteSvUq62XoiOpIOCiN5X89lHtff3pov oGu0Jl5jJgWEb+Sz7lBlFYXkcRYXXh5I5Iiw+gDOQyIKc1RnqYQNZmMl61Q9rsFt7n hlF6H+WvAeIzt8YQTYJBiUeLf/EQxxoZySSq7Rh4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ido Schimmel , Jiri Pirko , "David S. Miller" , Sasha Levin Subject: [PATCH 5.7 071/120] mlxsw: core: Increase scope of RCU read-side critical section Date: Mon, 3 Aug 2020 14:18:49 +0200 Message-Id: <20200803121906.257694156@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121902.860751811@linuxfoundation.org> References: <20200803121902.860751811@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ido Schimmel [ Upstream commit 7d8e8f3433dc8d1dc87c1aabe73a154978fb4c4d ] The lifetime of the Rx listener item ('rxl_item') is managed using RCU, but is dereferenced outside of RCU read-side critical section, which can lead to a use-after-free. Fix this by increasing the scope of the RCU read-side critical section. Fixes: 93c1edb27f9e ("mlxsw: Introduce Mellanox switch driver core") Signed-off-by: Ido Schimmel Reviewed-by: Jiri Pirko Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlxsw/core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c index d6d6fe64887b3..5e76a96a118eb 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core.c @@ -2051,11 +2051,13 @@ void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb, break; } } - rcu_read_unlock(); - if (!found) + if (!found) { + rcu_read_unlock(); goto drop; + } rxl->func(skb, local_port, rxl_item->priv); + rcu_read_unlock(); return; drop: