Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp256731pxj; Thu, 20 May 2021 08:43:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXR/rZ27kdTOm0VDfhLrTNKHNVr2eAfH7Mc3AGvmVzUr08EAxzaVqLvGLh1fQgvXAFKJ+Q X-Received: by 2002:a05:6602:1584:: with SMTP id e4mr5825113iow.4.1621525396721; Thu, 20 May 2021 08:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621525396; cv=none; d=google.com; s=arc-20160816; b=JxwTMp0Lw3HV5xLtuEQ+UUX/Ie50PO0U6ZcQsuTAAhOS9kEYGtKYMtrmoF+P3POb7c kHFjZxYN/QmqIdJxk67mDUow6GhdN+e9HVTRm0j5vq5SpQzo4BZ2L9QV1XHs2f0DVg8L TMO9FuK2iW9hilgdmjdmkYD41OsvKh+sTrPOPpJrxgI4Nj1Tu8+3fKAbGdG/8KVRm6ew XTGcTpV681eZKSrMSI9qSPvGOaAg+2VVnLqTEisKRHXiEvD1tklRxWpXYk2tnS+3LHQg k6jB3w+Jvak519up1i8q6wMdZtxzD5v3xZk62/NVqg7k0lwbmTAVr3B1DJrljFow4UFI WCyA== 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=20MNMYCtzvtOUoHZszpak1bU4eZQ1c3aMMNdvdniRIU=; b=C2OuZsioOy7JMGOQgXIB0V6aExFVniPI/raRkvRxWQ982xfEWLvThPP9f46GUugnqt NtRHpKzLZ7R/z3Sr7mNSo84eeY2Rna07XaUj9Blq8Tq6sjquKHUXER1p5Z0AGCiUm5/w xWxxB4BpgD3QPFnT2+7132Sb6pj+M1N31pGV3aVoM4+P1wL2pq5UOahebe1i/HSClIKl 8AcUd3trafZIcbjsLoKyt3AfUXtlJVQE5/3LEC4OZb0TQEixfk+wcW8k5i7DOC7p50Ey SHo+MyXfxErk7puVZSsYONRv6R/ONqhoBFZOaf3LKHLaGnmH+bOSqJoONA3GdxKUQXDt usWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e2y30rnM; 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 j188si2815780jac.58.2021.05.20.08.43.02; Thu, 20 May 2021 08:43:16 -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=e2y30rnM; 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 S233033AbhETJhP (ORCPT + 99 others); Thu, 20 May 2021 05:37:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:34688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232153AbhETJex (ORCPT ); Thu, 20 May 2021 05:34:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EEE75613F8; Thu, 20 May 2021 09:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621502962; bh=9IxrApo8rYDwKarf69LkThytLQ4vYKr81K0TEJpWtSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e2y30rnMQVvNSki05liaUWdgPrdejADWHvqEIwfdCZRb1qBGBTqGMEPxUzR4U7tAv pHMnHdPyjASHqLd3BNP2wiGeHUYHNA+VyS6O9IZLReMXdMl2L2SWlqZq8cXvpH3/2e f+rv2RNUCgCN61hx4kNWW4ujCv70b+vhX+m1w+os= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Zhengming , Zhao Lei , Wang Xiaogang , Nikolay Aleksandrov , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 24/37] bridge: Fix possible races between assigning rx_handler_data and setting IFF_BRIDGE_PORT bit Date: Thu, 20 May 2021 11:22:45 +0200 Message-Id: <20210520092053.071466519@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092052.265851579@linuxfoundation.org> References: <20210520092052.265851579@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: Zhang Zhengming [ Upstream commit 59259ff7a81b9eb6213891c6451221e567f8f22f ] There is a crash in the function br_get_link_af_size_filtered, as the port_exists(dev) is true and the rx_handler_data of dev is NULL. But the rx_handler_data of dev is correct saved in vmcore. The oops looks something like: ... pc : br_get_link_af_size_filtered+0x28/0x1c8 [bridge] ... Call trace: br_get_link_af_size_filtered+0x28/0x1c8 [bridge] if_nlmsg_size+0x180/0x1b0 rtnl_calcit.isra.12+0xf8/0x148 rtnetlink_rcv_msg+0x334/0x370 netlink_rcv_skb+0x64/0x130 rtnetlink_rcv+0x28/0x38 netlink_unicast+0x1f0/0x250 netlink_sendmsg+0x310/0x378 sock_sendmsg+0x4c/0x70 __sys_sendto+0x120/0x150 __arm64_sys_sendto+0x30/0x40 el0_svc_common+0x78/0x130 el0_svc_handler+0x38/0x78 el0_svc+0x8/0xc In br_add_if(), we found there is no guarantee that assigning rx_handler_data to dev->rx_handler_data will before setting the IFF_BRIDGE_PORT bit of priv_flags. So there is a possible data competition: CPU 0: CPU 1: (RCU read lock) (RTNL lock) rtnl_calcit() br_add_slave() if_nlmsg_size() br_add_if() br_get_link_af_size_filtered() -> netdev_rx_handler_register ... // The order is not guaranteed ... -> dev->priv_flags |= IFF_BRIDGE_PORT; // The IFF_BRIDGE_PORT bit of priv_flags has been set -> if (br_port_exists(dev)) { // The dev->rx_handler_data has NOT been assigned -> p = br_port_get_rcu(dev); .... -> rcu_assign_pointer(dev->rx_handler_data, rx_handler_data); ... Fix it in br_get_link_af_size_filtered, using br_port_get_check_rcu() and checking the return value. Signed-off-by: Zhang Zhengming Reviewed-by: Zhao Lei Reviewed-by: Wang Xiaogang Suggested-by: Nikolay Aleksandrov Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/bridge/br_netlink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index a0a54482aabc..8a664148f57a 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -99,8 +99,9 @@ static size_t br_get_link_af_size_filtered(const struct net_device *dev, rcu_read_lock(); if (netif_is_bridge_port(dev)) { - p = br_port_get_rcu(dev); - vg = nbp_vlan_group_rcu(p); + p = br_port_get_check_rcu(dev); + if (p) + vg = nbp_vlan_group_rcu(p); } else if (dev->priv_flags & IFF_EBRIDGE) { br = netdev_priv(dev); vg = br_vlan_group_rcu(br); -- 2.30.2