Patch "socket, bpf: fix possible use after free" has been added to the 4.13-stable tree
Subsystems (5)
This is a note to let you know that I've just added the patch titled
socket, bpf: fix possible use after free
to the 4.13-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
socket-bpf-fix-possible-use-after-free.patch
and it can be found in the queue-4.13 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From foo@baz Mon Oct 9 09:32:35 CEST 2017
From: Eric Dumazet <[email protected]>
Date: Mon, 2 Oct 2017 12:20:51 -0700
Subject: socket, bpf: fix possible use after free
From: Eric Dumazet <[email protected]>
[ Upstream commit eefca20eb20c66b06cf5ed09b49b1a7caaa27b7b ]
Starting from linux-4.4, 3WHS no longer takes the listener lock.
Since this time, we might hit a use-after-free in sk_filter_charge(), if the filter we got in the memcpy() of the listener content just happened to be replaced by a thread changing listener BPF filter.
To fix this, we need to make sure the filter refcount is not already zero before incrementing it again.
--- net/core/filter.c | 12 ++++++++---- net/core/sock.c | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-)
net/core/filter.c +8 -4
@@ -975,10 +975,14 @@ static bool __sk_filter_charge(struct sobool sk_filter_charge (struct sock *sk,struct sk_filter *fp) { -bool ret =__sk_filter_charge (sk, fp); -if (ret) -refcount_inc (&fp->refcnt); -return ret; +if (!refcount_inc_not_zero (&fp->refcnt)) +return false; + +if (!__sk_filter_charge (sk, fp)) { +sk_filter_release (fp); +return false; + } +return true; }static struct bpf_prog *bpf_migrate_filter (struct bpf_prog *fp)
net/core/sock.c +4 -1
@@ -1675,13 +1675,16 @@ struct sock *sk_clone_lock(const structsock_reset_flag (newsk,SOCK_DONE ); - filter =rcu_dereference_protected (newsk->sk_filter,1 ); +rcu_read_lock (); + filter =rcu_dereference (sk->sk_filter);if (filter !=NULL )/* though it's an empty new sock, the charging may fail * if sysctl_optmem_max was changed between creation of * original socket and cloning */ is_charged =sk_filter_charge (newsk, filter); +RCU_INIT_POINTER (newsk->sk_filter, filter); +rcu_read_unlock ();if (unlikely (!is_charged ||xfrm_sk_clone_policy (newsk, sk))) {/* We need to make sure that we don't uncharge the new
Patches currently in stable-queue which might be from [email protected] are
queue-4.13/packet-in-packet_do_bind-test-fanout-with-bind_lock-held.patch queue-4.13/socket-bpf-fix-possible-use-after-free.patch queue-4.13/bpf-do-not-disable-enable-bh-in-bpf_map_free_id.patch queue-4.13/packet-only-test-po-has_vnet_hdr-once-in-packet_snd.patch queue-4.13/8139too-revisit-napi_complete_done-usage.patch queue-4.13/net_sched-gen_estimator-fix-scaling-error-in-bytes-packets-samples.patch queue-4.13/tcp-fastopen-fix-on-syn-data-transmit-failure.patch queue-4.13/bpf-fix-bpf_tail_call-x64-jit.patch queue-4.13/net-set-sk_prot_creator-when-cloning-sockets-to-the-right-proto.patch queue-4.13/tcp-fix-data-delivery-rate.patch