Re: [PATCH bpf v2 2/2] selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after NUL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Nov 5, 2020, at 3:22 PM, Daniel Xu <dxu@xxxxxxxxx> 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@xxxxxxxxx> 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





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux