Skip to content

Commit

Permalink
bpf, net: Avoid loading module when calling bpf_setsockopt(TCP_CONGES…
Browse files Browse the repository at this point in the history
…TION)

When bpf prog changes tcp-cc by calling bpf_setsockopt(TCP_CONGESTION),
it should not try to load module which may be a blocking operation.
This details was correct in the v1 [0] but missed by mistake in the
later revision in commit cb388e7 ("bpf: net: Change do_tcp_setsockopt()
to use the sockopt's lock_sock() and capable()"). This patch fixes it by
checking the has_current_bpf_ctx().

  [0] https://lore.kernel.org/bpf/20220727060921.2373314-1-kafai@fb.com/

Fixes: cb388e7 ("bpf: net: Change do_tcp_setsockopt() to use the sockopt's lock_sock() and capable()")
Signed-off-by: Martin KaFai Lau <martin.lau@linux.dev>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220830231946.791504-1-martin.lau@linux.dev
  • Loading branch information
Martin KaFai Lau authored and Daniel Borkmann committed Aug 31, 2022
1 parent 14e5ce7 commit 84e5a0f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
name[val] = 0;

sockopt_lock_sock(sk);
err = tcp_set_congestion_control(sk, name, true,
err = tcp_set_congestion_control(sk, name, !has_current_bpf_ctx(),
sockopt_ns_capable(sock_net(sk)->user_ns,
CAP_NET_ADMIN));
sockopt_release_sock(sk);
Expand Down

0 comments on commit 84e5a0f

Please sign in to comment.