1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# What a data object's checksum has to cover. 5# 6# checksum_update_object() hashes the symbol's length, its bytes (when the 7# section has any -- .bss does not), and then 8# every relocation it carries -- as the target's name plus the adjusted addend, 9# except for a reference into a string section, which contributes the string's 10# contents instead. 11# 12# Each of those is load-bearing, and the failure is always the same shape: a 13# checksum that ignores one of them calls a changed object unchanged, klp diff 14# leaves it out of the patch, and the patched code goes on reading the 15# kernel's old copy. Nothing says so at build time. 16# 17# The string case is the one that cannot be caught by hashing bytes alone. The 18# pointer is identical -- same section, same offset -- and only the text it 19# refers to moved. 20# 21# Covers the same ground as corpus/x86_64/checksum-data-basic, 22# checksum-data-func-ptr, checksum-data-string-ptr and checksum-string-reloc in 23# Joe Lawrence's klp-build unit test corpus. 24 25. "$(dirname "$0")/../lib.sh" 26 27setup 28 29# check <flag> <symbol> <what changed> 30# 31# Build the pair with one difference and require that symbol's checksum to move. 32check() 33{ 34 build_pair checksum_data.c "-D$1" 35 run_checksum 36 37 assert_checksum_differs "$2" 38} 39 40# The object's own bytes. 41check PLAIN_VALUE plain 42# Its length, for a .bss object whose bytes are not hashed at all. 43check LONGER sized 44# A relocation's target: same bytes in the object, different symbol named. 45check WHICH_FUNC descriptor 46check WHICH_STR descriptor 47# The contents of a string the object points at, with the pointer untouched. 48check STR_CONTENT descriptor 49# A relocation's addend: same target symbol, different offset into it. 50check WHICH_SLOT descriptor 51# The same, for a static reached through its section symbol: the reference has 52# to be resolved back to the object before there is a name or offset to hash. 53check WHICH_PRIV descriptor 54 55# Having shown five things that must change it, show one that must not: an 56# unrelated edit elsewhere in the file leaves this object alone. 57build_pair checksum_data.c -DPLAIN_VALUE 58run_checksum 59assert_checksum_matches descriptor 60 61pass "data checksums cover length, bytes, reloc targets and string contents" 62