1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# A static branch key owned by a module is rejected whether the key is global 5# or file-local. 6# 7# The rejection matters because late module patching allows the livepatch 8# module to load before the module it depends on: the __jump_table klp reloc is 9# then unresolved, and jump_label_add_module() dereferences an uninitialized 10# pointer. Catching it at build time is the only defence. 11# 12# test-jump-label-module-key covers the global key. A file-local one reaches 13# the same check by a different route: the compiler emits the reference against 14# the section symbol plus an addend, so validate_special_section_klp_reloc() 15# has to resolve it to the underlying object before it can see a key at all. 16# Until it did, a static key was passed over as "not STT_OBJECT" and the 17# unsupported reference was emitted with nothing said. 18# 19# Fixed by f9fb44b0ecef ("objtool/klp: Fix detection of corrupt static 20# branch/call entries"). 21 22. "$(dirname "$0")/../lib.sh" 23 24setup 25build_pair jump_label.c -DSTATIC_KEY -DMODNAME='"klp_testmod"' 26 27require_input_section __jump_table 28 29# The premise: the key is reached through its section symbol, not by name. 30# Without that this is just a second copy of test-jump-label-module-key. 31input_jump_relocs="$(in_relocs orig.o | awk '/rela__jump_table/,/^$/')" 32 33echo "$input_jump_relocs" | grep -q klp_test_key || 34 fail "fixture produced no __jump_table reference to the key" 35echo "$input_jump_relocs" | grep -qE '\.(bss|data)\.klp_test_key' || 36 probe_skip "compiler referenced the static key by name, not through its section" 37 38run_diff 255 39 40diff_log | grep -q 'unsupported static branch key klp_test_key' || 41 fail "expected rejection, got: $(diff_log | tail -1)" 42[ -e "$workdir/out.o" ] && 43 fail "output object produced for a rejected input" 44 45pass "module-owned file-local static branch key rejected" 46