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: <f8d371f7-a0c1-b4d0-ee27-9dd64498daa0@fb.com>
Date:   Sun, 16 Dec 2018 05:31:43 +0000
From:   Yonghong Song <yhs@...com>
To:     Martin Lau <kafai@...com>
CC:     "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Kernel Team <Kernel-team@...com>
Subject: Re: [PATCH bpf-next v2 7/8] tools: bpftool: refactor
 btf_dumper_int_bits()



On 12/15/18 1:26 PM, Martin Lau wrote:
> On Fri, Dec 14, 2018 at 03:34:33PM -0800, Yonghong Song wrote:
>> The core dump funcitonality in btf_dumper_int_bits() is
>> refactored into a separate function btf_dumper_bitfield()
>> which will be used by the next patch.
>>
>> Signed-off-by: Yonghong Song <yhs@...com>
>> ---
>>   tools/bpf/bpftool/btf_dumper.c | 22 ++++++++++++++++------
>>   1 file changed, 16 insertions(+), 6 deletions(-)
>>
>> diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
>> index 5cdb2ef8b6f1..ec1da87c3d65 100644
>> --- a/tools/bpf/bpftool/btf_dumper.c
>> +++ b/tools/bpf/bpftool/btf_dumper.c
>> @@ -73,20 +73,17 @@ static int btf_dumper_array(const struct btf_dumper *d, __u32 type_id,
>>   	return ret;
>>   }
>>   
>> -static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
>> +static void btf_dumper_bitfield(__u32 nr_bits, __u8 bit_offset,
>>   				const void *data, json_writer_t *jw,
>>   				bool is_plain_text)
>>   {
>>   	int left_shift_bits, right_shift_bits;
>> -	int nr_bits = BTF_INT_BITS(int_type);
>> -	int total_bits_offset;
>>   	int bytes_to_copy;
>>   	int bits_to_copy;
>>   	__u64 print_num;
>>   
>> -	total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
>> -	data += BITS_ROUNDDOWN_BYTES(total_bits_offset);
>> -	bit_offset = BITS_PER_BYTE_MASKED(total_bits_offset);
>> +	data += BITS_ROUNDDOWN_BYTES(bit_offset);
>> +	bit_offset = BITS_PER_BYTE_MASKED(bit_offset);
>>   	bits_to_copy = bit_offset + nr_bits;
>>   	bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy);
>>   
>> @@ -109,6 +106,19 @@ static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
>>   		jsonw_printf(jw, "%llu", print_num);
>>   }
>>   
>> +
>> +static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
>> +				const void *data, json_writer_t *jw,
>> +				bool is_plain_text)
>> +{
>> +	int nr_bits = BTF_INT_BITS(int_type);
>> +	int total_bits_offset;
>> +
>> +	total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
>> +	btf_dumper_bitfield(nr_bits, total_bits_offset, data, jw,
> The 2nd arg is "__u8 bit_offset".  Can you check if total_bits_offset
> is fine here, considering BTF_INT_OFFSET() is 8 bits itself.
> A comment would help if it is safe.

This should be okay.

In kernel btf_int_check_meta, we have

         nr_bits = BTF_INT_BITS(int_data) + BTF_INT_OFFSET(int_data);

         if (nr_bits > BITS_PER_U64) {
                 btf_verifier_log_type(env, t, "nr_bits exceeds %zu",
                                       BITS_PER_U64);
                 return -EINVAL;
         }

So BTF_INT_OFFSET(int_data) at most BITS_PER_U64.
bit_offset at most 7, so total_bits_offset still within range.
kernel has similar implementation.
I will add a comment here.

> 
> Other than that,
> Acked-by: Martin KaFai Lau <kafai@...com>
> 
>> +			    is_plain_text);
>> +}
>> +
>>   static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset,
>>   			  const void *data, json_writer_t *jw,
>>   			  bool is_plain_text)
>> -- 
>> 2.17.1
>>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ