Commit 72dc21a
bpf: Treat bpf_sk_lookup remote_port as a 2-byte field
In commit 9a69e2b ("bpf: Make remote_port field in struct
bpf_sk_lookup 16-bit wide") the remote_port field has been split up and
re-declared from u32 to be16.
However, the accompanying changes to the context access converter have not
been well thought through when it comes big-endian platforms.
Today 2-byte wide loads from offsetof(struct bpf_sk_lookup, remote_port)
are handled as narrow loads from a 4-byte wide field.
This by itself is not enough to create a problem, but when we combine
1. 32-bit wide access to ->remote_port backed by a 16-wide wide load, with
2. inherent difference between litte- and big-endian in how narrow loads
need have to be handled (see bpf_ctx_narrow_access_offset),
we get inconsistent results for a 2-byte loads from &ctx->remote_port on LE
and BE architectures. This in turn makes BPF C code for the common case of
2-byte load from ctx->remote_port not portable.
To rectify it, inform the context access converter that remote_port is
2-byte wide field, and only 1-byte loads need to be treated as narrow
loads.
At the same time, we special-case the 4-byte load from &ctx->remote_port to
continue handling it the same way as do today, in order to keep the
existing BPF programs working.
Fixes: 9a69e2b ("bpf: Make remote_port field in struct bpf_sk_lookup 16-bit wide")
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>1 parent 7d802ee commit 72dc21a
1 file changed
+18
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10989 | 10989 | | |
10990 | 10990 | | |
10991 | 10991 | | |
10992 | | - | |
10993 | | - | |
10994 | 10992 | | |
10995 | 10993 | | |
10996 | 10994 | | |
10997 | 10995 | | |
10998 | 10996 | | |
| 10997 | + | |
| 10998 | + | |
| 10999 | + | |
| 11000 | + | |
| 11001 | + | |
| 11002 | + | |
| 11003 | + | |
| 11004 | + | |
| 11005 | + | |
| 11006 | + | |
| 11007 | + | |
| 11008 | + | |
| 11009 | + | |
10999 | 11010 | | |
11000 | 11011 | | |
11001 | 11012 | | |
| |||
11077 | 11088 | | |
11078 | 11089 | | |
11079 | 11090 | | |
| 11091 | + | |
| 11092 | + | |
| 11093 | + | |
| 11094 | + | |
| 11095 | + | |
11080 | 11096 | | |
11081 | 11097 | | |
11082 | 11098 | | |
| |||
0 commit comments