Commit e7b09357 authored by Andrii Nakryiko's avatar Andrii Nakryiko
Browse files

Merge branch 'Allow bpf_user_ringbuf_drain() callbacks to return 1'



David Vernet says:

====================
The bpf_user_ringbuf_drain() helper function allows a BPF program to
specify a callback that is invoked when draining entries from a
BPF_MAP_TYPE_USER_RINGBUF ring buffer map. The API is meant to allow the
callback to return 0 if it wants to continue draining samples, and 1 if
it's done draining. Unfortunately, bpf_user_ringbuf_drain() landed shortly
after commit 1bfe26fb ("bpf: Add verifier support for custom
callback return range"), which changed the default behavior of callbacks
to only support returning 0, and the corresponding necessary change to
bpf_user_ringbuf_drain() callbacks was missed.

This patch set fixes this oversight, and updates the user_ringbuf
selftests to return 1 in a callback to catch future instances of
regression.
====================

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parents 0326074f 6e44b9f3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6946,6 +6946,7 @@ static int set_user_ringbuf_callback_state(struct bpf_verifier_env *env,
	__mark_reg_not_init(env, &callee->regs[BPF_REG_5]);

	callee->in_callback_fn = true;
	callee->callback_ret_range = tnum_range(0, 1);
	return 0;
}

+2 −2
Original line number Diff line number Diff line
@@ -47,14 +47,14 @@ record_sample(struct bpf_dynptr *dynptr, void *context)
		if (status) {
			bpf_printk("bpf_dynptr_read() failed: %d\n", status);
			err = 1;
			return 0;
			return 1;
		}
	} else {
		sample = bpf_dynptr_data(dynptr, 0, sizeof(*sample));
		if (!sample) {
			bpf_printk("Unexpectedly failed to get sample\n");
			err = 2;
			return 0;
			return 1;
		}
		stack_sample = *sample;
	}