Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -9284,13 +9284,19 @@ static bool sock_addr_is_valid_access(int off, int size,
return false;
info->reg_type = PTR_TO_SOCKET;
break;
default:
case bpf_ctx_range(struct bpf_sock_addr, user_family):
case bpf_ctx_range(struct bpf_sock_addr, family):
case bpf_ctx_range(struct bpf_sock_addr, type):
case bpf_ctx_range(struct bpf_sock_addr, protocol):
if (type == BPF_READ) {
if (size != size_default)
return false;
} else {
return false;
}
break;
default:
return false;
}

return true;
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/bpf/progs/bpf_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@
#define __imm_ptr(name) [name]"r"(&name)
#define __imm_insn(name, expr) [name]"i"(*(long *)&(expr))

#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
#define offsetofend(TYPE, MEMBER) \
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))

/* Magic constants used with __retval() */
#define POINTER_VALUE 0xbadcafe
#define TEST_DATA_LEN 64
Expand Down
4 changes: 1 addition & 3 deletions tools/testing/selftests/bpf/progs/test_cls_redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "bpf_compiler.h"
#include "test_cls_redirect.h"
#include "bpf_misc.h"

#pragma GCC diagnostic ignored "-Waddress-of-packed-member"

Expand All @@ -31,9 +32,6 @@
#define INLINING __always_inline
#endif

#define offsetofend(TYPE, MEMBER) \
(offsetof(TYPE, MEMBER) + sizeof((((TYPE *)0)->MEMBER)))

#define IP_OFFSET_MASK (0x1FFF)
#define IP_MF (0x2000)

Expand Down
5 changes: 1 addition & 4 deletions tools/testing/selftests/bpf/progs/test_tcp_hdr_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
#include <bpf/bpf_endian.h>
#define BPF_PROG_TEST_TCP_HDR_OPTIONS
#include "test_tcp_hdr_options.h"

#ifndef sizeof_field
#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
#endif
#include "bpf_misc.h"

__u8 test_kind = TCPOPT_EXP;
__u16 test_magic = 0xeB9F;
Expand Down
26 changes: 24 additions & 2 deletions tools/testing/selftests/bpf/progs/verifier_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))

SEC("tc")
__description("context stores via BPF_ATOMIC")
__failure __msg("BPF_ATOMIC stores into R1 ctx is not allowed")
Expand Down Expand Up @@ -264,4 +262,28 @@ narrow_load("sockops", bpf_sock_ops, skb_hwtstamp);
unaligned_access("flow_dissector", __sk_buff, data);
unaligned_access("netfilter", bpf_nf_ctx, skb);

#define padding_access(type, ctx, prev_field, sz) \
SEC(type) \
__description("access on " #ctx " padding after " #prev_field) \
__naked void padding_ctx_access_##ctx(void) \
{ \
asm volatile (" \
r1 = *(u%[size] *)(r1 + %[off]); \
r0 = 0; \
exit;" \
: \
: __imm_const(size, sz * 8), \
__imm_const(off, offsetofend(struct ctx, prev_field)) \
: __clobber_all); \
}

__failure __msg("invalid bpf_context access")
padding_access("cgroup/bind4", bpf_sock_addr, msg_src_ip6[3], 4);

__success
padding_access("sk_lookup", bpf_sk_lookup, remote_port, 2);

__failure __msg("invalid bpf_context access")
padding_access("tc", __sk_buff, tstamp_type, 2);

char _license[] SEC("license") = "GPL";
4 changes: 0 additions & 4 deletions tools/testing/selftests/bpf/progs/verifier_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"

#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
#define offsetofend(TYPE, MEMBER) \
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))

struct {
__uint(type, BPF_MAP_TYPE_REUSEPORT_SOCKARRAY);
__uint(max_entries, 1);
Expand Down
Loading