Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3942297pxj; Mon, 21 Jun 2021 09:52:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJH35q7TjwqBz+ris0v3bgSKqltLBKNUWh5YRaIwpyAwTdd+hsAPrZQodLpUEZH413+cHn X-Received: by 2002:a02:b19b:: with SMTP id t27mr13628493jah.29.1624294334468; Mon, 21 Jun 2021 09:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294334; cv=none; d=google.com; s=arc-20160816; b=Q42TwMymyt9NOgvmAeqvyrGHWb6PhkxhH2V0GSqPedfAYG3sqenrbjRmErrrw3INfn g2SiMJwp+5uQJV0ke2KdNocsHB1zDf+js6A+YfxwftHxyDTE7bsoz3m3UGKnCcklaF5L MB9t5lKprSkBzEw6vQoUbtIIlnVGRvSso0Ahs7THAV5icBz3Yp8icPeaPzBGZDpdFkv+ oc9Rmyi5RWfeoAu8U7ywkjeCm5jQ4WP3N9Su9G/qPNOgidLNE/ivJnXqTcQ1NC4EnF7r KA+4PClnCzz2E6icQi41OHeTMK5rvJ9XE/WTl7r0v3F7cwqA8cqLZiz8mJNEd7cKQCHW VSGw== 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=eWGSJG3ZT8M96lAd5X+hi+wNb1rZVqwY3WFTG6SM/Ec=; b=JOa6P4NIuQL0nSuV4SOIHhNsJI4TAhhvYkp26nGDRnll8Outgw8/T9LWxeutcH8/NI FyT2YYHe6kzclvbUuu2WmD//bH+asbdKOk7EIOyXGfqvkS+3yd1TUYuhfLFKTX0qpUPg Yswieq3E8dqI8Qzp19VsdzqIgsyNCAJ+ITTIuT1XPMn2oApuCR1JEO28OB3BpsMjp5Sb xYMuIcGOeyIBo4EEQXRAMd4cFw0ST/ZEUeUl2pXd0I55l2DEUQXs9LucyNXHPYm0NigC 5OIpLMA1BoInAz/4qoayDEcmhqQOBlhkgKSYOrp+K+6RKULY7kD/XEfZnm4zGRtde7n2 +VQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pOMoHraE; 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 u1si1341166jat.64.2021.06.21.09.52.01; Mon, 21 Jun 2021 09:52:14 -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=pOMoHraE; 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 S232767AbhFUQxb (ORCPT + 99 others); Mon, 21 Jun 2021 12:53:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:38074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233221AbhFUQt0 (ORCPT ); Mon, 21 Jun 2021 12:49:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 687AC6128C; Mon, 21 Jun 2021 16:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293268; bh=83jq3viiSj6z8qlYsZ0Vfv/iGyQpkHRFzMx4UVz7zbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pOMoHraEWQizGXZkJlztmu7rdSNXbCOtYvN8dm1n6/2kd0Il7QzoBWns47TirBTbM Q2aW/+9S2xjuUJrFrUJM1U1giAoiOnhWkywLui1stiDJFmH4oq1gB7zXinwpTlg1Bw lbYfTFWzb/u4ElBp+bWDleA/D9ssphO0Gzb6fNVo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Avraham Stern , Luca Coelho , Johannes Berg Subject: [PATCH 5.12 159/178] cfg80211: avoid double free of PMSR request Date: Mon, 21 Jun 2021 18:16:13 +0200 Message-Id: <20210621154928.162912186@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@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: Avraham Stern commit 0288e5e16a2e18f0b7e61a2b70d9037fc6e4abeb upstream. If cfg80211_pmsr_process_abort() moves all the PMSR requests that need to be freed into a local list before aborting and freeing them. As a result, it is possible that cfg80211_pmsr_complete() will run in parallel and free the same PMSR request. Fix it by freeing the request in cfg80211_pmsr_complete() only if it is still in the original pmsr list. Cc: stable@vger.kernel.org Fixes: 9bb7e0f24e7e ("cfg80211: add peer measurement with FTM initiator API") Signed-off-by: Avraham Stern Signed-off-by: Luca Coelho Link: https://lore.kernel.org/r/iwlwifi.20210618133832.1fbef57e269a.I00294bebdb0680b892f8d1d5c871fd9dbe785a5e@changeid Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/wireless/pmsr.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/net/wireless/pmsr.c +++ b/net/wireless/pmsr.c @@ -324,6 +324,7 @@ void cfg80211_pmsr_complete(struct wirel gfp_t gfp) { struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); + struct cfg80211_pmsr_request *tmp, *prev, *to_free = NULL; struct sk_buff *msg; void *hdr; @@ -354,9 +355,20 @@ free_msg: nlmsg_free(msg); free_request: spin_lock_bh(&wdev->pmsr_lock); - list_del(&req->list); + /* + * cfg80211_pmsr_process_abort() may have already moved this request + * to the free list, and will free it later. In this case, don't free + * it here. + */ + list_for_each_entry_safe(tmp, prev, &wdev->pmsr_list, list) { + if (tmp == req) { + list_del(&req->list); + to_free = req; + break; + } + } spin_unlock_bh(&wdev->pmsr_lock); - kfree(req); + kfree(to_free); } EXPORT_SYMBOL_GPL(cfg80211_pmsr_complete);