Re: [RFC PATCH v2 01/11] objtool/klp: Fix checksums and copying of wide strings
From: Josh Poimboeuf
Date: Fri Nov 13 2026 - 04:38:56 EST
On Wed, Nov 04, 2026 at 09:31:47PM +0800, Longjun Luo wrote:
> SHF_STRINGS sections can contain elements wider than one byte. Using
> strlen() truncates their contents at an embedded zero byte, hiding
> changes and copying incomplete strings into the patch.
>
> Find the terminating zero element using sh_entsize. Use the resulting
> length for both reference checksums and copying, and propagate errors
> through checksum calculation. Keep single-byte string handling unchanged.
>
> Add a test for two- and four-byte strings, including references from data.
>
> Validated the available objtool tests with GCC 16.2.1 and Clang
> 22.1.8. No failures.
Please give example(s) of such "wide strings" in the changelog.
> Fixes: 0d83da43b1e1 ("objtool/klp: Add --checksum option to generate per-function checksums")
> Fixes: dd590d4d57eb ("objtool/klp: Introduce klp diff subcommand for diffing object files")
> Fixes: 873a2208ea31 ("objtool/klp: Calculate object checksums")
> Assisted-by: LLM
> Signed-off-by: Longjun Luo <luolongjuna@xxxxxxxxx>
> ---
> tools/objtool/elf.c | 29 +++++++++
> tools/objtool/include/objtool/elf.h | 1 +
> tools/objtool/klp-checksum.c | 44 ++++++++-----
> tools/objtool/klp-diff.c | 14 ++--
> .../tests/generic/fixtures/identity/common.h | 15 +++++
> .../generic/fixtures/identity/wide_string.c | 36 ++++++++++
> .../generic/test-checksum-wide-string.sh | 39 +++++++++++
> tools/objtool/tests/identity-lib.sh | 65 +++++++++++++++++++
> 8 files changed, 223 insertions(+), 20 deletions(-)
> create mode 100644 tools/objtool/tests/generic/fixtures/identity/common.h
> create mode 100644 tools/objtool/tests/generic/fixtures/identity/wide_string.c
> create mode 100755 tools/objtool/tests/generic/test-checksum-wide-string.sh
> create mode 100644 tools/objtool/tests/identity-lib.sh
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index a791f4ea6ec1..71f1a272e468 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -1382,6 +1382,35 @@ struct elf *elf_create_file(GElf_Ehdr *ehdr, const char *name)
> return elf;
> }
>
> +/* Wide strings, such as the u16 PSR setup table, end at an all-zero element. */
> +ssize_t elf_string_len(struct section *sec, unsigned long offset)
What is the "u16 PSR setup table"?
> +{
> + size_t entsize = sec->sh.sh_entsize, size, len;
> + const char *str;
> +
> + /*
> + * FIXME: GCC's range_string() uses a one-past-end string pointer.
> + * strlen() reads past the section; preserve the string base and addend.
> + */
> + if (entsize == 1)
> + return strlen(sec->data->d_buf + offset);
I don't understand what this comment means either. Please make sure all
comments and changelogs are written by humans, as LLMs tend to write
nonsensically.
--
Josh