From: sashiko-bot@kernel.org
To: "Artem Dinaburg" <artem@trailofbits.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.1.y 2/2] bpf: Defer work in bpf_timer_cancel_and_free
Date: Sat, 03 Oct 2026 01:33:47 +0000 [thread overview]
Message-ID: <20261003013347.C10671F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20261002193020.19392-3-artem@trailofbits.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: Use-After-Free in bpf_timer_cb() due to deferred cancellation
--
commit 12eef63fe47026afa8702d0bccb135f5bc2594fe
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Defer work in bpf_timer_cancel_and_free
This commit addresses a deadlock and potential use-after-free situation in
the BPF timer subsystem by deferring timer cancellation to a workqueue when
invoked from within a timer callback context.
Link: https://lore.kernel.org/r/20240709185440.1104957-3-memxor@gmail.com
[Severity: High]
Does this deferred cancellation introduce a use-after-free when map elements
are freed synchronously?
Looking at kernel/bpf/helpers.c in bpf_timer_cancel_and_free() (around line
1476), the code defers the cancellation by calling queue_work() if
this_cpu_read(hrtimer_running) is true.
However, if a BPF program executing in a timer callback deletes a map
element containing another timer, the deletion path in kernel/bpf/hashtab.c
(in free_htab_elem) calls bpf_timer_cancel_and_free(). Because the
cancellation is now deferred, free_htab_elem() continues and synchronously
frees the map element, for example by pushing it to the PCPU freelist for
preallocated maps.
If the deferred timer is currently running on another CPU or fires before
the workqueue executes, bpf_timer_cb() in kernel/bpf/helpers.c (around line
1162) will execute. It extracts the value pointer from the timer and passes
it to the BPF program callback:
callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);
Since the map element containing this value was already freed by
free_htab_elem(), could this allow the BPF program to read or write freed
memory?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261002193020.19392-1-artem@trailofbits.com?part=2
next prev parent reply other threads:[~2026-10-03 1:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 19:30 [PATCH 6.1.y 0/2] bpf: backport CVE-2024-41045 and CVE-2024-42239 fixes Artem Dinaburg
2026-10-02 19:30 ` [PATCH 6.1.y 1/2] bpf: Fail bpf_timer_cancel when callback is being cancelled Artem Dinaburg
2026-10-02 19:30 ` [PATCH 6.1.y 2/2] bpf: Defer work in bpf_timer_cancel_and_free Artem Dinaburg
2026-10-03 1:33 ` sashiko-bot [this message]
2026-10-03 22:32 ` [PATCH 6.1.y 0/2] bpf: backport CVE-2024-41045 and CVE-2024-42239 fixes 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=20261003013347.C10671F000FF@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