This is a note to let you know that I've just added the patch titled bpf: Fix a erroneous check after snprintf() to the 6.5-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: bpf-fix-a-erroneous-check-after-snprintf.patch and it can be found in the queue-6.5 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 700110c16d4e27592beb2a16f606263856bba573 Author: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx> Date: Fri Sep 8 18:33:35 2023 +0200 bpf: Fix a erroneous check after snprintf() [ Upstream commit a8f12572860ad8ba659d96eee9cf09e181f6ebcc ] snprintf() does not return negative error code on error, it returns the number of characters which *would* be generated for the given input. Fix the error handling check. Fixes: 57539b1c0ac2 ("bpf: Enable annotating trusted nested pointers") Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx> Link: https://lore.kernel.org/r/393bdebc87b22563c08ace094defa7160eb7a6c0.1694190795.git.christophe.jaillet@xxxxxxxxxx Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 4b38c97990872..197d8252ffc65 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -8498,7 +8498,7 @@ bool btf_nested_type_is_trusted(struct bpf_verifier_log *log, tname = btf_name_by_offset(btf, walk_type->name_off); ret = snprintf(safe_tname, sizeof(safe_tname), "%s%s", tname, suffix); - if (ret < 0) + if (ret >= sizeof(safe_tname)) return false; safe_id = btf_find_by_name_kind(btf, safe_tname, BTF_INFO_KIND(walk_type->info));