From: KP Singh <kpsingh@chromium.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: linux-security-module@vger.kernel.org,
open list <linux-kernel@vger.kernel.org>,
bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Paul Turner <pjt@google.com>, Jann Horn <jannh@google.com>,
Florent Revest <revest@chromium.org>,
Brendan Jackman <jackmanb@chromium.org>
Subject: Re: [PATCH bpf-next v2 3/7] bpf: Introduce BPF_MODIFY_RETURN
Date: Wed, 4 Mar 2020 16:13:03 +0100 [thread overview]
Message-ID: <20200304151303.GC9984@chromium.org> (raw)
In-Reply-To: <CAEf4BzbbaiLC+-Gytwcx=i0XTniNH6YNsfOfx3nrU1oo73VsKw@mail.gmail.com>
On 03-Mär 21:08, Andrii Nakryiko wrote:
> On Tue, Mar 3, 2020 at 5:56 PM KP Singh <kpsingh@chromium.org> wrote:
> >
> > From: KP Singh <kpsingh@google.com>
> >
> > When multiple programs are attached, each program receives the return
> > value from the previous program on the stack and the last program
> > provides the return value to the attached function.
> >
> > The fmod_ret bpf programs are run after the fentry programs and before
> > the fexit programs. The original function is only called if all the
> > fmod_ret programs return 0 to avoid any unintended side-effects. The
> > success value, i.e. 0 is not currently configurable but can be made so
> > where user-space can specify it at load time.
> >
> > For example:
> >
> > int func_to_be_attached(int a, int b)
> > { <--- do_fentry
> >
> > do_fmod_ret:
> > <update ret by calling fmod_ret>
> > if (ret != 0)
> > goto do_fexit;
> >
> > original_function:
> >
> > <side_effects_happen_here>
> >
> > } <--- do_fexit
> >
> > The fmod_ret program attached to this function can be defined as:
> >
> > SEC("fmod_ret/func_to_be_attached")
> > int BPF_PROG(func_name, int a, int b, int ret)
> > {
> > // This will skip the original function logic.
> > return 1;
> > }
> >
> > The first fmod_ret program is passed 0 in its return argument.
> >
> > Signed-off-by: KP Singh <kpsingh@google.com>
> > ---
> > arch/x86/net/bpf_jit_comp.c | 130 ++++++++++++++++++++++++++++++---
> > include/linux/bpf.h | 1 +
> > include/uapi/linux/bpf.h | 1 +
> > kernel/bpf/btf.c | 3 +-
> > kernel/bpf/syscall.c | 1 +
> > kernel/bpf/trampoline.c | 5 +-
> > kernel/bpf/verifier.c | 1 +
> > tools/include/uapi/linux/bpf.h | 1 +
> > 8 files changed, 130 insertions(+), 13 deletions(-)
> >
>
> This looks good, but I'll Alexei check all the assembly generation
> logic, not too big of an expert on that.
>
> [...]
>
>
> > static int emit_fallback_jump(u8 **pprog)
> > diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> > index 98ec10b23dbb..3cfdc216a2f4 100644
> > --- a/include/linux/bpf.h
> > +++ b/include/linux/bpf.h
> > @@ -473,6 +473,7 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start);
> >
> > enum bpf_tramp_prog_type {
> > BPF_TRAMP_FENTRY,
> > + BPF_TRAMP_MODIFY_RETURN,
>
> This is probably bad idea to re-number BPF_TRAMP_FEXIT for no good
> reason. E.g., if there are some drgn scripts that do some internal
> state printing, this is major inconvenience, while really providing no
> benefit in itself. Consider putting it right before BPF_TRAMP_MAX.
Makes sense, I somehow initially (incorrectly) assumed that the order
represented the order of execution. But the only real demarcation
is the BPF_TRAMP_MAX. Updated it for v3.
- KP
>
> > BPF_TRAMP_FEXIT,
> > BPF_TRAMP_MAX,
> > BPF_TRAMP_REPLACE, /* more than MAX */
>
> [...]
next prev parent reply other threads:[~2020-03-04 15:13 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-04 1:55 [PATCH bpf-next v2 0/7] Introduce BPF_MODIFY_RET tracing progs KP Singh
2020-03-04 1:55 ` [PATCH bpf-next v2 1/7] bpf: Refactor trampoline update code KP Singh
2020-03-04 4:49 ` Andrii Nakryiko
2020-03-04 15:11 ` KP Singh
2020-03-04 1:55 ` [PATCH bpf-next v2 2/7] bpf: JIT helpers for fmod_ret progs KP Singh
2020-03-04 4:52 ` Andrii Nakryiko
2020-03-04 15:11 ` KP Singh
2020-03-04 15:24 ` KP Singh
2020-03-04 1:55 ` [PATCH bpf-next v2 3/7] bpf: Introduce BPF_MODIFY_RETURN KP Singh
2020-03-04 5:08 ` Andrii Nakryiko
2020-03-04 15:13 ` KP Singh [this message]
2020-03-04 1:55 ` [PATCH bpf-next v2 4/7] bpf: Attachment verification for BPF_MODIFY_RETURN KP Singh
2020-03-04 5:12 ` Andrii Nakryiko
2020-03-04 15:13 ` KP Singh
2020-03-04 1:55 ` [PATCH bpf-next v2 5/7] tools/libbpf: Add support " KP Singh
2020-03-04 1:55 ` [PATCH bpf-next v2 6/7] bpf: Add test ops for BPF_PROG_TYPE_TRACING KP Singh
2020-03-04 5:14 ` Andrii Nakryiko
2020-03-04 1:55 ` [PATCH bpf-next v2 7/7] bpf: Add selftests for BPF_MODIFY_RETURN KP Singh
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=20200304151303.GC9984@chromium.org \
--to=kpsingh@chromium.org \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jackmanb@chromium.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=pjt@google.com \
--cc=revest@chromium.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.