blob: 921cf493cd7909d22ce4deb90f34974194e2f110 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Init code and data are freed after boot, so a klp relocation against them can
# never resolve. Such a patch must be rejected.
. "$(dirname "$0")/../lib.sh"
setup
build_pair init_reference.c
# The rejection can only happen if the patched build really does reference the
# init symbol. The fixture makes init_only volatile so the read cannot be
# folded away, and this checks that it worked: without a relocation klp diff
# would succeed, and the failure below would read as a missing check rather
# than as a fixture which stopped posing the question.
# Either spelling will do. A file-local variable is reached through its
# section symbol -- .init.data -- and a global one by name; which of the two
# the compiler picks is its business, and the reference is what matters.
in_relocs "$patched_obj" |
awk '$5 == ".init.data" || $5 == "init_only"' | grep -q . ||
fail "patched object has no reference into .init.data; the fixture tests nothing"
run_diff 255
diff_log | grep -q "can't patch or reference init code/data" ||
fail "expected rejection, got: $(diff_log | tail -1)"
pass "reference to init data rejected"
|