Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3143915lqo; Tue, 21 May 2024 08:04:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWCBGje6DPG25tZm2JGTq5BEED35OOqs0cM11nuWxZFRC6LmwuoOZ8t/IDQbfvx1EGlWiK2jScCDubb0dpuLD/nhiVEf4A4n/j0oMCsDA== X-Google-Smtp-Source: AGHT+IGs+KMjNKiidpDSJragwNgfRa+Cg5PR84WAOGZb6Su/HgmtQ9+2IhWwOQgii6YRVdg5LDHW X-Received: by 2002:a17:903:244c:b0:1f2:ff65:d2d8 with SMTP id d9443c01a7336-1f2ff65d60bmr87904635ad.27.1716303889078; Tue, 21 May 2024 08:04:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716303889; cv=pass; d=google.com; s=arc-20160816; b=0ZFugaIec8TZ3Cy75Ea+eHd3kd7QfDZhYLVRBAu/WSf6v1hgFVUQJJMQ2NBdqBe1bF /Imrt2dfUnyiZrhGXFl2rw/ihiQ+Rl0L4x+uyCboLIIa7j4HWSROvlLlFFzayhP45XsV C5nAJalwwUiUOXMExfI7tKQTaOiJXIovFFopacO9LFCzhGXXIHJ5PxaDEW5K00jQQiIP WRd+FhX1cVOpTYww24QCdIwGdXd9MNxh2MK1kugmB7beBFCNvO8pDXDmULalmbJJjOMy 6Y04Jhje2fVbnKWYgq8en+zlilYtBIhAvCuU1PegWjDaSkEbXuQgw4fWPTVOaLOWWsjj SZOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=MTWDyIfN1nMlCSjPE8NjqxUc6JP4iiU+F5dmQzZPITE=; fh=LzaG/PX8cFLbza4KKWJvq+RgVXTeAtS/WHa+nRl7A30=; b=YtdMmxIePW1ff790BOPx63xvqoRuCmAagjmEqkY36yD9nrecFuDf87EaGbHxQhmv4i Te8SSJaMDSj6+n4AMNmDKj7SKzEF3xs45ZFQ4s5PZ661uTPVpgPiDTglGA6/zAS6N5QV cmykW/5I0hK7O/5NZCmMH21D9Bs79kl4r00dWSTWsead+h7KGYSxXQH9YB/xTF+ghBpi gL8qblJWGpmS6WmqEUQtQ/zQ28+dm1kEM2tLyDxGhPXO3jcoPiwb5Yb/sWXmR4F0UL4k IjiVGsSRlzjxkdLW/3uso2tkFh8Bam0X/areUEFcXpfIQDQ0h5fclyCTOdlxhHLgKP4D lQNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@unstable.cc header.s=20220809-q8oc header.b=g1r8ZGJC; arc=pass (i=1 spf=pass spfdomain=unstable.cc dkim=pass dkdomain=unstable.cc); spf=pass (google.com: domain of linux-wireless+bounces-7903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-wireless+bounces-7903-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d9443c01a7336-1f3062833c2si22808005ad.486.2024.05.21.08.04.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 08:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-7903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@unstable.cc header.s=20220809-q8oc header.b=g1r8ZGJC; arc=pass (i=1 spf=pass spfdomain=unstable.cc dkim=pass dkdomain=unstable.cc); spf=pass (google.com: domain of linux-wireless+bounces-7903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-wireless+bounces-7903-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 08A3DB24D15 for ; Tue, 21 May 2024 14:50:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9DE27EEED; Tue, 21 May 2024 14:50:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=unstable.cc header.i=a@unstable.cc header.b="g1r8ZGJC" X-Original-To: linux-wireless@vger.kernel.org Received: from wilbur.contactoffice.com (wilbur.contactoffice.com [212.3.242.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BB831E87C; Tue, 21 May 2024 14:50:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.3.242.68 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716303036; cv=none; b=a/CZXYCqsJBfD0FgqGibQzskUx5XH1HiBkOT4cUOn6qAVlhYHz9w7kVOVGEzYjtbzfRgxicyvodCgVPHkMGldI67cs++AY3BUs62BQelCJWlLmlvYps4azWYHXO9MsnEmwHLeeXl6+/ZR7ZXrw5zEklHp+ivuVwh9l93EJguyr0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716303036; c=relaxed/simple; bh=m5joeQgS5ScfS+qukuUUac9hQNUzKQ5pTLsn+sKIlt4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aKTbxAIU0LD3qqByBpGfEYi1ywAtd70Hylo+MVAjbSDa7PYPdZJSmxWpDqqy+YEVmU07vPuXVyIePwrZOnv/wVwfrLpgXVKKRLL7OBDXFHmkrheP/t6EPWTydPziM5JOPRz91TkivlBuA/zbBi9jXWYG/EOBX9rV9TjCzBtcvnU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unstable.cc; spf=pass smtp.mailfrom=unstable.cc; dkim=pass (2048-bit key) header.d=unstable.cc header.i=a@unstable.cc header.b=g1r8ZGJC; arc=none smtp.client-ip=212.3.242.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unstable.cc Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unstable.cc Received: from smtpauth2.co-bxl (smtpauth2.co-bxl [10.2.0.24]) by wilbur.contactoffice.com (Postfix) with ESMTP id 085FC8BB; Tue, 21 May 2024 16:50:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1716303029; s=20220809-q8oc; d=unstable.cc; i=a@unstable.cc; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Content-Type:Content-Transfer-Encoding; l=2420; bh=MTWDyIfN1nMlCSjPE8NjqxUc6JP4iiU+F5dmQzZPITE=; b=g1r8ZGJCvPKEJVDzNsmbjEr/8t9llqk4+N4hhyd59SoskJ/tnKd4gw9bnZX1W6hg cPhrz8+vGFbnC35LOKEaLPQKAWyhQgt7BfFJXtR0KmBaq7gQKcGwni4OWTnc58Apppv IbRZkeccQZZNu3+5fcK2mC6sInP0giNjk3KIv03+uwMRRzzZg4lhbFezthDktl4QDXo abDSwkVIRsKI0HcfHKtVobpCTvf6QgXBJzR4/XatSr93KNA7NvZduB9/mBvhaN5ps0x Deod4iTikmSVuIUxgWdW1A5lTTJxiW9fL6HfHUibzLyWMfGEDJhhORiZRm1LRGW2QgG /aLeLJILNQ== Received: by smtp.mailfence.com with ESMTPSA ; Tue, 21 May 2024 16:50:26 +0200 (CEST) Message-ID: Date: Tue, 21 May 2024 16:51:52 +0200 Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] wifi: cfg80211: Lock wiphy in cfg80211_get_station To: Remi Pommarel , Johannes Berg Cc: linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org References: <983b24a6a176e0800c01aedcd74480d9b551cb13.1716046653.git.repk@triplefau.lt> Content-Language: en-US From: Antonio Quartulli In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Flag: NO X-ContactOffice-Account: com:375058688 Hi, On 21/05/2024 14:15, Remi Pommarel wrote: > On Tue, May 21, 2024 at 09:43:56AM +0200, Antonio Quartulli wrote: >> Hi, >> >> On 18/05/2024 17:50, Remi Pommarel wrote: >>> Wiphy should be locked before calling rdev_get_station() (see lockdep >>> assert in ieee80211_get_station()). >> >> Adding the lock is fine as nowadays it is taken in pre_doit and released in >> post_doit (with some exceptions). Therefore when invoking .get_station from >> a side path the lock should be taken too. >> >> It was actually a05829a7222e9d10c416dd2dbbf3929fe6646b89 that introduced >> this requirement AFAICS. > > IIUC lock requirement was already there before this commit, only it was on > rtnl lock to be taken instead of wiphy one. You're right. > >> >>> >>> This fixes the following kernel NULL dereference: >> >> As already said by Johannes, I am not sure it truly fixes this NULL >> dereference though. >> >> Have you checked where in ath10k_sta_statistics this is exactly happening? >> Do you think some sta was partly released and thus fields were NULLified? > > ath10k_sta_statistics+0x10 is associated with the arsta->arvif->ar > statement. It crashes because arsta->arvif is NULL. > > Here is a scenario that explains the crash where the same sta > disconnects then reconnects quickly (e.g. OPEN network): > > > CPU0: CPU1: > > batadv_v_elp_periodic_work() > queue_work(batadv_v_elp_get_throughput) > > ieee80211_del_station() > ieee80211_add_station() > sta_info_insert() > list_add_tail_rcu() > ath10k_sta_state() > memset(arsta, 0, sizeof(arsta)) > batadv_v_elp_get_throughput() > cfg80211_get_station() > ieee80211_get_station() <-- Find sta with its MAC in list > ath10k_sta_statistics() > arsta->arvif->ar <-- arsta is still zeroed > > > In other words if the same sta has enough time to disconnect then > reconnect before batadv_v_elp_get_throughput get scheduled, sta could be > partially initialized when ath10k_sta_statistics() is called. Locking > the wiphy ensure sta is fully initialized if found. > We were just wondering how you could get the arvif being NULL and your explanation makes sense. This said, holding the lock is required when invoking get_station via netlink, therefore it's meaningful to hold it even when side invoking it from another module. Acked-by: Antonio Quartulli -- Antonio Quartulli