From: Song Liu <songliubraving@fb.com>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>,
bpf <bpf@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf v2 2/2] selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL
Date: Thu, 5 Nov 2020 23:31:38 +0000 [thread overview]
Message-ID: <32285B9E-976A-4357-8C97-6A394926BDFE@fb.com> (raw)
In-Reply-To: <C6VPSZATLVIX.2PK5DDNA9QVDD@maharaja>
> On Nov 5, 2020, at 3:22 PM, Daniel Xu <dxu@dxuuu.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@dxuuu.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.
Thanks,
Song
next prev parent reply other threads:[~2020-11-05 23:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-05 2:25 [PATCH bpf v2 0/2] Fix bpf_probe_read_user_str() overcopying Daniel Xu
2020-11-05 2:25 ` [PATCH bpf v2 1/2] lib/strncpy_from_user.c: Don't overcopy bytes after NUL terminator Daniel Xu
2020-11-05 9:00 ` David Laight
2020-11-05 18:16 ` Song Liu
2020-11-05 18:18 ` Song Liu
2020-11-05 19:28 ` Daniel Xu
2020-11-15 10:41 ` [lib/strncpy_from_user.c] 2903f3d558: Kernel_panic-not_syncing:Attempted_to_kill_init!exitcode= kernel test robot
2020-11-05 2:25 ` [PATCH bpf v2 2/2] selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL Daniel Xu
2020-11-05 18:30 ` Song Liu
2020-11-05 19:27 ` Daniel Xu
2020-11-05 21:32 ` Andrii Nakryiko
2020-11-05 23:22 ` Daniel Xu
2020-11-05 23:31 ` Song Liu [this message]
2020-11-05 23:55 ` Daniel Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=32285B9E-976A-4357-8C97-6A394926BDFE@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dxu@dxuuu.xyz \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).