Commit df6f8237 authored by David S. Miller's avatar David S. Miller
Browse files


Daniel Borkmann says:

====================
pull-request: bpf 2021-05-11

The following pull-request contains BPF updates for your *net* tree.

We've added 13 non-merge commits during the last 8 day(s) which contain
a total of 21 files changed, 817 insertions(+), 382 deletions(-).

The main changes are:

1) Fix multiple ringbuf bugs in particular to prevent writable mmap of
   read-only pages, from Andrii Nakryiko & Thadeu Lima de Souza Cascardo.

2) Fix verifier alu32 known-const subregister bound tracking for bitwise
   operations and/or/xor, from Daniel Borkmann.

3) Reject trampoline attachment for functions with variable arguments,
   and also add a deny list of other forbidden functions, from Jiri Olsa.

4) Fix nested bpf_bprintf_prepare() calls used by various helpers by
   switching to per-CPU buffers, from Florent Revest.

5) Fix kernel compilation with BTF debug info on ppc64 due to pahole
   missing TCP-CC functions like cubictcp_init, from Martin KaFai Lau.

6) Add a kconfig entry to provide an option to disallow unprivileged
   BPF by default, from Daniel Borkmann.

7) Fix libbpf compilation for older libelf when GELF_ST_VISIBILITY()
   macro is not available, from Arnaldo Carvalho de Melo.

8) Migrate test_tc_redirect to test_progs framework as prep work
   for upcoming skb_change_head() fix & selftest, from Jussi Maki.

9) Fix a libbpf segfault in add_dummy_ksym_var() if BTF is not
   present, from Ian Rogers.

10) Fix tx_only micro-benchmark in xdpsock BPF sample with proper frame
    size, from Magnus Karlsson.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 9fe37a80 569c484f
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -1457,11 +1457,22 @@ unprivileged_bpf_disabled
=========================

Writing 1 to this entry will disable unprivileged calls to ``bpf()``;
once disabled, calling ``bpf()`` without ``CAP_SYS_ADMIN`` will return
``-EPERM``.
once disabled, calling ``bpf()`` without ``CAP_SYS_ADMIN`` or ``CAP_BPF``
will return ``-EPERM``. Once set to 1, this can't be cleared from the
running kernel anymore.

Once set, this can't be cleared.
Writing 2 to this entry will also disable unprivileged calls to ``bpf()``,
however, an admin can still change this setting later on, if needed, by
writing 0 or 1 to this entry.

If ``BPF_UNPRIV_DEFAULT_OFF`` is enabled in the kernel config, then this
entry will default to 2 instead of 0.

= =============================================================
0 Unprivileged calls to ``bpf()`` are enabled
1 Unprivileged calls to ``bpf()`` are disabled without recovery
2 Unprivileged calls to ``bpf()`` are disabled
= =============================================================

watchdog
========
+1 −40
Original line number Diff line number Diff line
@@ -442,6 +442,7 @@ config AUDITSYSCALL

source "kernel/irq/Kconfig"
source "kernel/time/Kconfig"
source "kernel/bpf/Kconfig"
source "kernel/Kconfig.preempt"

menu "CPU/Task time and stats accounting"
@@ -1713,46 +1714,6 @@ config KALLSYMS_BASE_RELATIVE

# syscall, maps, verifier

config BPF_LSM
	bool "LSM Instrumentation with BPF"
	depends on BPF_EVENTS
	depends on BPF_SYSCALL
	depends on SECURITY
	depends on BPF_JIT
	help
	  Enables instrumentation of the security hooks with eBPF programs for
	  implementing dynamic MAC and Audit Policies.

	  If you are unsure how to answer this question, answer N.

config BPF_SYSCALL
	bool "Enable bpf() system call"
	select BPF
	select IRQ_WORK
	select TASKS_TRACE_RCU
	select BINARY_PRINTF
	select NET_SOCK_MSG if INET
	default n
	help
	  Enable the bpf() system call that allows to manipulate eBPF
	  programs and maps via file descriptors.

config ARCH_WANT_DEFAULT_BPF_JIT
	bool

config BPF_JIT_ALWAYS_ON
	bool "Permanently enable BPF JIT and remove BPF interpreter"
	depends on BPF_SYSCALL && HAVE_EBPF_JIT && BPF_JIT
	help
	  Enables BPF JIT and removes BPF interpreter to avoid
	  speculative execution of BPF instructions by the interpreter

config BPF_JIT_DEFAULT_ON
	def_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON
	depends on HAVE_EBPF_JIT && BPF_JIT

source "kernel/bpf/preload/Kconfig"

config USERFAULTFD
	bool "Enable userfaultfd() system call"
	depends on MMU

kernel/bpf/Kconfig

0 → 100644
+88 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only

# BPF interpreter that, for example, classic socket filters depend on.
config BPF
	bool

# Used by archs to tell that they support BPF JIT compiler plus which
# flavour. Only one of the two can be selected for a specific arch since
# eBPF JIT supersedes the cBPF JIT.

# Classic BPF JIT (cBPF)
config HAVE_CBPF_JIT
	bool

# Extended BPF JIT (eBPF)
config HAVE_EBPF_JIT
	bool

# Used by archs to tell that they want the BPF JIT compiler enabled by
# default for kernels that were compiled with BPF JIT support.
config ARCH_WANT_DEFAULT_BPF_JIT
	bool

menu "BPF subsystem"

config BPF_SYSCALL
	bool "Enable bpf() system call"
	select BPF
	select IRQ_WORK
	select TASKS_TRACE_RCU
	select BINARY_PRINTF
	select NET_SOCK_MSG if INET
	default n
	help
	  Enable the bpf() system call that allows to manipulate BPF programs
	  and maps via file descriptors.

config BPF_JIT
	bool "Enable BPF Just In Time compiler"
	depends on HAVE_CBPF_JIT || HAVE_EBPF_JIT
	depends on MODULES
	help
	  BPF programs are normally handled by a BPF interpreter. This option
	  allows the kernel to generate native code when a program is loaded
	  into the kernel. This will significantly speed-up processing of BPF
	  programs.

	  Note, an admin should enable this feature changing:
	  /proc/sys/net/core/bpf_jit_enable
	  /proc/sys/net/core/bpf_jit_harden   (optional)
	  /proc/sys/net/core/bpf_jit_kallsyms (optional)

config BPF_JIT_ALWAYS_ON
	bool "Permanently enable BPF JIT and remove BPF interpreter"
	depends on BPF_SYSCALL && HAVE_EBPF_JIT && BPF_JIT
	help
	  Enables BPF JIT and removes BPF interpreter to avoid speculative
	  execution of BPF instructions by the interpreter.

config BPF_JIT_DEFAULT_ON
	def_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON
	depends on HAVE_EBPF_JIT && BPF_JIT

config BPF_UNPRIV_DEFAULT_OFF
	bool "Disable unprivileged BPF by default"
	depends on BPF_SYSCALL
	help
	  Disables unprivileged BPF by default by setting the corresponding
	  /proc/sys/kernel/unprivileged_bpf_disabled knob to 2. An admin can
	  still reenable it by setting it to 0 later on, or permanently
	  disable it by setting it to 1 (from which no other transition to
	  0 is possible anymore).

source "kernel/bpf/preload/Kconfig"

config BPF_LSM
	bool "Enable BPF LSM Instrumentation"
	depends on BPF_EVENTS
	depends on BPF_SYSCALL
	depends on SECURITY
	depends on BPF_JIT
	help
	  Enables instrumentation of the security hooks with BPF programs for
	  implementing dynamic MAC and Audit Policies.

	  If you are unsure how to answer this question, answer N.

endmenu # "BPF subsystem"
+12 −0
Original line number Diff line number Diff line
@@ -5206,6 +5206,12 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
	m->ret_size = ret;

	for (i = 0; i < nargs; i++) {
		if (i == nargs - 1 && args[i].type == 0) {
			bpf_log(log,
				"The function %s with variable args is unsupported.\n",
				tname);
			return -EINVAL;
		}
		ret = __get_type_size(btf, args[i].type, &t);
		if (ret < 0) {
			bpf_log(log,
@@ -5213,6 +5219,12 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
				tname, i, btf_kind_str[BTF_INFO_KIND(t->info)]);
			return -EINVAL;
		}
		if (ret == 0) {
			bpf_log(log,
				"The function %s has malformed void argument.\n",
				tname);
			return -EINVAL;
		}
		m->arg_size[i] = ret;
	}
	m->nr_args = nargs;
+14 −13
Original line number Diff line number Diff line
@@ -696,34 +696,35 @@ static int bpf_trace_copy_string(char *buf, void *unsafe_ptr, char fmt_ptype,
 */
#define MAX_PRINTF_BUF_LEN	512

struct bpf_printf_buf {
	char tmp_buf[MAX_PRINTF_BUF_LEN];
/* Support executing three nested bprintf helper calls on a given CPU */
struct bpf_bprintf_buffers {
	char tmp_bufs[3][MAX_PRINTF_BUF_LEN];
};
static DEFINE_PER_CPU(struct bpf_printf_buf, bpf_printf_buf);
static DEFINE_PER_CPU(int, bpf_printf_buf_used);
static DEFINE_PER_CPU(struct bpf_bprintf_buffers, bpf_bprintf_bufs);
static DEFINE_PER_CPU(int, bpf_bprintf_nest_level);

static int try_get_fmt_tmp_buf(char **tmp_buf)
{
	struct bpf_printf_buf *bufs;
	int used;
	struct bpf_bprintf_buffers *bufs;
	int nest_level;

	preempt_disable();
	used = this_cpu_inc_return(bpf_printf_buf_used);
	if (WARN_ON_ONCE(used > 1)) {
		this_cpu_dec(bpf_printf_buf_used);
	nest_level = this_cpu_inc_return(bpf_bprintf_nest_level);
	if (WARN_ON_ONCE(nest_level > ARRAY_SIZE(bufs->tmp_bufs))) {
		this_cpu_dec(bpf_bprintf_nest_level);
		preempt_enable();
		return -EBUSY;
	}
	bufs = this_cpu_ptr(&bpf_printf_buf);
	*tmp_buf = bufs->tmp_buf;
	bufs = this_cpu_ptr(&bpf_bprintf_bufs);
	*tmp_buf = bufs->tmp_bufs[nest_level - 1];

	return 0;
}

void bpf_bprintf_cleanup(void)
{
	if (this_cpu_read(bpf_printf_buf_used)) {
		this_cpu_dec(bpf_printf_buf_used);
	if (this_cpu_read(bpf_bprintf_nest_level)) {
		this_cpu_dec(bpf_bprintf_nest_level);
		preempt_enable();
	}
}
Loading