Re: [PATCH bpf] bpf: Ensure 8-byte alignment for lpm_trie map values

From: Alexei Starovoitov

Date: Mon Nov 23 2026 - 22:42:40 EST


On Thu, Nov 19, 2026 at 07:53 AM Tobias Philipp <tphilipp@xxxxxxxxx> wrote:
> In particular, for an IPv4 LPM trie (key_size = 8, data_size = 4), the
> map value base address is always 4-byte aligned (4 mod 8, and either 4
> or 12 mod 16). The verifier accepts 8-byte atomic operations

Only on 64-bit. On 32-bit that value is aligned today and this patch
breaks it. The node comes from bpf_mem_cache_alloc():

return !ret ? NULL : ret + LLIST_NODE_SZ;

LLIST_NODE_SZ is sizeof(struct llist_node). That's 4 bytes on 32-bit.
Offsets from the kmalloc() pointer for data_size == 4:

64-bit 32-bit
-------------------- ------------ ------------
node 8 4
node->data 32 20
value today 36, 4 mod 8 24, 0 mod 8
value with the patch 40, 0 mod 8 28, 4 mod 8

arm32 JIT doesn't support BPF_ATOMIC, so the interpreter calls
atomic64_add(). That's ldrexd on ARMv7. do_alignment() doesn't fix it up.
So a 64-bit atomic add on that value is fine today.
With the patch it's an oops.

> A standalone reproducer is available on request.

Pls add a _small_ selftest and target bpf-next.

> - u8 data[];
> + u8 data[] __aligned(8);

This changes nothing. data is at offset 24 or 16 already.
The node itself is misaligned. BPF_F_NO_PREALLOC hash and rhash have
the same bug on 32-bit.

> - return found->data + trie->data_size;
> + return found->data + round_up(trie->data_size, 8);

dev_map_lookup_elem() has the same problem on arm64.
It returns &obj->val:

offset 48 unsigned int idx;
offset 52 struct bpf_devmap_val val;

The map is read-only, but the verifier accepts a 64-bit load-acquire.
The JIT emits ldar. It faults without FEAT_LSE2.

pw-bot: cr