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