bpf: improve read-only handling
authorDaniel Borkmann <daniel@iogearbox.net>
Sat, 11 Mar 2017 15:55:49 +0000 (16:55 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 13 Mar 2017 06:51:34 +0000 (23:51 -0700)
commit65869a47f3488253f5fd88cc4f14e0a4e2601a55
treee34da15943fbe50adc5aeaac96fce51b0cedf8bf
parent1da8ac7c49fb2879ba95006d8bd1095e6870ea1a
bpf: improve read-only handling

Improve bpf_{prog,jit_binary}_{un,}lock_ro() by throwing a
one-time warning in case of an error when the image couldn't
be set read-only, and also mark struct bpf_prog as locked when
bpf_prog_lock_ro() was called.

Reason for the latter is that bpf_prog_unlock_ro() is called from
various places including error paths, and we shouldn't mess with
page attributes when really not needed.

For bpf_jit_binary_unlock_ro() this is not needed as jited flag
implicitly indicates this, thus for archs with ARCH_HAS_SET_MEMORY
we're guaranteed to have a previously locked image. Overall, this
should also help us to identify any further potential issues with
set_memory_*() helpers.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/filter.h