1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# Patching a module, where the patched code references a vmlinux symbol which 5# needs a klp relocation. 6# 7# The kernel does not allow a module-targeted klp relocation to reference a 8# vmlinux symbol, and a symbol exported with EXPORT_SYMBOL_FOR_MODULES gets a 9# klp relocation. Put together, filing that relocation under the patched 10# module produces a patch the kernel refuses to apply to its target. 11# 12# So it goes under vmlinux instead, and is applied when the patch module loads 13# rather than when the patched module does. That is the opposite of the rule 14# for a reference to a module's symbol, which test-module-object covers; this 15# is the other branch of the same decision. 16 17. "$(dirname "$0")/../lib.sh" 18 19setup 20# The object being patched is a module ... 21build_module_pair cross_module.c klp_testmod 22 23# ... and the symbol it references belongs to vmlinux, exported in a way that 24# still requires a klp relocation. 25export_syms 26add_exports_ns vmlinux module:kvm other_mod_func 27run_diff 28 29# Filed against vmlinux, applied when the patch loads. 30assert_section __klp_relocs.vmlinux 31assert_klp_sym other_mod_func vmlinux 32 33# Not against the patched module: that is the relocation the kernel rejects. 34assert_no_section __klp_relocs.klp_testmod 35 36run_post_link 37assert_klp_rela vmlinux .text.target 38assert_no_section ".klp.rela.klp_testmod..text.target" 39 40pass "klp relocation to a vmlinux symbol filed under vmlinux, not the patched module" 41