From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Tobias Philipp" <tphilipp@gmail.com>, <bpf@vger.kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Daniel Mack" <daniel@zonque.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf] bpf: Ensure 8-byte alignment for lpm_trie map values
Date: Tue, 24 Nov 2026 03:42:26 +0000 [thread overview]
Message-ID: <DN34PDK3NDWW.7JWY08DGJX89@gmail.com> (raw)
In-Reply-To: <20261119155317.11469-1-tphilipp@gmail.com>
On Thu, Nov 19, 2026 at 07:53 AM Tobias Philipp <tphilipp@gmail.com> 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
prev parent reply other threads:[~2026-11-24 3:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 15:53 [PATCH bpf] bpf: Ensure 8-byte alignment for lpm_trie map values Tobias Philipp
2026-11-24 3:42 ` Alexei Starovoitov [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=DN34PDK3NDWW.7JWY08DGJX89@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=daniel@zonque.org \
--cc=eddyz87@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=tphilipp@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.