Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3699838imu; Mon, 28 Jan 2019 09:15:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN5XwAkMvKqKSR7xhj8Om1RR9QQacPHze5A3VgGewKrvtnfHKVm29EYvtlj56iVyvCYNbakJ X-Received: by 2002:a62:1709:: with SMTP id 9mr22396337pfx.249.1548695716852; Mon, 28 Jan 2019 09:15:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695716; cv=none; d=google.com; s=arc-20160816; b=pFiz62eThKS0Cp9eaIqO4n/xXUJgsgKvsJrq9o3mTi5BDgt88LtDmQYaaR7k8N8yiR M6We0Omf4mNqBzo71XppwQJFdc4U9NWRsPcQkIR+IKXVZJE7q/MQgE4RySmECl+fLCCx zkVdfZ/IObD7K/X4Avk6iFopNLnMJ9BNxrcawtdvhd8PccxMUed5tS3s0XSu1tAiVpVf 5bvdyonbl4JjKvfdTBEVYbJ6i0Fl/TWOh3PfaqmTcXkmTdm9Rd7cHj+ipCeZ7/F7bAe3 hfwTQ8kR1sd3lmXnVB5XBv666QjrqAbB84urK7whm5TzVZuoyul961Gef/fOoIvKfSFX oEEg== 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=c/2Bxjd0FU9ZJ+PwHZGgMB5NLgfGmfP7Kbzk7fPBOd8=; b=NOW6A55nUg3VJUR+Hqz0GukUxml3Y7ietoZCsJcgD54gHip+ooaQLhsCrUCSTiEiuH JUSgE/2TKf5NSN/KzcfVf2yUquhPXd/XRaxVqGyxSj6pthIdd+dB0b2sDtIY/cyed+o7 0GdCXWZ4W5IgJsIbWoajnrzEwWA81bUA1tojPpZ6doQnlkjrrReNM//EC4jPX4vOBJMs CH5jLGigD/chCtu/qT76jU22QEOu4+xfn5wfsOc8d8lxe2f9+AqmVlR/Ro97HHfyHxBb 5leAEs5IiwagJ56MD7kJqvnh/8DvZVQeoUuYG7/WCtR9qQ1Si7pRO99jQgYhEhOy5Pye j0kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aQsJuV3G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id u21si1977924pgg.463.2019.01.28.09.14.59; Mon, 28 Jan 2019 09:15:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aQsJuV3G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1731930AbfA1RNL (ORCPT + 99 others); Mon, 28 Jan 2019 12:13:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:60342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730751AbfA1QI3 (ORCPT ); Mon, 28 Jan 2019 11:08:29 -0500 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 0E6F82147A; Mon, 28 Jan 2019 16:08:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691708; bh=Ya31zp4FLM1EhnlCS2TEnTvVz+C2ZIUHpbNTsNW9rzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQsJuV3GrM5eMKZvgMo0w5ekcS6n0m1z2upMoj1fzvIwYDpKmYg5gOL53UvpGU0he jvcRge1F5DSVPVL2YGegmDCdkuJh9kBxegBsIF/mL4Gts2IixgTrvSKcixsoQHXGUy oxI90bbAY6TjZK0HLkKN4CD6JZp+K61xP2MKn5fY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jia-Ju Bai , Kalle Valo , Sasha Levin , linux-wireless@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 193/258] cw1200: Fix concurrency use-after-free bugs in cw1200_hw_scan() Date: Mon, 28 Jan 2019 10:58:19 -0500 Message-Id: <20190128155924.51521-193-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 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: Jia-Ju Bai [ Upstream commit 4f68ef64cd7feb1220232bd8f501d8aad340a099 ] The function cw1200_bss_info_changed() and cw1200_hw_scan() can be concurrently executed. The two functions both access a possible shared variable "frame.skb". This shared variable is freed by dev_kfree_skb() in cw1200_upload_beacon(), which is called by cw1200_bss_info_changed(). The free operation is protected by a mutex lock "priv->conf_mutex" in cw1200_bss_info_changed(). In cw1200_hw_scan(), this shared variable is accessed without the protection of the mutex lock "priv->conf_mutex". Thus, concurrency use-after-free bugs may occur. To fix these bugs, the original calls to mutex_lock(&priv->conf_mutex) and mutex_unlock(&priv->conf_mutex) are moved to the places, which can protect the accesses to the shared variable. Signed-off-by: Jia-Ju Bai Signed-off-by: Kalle Valo Signed-off-by: Sasha Levin --- drivers/net/wireless/st/cw1200/scan.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/st/cw1200/scan.c b/drivers/net/wireless/st/cw1200/scan.c index 67213f11acbd..0a9eac93dd01 100644 --- a/drivers/net/wireless/st/cw1200/scan.c +++ b/drivers/net/wireless/st/cw1200/scan.c @@ -78,6 +78,10 @@ int cw1200_hw_scan(struct ieee80211_hw *hw, if (req->n_ssids > WSM_SCAN_MAX_NUM_OF_SSIDS) return -EINVAL; + /* will be unlocked in cw1200_scan_work() */ + down(&priv->scan.lock); + mutex_lock(&priv->conf_mutex); + frame.skb = ieee80211_probereq_get(hw, priv->vif->addr, NULL, 0, req->ie_len); if (!frame.skb) @@ -86,19 +90,15 @@ int cw1200_hw_scan(struct ieee80211_hw *hw, if (req->ie_len) skb_put_data(frame.skb, req->ie, req->ie_len); - /* will be unlocked in cw1200_scan_work() */ - down(&priv->scan.lock); - mutex_lock(&priv->conf_mutex); - ret = wsm_set_template_frame(priv, &frame); if (!ret) { /* Host want to be the probe responder. */ ret = wsm_set_probe_responder(priv, true); } if (ret) { + dev_kfree_skb(frame.skb); mutex_unlock(&priv->conf_mutex); up(&priv->scan.lock); - dev_kfree_skb(frame.skb); return ret; } @@ -120,10 +120,9 @@ int cw1200_hw_scan(struct ieee80211_hw *hw, ++priv->scan.n_ssids; } - mutex_unlock(&priv->conf_mutex); - if (frame.skb) dev_kfree_skb(frame.skb); + mutex_unlock(&priv->conf_mutex); queue_work(priv->workqueue, &priv->scan.work); return 0; } -- 2.19.1