From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 249B92309B0; Mon, 10 Mar 2025 18:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741630441; cv=none; b=RpSkLCNzy1/0HNZAfOg4j3IIq37iEovkxrasXiiAGWO8ZjFwqfiVPDJs0113MGbp7il7nyqMUqKPqdDchNqXbiSdSo1VdZI4UNi1fggTp7S+yAilrWB40AwyDBo7ZErPbHndniSDRgVGRsxBoF5tpFX4T87HgIdpNcB2WA1GUfg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741630441; c=relaxed/simple; bh=gb2SQef8eSyb57oG3fELCW5jea5WpRyZp9kMKUlGlpE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HT8xUPJ6TClF8OsL/tOzLo/VnDaIcjW5Oq3sDOcrj6mbpj2iH03MyIhIYDh2rSgoke/qUEbk0sdsJOEi4P6ZkJWFx0cqLdx1mBYIaLQabIICvvQF1ZHMxKY2xjYfoXnYfx4vg7wuvYwi+0LsOi7G61MV/JiGSM0UvccgS5au8lI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OSImKDoy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="OSImKDoy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1CCFC4CEE5; Mon, 10 Mar 2025 18:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741630441; bh=gb2SQef8eSyb57oG3fELCW5jea5WpRyZp9kMKUlGlpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OSImKDoy5WBWmk3D0DpqjllsIMZfQovSG5v8pA+Bj0rkKtuFpuF71u00grI89MX9X tfJWI+ZkJQjTFgTbw98u4hdoVGdBmfXUWB/U4T1zOeCfbXc5oOHL5wR4cSMU9Sx5js tWVy4wDSER0XwhmrLrNuKOIvmMN3/no8mF1IrOFg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Dumazet , Kuniyuki Iwashima , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 407/620] openvswitch: use RCU protection in ovs_vport_cmd_fill_info() Date: Mon, 10 Mar 2025 18:04:13 +0100 Message-ID: <20250310170601.655974268@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170545.553361750@linuxfoundation.org> References: <20250310170545.553361750@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 90b2f49a502fa71090d9f4fe29a2f51fe5dff76d ] ovs_vport_cmd_fill_info() can be called without RTNL or RCU. Use RCU protection and dev_net_rcu() to avoid potential UAF. Fixes: 9354d4520342 ("openvswitch: reliable interface indentification in port dumps") Signed-off-by: Eric Dumazet Reviewed-by: Kuniyuki Iwashima Link: https://patch.msgid.link/20250207135841.1948589-6-edumazet@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/openvswitch/datapath.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 0fc98e89a1149..c28b56c309169 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -2058,6 +2058,7 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, { struct ovs_header *ovs_header; struct ovs_vport_stats vport_stats; + struct net *net_vport; int err; ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family, @@ -2074,12 +2075,15 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex)) goto nla_put_failure; - if (!net_eq(net, dev_net(vport->dev))) { - int id = peernet2id_alloc(net, dev_net(vport->dev), gfp); + rcu_read_lock(); + net_vport = dev_net_rcu(vport->dev); + if (!net_eq(net, net_vport)) { + int id = peernet2id_alloc(net, net_vport, GFP_ATOMIC); if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id)) - goto nla_put_failure; + goto nla_put_failure_unlock; } + rcu_read_unlock(); ovs_vport_get_stats(vport, &vport_stats); if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS, @@ -2097,6 +2101,8 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb, genlmsg_end(skb, ovs_header); return 0; +nla_put_failure_unlock: + rcu_read_unlock(); nla_put_failure: err = -EMSGSIZE; error: -- 2.39.5