diff options
Diffstat (limited to 'kernel/bpf/syscall.c')
| -rw-r--r-- | kernel/bpf/syscall.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 536edc2be307..3bae6c591914 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | #include <linux/file.h> | 16 | #include <linux/file.h> |
| 17 | #include <linux/license.h> | 17 | #include <linux/license.h> |
| 18 | #include <linux/filter.h> | 18 | #include <linux/filter.h> |
| 19 | #include <linux/version.h> | ||
| 19 | 20 | ||
| 20 | static LIST_HEAD(bpf_map_types); | 21 | static LIST_HEAD(bpf_map_types); |
| 21 | 22 | ||
| @@ -354,10 +355,11 @@ static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog) | |||
| 354 | list_for_each_entry(tl, &bpf_prog_types, list_node) { | 355 | list_for_each_entry(tl, &bpf_prog_types, list_node) { |
| 355 | if (tl->type == type) { | 356 | if (tl->type == type) { |
| 356 | prog->aux->ops = tl->ops; | 357 | prog->aux->ops = tl->ops; |
| 357 | prog->aux->prog_type = type; | 358 | prog->type = type; |
| 358 | return 0; | 359 | return 0; |
| 359 | } | 360 | } |
| 360 | } | 361 | } |
| 362 | |||
| 361 | return -EINVAL; | 363 | return -EINVAL; |
| 362 | } | 364 | } |
| 363 | 365 | ||
| @@ -418,6 +420,7 @@ void bpf_prog_put(struct bpf_prog *prog) | |||
| 418 | bpf_prog_free(prog); | 420 | bpf_prog_free(prog); |
| 419 | } | 421 | } |
| 420 | } | 422 | } |
| 423 | EXPORT_SYMBOL_GPL(bpf_prog_put); | ||
| 421 | 424 | ||
| 422 | static int bpf_prog_release(struct inode *inode, struct file *filp) | 425 | static int bpf_prog_release(struct inode *inode, struct file *filp) |
| 423 | { | 426 | { |
| @@ -465,9 +468,10 @@ struct bpf_prog *bpf_prog_get(u32 ufd) | |||
| 465 | fdput(f); | 468 | fdput(f); |
| 466 | return prog; | 469 | return prog; |
| 467 | } | 470 | } |
| 471 | EXPORT_SYMBOL_GPL(bpf_prog_get); | ||
| 468 | 472 | ||
| 469 | /* last field in 'union bpf_attr' used by this command */ | 473 | /* last field in 'union bpf_attr' used by this command */ |
| 470 | #define BPF_PROG_LOAD_LAST_FIELD log_buf | 474 | #define BPF_PROG_LOAD_LAST_FIELD kern_version |
| 471 | 475 | ||
| 472 | static int bpf_prog_load(union bpf_attr *attr) | 476 | static int bpf_prog_load(union bpf_attr *attr) |
| 473 | { | 477 | { |
| @@ -492,6 +496,10 @@ static int bpf_prog_load(union bpf_attr *attr) | |||
| 492 | if (attr->insn_cnt >= BPF_MAXINSNS) | 496 | if (attr->insn_cnt >= BPF_MAXINSNS) |
| 493 | return -EINVAL; | 497 | return -EINVAL; |
| 494 | 498 | ||
| 499 | if (type == BPF_PROG_TYPE_KPROBE && | ||
| 500 | attr->kern_version != LINUX_VERSION_CODE) | ||
| 501 | return -EINVAL; | ||
| 502 | |||
| 495 | /* plain bpf_prog allocation */ | 503 | /* plain bpf_prog allocation */ |
| 496 | prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); | 504 | prog = bpf_prog_alloc(bpf_prog_size(attr->insn_cnt), GFP_USER); |
| 497 | if (!prog) | 505 | if (!prog) |
| @@ -508,7 +516,7 @@ static int bpf_prog_load(union bpf_attr *attr) | |||
| 508 | prog->jited = false; | 516 | prog->jited = false; |
| 509 | 517 | ||
| 510 | atomic_set(&prog->aux->refcnt, 1); | 518 | atomic_set(&prog->aux->refcnt, 1); |
| 511 | prog->aux->is_gpl_compatible = is_gpl; | 519 | prog->gpl_compatible = is_gpl; |
| 512 | 520 | ||
| 513 | /* find program type: socket_filter vs tracing_filter */ | 521 | /* find program type: socket_filter vs tracing_filter */ |
| 514 | err = find_prog_type(type, prog); | 522 | err = find_prog_type(type, prog); |
| @@ -516,8 +524,7 @@ static int bpf_prog_load(union bpf_attr *attr) | |||
| 516 | goto free_prog; | 524 | goto free_prog; |
| 517 | 525 | ||
| 518 | /* run eBPF verifier */ | 526 | /* run eBPF verifier */ |
| 519 | err = bpf_check(prog, attr); | 527 | err = bpf_check(&prog, attr); |
| 520 | |||
| 521 | if (err < 0) | 528 | if (err < 0) |
| 522 | goto free_used_maps; | 529 | goto free_used_maps; |
| 523 | 530 | ||
| @@ -528,7 +535,6 @@ static int bpf_prog_load(union bpf_attr *attr) | |||
| 528 | bpf_prog_select_runtime(prog); | 535 | bpf_prog_select_runtime(prog); |
| 529 | 536 | ||
| 530 | err = anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, O_RDWR | O_CLOEXEC); | 537 | err = anon_inode_getfd("bpf-prog", &bpf_prog_fops, prog, O_RDWR | O_CLOEXEC); |
| 531 | |||
| 532 | if (err < 0) | 538 | if (err < 0) |
| 533 | /* failed to allocate fd */ | 539 | /* failed to allocate fd */ |
| 534 | goto free_used_maps; | 540 | goto free_used_maps; |
