diff mbox series

[dwarves] btf_encoder: Fix a dwarf type DW_ATE_unsigned_1024 to btf encoding issue

Message ID 20230426055030.3743074-1-yhs@fb.com (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series [dwarves] btf_encoder: Fix a dwarf type DW_ATE_unsigned_1024 to btf encoding issue | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-PR success PR summary
bpf/vmtest-bpf-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-VM_Test-8 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-9 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-10 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-VM_Test-11 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-12 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-13 fail Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-14 fail Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-15 fail Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-VM_Test-16 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-17 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-18 fail Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-19 fail Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-20 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-VM_Test-21 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-22 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-23 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-25 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-26 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-27 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-28 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-29 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-30 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-31 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-VM_Test-32 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-VM_Test-33 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-VM_Test-34 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-VM_Test-35 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-VM_Test-36 success Logs for veristat

Commit Message

Yonghong Song April 26, 2023, 5:50 a.m. UTC
Nick Desaulniers reported an issue ([1]) where an 128-byte sized type
(DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message
likes below:
  $ pahole -J reduced.o
  [2] INT DW_ATE_unsigned_1024 Error emitting BTF type
  Encountered error while encoding BTF.
See [1] for how to reproduce the issue.

The failure is due to currently BTF int type only supports upto 16
bytes (__int128) and in this case the dwarf int type is 128-byte.

The DW_ATE_unsigned_1024 is not a normal type for variable/func
declaration etc. It is used in DW_AT_location. There are two
ways to resolve this issue.
  (1). If btf encoding is expected, remove all dwarf int types
       where btf encoding will failure, e.g., non-power-of-2
       bytes, or greater than 16 bytes.
  (2). do a sanitization in btf_encoder ([2]).

This patch uses method (2) since it is a simple fix in btf_encoder.
I checked my local built vmlinux with latest
bpf-next. There is only one instance of DW_ATE_unsigned_24 (used in
DW_AT_location) so I expect irregular int types should be very rare.

  [1] https://github.com/libbpf/libbpf/pull/680
  [2] commit 7d8e829f636f ("btf_encoder: Sanitize non-regular int base type")

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 btf_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nick Desaulniers April 26, 2023, 6:09 p.m. UTC | #1
On Tue, Apr 25, 2023 at 10:50 PM Yonghong Song <yhs@fb.com> wrote:
>
> Nick Desaulniers reported an issue ([1]) where an 128-byte sized type
> (DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message
> likes below:
>   $ pahole -J reduced.o
>   [2] INT DW_ATE_unsigned_1024 Error emitting BTF type
>   Encountered error while encoding BTF.
> See [1] for how to reproduce the issue.
>
> The failure is due to currently BTF int type only supports upto 16
> bytes (__int128) and in this case the dwarf int type is 128-byte.
>
> The DW_ATE_unsigned_1024 is not a normal type for variable/func
> declaration etc. It is used in DW_AT_location. There are two
> ways to resolve this issue.
>   (1). If btf encoding is expected, remove all dwarf int types
>        where btf encoding will failure, e.g., non-power-of-2
>        bytes, or greater than 16 bytes.
>   (2). do a sanitization in btf_encoder ([2]).
>
> This patch uses method (2) since it is a simple fix in btf_encoder.
> I checked my local built vmlinux with latest
> bpf-next. There is only one instance of DW_ATE_unsigned_24 (used in
> DW_AT_location) so I expect irregular int types should be very rare.
>
>   [1] https://github.com/libbpf/libbpf/pull/680
>   [2] commit 7d8e829f636f ("btf_encoder: Sanitize non-regular int base type")
>
> Signed-off-by: Yonghong Song <yhs@fb.com>

Thanks, this fixed the above reported error for me.  My report is just
forwarded from Satya.

Reported-by: Satya Durga Srinivasu Prabhala <quic_satyap@quicinc.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>

I don't know if that change has other implications for unusual byte sizes.

We might need to consider at some point waiting to validate
DW_TAG_base_type until we know that they're not used outside of
DW_AT_location expressions.

> ---
>  btf_encoder.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/btf_encoder.c b/btf_encoder.c
> index 65f6e71..1aa0ad0 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -394,7 +394,7 @@ static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str
>          * these non-regular int types to avoid libbpf/kernel complaints.
>          */
>         byte_sz = BITS_ROUNDUP_BYTES(bt->bit_size);
> -       if (!byte_sz || (byte_sz & (byte_sz - 1))) {
> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16) {
>                 name = "__SANITIZED_FAKE_INT__";
>                 byte_sz = 4;
>         }
> --
> 2.34.1
>
Yonghong Song April 26, 2023, 8:49 p.m. UTC | #2
On 4/26/23 11:09 AM, Nick Desaulniers wrote:
> On Tue, Apr 25, 2023 at 10:50 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> Nick Desaulniers reported an issue ([1]) where an 128-byte sized type
>> (DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message
>> likes below:
>>    $ pahole -J reduced.o
>>    [2] INT DW_ATE_unsigned_1024 Error emitting BTF type
>>    Encountered error while encoding BTF.
>> See [1] for how to reproduce the issue.
>>
>> The failure is due to currently BTF int type only supports upto 16
>> bytes (__int128) and in this case the dwarf int type is 128-byte.
>>
>> The DW_ATE_unsigned_1024 is not a normal type for variable/func
>> declaration etc. It is used in DW_AT_location. There are two
>> ways to resolve this issue.
>>    (1). If btf encoding is expected, remove all dwarf int types
>>         where btf encoding will failure, e.g., non-power-of-2
>>         bytes, or greater than 16 bytes.
>>    (2). do a sanitization in btf_encoder ([2]).
>>
>> This patch uses method (2) since it is a simple fix in btf_encoder.
>> I checked my local built vmlinux with latest
>> bpf-next. There is only one instance of DW_ATE_unsigned_24 (used in
>> DW_AT_location) so I expect irregular int types should be very rare.
>>
>>    [1] https://github.com/libbpf/libbpf/pull/680
>>    [2] commit 7d8e829f636f ("btf_encoder: Sanitize non-regular int base type")
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
> 
> Thanks, this fixed the above reported error for me.  My report is just
> forwarded from Satya.
> 
> Reported-by: Satya Durga Srinivasu Prabhala <quic_satyap@quicinc.com>
> Tested-by: Nick Desaulniers <ndesaulniers@google.com>
> 
> I don't know if that change has other implications for unusual byte sizes.
> 
> We might need to consider at some point waiting to validate
> DW_TAG_base_type until we know that they're not used outside of
> DW_AT_location expressions.

David Blaikie confirmed that indeed special types like 
DW_ATE_unsigned_1024 is indeed generated for DW_AT_location.
See https://github.com/libbpf/libbpf/pull/680 for details.

> 
>> ---
>>   btf_encoder.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/btf_encoder.c b/btf_encoder.c
>> index 65f6e71..1aa0ad0 100644
>> --- a/btf_encoder.c
>> +++ b/btf_encoder.c
>> @@ -394,7 +394,7 @@ static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str
>>           * these non-regular int types to avoid libbpf/kernel complaints.
>>           */
>>          byte_sz = BITS_ROUNDUP_BYTES(bt->bit_size);
>> -       if (!byte_sz || (byte_sz & (byte_sz - 1))) {
>> +       if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16) {
>>                  name = "__SANITIZED_FAKE_INT__";
>>                  byte_sz = 4;
>>          }
>> --
>> 2.34.1
>>
> 
>
diff mbox series

Patch

diff --git a/btf_encoder.c b/btf_encoder.c
index 65f6e71..1aa0ad0 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -394,7 +394,7 @@  static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str
 	 * these non-regular int types to avoid libbpf/kernel complaints.
 	 */
 	byte_sz = BITS_ROUNDUP_BYTES(bt->bit_size);
-	if (!byte_sz || (byte_sz & (byte_sz - 1))) {
+	if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16) {
 		name = "__SANITIZED_FAKE_INT__";
 		byte_sz = 4;
 	}