Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3932096pxj; Mon, 21 Jun 2021 09:38:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP8y3YlrcH/ET/R7MsoViNEdJuHtgChftKNtXbOmGzAg05A45QccM54vZ0MbRJoBotSJvL X-Received: by 2002:a17:906:2dc2:: with SMTP id h2mr25375101eji.479.1624293516217; Mon, 21 Jun 2021 09:38:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293516; cv=none; d=google.com; s=arc-20160816; b=oex8SV6GwKWMvDLssyb9LLWF5OPYVIOMATjs/750ocMOR2DTdnG+Pu5zkOynOLN+C4 TfRriC8RE32dRb+xFWNUYULqyDwGgUyHHYrABNh34O4Rd31Cd87dD7lXAvlDHKMpMTR+ IHSUuhHojICH2W7zFjxrN0gi//KucOVlrNjDSrRKZDUimp4o83Qmqo2fjnvic+Yyn3wu h9+u+q6BClghVSd4EoCKJ1+FW5Lx6LbN0/FjZAUCA9P++C0OQa3OdZFKRNeJUj86flnK XenylnouvAxpJwsBP3bZk48SicoJCiADz1VXoU+iGvshQACEUCy2wgEcw3uZ9s477ZkF GqVg== 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=Qer7zZLVahNEBz9+atKpHU9eJQLDu5DYbwjf86uR0F+B+4SrZXnn6Dzjg5k3quURO3 hrr5pp0nurhoJgLlL2i816Hh6Isj4ZbikXrXYFi/3wzY24f+aBXv2PbkioMO8qJ3f1yO WUIOtb9EeGbiZ0gQCavtRUIdesNrR4XX02c779IZKWJcgn9nMTutXVRBJfnTLBF1zAGc jouymZ1soieA4A+4pmrchXhncMjKvUjdMqp6MA+yGpZIYmH5MOnW+hK0+1aGoJb6CUV8 5umu79HzH9Q5Fps1As5c05U9WLlH0MAt4E+dBw6bSbfwXsCYBCmntubZoXcfMK5no9NY dZjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vjROoTeJ; 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 z12si8074015edb.437.2021.06.21.09.38.13; Mon, 21 Jun 2021 09:38:36 -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=vjROoTeJ; 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 S232719AbhFUQhW (ORCPT + 99 others); Mon, 21 Jun 2021 12:37:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:56040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232246AbhFUQdN (ORCPT ); Mon, 21 Jun 2021 12:33:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3AD1161411; Mon, 21 Jun 2021 16:26:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292783; bh=83jq3viiSj6z8qlYsZ0Vfv/iGyQpkHRFzMx4UVz7zbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vjROoTeJ/Sxf2NtwRnkqCxFmlMe9JSrNl3Hi9TDjaNU9ajt9NkYmeSUR9tPwJt6Ai DZE/9QKfRw3v8qZf0QoR3jAv1OTZ2rZLMo7o22wR8zmKAf9Vwds0sQzZUdD0Cd6RR5 p5kp9sx/XJyz4IIqGMayhmduORu55/RSKza9NFZU= 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.10 129/146] cfg80211: avoid double free of PMSR request Date: Mon, 21 Jun 2021 18:15:59 +0200 Message-Id: <20210621154919.672936333@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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);