Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp54443ybg; Mon, 8 Jun 2020 16:15:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU7RD9NApcMPdnhMkzR4mejN39PeDdhl73bjjH8temCpi5ltacmeO5xS84Lue6BwUJveyf X-Received: by 2002:a17:906:7d91:: with SMTP id v17mr23484479ejo.463.1591658112048; Mon, 08 Jun 2020 16:15:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591658112; cv=none; d=google.com; s=arc-20160816; b=0C1nG8tiys4a+x58w9XAPjaK9a0axifysQF3qD5l5IhLdIY6d4mI1IG9VZ+UKHZ2Jr kvjcDFMHmvfapBJEq4LFK8R2GjusU64cFXAoiAYWjlPVECfEF/qbHnMPMoK3SvKPsmBz MvWN7kDR4KU0Ugo4/n8s91JmVTB6EVUadMVkLL4JWcnipS5Pa7AssbpTUwzuguqGRaew yqTUjytD+oTDjyBdHxL745JiBw5MrQj6h+8kK36bjB3LFHKdeZ6rY8swuSNv59iHbnyI YowXVYVelHKmWXwX4kW4B5JQswQsNelArJ5jLdQsQbCDnQPiCuWYFHtK/RSmpbHdrDi5 teGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ntuMfNyBnSRTPE+XBEa4Cu4TvSD+sdUk8UKpZHy4tWg=; b=sclyPpijd5K3K9ceCc1sLeIy9BrWN06s+JgJW7CkE5l6eZUnPA413/OmYF92sv6DyT IfBpd9fdlkJelaCRVFki/5CA3Y/uRAd1EbBx+zjy1xTP2hD+JS7NcL2008g7lii0Z3HW fyUZVE2QiBw41mFcdsvIbOANd79WaQdovsLuvQn+QittxEbZEVQs0iz1KUZGTFoqMK6K N6Snf8y2k+/LvgbnLNNNjazcD4dg55kvPEVIodMzTDfz2e8uRdXNY7O6WW1FGydUY0gk 0nGSRdjZ8u9+39rf0VRKNNDLwiiLqFOK5j6aywef5OYuBbl7Z+s+lm+oj3YPxr+i6b5B 7oWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0VmBMrZa; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g30si10378724ede.28.2020.06.08.16.14.49; Mon, 08 Jun 2020 16:15:12 -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=@kernel.org header.s=default header.b=0VmBMrZa; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727980AbgFHXMg (ORCPT + 99 others); Mon, 8 Jun 2020 19:12:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:56910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728747AbgFHXKp (ORCPT ); Mon, 8 Jun 2020 19:10:45 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C651920897; Mon, 8 Jun 2020 23:10:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657844; bh=IAEmTo8r0QTBrTT1aCXKT7SMUHR0JX6FwVOf55EPqtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0VmBMrZaLfk8vkFANAePFo0o2uoc8rwD+6Xppr4HetC9OmAkJBHlPuts4LNJ3UoUH OCE2yEG3W7oFksGtmY8eZN5JZbr8Ez8lPZ5e/E3CdsOfKEjVkYzkcUvFQprak+7QUQ zRa7bPlmUFskKnqOsCSj3kpOovAtfr5wLPZm/PK8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= , Ganapathi Bhat , Kalle Valo , Sasha Levin , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 211/274] mwifiex: Fix memory corruption in dump_station Date: Mon, 8 Jun 2020 19:05:04 -0400 Message-Id: <20200608230607.3361041-211-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pali Rohár [ Upstream commit 3aa42bae9c4d1641aeb36f1a8585cd1d506cf471 ] The mwifiex_cfg80211_dump_station() uses static variable for iterating over a linked list of all associated stations (when the driver is in UAP role). This has a race condition if .dump_station is called in parallel for multiple interfaces. This corruption can be triggered by registering multiple SSIDs and calling, in parallel for multiple interfaces iw dev station dump [16750.719775] Unable to handle kernel paging request at virtual address dead000000000110 ... [16750.899173] Call trace: [16750.901696] mwifiex_cfg80211_dump_station+0x94/0x100 [mwifiex] [16750.907824] nl80211_dump_station+0xbc/0x278 [cfg80211] [16750.913160] netlink_dump+0xe8/0x320 [16750.916827] netlink_recvmsg+0x1b4/0x338 [16750.920861] ____sys_recvmsg+0x7c/0x2b0 [16750.924801] ___sys_recvmsg+0x70/0x98 [16750.928564] __sys_recvmsg+0x58/0xa0 [16750.932238] __arm64_sys_recvmsg+0x28/0x30 [16750.936453] el0_svc_common.constprop.3+0x90/0x158 [16750.941378] do_el0_svc+0x74/0x90 [16750.944784] el0_sync_handler+0x12c/0x1a8 [16750.948903] el0_sync+0x114/0x140 [16750.952312] Code: f9400003 f907f423 eb02007f 54fffd60 (b9401060) [16750.958583] ---[ end trace c8ad181c2f4b8576 ]--- This patch drops the use of the static iterator, and instead every time the function is called iterates to the idx-th position of the linked-list. It would be better to convert the code not to use linked list for associated stations storage (since the chip has a limited number of associated stations anyway - it could just be an array). Such a change may be proposed in the future. In the meantime this patch can backported into stable kernels in this simple form. Fixes: 8baca1a34d4c ("mwifiex: dump station support in uap mode") Signed-off-by: Pali Rohár Acked-by: Ganapathi Bhat Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20200515075924.13841-1-pali@kernel.org Signed-off-by: Sasha Levin --- drivers/net/wireless/marvell/mwifiex/cfg80211.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c index 1566d2197906..12bfd653a405 100644 --- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c +++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c @@ -1496,7 +1496,8 @@ mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev, int idx, u8 *mac, struct station_info *sinfo) { struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev); - static struct mwifiex_sta_node *node; + struct mwifiex_sta_node *node; + int i; if ((GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA) && priv->media_connected && idx == 0) { @@ -1506,13 +1507,10 @@ mwifiex_cfg80211_dump_station(struct wiphy *wiphy, struct net_device *dev, mwifiex_send_cmd(priv, HOST_CMD_APCMD_STA_LIST, HostCmd_ACT_GEN_GET, 0, NULL, true); - if (node && (&node->list == &priv->sta_list)) { - node = NULL; - return -ENOENT; - } - - node = list_prepare_entry(node, &priv->sta_list, list); - list_for_each_entry_continue(node, &priv->sta_list, list) { + i = 0; + list_for_each_entry(node, &priv->sta_list, list) { + if (i++ != idx) + continue; ether_addr_copy(mac, node->mac_addr); return mwifiex_dump_station_info(priv, node, sinfo); } -- 2.25.1