Skip to content

Commit 9c019e2

Browse files
yonghong-songdavem330
authored andcommitted
bpf: change helper bpf_probe_read arg2 type to ARG_CONST_SIZE_OR_ZERO
The helper bpf_probe_read arg2 type is changed from ARG_CONST_SIZE to ARG_CONST_SIZE_OR_ZERO to permit size-0 buffer. Together with newer ARG_CONST_SIZE_OR_ZERO semantics which allows non-NULL buffer with size 0, this allows simpler bpf programs with verifier acceptance. The previous commit which changes ARG_CONST_SIZE_OR_ZERO semantics has details on examples. Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9fd29c0 commit 9c019e2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

kernel/trace/bpf_trace.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ EXPORT_SYMBOL_GPL(trace_call_bpf);
7878

7979
BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, const void *, unsafe_ptr)
8080
{
81-
int ret;
81+
int ret = 0;
82+
83+
if (unlikely(size == 0))
84+
goto out;
8285

8386
ret = probe_kernel_read(dst, unsafe_ptr, size);
8487
if (unlikely(ret < 0))
8588
memset(dst, 0, size);
8689

90+
out:
8791
return ret;
8892
}
8993

@@ -92,7 +96,7 @@ static const struct bpf_func_proto bpf_probe_read_proto = {
9296
.gpl_only = true,
9397
.ret_type = RET_INTEGER,
9498
.arg1_type = ARG_PTR_TO_UNINIT_MEM,
95-
.arg2_type = ARG_CONST_SIZE,
99+
.arg2_type = ARG_CONST_SIZE_OR_ZERO,
96100
.arg3_type = ARG_ANYTHING,
97101
};
98102

0 commit comments

Comments
 (0)