Skip to content

Commit a80afe8

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf
Daniel Borkmann says: ==================== pull-request: bpf 2018-09-02 The following pull-request contains BPF updates for your *net* tree. The main changes are: 1) Fix one remaining buggy offset override in sockmap's bpf_msg_pull_data() when linearizing multiple scatterlist elements, from Tushar. 2) Fix BPF sockmap's misuse of ULP when a collision with another ULP is found on map update where it would release existing ULP. syzbot found and triggered this couple of times now, fix from John. 3) Add missing xskmap type to bpftool so it will properly show the type on map dump, from Prashant. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 15a81b4 + 597222f commit a80afe8

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

kernel/bpf/sockmap.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,10 +1462,16 @@ static void smap_destroy_psock(struct rcu_head *rcu)
14621462
schedule_work(&psock->gc_work);
14631463
}
14641464

1465+
static bool psock_is_smap_sk(struct sock *sk)
1466+
{
1467+
return inet_csk(sk)->icsk_ulp_ops == &bpf_tcp_ulp_ops;
1468+
}
1469+
14651470
static void smap_release_sock(struct smap_psock *psock, struct sock *sock)
14661471
{
14671472
if (refcount_dec_and_test(&psock->refcnt)) {
1468-
tcp_cleanup_ulp(sock);
1473+
if (psock_is_smap_sk(sock))
1474+
tcp_cleanup_ulp(sock);
14691475
write_lock_bh(&sock->sk_callback_lock);
14701476
smap_stop_sock(psock, sock);
14711477
write_unlock_bh(&sock->sk_callback_lock);
@@ -1892,6 +1898,10 @@ static int __sock_map_ctx_update_elem(struct bpf_map *map,
18921898
* doesn't update user data.
18931899
*/
18941900
if (psock) {
1901+
if (!psock_is_smap_sk(sock)) {
1902+
err = -EBUSY;
1903+
goto out_progs;
1904+
}
18951905
if (READ_ONCE(psock->bpf_parse) && parse) {
18961906
err = -EBUSY;
18971907
goto out_progs;

net/core/filter.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
22922292
BPF_CALL_4(bpf_msg_pull_data,
22932293
struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags)
22942294
{
2295-
unsigned int len = 0, offset = 0, copy = 0;
2295+
unsigned int len = 0, offset = 0, copy = 0, poffset = 0;
22962296
int bytes = end - start, bytes_sg_total;
22972297
struct scatterlist *sg = msg->sg_data;
22982298
int first_sg, last_sg, i, shift;
@@ -2348,16 +2348,15 @@ BPF_CALL_4(bpf_msg_pull_data,
23482348
if (unlikely(!page))
23492349
return -ENOMEM;
23502350
p = page_address(page);
2351-
offset = 0;
23522351

23532352
i = first_sg;
23542353
do {
23552354
from = sg_virt(&sg[i]);
23562355
len = sg[i].length;
2357-
to = p + offset;
2356+
to = p + poffset;
23582357

23592358
memcpy(to, from, len);
2360-
offset += len;
2359+
poffset += len;
23612360
sg[i].length = 0;
23622361
put_page(sg_page(&sg[i]));
23632362

tools/bpf/bpftool/map.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static const char * const map_type_name[] = {
6868
[BPF_MAP_TYPE_DEVMAP] = "devmap",
6969
[BPF_MAP_TYPE_SOCKMAP] = "sockmap",
7070
[BPF_MAP_TYPE_CPUMAP] = "cpumap",
71+
[BPF_MAP_TYPE_XSKMAP] = "xskmap",
7172
[BPF_MAP_TYPE_SOCKHASH] = "sockhash",
7273
[BPF_MAP_TYPE_CGROUP_STORAGE] = "cgroup_storage",
7374
};

0 commit comments

Comments
 (0)