@@ -33,6 +33,7 @@ static struct {
{"test_dynptr_skb_tp_btf", SETUP_SKB_PROG_TP},
{"test_probe_read_kernel_dynptr", SETUP_RINGBUF},
{"test_probe_read_user_dynptr", SETUP_RINGBUF},
+ {"test_copy_from_user_dynptr", SETUP_RINGBUF},
};
static int ringbuf_cb(void *ctx, void *data, size_t len)
@@ -43,6 +44,8 @@ static int ringbuf_cb(void *ctx, void *data, size_t len)
if (!ASSERT_EQ(len, skel->data->test_buf.length, "length"))
return -E2BIG;
+ ASSERT_EQ(skel->bss->err, 0, "err");
+
if (!ASSERT_MEMEQ(buf, skel->data->test_buf.buf, len, "ringbuf_cb"))
return -EINVAL;
@@ -639,3 +639,37 @@ int test_probe_read_user_dynptr(void *ctx)
bpf_ringbuf_submit_dynptr(&ptr, 0);
return 0;
}
+
+SEC("?fentry.s/" SYS_PREFIX "sys_nanosleep")
+int test_copy_from_user_dynptr(void *ctx)
+{
+ struct bpf_dynptr ptr;
+ int copy_len;
+
+ if (bpf_get_current_pid_tgid() >> 32 != pid)
+ return 0;
+
+ err = bpf_probe_read_user(©_len, sizeof(copy_len), &user_ptr->length);
+ if (err < 0 || copy_len < 0) {
+ err = 1;
+ return 0;
+ }
+
+ if (copy_len > MAX_BUFFER_LEN)
+ copy_len = MAX_BUFFER_LEN;
+
+ bpf_ringbuf_reserve_dynptr(&ringbuf, copy_len, 0, &ptr);
+
+ if (-E2BIG != bpf_copy_from_user_dynptr(&ptr, 0, MAX_BUFFER_LEN + 1,
+ &user_ptr->buf, 0)) {
+ err = 2;
+ goto cleanup;
+ }
+
+ err = bpf_copy_from_user_dynptr(&ptr, 0, copy_len,
+ &user_ptr->buf, 0);
+
+cleanup:
+ bpf_ringbuf_submit_dynptr(&ptr, 0);
+ return 0;
+}