From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Greg KH <gregkh@linuxfoundation.org>,
Jiri Kosina <jikos@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>
Cc: Tero Kristo <tero.kristo@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
bpf@vger.kernel.org,
Benjamin Tissoires <benjamin.tissoires@redhat.com>
Subject: [RFC bpf-next v4 3/7] error-inject: add new type that carries if the function is non sleepable
Date: Thu, 21 Apr 2022 16:07:36 +0200 [thread overview]
Message-ID: <20220421140740.459558-4-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <20220421140740.459558-1-benjamin.tissoires@redhat.com>
When using error-injection function through bpf to change the return
code, we need to know if the function is sleepable or not.
Currently the code assumes that all error-inject functions are sleepable,
except for a few selected of them, hardcoded in kernel/bpf/verifier.c
Add a new flag to error-inject so we can code that information where the
function is declared.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
new in v4:
- another approach would be to define a new kfunc_set, and register
it with btf. But in that case, what program type would we use?
BPF_PROG_TYPE_UNSPEC?
- also note that maybe we should consider all of the functions
non-sleepable and only mark some as sleepable. IMO it makes more
sense to be more restrictive by default.
---
include/asm-generic/error-injection.h | 1 +
kernel/bpf/verifier.c | 10 ++++++++--
lib/error-inject.c | 2 ++
3 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h
index fbca56bd9cbc..5974942353a6 100644
--- a/include/asm-generic/error-injection.h
+++ b/include/asm-generic/error-injection.h
@@ -9,6 +9,7 @@ enum {
EI_ETYPE_ERRNO, /* Return -ERRNO if failure */
EI_ETYPE_ERRNO_NULL, /* Return -ERRNO or NULL if failure */
EI_ETYPE_TRUE, /* Return true if failure */
+ EI_ETYPE_NS_ERRNO, /* Return -ERRNO if failure and tag the function as non-sleepable */
};
struct error_injection_entry {
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 0f339f9058f3..45c8feea6478 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -14085,6 +14085,11 @@ static int check_non_sleepable_error_inject(u32 btf_id)
return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id);
}
+static int is_non_sleepable_error_inject(unsigned long addr)
+{
+ return get_injectable_error_type(addr) == EI_ETYPE_NS_ERRNO;
+}
+
int bpf_check_attach_target(struct bpf_verifier_log *log,
const struct bpf_prog *prog,
const struct bpf_prog *tgt_prog,
@@ -14281,8 +14286,9 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
/* fentry/fexit/fmod_ret progs can be sleepable only if they are
* attached to ALLOW_ERROR_INJECTION and are not in denylist.
*/
- if (!check_non_sleepable_error_inject(btf_id) &&
- within_error_injection_list(addr))
+ if (within_error_injection_list(addr) &&
+ !check_non_sleepable_error_inject(btf_id) &&
+ !is_non_sleepable_error_inject(addr))
ret = 0;
break;
case BPF_PROG_TYPE_LSM:
diff --git a/lib/error-inject.c b/lib/error-inject.c
index 2ff5ef689d72..560c3b18f439 100644
--- a/lib/error-inject.c
+++ b/lib/error-inject.c
@@ -183,6 +183,8 @@ static const char *error_type_string(int etype)
return "ERRNO_NULL";
case EI_ETYPE_TRUE:
return "TRUE";
+ case EI_ETYPE_NS_ERRNO:
+ return "NS_ERRNO";
default:
return "(unknown)";
}
--
2.35.1
next prev parent reply other threads:[~2022-04-21 14:08 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 14:07 [RFC bpf-next v4 0/7] Introduce eBPF support for HID devices (new attempt) Benjamin Tissoires
2022-04-21 14:07 ` [RFC bpf-next v4 1/7] bpf/btf: also allow kfunc in tracing programs Benjamin Tissoires
2022-04-21 14:07 ` [RFC bpf-next v4 2/7] bpf/verifier: allow kfunc to return an allocated mem Benjamin Tissoires
2022-04-26 4:08 ` Alexei Starovoitov
2022-04-26 7:30 ` Benjamin Tissoires
2022-04-30 3:25 ` Alexei Starovoitov
2022-04-30 7:17 ` Benjamin Tissoires
2022-04-21 14:07 ` Benjamin Tissoires [this message]
2022-04-26 4:11 ` [RFC bpf-next v4 3/7] error-inject: add new type that carries if the function is non sleepable Alexei Starovoitov
2022-04-26 7:52 ` Benjamin Tissoires
2022-04-30 3:29 ` Alexei Starovoitov
2022-04-30 7:24 ` Benjamin Tissoires
2022-04-21 14:07 ` [RFC bpf-next v4 4/7] btf: Add a new kfunc set which allows to mark a function to be sleepable Benjamin Tissoires
2022-04-26 4:12 ` Alexei Starovoitov
2022-04-21 14:07 ` [RFC bpf-next v4 5/7] HID: initial BPF new way implementation Benjamin Tissoires
2022-04-26 4:19 ` Alexei Starovoitov
2022-04-21 14:07 ` [RFC bpf-next v4 6/7] samples/bpf: add new hid_mouse example Benjamin Tissoires
2022-04-21 14:07 ` [RFC bpf-next v4 7/7] selftests/bpf: add tests for the HID-bpf initial implementation Benjamin Tissoires
2022-04-26 4:03 ` [RFC bpf-next v4 0/7] Introduce eBPF support for HID devices (new attempt) Alexei Starovoitov
2022-04-26 7:20 ` Benjamin Tissoires
2022-04-30 3:00 ` Alexei Starovoitov
2022-04-30 7:12 ` Benjamin Tissoires
2022-05-02 21:43 ` Benjamin Tissoires
2022-05-12 4:16 ` Alexei Starovoitov
2022-05-13 16:59 ` Benjamin Tissoires
2022-05-12 4:23 ` Alexei Starovoitov
2022-05-13 17:02 ` Benjamin Tissoires
2022-05-13 19:42 ` 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=20220421140740.459558-4-benjamin.tissoires@redhat.com \
--to=benjamin.tissoires@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=gregkh@linuxfoundation.org \
--cc=jikos@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=tero.kristo@linux.intel.com \
--cc=yhs@fb.com \
/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
all inboxes | Powered by JetHome®