lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <67bd8a7e-aef2-7556-e16c-b94e9a2d0ba8@huawei.com>
Date:   Mon, 8 Nov 2021 21:45:28 +0800
From:   Hou Tao <houtao1@...wei.com>
To:     Alexei Starovoitov <alexei.starovoitov@...il.com>
CC:     Alexei Starovoitov <ast@...nel.org>,
        Martin KaFai Lau <kafai@...com>, Yonghong Song <yhs@...com>,
        Song Liu <songliubraving@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>, <netdev@...r.kernel.org>,
        <bpf@...r.kernel.org>
Subject: Re: [RFC PATCH bpf-next 1/2] bpf: add bpf_strncmp helper

Hi,

On 11/7/2021 3:26 AM, Alexei Starovoitov wrote:
> On Sat, Nov 06, 2021 at 09:28:21PM +0800, Hou Tao wrote:
>> The helper compares two strings: one string is a null-terminated
>> read-only string, and another one has const max storage size. And
>> it can be used to compare file name in tracing or LSM program.
>>
>> We don't check whether or not s2 in bpf_strncmp() is null-terminated,
>> because its content may be changed by malicous program, and we only
>> ensure the memory accessed is bounded by s2_sz.
> I think "malicous" adjective is unnecessary and misleading.
> It's also misspelled.
> Just mention that 2nd argument doesn't have to be null terminated.
Will do.
>> + * long bpf_strncmp(const char *s1, const char *s2, u32 s2_sz)
> ...
>> +BPF_CALL_3(bpf_strncmp, const char *, s1, const char *, s2, size_t, s2_sz)
> probably should match u32 instead of size_t.
Yes, will use u32 instead. I forgot to synchronize between these two declarations.
>
>> @@ -1210,6 +1210,8 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>>  		return &bpf_get_branch_snapshot_proto;
>>  	case BPF_FUNC_trace_vprintk:
>>  		return bpf_get_trace_vprintk_proto();
>> +	case BPF_FUNC_strncmp:
>> +		return &bpf_strncmp_proto;
> why tracing only?
> Should probably be in bpf_base_func_proto.
Because in our use case, bpf_strncmp() is only used by tracing program, but moving
it to bpf_base_func_proto() incurs no harm, so will do it.
>
> I was thinking whether the proto could be:
> long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)
> but I think your version is better though having const string as 1st arg
> is a bit odd in normal C.
>
> Would it make sense to add bpf_memchr as well while we are at it?
> And
> static inline bpf_strnlen(const char *s, u32 sz)
> {
>   return bpf_memchr(s, sz, 0);
> }
> to bpf_helpers.h ?
> .
It is OK to add it, although I don't have a use case for it.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ