]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Make sure TLD_DEFINE_KEY runs first
authorAmery Hung <ameryhung@gmail.com>
Tue, 31 Mar 2026 21:35:53 +0000 (14:35 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 2 Apr 2026 22:11:08 +0000 (15:11 -0700)
Without specifying constructor priority of the hidden constructor
function defined by TLD_DEFINE_KEY, __tld_create_key(..., dyn_data =
false) may run after tld_get_data() called from other constructors.
Threads calling tld_get_data() before __tld_create_key(..., dyn_data
= false) will not allocate enough memory for all TLDs and later result
in OOB access. Therefore, set it to the lowest value available to
users. Note that lower means higher priority and 0-100 is reserved to
the compiler.

Acked-by: Mykyta Yatsenko <yatsenko@meta.com>
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Acked-by: Sun Jian <sun.jian.kdev@gmail.com>
Link: https://lore.kernel.org/r/20260331213555.1993883-4-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/task_local_data.h

index 366a6739c08622082b5d86394f155b11a2941472..e242c455ddae21c967d94fa567312756d7ab5941 100644 (file)
@@ -278,7 +278,7 @@ retry:
 #define TLD_DEFINE_KEY(key, name, size)                        \
 tld_key_t key;                                         \
                                                        \
-__attribute__((constructor))                           \
+__attribute__((constructor(101)))                      \
 void __tld_define_key_##key(void)                      \
 {                                                      \
        key = __tld_create_key(name, size, false);      \