18c2ecf20Sopenharmony_ci===========================
28c2ecf20Sopenharmony_ciLivepatch module Elf format
38c2ecf20Sopenharmony_ci===========================
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ciThis document outlines the Elf format requirements that livepatch modules must follow.
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci.. Table of Contents
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci   1. Background and motivation
118c2ecf20Sopenharmony_ci   2. Livepatch modinfo field
128c2ecf20Sopenharmony_ci   3. Livepatch relocation sections
138c2ecf20Sopenharmony_ci      3.1 Livepatch relocation section format
148c2ecf20Sopenharmony_ci   4. Livepatch symbols
158c2ecf20Sopenharmony_ci      4.1 A livepatch module's symbol table
168c2ecf20Sopenharmony_ci      4.2 Livepatch symbol format
178c2ecf20Sopenharmony_ci   5. Symbol table and Elf section access
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci1. Background and motivation
208c2ecf20Sopenharmony_ci============================
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciFormerly, livepatch required separate architecture-specific code to write
238c2ecf20Sopenharmony_cirelocations. However, arch-specific code to write relocations already
248c2ecf20Sopenharmony_ciexists in the module loader, so this former approach produced redundant
258c2ecf20Sopenharmony_cicode. So, instead of duplicating code and re-implementing what the module
268c2ecf20Sopenharmony_ciloader can already do, livepatch leverages existing code in the module
278c2ecf20Sopenharmony_ciloader to perform the all the arch-specific relocation work. Specifically,
288c2ecf20Sopenharmony_cilivepatch reuses the apply_relocate_add() function in the module loader to
298c2ecf20Sopenharmony_ciwrite relocations. The patch module Elf format described in this document
308c2ecf20Sopenharmony_cienables livepatch to be able to do this. The hope is that this will make
318c2ecf20Sopenharmony_cilivepatch more easily portable to other architectures and reduce the amount
328c2ecf20Sopenharmony_ciof arch-specific code required to port livepatch to a particular
338c2ecf20Sopenharmony_ciarchitecture.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciSince apply_relocate_add() requires access to a module's section header
368c2ecf20Sopenharmony_citable, symbol table, and relocation section indices, Elf information is
378c2ecf20Sopenharmony_cipreserved for livepatch modules (see section 5). Livepatch manages its own
388c2ecf20Sopenharmony_cirelocation sections and symbols, which are described in this document. The
398c2ecf20Sopenharmony_ciElf constants used to mark livepatch symbols and relocation sections were
408c2ecf20Sopenharmony_ciselected from OS-specific ranges according to the definitions from glibc.
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciWhy does livepatch need to write its own relocations?
438c2ecf20Sopenharmony_ci-----------------------------------------------------
448c2ecf20Sopenharmony_ciA typical livepatch module contains patched versions of functions that can
458c2ecf20Sopenharmony_cireference non-exported global symbols and non-included local symbols.
468c2ecf20Sopenharmony_ciRelocations referencing these types of symbols cannot be left in as-is
478c2ecf20Sopenharmony_cisince the kernel module loader cannot resolve them and will therefore
488c2ecf20Sopenharmony_cireject the livepatch module. Furthermore, we cannot apply relocations that
498c2ecf20Sopenharmony_ciaffect modules not yet loaded at patch module load time (e.g. a patch to a
508c2ecf20Sopenharmony_cidriver that is not loaded). Formerly, livepatch solved this problem by
518c2ecf20Sopenharmony_ciembedding special "dynrela" (dynamic rela) sections in the resulting patch
528c2ecf20Sopenharmony_cimodule Elf output. Using these dynrela sections, livepatch could resolve
538c2ecf20Sopenharmony_cisymbols while taking into account its scope and what module the symbol
548c2ecf20Sopenharmony_cibelongs to, and then manually apply the dynamic relocations. However this
558c2ecf20Sopenharmony_ciapproach required livepatch to supply arch-specific code in order to write
568c2ecf20Sopenharmony_cithese relocations. In the new format, livepatch manages its own SHT_RELA
578c2ecf20Sopenharmony_cirelocation sections in place of dynrela sections, and the symbols that the
588c2ecf20Sopenharmony_cirelas reference are special livepatch symbols (see section 2 and 3). The
598c2ecf20Sopenharmony_ciarch-specific livepatch relocation code is replaced by a call to
608c2ecf20Sopenharmony_ciapply_relocate_add().
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci2. Livepatch modinfo field
638c2ecf20Sopenharmony_ci==========================
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciLivepatch modules are required to have the "livepatch" modinfo attribute.
668c2ecf20Sopenharmony_ciSee the sample livepatch module in samples/livepatch/ for how this is done.
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ciLivepatch modules can be identified by users by using the 'modinfo' command
698c2ecf20Sopenharmony_ciand looking for the presence of the "livepatch" field. This field is also
708c2ecf20Sopenharmony_ciused by the kernel module loader to identify livepatch modules.
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciExample:
738c2ecf20Sopenharmony_ci--------
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci**Modinfo output:**
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci::
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	% modinfo livepatch-meminfo.ko
808c2ecf20Sopenharmony_ci	filename:		livepatch-meminfo.ko
818c2ecf20Sopenharmony_ci	livepatch:		Y
828c2ecf20Sopenharmony_ci	license:		GPL
838c2ecf20Sopenharmony_ci	depends:
848c2ecf20Sopenharmony_ci	vermagic:		4.3.0+ SMP mod_unload
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci3. Livepatch relocation sections
878c2ecf20Sopenharmony_ci================================
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciA livepatch module manages its own Elf relocation sections to apply
908c2ecf20Sopenharmony_cirelocations to modules as well as to the kernel (vmlinux) at the
918c2ecf20Sopenharmony_ciappropriate time. For example, if a patch module patches a driver that is
928c2ecf20Sopenharmony_cinot currently loaded, livepatch will apply the corresponding livepatch
938c2ecf20Sopenharmony_cirelocation section(s) to the driver once it loads.
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciEach "object" (e.g. vmlinux, or a module) within a patch module may have
968c2ecf20Sopenharmony_cimultiple livepatch relocation sections associated with it (e.g. patches to
978c2ecf20Sopenharmony_cimultiple functions within the same object). There is a 1-1 correspondence
988c2ecf20Sopenharmony_cibetween a livepatch relocation section and the target section (usually the
998c2ecf20Sopenharmony_citext section of a function) to which the relocation(s) apply. It is
1008c2ecf20Sopenharmony_cialso possible for a livepatch module to have no livepatch relocation
1018c2ecf20Sopenharmony_cisections, as in the case of the sample livepatch module (see
1028c2ecf20Sopenharmony_cisamples/livepatch).
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciSince Elf information is preserved for livepatch modules (see Section 5), a
1058c2ecf20Sopenharmony_cilivepatch relocation section can be applied simply by passing in the
1068c2ecf20Sopenharmony_ciappropriate section index to apply_relocate_add(), which then uses it to
1078c2ecf20Sopenharmony_ciaccess the relocation section and apply the relocations.
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciEvery symbol referenced by a rela in a livepatch relocation section is a
1108c2ecf20Sopenharmony_cilivepatch symbol. These must be resolved before livepatch can call
1118c2ecf20Sopenharmony_ciapply_relocate_add(). See Section 3 for more information.
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci3.1 Livepatch relocation section format
1148c2ecf20Sopenharmony_ci=======================================
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ciLivepatch relocation sections must be marked with the SHF_RELA_LIVEPATCH
1178c2ecf20Sopenharmony_cisection flag. See include/uapi/linux/elf.h for the definition. The module
1188c2ecf20Sopenharmony_ciloader recognizes this flag and will avoid applying those relocation sections
1198c2ecf20Sopenharmony_ciat patch module load time. These sections must also be marked with SHF_ALLOC,
1208c2ecf20Sopenharmony_ciso that the module loader doesn't discard them on module load (i.e. they will
1218c2ecf20Sopenharmony_cibe copied into memory along with the other SHF_ALLOC sections).
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciThe name of a livepatch relocation section must conform to the following
1248c2ecf20Sopenharmony_ciformat::
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci  .klp.rela.objname.section_name
1278c2ecf20Sopenharmony_ci  ^        ^^     ^ ^          ^
1288c2ecf20Sopenharmony_ci  |________||_____| |__________|
1298c2ecf20Sopenharmony_ci     [A]      [B]        [C]
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci[A]
1328c2ecf20Sopenharmony_ci  The relocation section name is prefixed with the string ".klp.rela."
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci[B]
1358c2ecf20Sopenharmony_ci  The name of the object (i.e. "vmlinux" or name of module) to
1368c2ecf20Sopenharmony_ci  which the relocation section belongs follows immediately after the prefix.
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci[C]
1398c2ecf20Sopenharmony_ci  The actual name of the section to which this relocation section applies.
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ciExamples:
1428c2ecf20Sopenharmony_ci---------
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci**Livepatch relocation section names:**
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci::
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci  .klp.rela.ext4.text.ext4_attr_store
1498c2ecf20Sopenharmony_ci  .klp.rela.vmlinux.text.cmdline_proc_show
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci**`readelf --sections` output for a patch
1528c2ecf20Sopenharmony_cimodule that patches vmlinux and modules 9p, btrfs, ext4:**
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci::
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci  Section Headers:
1578c2ecf20Sopenharmony_ci  [Nr] Name                          Type                    Address          Off    Size   ES Flg Lk Inf Al
1588c2ecf20Sopenharmony_ci  [ snip ]
1598c2ecf20Sopenharmony_ci  [29] .klp.rela.9p.text.caches.show RELA                    0000000000000000 002d58 0000c0 18 AIo 64   9  8
1608c2ecf20Sopenharmony_ci  [30] .klp.rela.btrfs.text.btrfs.feature.attr.show RELA     0000000000000000 002e18 000060 18 AIo 64  11  8
1618c2ecf20Sopenharmony_ci  [ snip ]
1628c2ecf20Sopenharmony_ci  [34] .klp.rela.ext4.text.ext4.attr.store RELA              0000000000000000 002fd8 0000d8 18 AIo 64  13  8
1638c2ecf20Sopenharmony_ci  [35] .klp.rela.ext4.text.ext4.attr.show RELA               0000000000000000 0030b0 000150 18 AIo 64  15  8
1648c2ecf20Sopenharmony_ci  [36] .klp.rela.vmlinux.text.cmdline.proc.show RELA         0000000000000000 003200 000018 18 AIo 64  17  8
1658c2ecf20Sopenharmony_ci  [37] .klp.rela.vmlinux.text.meminfo.proc.show RELA         0000000000000000 003218 0000f0 18 AIo 64  19  8
1668c2ecf20Sopenharmony_ci  [ snip ]                                       ^                                             ^
1678c2ecf20Sopenharmony_ci                                                 |                                             |
1688c2ecf20Sopenharmony_ci                                                [*]                                           [*]
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci[*]
1718c2ecf20Sopenharmony_ci  Livepatch relocation sections are SHT_RELA sections but with a few special
1728c2ecf20Sopenharmony_ci  characteristics. Notice that they are marked SHF_ALLOC ("A") so that they will
1738c2ecf20Sopenharmony_ci  not be discarded when the module is loaded into memory, as well as with the
1748c2ecf20Sopenharmony_ci  SHF_RELA_LIVEPATCH flag ("o" - for OS-specific).
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci**`readelf --relocs` output for a patch module:**
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci::
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci  Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries:
1818c2ecf20Sopenharmony_ci      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
1828c2ecf20Sopenharmony_ci  000000000000001f  0000005e00000002 R_X86_64_PC32          0000000000000000 .klp.sym.vmlinux.printk,0 - 4
1838c2ecf20Sopenharmony_ci  0000000000000028  0000003d0000000b R_X86_64_32S           0000000000000000 .klp.sym.btrfs.btrfs_ktype,0 + 0
1848c2ecf20Sopenharmony_ci  0000000000000036  0000003b00000002 R_X86_64_PC32          0000000000000000 .klp.sym.btrfs.can_modify_feature.isra.3,0 - 4
1858c2ecf20Sopenharmony_ci  000000000000004c  0000004900000002 R_X86_64_PC32          0000000000000000 .klp.sym.vmlinux.snprintf,0 - 4
1868c2ecf20Sopenharmony_ci  [ snip ]                                                                   ^
1878c2ecf20Sopenharmony_ci                                                                             |
1888c2ecf20Sopenharmony_ci                                                                            [*]
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci[*]
1918c2ecf20Sopenharmony_ci  Every symbol referenced by a relocation is a livepatch symbol.
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci4. Livepatch symbols
1948c2ecf20Sopenharmony_ci====================
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ciLivepatch symbols are symbols referred to by livepatch relocation sections.
1978c2ecf20Sopenharmony_ciThese are symbols accessed from new versions of functions for patched
1988c2ecf20Sopenharmony_ciobjects, whose addresses cannot be resolved by the module loader (because
1998c2ecf20Sopenharmony_cithey are local or unexported global syms). Since the module loader only
2008c2ecf20Sopenharmony_ciresolves exported syms, and not every symbol referenced by the new patched
2018c2ecf20Sopenharmony_cifunctions is exported, livepatch symbols were introduced. They are used
2028c2ecf20Sopenharmony_cialso in cases where we cannot immediately know the address of a symbol when
2038c2ecf20Sopenharmony_cia patch module loads. For example, this is the case when livepatch patches
2048c2ecf20Sopenharmony_cia module that is not loaded yet. In this case, the relevant livepatch
2058c2ecf20Sopenharmony_cisymbols are resolved simply when the target module loads. In any case, for
2068c2ecf20Sopenharmony_ciany livepatch relocation section, all livepatch symbols referenced by that
2078c2ecf20Sopenharmony_cisection must be resolved before livepatch can call apply_relocate_add() for
2088c2ecf20Sopenharmony_cithat reloc section.
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ciLivepatch symbols must be marked with SHN_LIVEPATCH so that the module
2118c2ecf20Sopenharmony_ciloader can identify and ignore them. Livepatch modules keep these symbols
2128c2ecf20Sopenharmony_ciin their symbol tables, and the symbol table is made accessible through
2138c2ecf20Sopenharmony_cimodule->symtab.
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci4.1 A livepatch module's symbol table
2168c2ecf20Sopenharmony_ci=====================================
2178c2ecf20Sopenharmony_ciNormally, a stripped down copy of a module's symbol table (containing only
2188c2ecf20Sopenharmony_ci"core" symbols) is made available through module->symtab (See layout_symtab()
2198c2ecf20Sopenharmony_ciin kernel/module.c). For livepatch modules, the symbol table copied into memory
2208c2ecf20Sopenharmony_cion module load must be exactly the same as the symbol table produced when the
2218c2ecf20Sopenharmony_cipatch module was compiled. This is because the relocations in each livepatch
2228c2ecf20Sopenharmony_cirelocation section refer to their respective symbols with their symbol indices,
2238c2ecf20Sopenharmony_ciand the original symbol indices (and thus the symtab ordering) must be
2248c2ecf20Sopenharmony_cipreserved in order for apply_relocate_add() to find the right symbol.
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ciFor example, take this particular rela from a livepatch module:::
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci  Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries:
2298c2ecf20Sopenharmony_ci      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
2308c2ecf20Sopenharmony_ci  000000000000001f  0000005e00000002 R_X86_64_PC32          0000000000000000 .klp.sym.vmlinux.printk,0 - 4
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci  This rela refers to the symbol '.klp.sym.vmlinux.printk,0', and the symbol index is encoded
2338c2ecf20Sopenharmony_ci  in 'Info'. Here its symbol index is 0x5e, which is 94 in decimal, which refers to the
2348c2ecf20Sopenharmony_ci  symbol index 94.
2358c2ecf20Sopenharmony_ci  And in this patch module's corresponding symbol table, symbol index 94 refers to that very symbol:
2368c2ecf20Sopenharmony_ci  [ snip ]
2378c2ecf20Sopenharmony_ci  94: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.printk,0
2388c2ecf20Sopenharmony_ci  [ snip ]
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci4.2 Livepatch symbol format
2418c2ecf20Sopenharmony_ci===========================
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ciLivepatch symbols must have their section index marked as SHN_LIVEPATCH, so
2448c2ecf20Sopenharmony_cithat the module loader can identify them and not attempt to resolve them.
2458c2ecf20Sopenharmony_ciSee include/uapi/linux/elf.h for the actual definitions.
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ciLivepatch symbol names must conform to the following format::
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci  .klp.sym.objname.symbol_name,sympos
2508c2ecf20Sopenharmony_ci  ^       ^^     ^ ^         ^ ^
2518c2ecf20Sopenharmony_ci  |_______||_____| |_________| |
2528c2ecf20Sopenharmony_ci     [A]     [B]       [C]    [D]
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci[A]
2558c2ecf20Sopenharmony_ci  The symbol name is prefixed with the string ".klp.sym."
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci[B]
2588c2ecf20Sopenharmony_ci  The name of the object (i.e. "vmlinux" or name of module) to
2598c2ecf20Sopenharmony_ci  which the symbol belongs follows immediately after the prefix.
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci[C]
2628c2ecf20Sopenharmony_ci  The actual name of the symbol.
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci[D]
2658c2ecf20Sopenharmony_ci  The position of the symbol in the object (as according to kallsyms)
2668c2ecf20Sopenharmony_ci  This is used to differentiate duplicate symbols within the same
2678c2ecf20Sopenharmony_ci  object. The symbol position is expressed numerically (0, 1, 2...).
2688c2ecf20Sopenharmony_ci  The symbol position of a unique symbol is 0.
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ciExamples:
2718c2ecf20Sopenharmony_ci---------
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci**Livepatch symbol names:**
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci::
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	.klp.sym.vmlinux.snprintf,0
2788c2ecf20Sopenharmony_ci	.klp.sym.vmlinux.printk,0
2798c2ecf20Sopenharmony_ci	.klp.sym.btrfs.btrfs_ktype,0
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci**`readelf --symbols` output for a patch module:**
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci::
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci  Symbol table '.symtab' contains 127 entries:
2868c2ecf20Sopenharmony_ci     Num:    Value          Size Type    Bind   Vis     Ndx         Name
2878c2ecf20Sopenharmony_ci     [ snip ]
2888c2ecf20Sopenharmony_ci      73: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.snprintf,0
2898c2ecf20Sopenharmony_ci      74: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.capable,0
2908c2ecf20Sopenharmony_ci      75: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.find_next_bit,0
2918c2ecf20Sopenharmony_ci      76: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.si_swapinfo,0
2928c2ecf20Sopenharmony_ci    [ snip ]                                               ^
2938c2ecf20Sopenharmony_ci                                                           |
2948c2ecf20Sopenharmony_ci                                                          [*]
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci[*]
2978c2ecf20Sopenharmony_ci  Note that the 'Ndx' (Section index) for these symbols is SHN_LIVEPATCH (0xff20).
2988c2ecf20Sopenharmony_ci  "OS" means OS-specific.
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci5. Symbol table and Elf section access
3018c2ecf20Sopenharmony_ci======================================
3028c2ecf20Sopenharmony_ciA livepatch module's symbol table is accessible through module->symtab.
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ciSince apply_relocate_add() requires access to a module's section headers,
3058c2ecf20Sopenharmony_cisymbol table, and relocation section indices, Elf information is preserved for
3068c2ecf20Sopenharmony_cilivepatch modules and is made accessible by the module loader through
3078c2ecf20Sopenharmony_cimodule->klp_info, which is a klp_modinfo struct. When a livepatch module loads,
3088c2ecf20Sopenharmony_cithis struct is filled in by the module loader. Its fields are documented below::
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	struct klp_modinfo {
3118c2ecf20Sopenharmony_ci		Elf_Ehdr hdr; /* Elf header */
3128c2ecf20Sopenharmony_ci		Elf_Shdr *sechdrs; /* Section header table */
3138c2ecf20Sopenharmony_ci		char *secstrings; /* String table for the section headers */
3148c2ecf20Sopenharmony_ci		unsigned int symndx; /* The symbol table section index */
3158c2ecf20Sopenharmony_ci	};
316