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: <223f19c0-70a7-3b1f-6166-22d494b62b6e@nfschina.com>
Date:   Fri, 13 May 2022 01:08:35 +0800
From:   liqiong <liqiong@...china.com>
To:     Yonghong Song <yhs@...com>, Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>
Cc:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>, netdev@...r.kernel.org,
        bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
        hukun@...china.com, qixu@...china.com, yuzhe@...china.com,
        renyu@...china.com
Subject: Re: [PATCH 1/2] kernel/bpf: change "char *" string form to "char []"

在 2022年05月12日 23:16, Yonghong Song 写道:
>
>
> On 5/12/22 7:28 AM, liqiong wrote:
>> The string form of "char []" declares a single variable. It is better
>> than "char *" which creates two variables.
>
> Could you explain in details about why it is better in generated codes?
> It is not clear to me why your patch is better than the original code.

Hi there,

The  string form of "char *" creates two variables in the final assembly output,
a static string, and a char pointer to the static string.  Use  "objdump -S -D  *.o",
can find out the static string  occurring  at "Contents of section .rodata".

>
>>
>> Signed-off-by: liqiong <liqiong@...china.com>
>> ---
>>   kernel/bpf/btf.c      | 4 ++--
>>   kernel/bpf/verifier.c | 2 +-
>>   2 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> index 0918a39279f6..218a8ac73644 100644
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>> @@ -894,10 +894,10 @@ static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf,
>>   static const char *btf_show_name(struct btf_show *show)
>>   {
>>       /* BTF_MAX_ITER array suffixes "[]" */
>> -    const char *array_suffixes = "[][][][][][][][][][]";
>> +    static const char array_suffixes[] = "[][][][][][][][][][]";
>>       const char *array_suffix = &array_suffixes[strlen(array_suffixes)];
>>       /* BTF_MAX_ITER pointer suffixes "*" */
>> -    const char *ptr_suffixes = "**********";
>> +    static const char ptr_suffixes[] = "**********";
>>       const char *ptr_suffix = &ptr_suffixes[strlen(ptr_suffixes)];
>>       const char *name = NULL, *prefix = "", *parens = "";
>>       const struct btf_member *m = show->state.member;
>> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
>> index d175b70067b3..78a090fcbc72 100644
>> --- a/kernel/bpf/verifier.c
>> +++ b/kernel/bpf/verifier.c
>> @@ -7346,7 +7346,7 @@ static int sanitize_err(struct bpf_verifier_env *env,
>>               const struct bpf_reg_state *off_reg,
>>               const struct bpf_reg_state *dst_reg)
>>   {
>> -    static const char *err = "pointer arithmetic with it prohibited for !root";
>> +    static const char err[] = "pointer arithmetic with it prohibited for !root";
>>       const char *op = BPF_OP(insn->code) == BPF_ADD ? "add" : "sub";
>>       u32 dst = insn->dst_reg, src = insn->src_reg;
>>   

-- 
李力琼 <13524287433>
上海市浦东新区海科路99号中科院上海高等研究院3号楼3楼

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ