Skip to content

Commit d277598

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Daniel Borkmann says: ==================== pull-request: bpf 2020-10-22 1) Fix enforcing NULL check in verifier for new helper return types of RET_PTR_TO_{BTF_ID,MEM_OR_BTF_ID}_OR_NULL, from Martin KaFai Lau. 2) Fix bpf_redirect_neigh() helper API before it becomes frozen by adding nexthop information as argument, from Toke Høiland-Jørgensen. 3) Guard & fix compilation of bpf_tail_call_static() when __bpf__ arch is not defined by compiler or clang too old, from Daniel Borkmann. 4) Remove misplaced break after return in attach_type_to_prog_type(), from Tom Rix. ==================== Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents d9b0e59 + 3652c9a commit d277598

16 files changed

Lines changed: 426 additions & 102 deletions

File tree

MAINTAINERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3244,7 +3244,8 @@ R: KP Singh <kpsingh@chromium.org>
32443244
L: netdev@vger.kernel.org
32453245
L: bpf@vger.kernel.org
32463246
S: Supported
3247-
Q: https://patchwork.ozlabs.org/project/netdev/list/?delegate=77147
3247+
W: https://bpf.io/
3248+
Q: https://patchwork.kernel.org/project/netdevbpf/list/?delegate=121173
32483249
T: git git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git
32493250
T: git git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git
32503251
F: Documentation/bpf/

include/linux/filter.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,21 @@ struct bpf_skb_data_end {
607607
void *data_end;
608608
};
609609

610+
struct bpf_nh_params {
611+
u32 nh_family;
612+
union {
613+
u32 ipv4_nh;
614+
struct in6_addr ipv6_nh;
615+
};
616+
};
617+
610618
struct bpf_redirect_info {
611619
u32 flags;
612620
u32 tgt_index;
613621
void *tgt_value;
614622
struct bpf_map *map;
615623
u32 kern_flags;
624+
struct bpf_nh_params nh;
616625
};
617626

618627
DECLARE_PER_CPU(struct bpf_redirect_info, bpf_redirect_info);

include/uapi/linux/bpf.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,15 +3677,19 @@ union bpf_attr {
36773677
* Return
36783678
* The id is returned or 0 in case the id could not be retrieved.
36793679
*
3680-
* long bpf_redirect_neigh(u32 ifindex, u64 flags)
3680+
* long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
36813681
* Description
36823682
* Redirect the packet to another net device of index *ifindex*
36833683
* and fill in L2 addresses from neighboring subsystem. This helper
36843684
* is somewhat similar to **bpf_redirect**\ (), except that it
36853685
* populates L2 addresses as well, meaning, internally, the helper
3686-
* performs a FIB lookup based on the skb's networking header to
3687-
* get the address of the next hop and then relies on the neighbor
3688-
* lookup for the L2 address of the nexthop.
3686+
* relies on the neighbor lookup for the L2 address of the nexthop.
3687+
*
3688+
* The helper will perform a FIB lookup based on the skb's
3689+
* networking header to get the address of the next hop, unless
3690+
* this is supplied by the caller in the *params* argument. The
3691+
* *plen* argument indicates the len of *params* and should be set
3692+
* to 0 if *params* is NULL.
36893693
*
36903694
* The *flags* argument is reserved and must be 0. The helper is
36913695
* currently only supported for tc BPF program types, and enabled
@@ -4906,6 +4910,16 @@ struct bpf_fib_lookup {
49064910
__u8 dmac[6]; /* ETH_ALEN */
49074911
};
49084912

4913+
struct bpf_redir_neigh {
4914+
/* network family for lookup (AF_INET, AF_INET6) */
4915+
__u32 nh_family;
4916+
/* network address of nexthop; skips fib lookup to find gateway */
4917+
union {
4918+
__be32 ipv4_nh;
4919+
__u32 ipv6_nh[4]; /* in6_addr; network order */
4920+
};
4921+
};
4922+
49094923
enum bpf_task_fd_type {
49104924
BPF_FD_TYPE_RAW_TRACEPOINT, /* tp name */
49114925
BPF_FD_TYPE_TRACEPOINT, /* tp name */

kernel/bpf/syscall.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,6 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type)
29132913
case BPF_CGROUP_INET_INGRESS:
29142914
case BPF_CGROUP_INET_EGRESS:
29152915
return BPF_PROG_TYPE_CGROUP_SKB;
2916-
break;
29172916
case BPF_CGROUP_INET_SOCK_CREATE:
29182917
case BPF_CGROUP_INET_SOCK_RELEASE:
29192918
case BPF_CGROUP_INET4_POST_BIND:

kernel/bpf/verifier.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5133,24 +5133,19 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
51335133
regs[BPF_REG_0].id = ++env->id_gen;
51345134
} else {
51355135
regs[BPF_REG_0].type = PTR_TO_MAP_VALUE_OR_NULL;
5136-
regs[BPF_REG_0].id = ++env->id_gen;
51375136
}
51385137
} else if (fn->ret_type == RET_PTR_TO_SOCKET_OR_NULL) {
51395138
mark_reg_known_zero(env, regs, BPF_REG_0);
51405139
regs[BPF_REG_0].type = PTR_TO_SOCKET_OR_NULL;
5141-
regs[BPF_REG_0].id = ++env->id_gen;
51425140
} else if (fn->ret_type == RET_PTR_TO_SOCK_COMMON_OR_NULL) {
51435141
mark_reg_known_zero(env, regs, BPF_REG_0);
51445142
regs[BPF_REG_0].type = PTR_TO_SOCK_COMMON_OR_NULL;
5145-
regs[BPF_REG_0].id = ++env->id_gen;
51465143
} else if (fn->ret_type == RET_PTR_TO_TCP_SOCK_OR_NULL) {
51475144
mark_reg_known_zero(env, regs, BPF_REG_0);
51485145
regs[BPF_REG_0].type = PTR_TO_TCP_SOCK_OR_NULL;
5149-
regs[BPF_REG_0].id = ++env->id_gen;
51505146
} else if (fn->ret_type == RET_PTR_TO_ALLOC_MEM_OR_NULL) {
51515147
mark_reg_known_zero(env, regs, BPF_REG_0);
51525148
regs[BPF_REG_0].type = PTR_TO_MEM_OR_NULL;
5153-
regs[BPF_REG_0].id = ++env->id_gen;
51545149
regs[BPF_REG_0].mem_size = meta.mem_size;
51555150
} else if (fn->ret_type == RET_PTR_TO_MEM_OR_BTF_ID_OR_NULL ||
51565151
fn->ret_type == RET_PTR_TO_MEM_OR_BTF_ID) {
@@ -5199,6 +5194,9 @@ static int check_helper_call(struct bpf_verifier_env *env, int func_id, int insn
51995194
return -EINVAL;
52005195
}
52015196

5197+
if (reg_type_may_be_null(regs[BPF_REG_0].type))
5198+
regs[BPF_REG_0].id = ++env->id_gen;
5199+
52025200
if (is_ptr_cast_function(func_id)) {
52035201
/* For release_reference() */
52045202
regs[BPF_REG_0].ref_obj_id = meta.ref_obj_id;
@@ -7212,7 +7210,8 @@ static void mark_ptr_or_null_reg(struct bpf_func_state *state,
72127210
struct bpf_reg_state *reg, u32 id,
72137211
bool is_null)
72147212
{
7215-
if (reg_type_may_be_null(reg->type) && reg->id == id) {
7213+
if (reg_type_may_be_null(reg->type) && reg->id == id &&
7214+
!WARN_ON_ONCE(!reg->id)) {
72167215
/* Old offset (both fixed and variable parts) should
72177216
* have been known-zero, because we don't allow pointer
72187217
* arithmetic on pointers that might be NULL.

0 commit comments

Comments
 (0)