linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Josef Bacik <josef@toxicpanda.com>,
	rostedt@goodmis.org, mingo@redhat.com, davem@davemloft.net,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	ast@kernel.org, kernel-team@fb.com
Cc: Josef Bacik <jbacik@fb.com>
Subject: Re: [PATCH 1/2] bpf: add a bpf_override_function helper
Date: Fri, 03 Nov 2017 00:12:13 +0100	[thread overview]
Message-ID: <59FBA64D.1050400@iogearbox.net> (raw)
In-Reply-To: <1509633431-2184-2-git-send-email-josef@toxicpanda.com>

Hi Josef,

one more issue I just noticed, see comment below:

On 11/02/2017 03:37 PM, Josef Bacik wrote:
[...]
> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index cdd78a7beaae..dfa44fd74bae 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -458,7 +458,8 @@ struct bpf_prog {
>   				locked:1,	/* Program image locked? */
>   				gpl_compatible:1, /* Is filter GPL compatible? */
>   				cb_access:1,	/* Is control block accessed? */
> -				dst_needed:1;	/* Do we need dst entry? */
> +				dst_needed:1,	/* Do we need dst entry? */
> +				kprobe_override:1; /* Do we override a kprobe? */
>   	kmemcheck_bitfield_end(meta);
>   	enum bpf_prog_type	type;		/* Type of BPF program */
>   	u32			len;		/* Number of filter blocks */
[...]
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index d906775e12c1..f8f7927a9152 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -4189,6 +4189,8 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
>   			prog->dst_needed = 1;
>   		if (insn->imm == BPF_FUNC_get_prandom_u32)
>   			bpf_user_rnd_init_once();
> +		if (insn->imm == BPF_FUNC_override_return)
> +			prog->kprobe_override = 1;
>   		if (insn->imm == BPF_FUNC_tail_call) {
>   			/* If we tail call into other programs, we
>   			 * cannot make any assumptions since they can
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index 9660ee65fbef..0d7fce52391d 100644
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -8169,6 +8169,13 @@ static int perf_event_set_bpf_prog(struct perf_event *event, u32 prog_fd)
>   		return -EINVAL;
>   	}
>
> +	/* Kprobe override only works for kprobes, not uprobes. */
> +	if (prog->kprobe_override &&
> +	    !(event->tp_event->flags & TRACE_EVENT_FL_KPROBE)) {
> +		bpf_prog_put(prog);
> +		return -EINVAL;
> +	}

Can we somehow avoid the prog->kprobe_override flag here completely
and also same in the perf_event_attach_bpf_prog() handler?

Reason is that it's not reliable for bailing out this way: Think of
the main program you're attaching doesn't use bpf_override_return()
helper, but it tail-calls into other BPF progs that make use of it
instead. So above check would be useless and will fail and we continue
to attach the prog for probes where it's not intended to be used.

We've had similar issues in the past e.g. c2002f983767 ("bpf: fix
checking xdp_adjust_head on tail calls") is just one of those. Thus,
can we avoid the flag altogether and handle such error case differently?

>   	if (is_tracepoint || is_syscall_tp) {
>   		int off = trace_event_get_offsets(event->tp_event);

Thanks,
Daniel

  reply	other threads:[~2017-11-02 23:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 14:37 [PATCH 0/2][v4] Add the ability to do BPF directed error injection Josef Bacik
2017-11-02 14:37 ` [PATCH 1/2] bpf: add a bpf_override_function helper Josef Bacik
2017-11-02 23:12   ` Daniel Borkmann [this message]
2017-11-03 14:31     ` Josef Bacik
2017-11-03 16:52       ` Daniel Borkmann
2017-11-03 21:07         ` Alexei Starovoitov
2017-11-02 14:37 ` [PATCH 2/2] samples/bpf: add a test for bpf_override_return Josef Bacik
  -- strict thread matches above, loose matches on Subject: below --
2017-11-07 20:28 [PATCH 0/2][v5] Add the ability to do BPF directed error injection Josef Bacik
2017-11-07 20:28 ` [PATCH 1/2] bpf: add a bpf_override_function helper Josef Bacik
2017-11-08  2:28   ` Daniel Borkmann
2017-11-10  9:34   ` Ingo Molnar
2017-11-10 17:14     ` Josef Bacik
2017-11-11  8:14       ` Ingo Molnar
2017-11-11 11:51         ` Josef Bacik
2017-11-12  6:49         ` Alexei Starovoitov
2017-11-12 10:38           ` Ingo Molnar
2017-11-13 15:57             ` Josef Bacik
2017-11-15  7:34               ` Ingo Molnar
2017-11-01 17:00 [PATCH 0/2][v3] Add the ability to do BPF directed error injection Josef Bacik
2017-11-01 17:00 ` [PATCH 1/2] bpf: add a bpf_override_function helper Josef Bacik
2017-11-01 17:18   ` Alexei Starovoitov
2017-11-02  1:08   ` Daniel Borkmann
2017-10-31 15:45 [PATCH 0/2][v2] Add the ability to do BPF directed error injection Josef Bacik
2017-10-31 15:45 ` [PATCH 1/2] bpf: add a bpf_override_function helper Josef Bacik
2017-11-01  4:47   ` Alexei Starovoitov
2017-10-30 21:19 [PATCH 0/2] Add the ability to do BPF directed error injection Josef Bacik
2017-10-30 21:19 ` [PATCH 1/2] bpf: add a bpf_override_function helper Josef Bacik
2017-10-31  1:35   ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=59FBA64D.1050400@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=ast@kernel.org \
    --cc=davem@davemloft.net \
    --cc=jbacik@fb.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).