b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Remi Pommarel <repk@triplefau.lt>
To: Antonio Quartulli <a@unstable.cc>
Cc: Johannes Berg <johannes@sipsolutions.net>,
	linux-wireless@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] wifi: cfg80211: Lock wiphy in cfg80211_get_station
Date: Tue, 21 May 2024 14:15:56 +0200	[thread overview]
Message-ID: <ZkyQfL6JjJBTHtwN@pilgrim> (raw)
In-Reply-To: <cef03d6c-7be8-4527-b38b-eadca2789f9b@unstable.cc>

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.

> 
> > 
> > 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.

Thanks,

-- 
Remi



  reply	other threads:[~2024-05-21 12:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-18 15:50 [PATCH] wifi: cfg80211: Lock wiphy in cfg80211_get_station Remi Pommarel
2024-05-21  7:01 ` Nicolas Escande
2024-05-21  7:12 ` Johannes Berg
2024-05-21  7:43 ` Antonio Quartulli
2024-05-21 12:15   ` Remi Pommarel [this message]
2024-05-21 14:51     ` Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZkyQfL6JjJBTHtwN@pilgrim \
    --to=repk@triplefau.lt \
    --cc=a@unstable.cc \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).