]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commit
bpf: sockmap, fix error handling in redirect failures
authorJohn Fastabend <john.fastabend@gmail.com>
Wed, 2 May 2018 20:50:29 +0000 (13:50 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 2 May 2018 22:30:45 +0000 (15:30 -0700)
commitabaeb096ca38cad02c8a68c49ddd7efc043c319a
tree789a726515dde9027f593db1f085e436341bcdc4
parentfec51d40ea65dd8f51a3e27fc69b4e7dc4f17776
bpf: sockmap, fix error handling in redirect failures

When a redirect failure happens we release the buffers in-flight
without calling a sk_mem_uncharge(), the uncharge is called before
dropping the sock lock for the redirecte, however we missed updating
the ring start index. When no apply actions are in progress this
is OK because we uncharge the entire buffer before the redirect.
But, when we have apply logic running its possible that only a
portion of the buffer is being redirected. In this case we only
do memory accounting for the buffer slice being redirected and
expect to be able to loop over the BPF program again and/or if
a sock is closed uncharge the memory at sock destruct time.

With an invalid start index however the program logic looks at
the start pointer index, checks the length, and when seeing the
length is zero (from the initial release and failure to update
the pointer) aborts without uncharging/releasing the remaining
memory.

The fix for this is simply to update the start index. To avoid
fixing this error in two locations we do a small refactor and
remove one case where it is open-coded. Then fix it in the
single function.

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/sockmap.c