Skip to content

Commit fdaff05

Browse files
committed
Daniel Borkmann says: ==================== pull-request: bpf 2023-07-05 We've added 2 non-merge commits during the last 1 day(s) which contain a total of 3 files changed, 16 insertions(+), 4 deletions(-). The main changes are: 1) Fix BTF to warn but not returning an error for a NULL BTF to still be able to load modules under CONFIG_DEBUG_INFO_BTF, from SeongJae Park. 2) Fix xsk sockets to honor SO_BINDTODEVICE in bind(), from Ilya Maximets. * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: xsk: Honor SO_BINDTODEVICE on bind bpf, btf: Warn but return no error for NULL btf from __register_btf_kfunc_id_set() ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents c451410 + f7306ac commit fdaff05

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Documentation/networking/af_xdp.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,15 @@ start N bytes into the buffer leaving the first N bytes for the
433433
application to use. The final option is the flags field, but it will
434434
be dealt with in separate sections for each UMEM flag.
435435

436+
SO_BINDTODEVICE setsockopt
437+
--------------------------
438+
439+
This is a generic SOL_SOCKET option that can be used to tie AF_XDP
440+
socket to a particular network interface. It is useful when a socket
441+
is created by a privileged process and passed to a non-privileged one.
442+
Once the option is set, kernel will refuse attempts to bind that socket
443+
to a different interface. Updating the value requires CAP_NET_RAW.
444+
436445
XDP_STATISTICS getsockopt
437446
-------------------------
438447

kernel/bpf/btf.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7891,10 +7891,8 @@ static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,
78917891
pr_err("missing vmlinux BTF, cannot register kfuncs\n");
78927892
return -ENOENT;
78937893
}
7894-
if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES)) {
7895-
pr_err("missing module BTF, cannot register kfuncs\n");
7896-
return -ENOENT;
7897-
}
7894+
if (kset->owner && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))
7895+
pr_warn("missing module BTF, cannot register kfuncs\n");
78987896
return 0;
78997897
}
79007898
if (IS_ERR(btf))

net/xdp/xsk.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
886886
struct sock *sk = sock->sk;
887887
struct xdp_sock *xs = xdp_sk(sk);
888888
struct net_device *dev;
889+
int bound_dev_if;
889890
u32 flags, qid;
890891
int err = 0;
891892

@@ -899,6 +900,10 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
899900
XDP_USE_NEED_WAKEUP))
900901
return -EINVAL;
901902

903+
bound_dev_if = READ_ONCE(sk->sk_bound_dev_if);
904+
if (bound_dev_if && bound_dev_if != sxdp->sxdp_ifindex)
905+
return -EINVAL;
906+
902907
rtnl_lock();
903908
mutex_lock(&xs->mutex);
904909
if (xs->state != XSK_READY) {

0 commit comments

Comments
 (0)