Thread (15 messages) 15 messages, 2 authors, 2026-06-05

Re: [PATCH bpf-next v2 3/5] bpf: Compare parent_id in refsafe() for REF_TYPE_PTR

From: Amery Hung <hidden>
Date: 2026-06-05 20:00:47
Also in: bpf

On Fri, Jun 5, 2026 at 12:27 PM [off-list ref] wrote:
quoted
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 5945956a7573..06d9ae24f006 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -890,6 +890,9 @@ static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *c
                      return false;
              switch (old->refs[i].type) {
              case REF_TYPE_PTR:
+                     if (!check_ids(old->refs[i].parent_id, cur->refs[i].parent_id, idmap))
+                             return false;
+                     break;
              case REF_TYPE_IRQ:
                      break;
              case REF_TYPE_LOCK:
This change now feeds parent_id values through check_ids() in addition to
register and stack slot ids.

In the v1 discussion, Eduard Zingerman noted that since not all ids
correspond to register or stack slots anymore, the WARN_ON_ONCE(1) in
check_ids() on idmap exhaustion should be removed:

kernel/bpf/states.c:check_ids() {
        ...
        /* Reached the end of known mappings; haven't seen this id before */
        if (idmap->cnt < BPF_ID_MAP_SIZE) {
                map[idmap->cnt].old = old_id;
                map[idmap->cnt].cur = cur_id;
                idmap->cnt++;
                return true;
        }

        /* We ran out of idmap slots, which should be impossible */
        WARN_ON_ONCE(1);
        return false;
}

The concern raised by the CI and Sashiko bots was that a BPF program
leaking many references could exhaust BPF_ID_MAP_SIZE and trigger this
warning, which under panic_on_warn becomes a denial of service. Returning
false on exhaustion was agreed to be acceptable; only the warning was
questioned.

The reply on the thread acknowledged this ("Ack. I will drop
WARN_ON_ONCE(1)."), but the WARN_ON_ONCE(1) is still present in this commit.

Was the WARN_ON_ONCE(1) removal intended for a separate patch in the
series, or should it be folded in here?
This is dropped in patch 4
Reference:
https://lore.kernel.org/bpf/6d86c2fae9be63eb110ebd5b3fc19bc4cf1de2dc.camel@gmail.com/ (local)


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/27034008594
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help