Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4445151rwb; Tue, 6 Sep 2022 07:38:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR7uMwV0pYjRj4foTkbfAxy6LdNqmxXGgX3iqZoL7qKvb6L0lE66PnSqtHCWd8hPM9opFLOl X-Received: by 2002:a17:906:8a79:b0:76f:55ff:5ced with SMTP id hy25-20020a1709068a7900b0076f55ff5cedmr1725396ejc.765.1662475121872; Tue, 06 Sep 2022 07:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662475121; cv=none; d=google.com; s=arc-20160816; b=cFsEpvU9pyWg+ZtmOyrgNlGxTYt9hgbdfDivkwj2B8eProOaH8SaGjWTN3ELPERqK/ HBKfPxEFzdMnEPAzvMtM8eVGdZHr4FhmcxkzbaDWQqgvO8WzXtHRnuTeWSRLy44Bd6bk 1e8eUZFdcl4KZxExUrTcuPnqTUaTrQxl0ipYGtTHW1xQiHtf+7A2E3ztarIsSsSkP2nF RBVp1SvLnZwaHHUJgIiPrqoF3DYL0WYjQsPNzVukmVO4WUf3QWCs7oOBK2yJr0mrdTfw yV8+qaYrL+9y6fOGn0D7XDpQB8okVR+7wX7B5HS+dMTiacD8ABbLbXJ3Lfc3aXhKZUpo cVTg== 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=9IxVhFSmBEFzZFC3zLGsGPABKirsnMVBbVLDrL5EsYs=; b=RxEOAzyJHozZM48Rqp9v2wyQU1e4f6qfGwA6TbOFAeHjXn1R4kHqr1lyXU9pn8u99R x/MOGhyEQhXYMzvYA1dyzRaaYRxo7UAf9Ou5r+16xewfE/FTQd/Iqyef59lqZV+GZF9t A1zR32ZGosluRNwdRWBrX/bcY3Ruc4JA549KAINfNN9vTZfu4flGisWwZowGCe6imKz6 XWKEgz7Hjway3Z/UKh7Won2cLZQyIDY7XdtmZX3ZhOxvwy0zEdc4+gV9vgauVHuT6MpQ +mkZPEKBSDa1zTY7cPlXOorAyWiUsRVdzK3ylhNt1YsOrvwfc4ZHa82iPd7327UdiZzf mB8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0uWwmCVI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a1709064cc600b007418e87eea8si1028335ejt.770.2022.09.06.07.38.13; Tue, 06 Sep 2022 07:38:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0uWwmCVI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240816AbiIFOVO (ORCPT + 99 others); Tue, 6 Sep 2022 10:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241774AbiIFOSp (ORCPT ); Tue, 6 Sep 2022 10:18:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A72C325EB2; Tue, 6 Sep 2022 06:49:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D98261554; Tue, 6 Sep 2022 13:48:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65715C433D7; Tue, 6 Sep 2022 13:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662472138; bh=fP2ch1wSr3VNPDcYbIscPwWO18Bj7KdWa/tFLDyAr8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0uWwmCVIWFojZyUBsyfTJsv66a7kA0zWUsHRqObvCujpYGY6ELK9KeTv5p1zuIkRV D2MtN2HJvKfGBr9yBliO2JMonb3yF9MR0oMuTQUZrgrgKd3b/XRnMakQI2PYwkfKog v4GQEQV13sg0VoVYIZrmSswvGyunRrVRtsrT0qSA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f9acff9bf08a845f225d@syzkaller.appspotmail.com, Johannes Berg , Siddh Raman Pant , Johannes Berg Subject: [PATCH 5.19 140/155] wifi: mac80211: Fix UAF in ieee80211_scan_rx() Date: Tue, 6 Sep 2022 15:31:28 +0200 Message-Id: <20220906132835.366533720@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Siddh Raman Pant commit 60deb9f10eec5c6a20252ed36238b55d8b614a2c upstream. ieee80211_scan_rx() tries to access scan_req->flags after a null check, but a UAF is observed when the scan is completed and __ieee80211_scan_completed() executes, which then calls cfg80211_scan_done() leading to the freeing of scan_req. Since scan_req is rcu_dereference()'d, prevent the racing in __ieee80211_scan_completed() by ensuring that from mac80211's POV it is no longer accessed from an RCU read critical section before we call cfg80211_scan_done(). Cc: stable@vger.kernel.org Link: https://syzkaller.appspot.com/bug?extid=f9acff9bf08a845f225d Reported-by: syzbot+f9acff9bf08a845f225d@syzkaller.appspotmail.com Suggested-by: Johannes Berg Signed-off-by: Siddh Raman Pant Link: https://lore.kernel.org/r/20220819200340.34826-1-code@siddh.me Signed-off-by: Johannes Berg Signed-off-by: Greg Kroah-Hartman --- net/mac80211/scan.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -465,16 +465,19 @@ static void __ieee80211_scan_completed(s scan_req = rcu_dereference_protected(local->scan_req, lockdep_is_held(&local->mtx)); - if (scan_req != local->int_scan_req) { - local->scan_info.aborted = aborted; - cfg80211_scan_done(scan_req, &local->scan_info); - } RCU_INIT_POINTER(local->scan_req, NULL); RCU_INIT_POINTER(local->scan_sdata, NULL); local->scanning = 0; local->scan_chandef.chan = NULL; + synchronize_rcu(); + + if (scan_req != local->int_scan_req) { + local->scan_info.aborted = aborted; + cfg80211_scan_done(scan_req, &local->scan_info); + } + /* Set power back to normal operating levels. */ ieee80211_hw_config(local, 0);