[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <C6VQIBZJGQ3W.22AG4C72KZQLI@maharaja>
Date: Thu, 05 Nov 2020 15:55:40 -0800
From: "Daniel Xu" <dxu@...uu.xyz>
To: "Song Liu" <songliubraving@...com>
Cc: "Andrii Nakryiko" <andrii.nakryiko@...il.com>,
"bpf" <bpf@...r.kernel.org>,
"open list" <linux-kernel@...r.kernel.org>,
"Alexei Starovoitov" <ast@...nel.org>,
"Daniel Borkmann" <daniel@...earbox.net>,
"Kernel Team" <Kernel-team@...com>
Subject: Re: [PATCH bpf v2 2/2] selftest/bpf: Test bpf_probe_read_user_str()
strips trailing bytes after NUL
On Thu Nov 5, 2020 at 3:31 PM PST, Song Liu wrote:
>
>
> > On Nov 5, 2020, at 3:22 PM, Daniel Xu <dxu@...uu.xyz> wrote:
> >
> > On Thu Nov 5, 2020 at 1:32 PM PST, Andrii Nakryiko wrote:
> >> On Wed, Nov 4, 2020 at 8:51 PM Daniel Xu <dxu@...uu.xyz> wrote:
> > [...]
> >>> diff --git a/tools/testing/selftests/bpf/progs/test_probe_read_user_str.c b/tools/testing/selftests/bpf/progs/test_probe_read_user_str.c
> >>> new file mode 100644
> >>> index 000000000000..41c3e296566e
> >>> --- /dev/null
> >>> +++ b/tools/testing/selftests/bpf/progs/test_probe_read_user_str.c
> >>> @@ -0,0 +1,34 @@
> >>> +// SPDX-License-Identifier: GPL-2.0
> >>> +
> >>> +#include <linux/bpf.h>
> >>> +#include <bpf/bpf_helpers.h>
> >>> +#include <bpf/bpf_tracing.h>
> >>> +
> >>> +#include <sys/types.h>
> >>> +
> >>> +struct sys_enter_write_args {
> >>> + unsigned long long pad;
> >>> + int syscall_nr;
> >>> + int pad1; /* 4 byte hole */
> >>
> >> I have a hunch that this explicit padding might break on big-endian
> >> architectures?..
> >>
> >> Can you instead include "vmlinux.h" in this file and use struct
> >> trace_event_raw_sys_enter? you'll just need ctx->args[2] to get that
> >> buffer pointer.
> >>
> >> Alternatively, and it's probably simpler overall would be to just
> >> provide user-space pointer through global variable:
> >>
> >> void *user_ptr;
> >>
> >>
> >> bpf_probe_read_user_str(buf, ..., user_ptr);
> >>
> >> From user-space:
> >>
> >> skel->bss->user_ptr = &my_userspace_buf;
> >>
> >> Full control. You can trigger tracepoint with just an usleep(1), for
> >> instance.
> >
> > Yeah, that sounds better. I'll send a v4 with passing a ptr.
> >
> > Thanks,
> > Daniel
>
> One more comment, how about we test multiple strings with different
> lengths? In this way, we can catch other alignment issues.
Sure, will do that in v4 also.
Powered by blists - more mailing lists