diff options
author | Alexei Starovoitov <ast@fb.com> | 2017-10-03 01:50:22 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-10-04 19:05:05 -0400 |
commit | 468e2f64d220fe2dc11caa2bcb9b3a1e50fc7321 (patch) | |
tree | da21e580b4a534f6feab72ba479b6d3e0ad951f1 /kernel/bpf/core.c | |
parent | 324bda9e6c5add86ba2e1066476481c48132aca0 (diff) |
bpf: introduce BPF_PROG_QUERY command
introduce BPF_PROG_QUERY command to retrieve a set of either
attached programs to given cgroup or a set of effective programs
that will execute for events within a cgroup
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
for cgroup bits
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/core.c')
-rw-r--r-- | kernel/bpf/core.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 6b49e1991ae7..eba966c09053 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c | |||
@@ -1412,6 +1412,44 @@ void bpf_prog_array_free(struct bpf_prog_array __rcu *progs) | |||
1412 | kfree_rcu(progs, rcu); | 1412 | kfree_rcu(progs, rcu); |
1413 | } | 1413 | } |
1414 | 1414 | ||
1415 | int bpf_prog_array_length(struct bpf_prog_array __rcu *progs) | ||
1416 | { | ||
1417 | struct bpf_prog **prog; | ||
1418 | u32 cnt = 0; | ||
1419 | |||
1420 | rcu_read_lock(); | ||
1421 | prog = rcu_dereference(progs)->progs; | ||
1422 | for (; *prog; prog++) | ||
1423 | cnt++; | ||
1424 | rcu_read_unlock(); | ||
1425 | return cnt; | ||
1426 | } | ||
1427 | |||
1428 | int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs, | ||
1429 | __u32 __user *prog_ids, u32 cnt) | ||
1430 | { | ||
1431 | struct bpf_prog **prog; | ||
1432 | u32 i = 0, id; | ||
1433 | |||
1434 | rcu_read_lock(); | ||
1435 | prog = rcu_dereference(progs)->progs; | ||
1436 | for (; *prog; prog++) { | ||
1437 | id = (*prog)->aux->id; | ||
1438 | if (copy_to_user(prog_ids + i, &id, sizeof(id))) { | ||
1439 | rcu_read_unlock(); | ||
1440 | return -EFAULT; | ||
1441 | } | ||
1442 | if (++i == cnt) { | ||
1443 | prog++; | ||
1444 | break; | ||
1445 | } | ||
1446 | } | ||
1447 | rcu_read_unlock(); | ||
1448 | if (*prog) | ||
1449 | return -ENOSPC; | ||
1450 | return 0; | ||
1451 | } | ||
1452 | |||
1415 | static void bpf_prog_free_deferred(struct work_struct *work) | 1453 | static void bpf_prog_free_deferred(struct work_struct *work) |
1416 | { | 1454 | { |
1417 | struct bpf_prog_aux *aux; | 1455 | struct bpf_prog_aux *aux; |