Skip to content

Commit 20192d9

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Andrii Nakryiko says: ==================== pull-request: bpf 2021-07-15 The following pull-request contains BPF updates for your *net* tree. We've added 9 non-merge commits during the last 5 day(s) which contain a total of 9 files changed, 37 insertions(+), 15 deletions(-). The main changes are: 1) Fix NULL pointer dereference in BPF_TEST_RUN for BPF_XDP_DEVMAP and BPF_XDP_CPUMAP programs, from Xuan Zhuo. 2) Fix use-after-free of net_device in XDP bpf_link, from Xuan Zhuo. 3) Follow-up fix to subprog poke descriptor use-after-free problem, from Daniel Borkmann and John Fastabend. 4) Fix out-of-range array access in s390 BPF JIT backend, from Colin Ian King. 5) Fix memory leak in BPF sockmap, from John Fastabend. 6) Fix for sockmap to prevent proc stats reporting bug, from John Fastabend and Jakub Sitnicki. 7) Fix NULL pointer dereference in bpftool, from Tobias Klauser. 8) AF_XDP documentation fixes, from Baruch Siach. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents a6ecfb3 + d444b06 commit 20192d9

File tree

9 files changed

+37
-15
lines changed

9 files changed

+37
-15
lines changed

Documentation/networking/af_xdp.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,16 +243,16 @@ Configuration Flags and Socket Options
243243
These are the various configuration flags that can be used to control
244244
and monitor the behavior of AF_XDP sockets.
245245

246-
XDP_COPY and XDP_ZERO_COPY bind flags
247-
-------------------------------------
246+
XDP_COPY and XDP_ZEROCOPY bind flags
247+
------------------------------------
248248

249249
When you bind to a socket, the kernel will first try to use zero-copy
250250
copy. If zero-copy is not supported, it will fall back on using copy
251251
mode, i.e. copying all packets out to user space. But if you would
252252
like to force a certain mode, you can use the following flags. If you
253253
pass the XDP_COPY flag to the bind call, the kernel will force the
254254
socket into copy mode. If it cannot use copy mode, the bind call will
255-
fail with an error. Conversely, the XDP_ZERO_COPY flag will force the
255+
fail with an error. Conversely, the XDP_ZEROCOPY flag will force the
256256
socket into zero-copy mode or fail.
257257

258258
XDP_SHARED_UMEM bind flag

arch/s390/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static inline void reg_set_seen(struct bpf_jit *jit, u32 b1)
112112
{
113113
u32 r1 = reg2hex[b1];
114114

115-
if (!jit->seen_reg[r1] && r1 >= 6 && r1 <= 15)
115+
if (r1 >= 6 && r1 <= 15 && !jit->seen_reg[r1])
116116
jit->seen_reg[r1] = 1;
117117
}
118118

kernel/bpf/verifier.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3677,6 +3677,8 @@ static int check_max_stack_depth(struct bpf_verifier_env *env)
36773677
if (tail_call_reachable)
36783678
for (j = 0; j < frame; j++)
36793679
subprog[ret_prog[j]].tail_call_reachable = true;
3680+
if (subprog[0].tail_call_reachable)
3681+
env->prog->aux->tail_call_reachable = true;
36803682

36813683
/* end of for() loop means the last insn of the 'subprog'
36823684
* was reached. Doesn't matter whether it was JA or EXIT

net/bpf/test_run.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
701701
void *data;
702702
int ret;
703703

704+
if (prog->expected_attach_type == BPF_XDP_DEVMAP ||
705+
prog->expected_attach_type == BPF_XDP_CPUMAP)
706+
return -EINVAL;
704707
if (kattr->test.ctx_in || kattr->test.ctx_out)
705708
return -EINVAL;
706709

net/core/dev.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9712,14 +9712,17 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
97129712
struct net_device *dev;
97139713
int err, fd;
97149714

9715+
rtnl_lock();
97159716
dev = dev_get_by_index(net, attr->link_create.target_ifindex);
9716-
if (!dev)
9717+
if (!dev) {
9718+
rtnl_unlock();
97179719
return -EINVAL;
9720+
}
97189721

97199722
link = kzalloc(sizeof(*link), GFP_USER);
97209723
if (!link) {
97219724
err = -ENOMEM;
9722-
goto out_put_dev;
9725+
goto unlock;
97239726
}
97249727

97259728
bpf_link_init(&link->link, BPF_LINK_TYPE_XDP, &bpf_xdp_link_lops, prog);
@@ -9729,14 +9732,14 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
97299732
err = bpf_link_prime(&link->link, &link_primer);
97309733
if (err) {
97319734
kfree(link);
9732-
goto out_put_dev;
9735+
goto unlock;
97339736
}
97349737

9735-
rtnl_lock();
97369738
err = dev_xdp_attach_link(dev, NULL, link);
97379739
rtnl_unlock();
97389740

97399741
if (err) {
9742+
link->dev = NULL;
97409743
bpf_link_cleanup(&link_primer);
97419744
goto out_put_dev;
97429745
}
@@ -9746,6 +9749,9 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
97469749
dev_put(dev);
97479750
return fd;
97489751

9752+
unlock:
9753+
rtnl_unlock();
9754+
97499755
out_put_dev:
97509756
dev_put(dev);
97519757
return err;

net/core/skmsg.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,8 @@ static int sk_psock_skb_ingress_enqueue(struct sk_buff *skb,
508508
if (skb_linearize(skb))
509509
return -EAGAIN;
510510
num_sge = skb_to_sgvec(skb, msg->sg.data, 0, skb->len);
511-
if (unlikely(num_sge < 0)) {
512-
kfree(msg);
511+
if (unlikely(num_sge < 0))
513512
return num_sge;
514-
}
515513

516514
copied = skb->len;
517515
msg->sg.start = 0;
@@ -530,6 +528,7 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
530528
{
531529
struct sock *sk = psock->sk;
532530
struct sk_msg *msg;
531+
int err;
533532

534533
/* If we are receiving on the same sock skb->sk is already assigned,
535534
* skip memory accounting and owner transition seeing it already set
@@ -548,7 +547,10 @@ static int sk_psock_skb_ingress(struct sk_psock *psock, struct sk_buff *skb)
548547
* into user buffers.
549548
*/
550549
skb_set_owner_r(skb, sk);
551-
return sk_psock_skb_ingress_enqueue(skb, psock, sk, msg);
550+
err = sk_psock_skb_ingress_enqueue(skb, psock, sk, msg);
551+
if (err < 0)
552+
kfree(msg);
553+
return err;
552554
}
553555

554556
/* Puts an skb on the ingress queue of the socket already assigned to the
@@ -559,12 +561,16 @@ static int sk_psock_skb_ingress_self(struct sk_psock *psock, struct sk_buff *skb
559561
{
560562
struct sk_msg *msg = kzalloc(sizeof(*msg), __GFP_NOWARN | GFP_ATOMIC);
561563
struct sock *sk = psock->sk;
564+
int err;
562565

563566
if (unlikely(!msg))
564567
return -EAGAIN;
565568
sk_msg_init(msg);
566569
skb_set_owner_r(skb, sk);
567-
return sk_psock_skb_ingress_enqueue(skb, psock, sk, msg);
570+
err = sk_psock_skb_ingress_enqueue(skb, psock, sk, msg);
571+
if (err < 0)
572+
kfree(msg);
573+
return err;
568574
}
569575

570576
static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb,

net/ipv4/tcp_bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ static int __init tcp_bpf_v4_build_proto(void)
503503
tcp_bpf_rebuild_protos(tcp_bpf_prots[TCP_BPF_IPV4], &tcp_prot);
504504
return 0;
505505
}
506-
core_initcall(tcp_bpf_v4_build_proto);
506+
late_initcall(tcp_bpf_v4_build_proto);
507507

508508
static int tcp_bpf_assert_proto_ops(struct proto *ops)
509509
{

net/ipv4/udp_bpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int __init udp_bpf_v4_build_proto(void)
134134
udp_bpf_rebuild_protos(&udp_bpf_prots[UDP_BPF_IPV4], &udp_prot);
135135
return 0;
136136
}
137-
core_initcall(udp_bpf_v4_build_proto);
137+
late_initcall(udp_bpf_v4_build_proto);
138138

139139
int udp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore)
140140
{

tools/bpf/bpftool/common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ int mount_bpffs_for_pin(const char *name)
222222
int err = 0;
223223

224224
file = malloc(strlen(name) + 1);
225+
if (!file) {
226+
p_err("mem alloc failed");
227+
return -1;
228+
}
229+
225230
strcpy(file, name);
226231
dir = dirname(file);
227232

0 commit comments

Comments
 (0)