Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3921213pxj; Mon, 21 Jun 2021 09:24:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKjMfmUDYQNA1NfHYow/5OumPHE6o0UM86FQSnGBLdVQZgdsEIlN9d39/KZPjpzlkrKv27 X-Received: by 2002:a17:907:728d:: with SMTP id dt13mr12207532ejc.390.1624292684064; Mon, 21 Jun 2021 09:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292684; cv=none; d=google.com; s=arc-20160816; b=LVl6vxWiFlLMzM/Z/m4YrNCchz0pmjI19DiyCLhL8hN0xX2G/Q45ZZ9yPcPp8OfeZf j3wuYM1zzLWL79SI2JelmYvLvjM7ISLbdQbPQaJhQUYlVzxYABoCMYioY3+rPpeJ2xJM tV+cjYtKOrf1mqG7m3Zm/H1QM/yYUY5ZWkIqydQJPFqtYPr03gxD6s3ZiSJXvhvo/0QZ h2Hz7xw8xwgd5AkIT5c+orjZWvTNyroaP2g0TFTwp8DliBI0els0bgPHTneX4utpju86 Ny6Y5CQ9PjamByc/skyf9+UEcza7DSQOlGj+49n7tIQOGnGC+16m6ycT8Q62bt2a7wtD vQyQ== 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=308YrqHGWnk3nd5X+BQX2c3O74R6sPPyycYZbdiDQ0A=; b=Yd68X8Y8kfeMfmnaFcU2uBrIAe5MBvpyw+vmdv0aiwQS0q50qXdiQ9NHVz2S8LuHL0 VTwC658LDaRlZhvTF/rOFbtEt+tIr+qKAkD25DsqL7J4E9heerUXC7qjtF93fkkwVieq zxdNkEAsK6E4YWJyNTs2XDnc3FVsyCL+gXlpyMNle8B+HvFq6KIhTQddzjlSsfeaBiqW PNG13MC4lZyyHLAeq+kxSXrk8lcyxlRDrbTDBO3bqdbi5iLmejIRKml8XVYB6SIJ8M8s /jKKtXdVkjVPWHZHEY+0kTz0l8lDO28fV3eydXJXrgRn7EKE82UGu+QWrA1lRk/Ax6Fg lz8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LWkb3FZb; 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 j3si4319954eds.548.2021.06.21.09.24.22; Mon, 21 Jun 2021 09:24:44 -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=LWkb3FZb; 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 S232214AbhFUQZm (ORCPT + 99 others); Mon, 21 Jun 2021 12:25:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:42544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231869AbhFUQYI (ORCPT ); Mon, 21 Jun 2021 12:24:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F85161361; Mon, 21 Jun 2021 16:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292458; bh=bvVWjjst/6gC7bJkUleLE7w8/ink/O+2lWVwNgYKnJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LWkb3FZbE7C5JDEhUChXJu80Yi9qoXTTgRHc6b/eLp9SgK89HrLK2JAN0QjkawJOm VltiNVB/dJjcRj6zI88l2E6tPYorK+tn3SRy2CeU9Pe4XITjb3Ge7/fejQC8EdfzrB YkgbbxKAcAwnWsa+K5PODs7Abl4AUqFeN8fPtf9o= 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.4 71/90] cfg80211: avoid double free of PMSR request Date: Mon, 21 Jun 2021 18:15:46 +0200 Message-Id: <20210621154906.557071252@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@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 @@ -293,6 +293,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; @@ -323,9 +324,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);