From: sashiko-bot@kernel.org
To: "Artem Dinaburg" <artem@trailofbits.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.6.y] bpf: Defer work in bpf_timer_cancel_and_free
Date: Tue, 29 Sep 2026 03:20:01 +0000 [thread overview]
Message-ID: <20260929032002.0548A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260929030524.86560-1-artem@trailofbits.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: UAF in bpf_timer_cb due to deferred map element cancellation
--
commit 7fae89f817868d5f5aa9bd764292b2373d1f4677
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Defer work in bpf_timer_cancel_and_free
This commit addresses a deadlock and use-after-free scenario in
bpf_timer_cancel_and_free() by deferring the cancellation of hrtimers to a
workqueue when running within a timer callback.
Link: https://lore.kernel.org/r/20240709185440.1104957-3-memxor@gmail.com
> diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
> --- a/kernel/bpf/helpers.c
> +++ b/kernel/bpf/helpers.c
[ ... ]
> @@ -1484,14 +1504,8 @@ void bpf_timer_cancel_and_free(void *val)
[ ... ]
> * CPU 1 (timer1_cb) CPU 2 (timer2_cb)
> * bpf_timer_cancel_and_free(timer2) bpf_timer_cancel_and_free(timer1)
> *
> * To avoid these issues, punt to workqueue context when we are in a
> * timer callback.
> */
> - if (this_cpu_read(hrtimer_running) != t)
> - hrtimer_cancel(&t->timer);
> - kfree_rcu(t, cb.rcu);
> + if (this_cpu_read(hrtimer_running))
> + queue_work(system_unbound_wq, &t->cb.delete_work);
[Severity: High]
Does punting the cancellation to a workqueue and returning immediately break
the synchronous cancellation guarantee?
If a BPF program running in a timer callback deletes an element containing a
second timer from a preallocated hash map (or updates an array map),
bpf_timer_cancel_and_free() defers hrtimer_cancel() to the workqueue and
returns immediately.
This allows the caller to immediately recycle the map element (pushing it
to a freelist for preallocated maps, or overwriting it in array maps)
without waiting for the timer callback to finish. If the second timer's
callback is currently executing on another CPU, it will continue to read
and write the map element data, which now belongs to a different key or
has been overwritten.
Can this lead to a use-after-free and data corruption in BPF map elements?
> + else
> + bpf_timer_delete_work(&t->cb.delete_work);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260929030524.86560-1-artem@trailofbits.com?part=1
next prev parent reply other threads:[~2026-09-29 3:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 3:05 [PATCH 6.6.y] bpf: Defer work in bpf_timer_cancel_and_free Artem Dinaburg
2026-09-29 3:20 ` sashiko-bot [this message]
2026-09-29 18:50 ` Sasha Levin
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=20260929032002.0548A1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=artem@trailofbits.com \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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