diff options
| author | David S. Miller <davem@davemloft.net> | 2016-04-14 21:40:53 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2016-04-14 21:40:53 -0400 |
| commit | 548aacdd742b963983f13c523dad8c169c406a19 (patch) | |
| tree | 8fe6af71ebb2dca7862b47c7514e27f2a7e12da3 /kernel/bpf/helpers.c | |
| parent | 486bdee0134cf21c3714ded809d5933d2b8dfb81 (diff) | |
| parent | 3f2050e20e6f3a762eb08397db651dcec9498998 (diff) | |
| download | linux-548aacdd742b963983f13c523dad8c169c406a19.tar.gz linux-548aacdd742b963983f13c523dad8c169c406a19.tar.bz2 linux-548aacdd742b963983f13c523dad8c169c406a19.zip | |
Merge branch 'bpf-ARG_PTR_TO_RAW_STACK'
Merge branch 'bpf-ARG_PTR_TO_RAW_STACK'
Daniel Borkmann says:
====================
BPF updates
This series adds a new verifier argument type called
ARG_PTR_TO_RAW_STACK and converts related helpers to make
use of it. Basic idea is that we can save init of stack
memory when the helper function is guaranteed to fully
fill out the passed buffer in every path. Series also adds
test cases and converts samples. For more details, please
see individual patches.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/helpers.c')
| -rw-r--r-- | kernel/bpf/helpers.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index 50da680c479f..ad7a0573f71b 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -163,17 +163,26 @@ static u64 bpf_get_current_comm(u64 r1, u64 size, u64 r3, u64 r4, u64 r5) struct task_struct *task = current; char *buf = (char *) (long) r1; - if (!task) - return -EINVAL; + if (unlikely(!task)) + goto err_clear; - strlcpy(buf, task->comm, min_t(size_t, size, sizeof(task->comm))); + strncpy(buf, task->comm, size); + + /* Verifier guarantees that size > 0. For task->comm exceeding + * size, guarantee that buf is %NUL-terminated. Unconditionally + * done here to save the size test. + */ + buf[size - 1] = 0; return 0; +err_clear: + memset(buf, 0, size); + return -EINVAL; } const struct bpf_func_proto bpf_get_current_comm_proto = { .func = bpf_get_current_comm, .gpl_only = false, .ret_type = RET_INTEGER, - .arg1_type = ARG_PTR_TO_STACK, + .arg1_type = ARG_PTR_TO_RAW_STACK, .arg2_type = ARG_CONST_STACK_SIZE, }; |
