Skip to content

Commit 2c23817

Browse files
iii-iborkmann
authored andcommitted
bpf: allow narrow loads of some sk_reuseport_md fields with offset > 0
test_select_reuseport fails on s390 due to verifier rejecting test_select_reuseport_kern.o with the following message: ; data_check.eth_protocol = reuse_md->eth_protocol; 18: (69) r1 = *(u16 *)(r6 +22) invalid bpf_context access off=22 size=2 This is because on big-endian machines casts from __u32 to __u16 are generated by referencing the respective variable as __u16 with an offset of 2 (as opposed to 0 on little-endian machines). The verifier already has all the infrastructure in place to allow such accesses, it's just that they are not explicitly enabled for eth_protocol field. Enable them for eth_protocol field by using bpf_ctx_range instead of offsetof. Ditto for ip_protocol, bind_inany and len, since they already allow narrowing, and the same problem can arise when working with them. Fixes: 2dbb9b9 ("bpf: Introduce BPF_PROG_TYPE_SK_REUSEPORT") Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent c751798 commit 2c23817

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎net/core/filter.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8757,13 +8757,13 @@ sk_reuseport_is_valid_access(int off, int size,
87578757
return size == size_default;
87588758

87598759
/* Fields that allow narrowing */
8760-
case offsetof(struct sk_reuseport_md, eth_protocol):
8760+
case bpf_ctx_range(struct sk_reuseport_md, eth_protocol):
87618761
if (size < FIELD_SIZEOF(struct sk_buff, protocol))
87628762
return false;
87638763
/* fall through */
8764-
case offsetof(struct sk_reuseport_md, ip_protocol):
8765-
case offsetof(struct sk_reuseport_md, bind_inany):
8766-
case offsetof(struct sk_reuseport_md, len):
8764+
case bpf_ctx_range(struct sk_reuseport_md, ip_protocol):
8765+
case bpf_ctx_range(struct sk_reuseport_md, bind_inany):
8766+
case bpf_ctx_range(struct sk_reuseport_md, len):
87678767
bpf_ctx_record_field_size(info, size_default);
87688768
return bpf_ctx_narrow_access_ok(off, size, size_default);
87698769

0 commit comments

Comments
 (0)