Skip to content

Commit 74769d8

Browse files
author
Paolo Abeni
committed
Daniel Borkmann says: ==================== pull-request: bpf 2023-12-21 Hi David, hi Jakub, hi Paolo, hi Eric, The following pull-request contains BPF updates for your *net* tree. We've added 3 non-merge commits during the last 5 day(s) which contain a total of 4 files changed, 45 insertions(+). The main changes are: 1) Fix a syzkaller splat which triggered an oob issue in bpf_link_show_fdinfo(), from Jiri Olsa. 2) Fix another syzkaller-found issue which triggered a NULL pointer dereference in BPF sockmap for unconnected unix sockets, from John Fastabend. bpf-for-netdev * tag 'for-netdev' of https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf: bpf: Add missing BPF_LINK_TYPE invocations bpf: sockmap, test for unconnected af_unix sock bpf: syzkaller found null ptr deref in unix_bpf proto add ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents 24ab059 + 117211a commit 74769d8

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

include/linux/bpf_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,13 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter)
142142
#ifdef CONFIG_NET
143143
BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns)
144144
BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp)
145+
BPF_LINK_TYPE(BPF_LINK_TYPE_NETFILTER, netfilter)
146+
BPF_LINK_TYPE(BPF_LINK_TYPE_TCX, tcx)
147+
BPF_LINK_TYPE(BPF_LINK_TYPE_NETKIT, netkit)
145148
#endif
146149
#ifdef CONFIG_PERF_EVENTS
147150
BPF_LINK_TYPE(BPF_LINK_TYPE_PERF_EVENT, perf)
148151
#endif
149152
BPF_LINK_TYPE(BPF_LINK_TYPE_KPROBE_MULTI, kprobe_multi)
150153
BPF_LINK_TYPE(BPF_LINK_TYPE_STRUCT_OPS, struct_ops)
154+
BPF_LINK_TYPE(BPF_LINK_TYPE_UPROBE_MULTI, uprobe_multi)

include/net/sock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2799,6 +2799,11 @@ static inline bool sk_is_tcp(const struct sock *sk)
27992799
return sk->sk_type == SOCK_STREAM && sk->sk_protocol == IPPROTO_TCP;
28002800
}
28012801

2802+
static inline bool sk_is_stream_unix(const struct sock *sk)
2803+
{
2804+
return sk->sk_family == AF_UNIX && sk->sk_type == SOCK_STREAM;
2805+
}
2806+
28022807
/**
28032808
* sk_eat_skb - Release a skb if it is no longer needed
28042809
* @sk: socket to eat this skb from

net/core/sock_map.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ static bool sock_map_sk_state_allowed(const struct sock *sk)
536536
{
537537
if (sk_is_tcp(sk))
538538
return (1 << sk->sk_state) & (TCPF_ESTABLISHED | TCPF_LISTEN);
539+
if (sk_is_stream_unix(sk))
540+
return (1 << sk->sk_state) & TCPF_ESTABLISHED;
539541
return true;
540542
}
541543

tools/testing/selftests/bpf/prog_tests/sockmap_basic.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,37 @@ static void test_sockmap_skb_verdict_peek(void)
524524
test_sockmap_pass_prog__destroy(pass);
525525
}
526526

527+
static void test_sockmap_unconnected_unix(void)
528+
{
529+
int err, map, stream = 0, dgram = 0, zero = 0;
530+
struct test_sockmap_pass_prog *skel;
531+
532+
skel = test_sockmap_pass_prog__open_and_load();
533+
if (!ASSERT_OK_PTR(skel, "open_and_load"))
534+
return;
535+
536+
map = bpf_map__fd(skel->maps.sock_map_rx);
537+
538+
stream = xsocket(AF_UNIX, SOCK_STREAM, 0);
539+
if (stream < 0)
540+
return;
541+
542+
dgram = xsocket(AF_UNIX, SOCK_DGRAM, 0);
543+
if (dgram < 0) {
544+
close(stream);
545+
return;
546+
}
547+
548+
err = bpf_map_update_elem(map, &zero, &stream, BPF_ANY);
549+
ASSERT_ERR(err, "bpf_map_update_elem(stream)");
550+
551+
err = bpf_map_update_elem(map, &zero, &dgram, BPF_ANY);
552+
ASSERT_OK(err, "bpf_map_update_elem(dgram)");
553+
554+
close(stream);
555+
close(dgram);
556+
}
557+
527558
void test_sockmap_basic(void)
528559
{
529560
if (test__start_subtest("sockmap create_update_free"))
@@ -566,4 +597,7 @@ void test_sockmap_basic(void)
566597
test_sockmap_skb_verdict_fionread(false);
567598
if (test__start_subtest("sockmap skb_verdict msg_f_peek"))
568599
test_sockmap_skb_verdict_peek();
600+
601+
if (test__start_subtest("sockmap unconnected af_unix"))
602+
test_sockmap_unconnected_unix();
569603
}

0 commit comments

Comments
 (0)