Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1471072 > unrolled thread
| Started by | Alexei Starovoitov <ast@fb.com> |
|---|---|
| First post | 2016-08-27 04:40 +0200 |
| Last post | 2016-08-30 02:40 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH net-next 3/6] bpf: perf_event progs should only use preallocated maps Alexei Starovoitov <ast@fb.com> - 2016-08-27 04:40 +0200
Re: [PATCH net-next 3/6] bpf: perf_event progs should only use preallocated maps Daniel Borkmann <daniel@iogearbox.net> - 2016-08-30 02:40 +0200
| From | Alexei Starovoitov <ast@fb.com> |
|---|---|
| Date | 2016-08-27 04:40 +0200 |
| Subject | [PATCH net-next 3/6] bpf: perf_event progs should only use preallocated maps |
| Message-ID | <saBHj-793-1@gated-at.bofh.it> |
Make sure that BPF_PROG_TYPE_PERF_EVENT programs only use
preallocated hash maps, since doing memory allocation
in overflow_handler can crash depending on where nmi got triggered.
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
---
kernel/bpf/verifier.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index c1c9e441f0f5..48c2705db22c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -2511,6 +2511,20 @@ process_bpf_exit:
return 0;
}
+static int check_map_prog_compatibility(struct bpf_map *map,
+ struct bpf_prog *prog)
+
+{
+ if (prog->type == BPF_PROG_TYPE_PERF_EVENT &&
+ (map->map_type == BPF_MAP_TYPE_HASH ||
+ map->map_type == BPF_MAP_TYPE_PERCPU_HASH) &&
+ (map->map_flags & BPF_F_NO_PREALLOC)) {
+ verbose("perf_event programs can only use preallocated hash map\n");
+ return -EINVAL;
+ }
+ return 0;
+}
+
/* look for pseudo eBPF instructions that access map FDs and
* replace them with actual map pointers
*/
@@ -2518,7 +2532,7 @@ static int replace_map_fd_with_map_ptr(struct verifier_env *env)
{
struct bpf_insn *insn = env->prog->insnsi;
int insn_cnt = env->prog->len;
- int i, j;
+ int i, j, err;
for (i = 0; i < insn_cnt; i++, insn++) {
if (BPF_CLASS(insn->code) == BPF_LDX &&
@@ -2562,6 +2576,12 @@ static int replace_map_fd_with_map_ptr(struct verifier_env *env)
return PTR_ERR(map);
}
+ err = check_map_prog_compatibility(map, env->prog);
+ if (err) {
+ fdput(f);
+ return err;
+ }
+
/* store map pointer inside BPF_LD_IMM64 instruction */
insn[0].imm = (u32) (unsigned long) map;
insn[1].imm = ((u64) (unsigned long) map) >> 32;
--
2.8.0
[toc] | [next] | [standalone]
| From | Daniel Borkmann <daniel@iogearbox.net> |
|---|---|
| Date | 2016-08-30 02:40 +0200 |
| Subject | Re: [PATCH net-next 3/6] bpf: perf_event progs should only use preallocated maps |
| Message-ID | <sbFfP-5Zk-5@gated-at.bofh.it> |
| In reply to | #1471072 |
On 08/27/2016 04:31 AM, Alexei Starovoitov wrote: > Make sure that BPF_PROG_TYPE_PERF_EVENT programs only use > preallocated hash maps, since doing memory allocation > in overflow_handler can crash depending on where nmi got triggered. > > Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web