Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2684997imj; Mon, 11 Feb 2019 07:01:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IY1RR7MMrv0G8s8WDfKmjnc28ePFU+vxTg8l9vVPxgAClbeCravzfY/ri/a+vJ7kJH9UN05 X-Received: by 2002:a63:6cc8:: with SMTP id h191mr32760804pgc.366.1549897282814; Mon, 11 Feb 2019 07:01:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549897282; cv=none; d=google.com; s=arc-20160816; b=Bp/uH2IcAbbxoxpj7OWhF8aaSD5qesS3mNR7RLUilBm3Jj9cK3HJ7s72oCfzUTXdyM dnCbncHVLaRP3EvH6BbYCByOS8FSFHGxsGetT8CS0hsloPnNhKHdHDBx8if1XoUnYexL hW3Q0CLFT7zXroUj7O2P51q73EqaoqnXT+JX6BhnKGA6FYfLRujN0spdS8HBSD4bcPF3 3XPfEcnxi+IZ+a8z3WTjevKQ7czNsKm3jw/4LZdEuMT+2ZwmDoHcuMhatLXOQqnmfX+T 0QWcqGhXls0HXghip85wvUy+Bz/B81dmVGoUD6qOAJfvEXe1wtL+DQx/UsZCnIT4qM1I dHjA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QsoL5MmbvIHn2+4WTdlj0kTnYiRUA+Fw/H6vX2ziXnA=; b=rrZ4lPBNPU9Gi4AW4DzyCyYorjlIKOHYn3VfAk4Pkih6uUJOAMMCOagbX9PFZxOu69 y2F2dKn+kPPoX86/Imhb4OWLeAuvZJ7cYpacJwWx0rDPOnUfQJgZ8LVo1RpWnSgVL+zj ubLGQpisXodXU6h63lARS0xdCsLAEo0GJxyiocLAL8Nd9+2maJdlgmc8dMDlmxVgeaaO RdzSZq5k6ARrQYG4nIun5qUICSKGs4sRQMKej7laF4agdeCJ8lxR49isuKTUlD/JSbTL 4gVf4/ha8mDQPGxgwhO7f5v/sYGQBm+KwAqi4W97sNFl8nVllQ52G7iI4xYh488yJUrh WvaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FX5sReRx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 15si7877214pfq.11.2019.02.11.07.01.03; Mon, 11 Feb 2019 07:01:22 -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=FX5sReRx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389917AbfBKPAC (ORCPT + 99 others); Mon, 11 Feb 2019 10:00:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:47842 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727896AbfBKPAA (ORCPT ); Mon, 11 Feb 2019 10:00:00 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 3F1B2206BA; Mon, 11 Feb 2019 14:59:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897199; bh=yMEyF96nlmL8h4jjM3M4zj/XhLZeLh91c8jTTDmA2po=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FX5sReRxvXZ8N/J0mEZCt96XZ4DxYw1gNdBLOG2XiDzvvkN/0W+IDLWaADqrT1T4X QQGTIkjMC9OdJabI6zTt7TLN0U9dQcVHfhekj42tNYpFXAaDK9kQQjFzbhKUL+CS+Z 9J9DUdjAE7mdd2TMrASc7Mso6qOgnPQ/rsDNY4yY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jia-Ju Bai , Kalle Valo , Sasha Levin Subject: [PATCH 4.14 116/205] cw1200: Fix concurrency use-after-free bugs in cw1200_hw_scan() Date: Mon, 11 Feb 2019 15:18:34 +0100 Message-Id: <20190211141836.065387155@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 cc2ce60f4f09..f22c8ae15ad8 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