From 7f1726aa884c870b1b054d90a95510fd1286c701 Mon Sep 17 00:00:00 2001 From: bitcoffee Date: Mon, 6 May 2024 09:57:14 +0800 Subject: [PATCH] btf_encoder: Fix dwarf int type with greater-than-16 byte issue Nick Desaulniers and Xin Liu separately reported that int type might have greater-than-16 byte size ([1] and [2]). More specifically, the reported int type sizes are 1024 and 64 bytes. The libbpf and bpf program does not really support any int type greater than 16 bytes. Therefore, with current pahole, btf encoding will fail with greater-than-16 byte int types. Since for now bpf does not support '> 16' bytes int type, the simplest way is to sanitize such types, similar to existing conditions like '!byte_sz' and 'byte_sz & (byte_sz - 1)'. This way, pahole won't call libbpf with an unsupported int type size. The patch [3] was proposed before. Now I resubmitted this patch as there are another failure due to the same issue. Signed-off-by: bitcoffee (cherry picked from commit 4edfa257cd9982267aea870609a4a22884f28b96) --- ...dwarf-int-type-with-greater-than-16-.patch | 47 +++++++++++++++++++ dwarves.spec | 9 +++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 backport-btf_encoder-Fix-dwarf-int-type-with-greater-than-16-.patch diff --git a/backport-btf_encoder-Fix-dwarf-int-type-with-greater-than-16-.patch b/backport-btf_encoder-Fix-dwarf-int-type-with-greater-than-16-.patch new file mode 100644 index 0000000..4a931ea --- /dev/null +++ b/backport-btf_encoder-Fix-dwarf-int-type-with-greater-than-16-.patch @@ -0,0 +1,47 @@ +From b9607b8bf5fe3180ae4cd44cddaf054e5595e699 Mon Sep 17 00:00:00 2001 +From: Yonghong Song +Date: Wed, 24 Apr 2024 15:35:38 -0700 +Subject: [PATCH dwarves] btf_encoder: Fix dwarf int type with greater-than-16 byte issue + +Nick Desaulniers and Xin Liu separately reported that int type might +have greater-than-16 byte size ([1] and [2]). More specifically, the +reported int type sizes are 1024 and 64 bytes. + +The libbpf and bpf program does not really support any int type greater +than 16 bytes. Therefore, with current pahole, btf encoding will fail +with greater-than-16 byte int types. + +Since for now bpf does not support '> 16' bytes int type, the simplest +way is to sanitize such types, similar to existing conditions like +'!byte_sz' and 'byte_sz & (byte_sz - 1)'. This way, pahole won't +call libbpf with an unsupported int type size. The patch [3] was +proposed before. Now I resubmitted this patch as there are another +failure due to the same issue. + + [1] https://github.com/libbpf/libbpf/pull/680 + [2]https://lore.kernel.org/bpf/20240422144538.351722-1-liuxin350@huawei.com/ + [3] https://lore.kernel.org/bpf/20230426055030.3743074-1-yhs@fb.com/ + +Cc: Xin Liu +Cc: Alan Maguire +Signed-off-by: Yonghong Song +--- + 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.33.0 + diff --git a/dwarves.spec b/dwarves.spec index 09d6635..4d71c6e 100644 --- a/dwarves.spec +++ b/dwarves.spec @@ -4,7 +4,7 @@ Name: dwarves Version: 1.22 -Release: 2 +Release: 3 License: GPLv2 Summary: Debugging Information Manipulation Tools URL: http://acmel.wordpress.com @@ -18,6 +18,7 @@ BuildRequires: elfutils-devel >= 0.170 Patch0: replace-deprecated-libbpf-APIs-with-new-ones.patch Patch1: backport-dwarf_loader-Support-DW_TAG_label-outside-DW_TAG_lex.patch +Patch2: backport-btf_encoder-Fix-dwarf-int-type-with-greater-than-16-.patch %description dwarves is a set of tools that use the debugging information inserted in @@ -85,6 +86,12 @@ make install DESTDIR=%{buildroot} %{_libdir}/%{libname}_reorganize.so %changelog +* Mon May 6 2024 - liuxin - 1.22-3 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix dwarf int type with greater than 16 bytes issue + * Mon Mar 21 2022 - Kai Liu - 1.22-2 - Type:bugfix - ID:NA -- Gitee