From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org,
Soowan Park <swan2718@snu.ac.kr>
Cc: marek.lindner@mailbox.org, sw@simonwunderlich.de,
antonio@mandelbit.com, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
Soowan Park <swan2718@snu.ac.kr>, Tejun Heo <tj@kernel.org>
Subject: Re: [PATCH] batman-adv: fix DAT purge use-after-free on teardown
Date: Tue, 26 May 2026 09:30:07 +0200 [thread overview]
Message-ID: <14018241.uLZWGnKmhe@ripper> (raw)
In-Reply-To: <20260526064835.2233822-1-swan2718@snu.ac.kr>
[-- Attachment #1: Type: text/plain, Size: 2521 bytes --]
On Tuesday, 26 May 2026 08:48:35 CEST Soowan Park wrote:
> batadv_dat_purge() is a periodic delayed work that re-queues itself via
> batadv_dat_start_timer() at the end of each run. When the mesh interface
> is torn down, batadv_dat_free() calls cancel_delayed_work_sync() to stop
> the purge work before freeing the DAT hash table.
>
> However, cancel_delayed_work_sync() leaves the work in an enabled state.
> If the purge work is currently executing and re-queues itself before
> cancel_delayed_work_sync() internally marks it for cancellation, the
> newly queued work escapes cancellation. This re-queued work then fires
> after batadv_dat_hash_free() has already freed the hash table but before
> the pointer is set to NULL, causing __batadv_dat_purge() to operate on a
> dangling pointer that passes the NULL check, and spin indefinitely on a
> spinlock in freed memory.
You are talking about a re-queue by batadv_dat_start_timer(). This only
happens when the DAT gets initialized or via the worker (batadv_dat_purge)
itself. How can the worker which is cancelled (with sync) re-queue itself?
Isn't this breaking a guarantee of cancel_delayed_work_sync() or did I
misunderstand this part of the documentation?
"This is cancel_work_sync() for delayed works." [1]
"Cancel work and wait for its execution to finish. This function can be used
even if the work re-queues itself or migrates to another workqueue. On return
from this function, work is guaranteed to be not pending or executing on any
CPU as long as there aren’t racing enqueues." [2]
(the part "This function can be used even if the work re-queues itself" is
the important part here).
> Replace cancel_delayed_work_sync() with disable_delayed_work_sync(),
> which additionally disables the work so that any concurrent
> queue_delayed_work() call from the running batadv_dat_purge() is
> silently rejected. This guarantees no re-queued work can fire after
> disable_delayed_work_sync() returns.
I have no problem with using "disabled_*" everywhere (I even have a pending
patchset to use it - just to avoid problems with code changes in the future).
But since this is a fix which I don't get in the moment, I would like to
understand the problem you are describing better before applying it.
Regards,
Sven
[1] https://www.kernel.org/doc/html/v7.0/core-api/workqueue.html#c.cancel_delayed_work_sync
[2] https://www.kernel.org/doc/html/v7.0/core-api/workqueue.html#c.cancel_work_sync
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
prev parent reply other threads:[~2026-05-26 7:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 6:48 [PATCH] batman-adv: fix DAT purge use-after-free on teardown Soowan Park
2026-05-26 7:30 ` Sven Eckelmann [this message]
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=14018241.uLZWGnKmhe@ripper \
--to=sven@narfation.org \
--cc=antonio@mandelbit.com \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=marek.lindner@mailbox.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sw@simonwunderlich.de \
--cc=swan2718@snu.ac.kr \
--cc=tj@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