Instead of having a special case in the core kernel's module loader that treats a module called 'fips140.ko' in a special way, use a host tool to tweak the ELF metadata of this module so that the RELA data is preserved and accessible to the module init code. This is done in the following way: - each RELA section that we care about (the ones for .text and .rodata at the moment) is copied into a new section called .init.rela.<name> with the SHF_ALLOC attribute, so that the module loader will copy it into __init memory at load time; - for each such section, an offset/count tuple is added as a global variable to the module; - the count field of those tuples is populated directly by the host tool based on the actual size of the RELA section in question; - the offset field is decorated with a place-relative relocation against the start of the copied RELA section via a weak symbol reference, which causes an entry to be emitted into the ELF symbol table; - these ELF symbol table entries are updated by the host tool and turned into STT_SECTION type symbols with STB_GLOBAL linkage, carrying the correct section index. With these changes in place, the unmodified module loader will load all required information into memory in a way that permits the module init code to locate the relocations, and apply them in reverse. Bug: 153614920 Bug: 188620248 Change-Id: I07d9704febdf913834502dd09c19aa4a04d983b1 Signed-off-by: Ard Biesheuvel <ardb@google.com> (cherry picked from commit 502af6e3490d3ed51cf2131306303445b0d56579)
35 lines
1.0 KiB
ArmAsm
35 lines
1.0 KiB
ArmAsm
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright 2021 Google LLC
|
|
* Author: Ard Biesheuvel <ardb@google.com>
|
|
*
|
|
* This file contains the variable definitions that will be used by the FIPS140
|
|
* s/w module to access the RELA sections in the ELF image. These are used to
|
|
* apply the relocations applied by the module loader in reverse, so that we
|
|
* can reconstruct the image that was used to derive the HMAC used by the
|
|
* integrity check.
|
|
*
|
|
* The first .long of each entry will be populated by the module loader based
|
|
* on the actual placement of the respective RELA section in memory. The second
|
|
* .long carries the RELA entry count, and is populated by the host tool that
|
|
* also generates the HMAC of the contents of .text and .rodata.
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
|
#include <asm/assembler.h>
|
|
|
|
.section ".init.rodata", "a"
|
|
|
|
.align 2
|
|
.globl fips140_rela_text
|
|
fips140_rela_text:
|
|
.weak __sec_rela_text
|
|
.long __sec_rela_text - .
|
|
.long 0
|
|
|
|
.globl fips140_rela_rodata
|
|
fips140_rela_rodata:
|
|
.weak __sec_rela_rodata
|
|
.long __sec_rela_rodata - .
|
|
.long 0
|