~sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget//translations/zh_CN/livepatch/module-elf-formatmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget//translations/zh_TW/livepatch/module-elf-formatmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget//translations/it_IT/livepatch/module-elf-formatmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget//translations/ja_JP/livepatch/module-elf-formatmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget//translations/ko_KR/livepatch/module-elf-formatmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget//translations/sp_SP/livepatch/module-elf-formatmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhsection)}(hhh](htitle)}(hLivepatch module ELF formath]hLivepatch module ELF format}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhI/var/lib/git/docbuild/linux/Documentation/livepatch/module-elf-format.rsthKubh paragraph)}(hVThis document outlines the ELF format requirements that livepatch modules must follow.h]hVThis document outlines the ELF format requirements that livepatch modules must follow.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubhcomment)}(hTable of Contentsh]hTable of Contents}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhhhhK ubhtopic)}(hhh]h bullet_list)}(hhh](h list_item)}(hhh](h)}(hhh]h reference)}(hhh]h1. Background and motivation}(hhhhhNhNubah}(h]id2ah ]h"]h$]h&]refidbackground-and-motivationuh1hhhubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h)}(hhh]h5Why does livepatch need to write its own relocations?}(hj hhhNhNubah}(h]id3ah ]h"]h$]h&]refid4why-does-livepatch-need-to-write-its-own-relocationsuh1hhj ubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]h2. Livepatch modinfo field}(hj:hhhNhNubah}(h]id4ah ]h"]h$]h&]refidlivepatch-modinfo-fielduh1hhj7ubah}(h]h ]h"]h$]h&]uh1hhj4ubh)}(hhh]h)}(hhh]h)}(hhh]h)}(hhh]hExample:}(hjYhhhNhNubah}(h]id5ah ]h"]h$]h&]refidexampleuh1hhjVubah}(h]h ]h"]h$]h&]uh1hhjSubah}(h]h ]h"]h$]h&]uh1hhjPubah}(h]h ]h"]h$]h&]uh1hhj4ubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h 3. Livepatch relocation sections}(hjhhhNhNubah}(h]id6ah ]h"]h$]h&]refidlivepatch-relocation-sectionsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]h'3.1 Livepatch relocation section format}(hjhhhNhNubah}(h]id7ah ]h"]h$]h&]refid#livepatch-relocation-section-formatuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubh)}(hhh]h)}(hhh]h)}(hhh]h)}(hhh]h Examples:}(hjhhhNhNubah}(h]id8ah ]h"]h$]h&]refidexamplesuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h4. Livepatch symbols}(hjhhhNhNubah}(h]id9ah ]h"]h$]h&]refidlivepatch-symbolsuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h'4.1 A livepatch module’s symbol table}(hjhhhNhNubah}(h]id10ah ]h"]h$]h&]refid!a-livepatch-module-s-symbol-tableuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh](h)}(hhh]h)}(hhh]h4.2 Livepatch symbol format}(hj:hhhNhNubah}(h]id11ah ]h"]h$]h&]refidlivepatch-symbol-formatuh1hhj7ubah}(h]h ]h"]h$]h&]uh1hhj4ubh)}(hhh]h)}(hhh]h)}(hhh]h)}(hhh]h Examples:}(hjYhhhNhNubah}(h]id12ah ]h"]h$]h&]refidid1uh1hhjVubah}(h]h ]h"]h$]h&]uh1hhjSubah}(h]h ]h"]h$]h&]uh1hhjPubah}(h]h ]h"]h$]h&]uh1hhj4ubeh}(h]h ]h"]h$]h&]uh1hhhubh)}(hhh]h)}(hhh]h)}(hhh]h&5. Symbol table and ELF section access}(hjhhhNhNubah}(h]id13ah ]h"]h$]h&]refid#symbol-table-and-elf-section-accessuh1hhjubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]uh1hhhubeh}(h]h ]h"]h$]h&]uh1hhhhhhNhNubah}(h]contentsah ](contentslocaleh"]contentsah$]h&]uh1hhhhK hhhhubh)}(hhh](h)}(h1. Background and motivationh]h1. Background and motivation}(hjhhhNhNubah}(h]h ]h"]h$]h&]refidhuh1hhjhhhhhKubh)}(hX,Formerly, livepatch required separate architecture-specific code to write relocations. However, arch-specific code to write relocations already exists in the module loader, so this former approach produced redundant code. So, instead of duplicating code and re-implementing what the module loader can already do, livepatch leverages existing code in the module loader to perform the all the arch-specific relocation work. Specifically, livepatch reuses the apply_relocate_add() function in the module loader to write relocations. The patch module ELF format described in this document enables livepatch to be able to do this. The hope is that this will make livepatch more easily portable to other architectures and reduce the amount of arch-specific code required to port livepatch to a particular architecture.h]hX,Formerly, livepatch required separate architecture-specific code to write relocations. However, arch-specific code to write relocations already exists in the module loader, so this former approach produced redundant code. So, instead of duplicating code and re-implementing what the module loader can already do, livepatch leverages existing code in the module loader to perform the all the arch-specific relocation work. Specifically, livepatch reuses the apply_relocate_add() function in the module loader to write relocations. The patch module ELF format described in this document enables livepatch to be able to do this. The hope is that this will make livepatch more easily portable to other architectures and reduce the amount of arch-specific code required to port livepatch to a particular architecture.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXSince apply_relocate_add() requires access to a module's section header table, symbol table, and relocation section indices, ELF information is preserved for livepatch modules (see section 5). Livepatch manages its own relocation sections and symbols, which are described in this document. The ELF constants used to mark livepatch symbols and relocation sections were selected from OS-specific ranges according to the definitions from glibc.h]hXSince apply_relocate_add() requires access to a module’s section header table, symbol table, and relocation section indices, ELF information is preserved for livepatch modules (see section 5). Livepatch manages its own relocation sections and symbols, which are described in this document. The ELF constants used to mark livepatch symbols and relocation sections were selected from OS-specific ranges according to the definitions from glibc.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hhh](h)}(h5Why does livepatch need to write its own relocations?h]h5Why does livepatch need to write its own relocations?}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhK%ubh)}(hXA typical livepatch module contains patched versions of functions that can reference non-exported global symbols and non-included local symbols. Relocations referencing these types of symbols cannot be left in as-is since the kernel module loader cannot resolve them and will therefore reject the livepatch module. Furthermore, we cannot apply relocations that affect modules not yet loaded at patch module load time (e.g. a patch to a driver that is not loaded). Formerly, livepatch solved this problem by embedding special "dynrela" (dynamic rela) sections in the resulting patch module ELF output. Using these dynrela sections, livepatch could resolve symbols while taking into account its scope and what module the symbol belongs to, and then manually apply the dynamic relocations. However this approach required livepatch to supply arch-specific code in order to write these relocations. In the new format, livepatch manages its own SHT_RELA relocation sections in place of dynrela sections, and the symbols that the relas reference are special livepatch symbols (see section 2 and 3). The arch-specific livepatch relocation code is replaced by a call to apply_relocate_add().h]hXA typical livepatch module contains patched versions of functions that can reference non-exported global symbols and non-included local symbols. Relocations referencing these types of symbols cannot be left in as-is since the kernel module loader cannot resolve them and will therefore reject the livepatch module. Furthermore, we cannot apply relocations that affect modules not yet loaded at patch module load time (e.g. a patch to a driver that is not loaded). Formerly, livepatch solved this problem by embedding special “dynrela” (dynamic rela) sections in the resulting patch module ELF output. Using these dynrela sections, livepatch could resolve symbols while taking into account its scope and what module the symbol belongs to, and then manually apply the dynamic relocations. However this approach required livepatch to supply arch-specific code in order to write these relocations. In the new format, livepatch manages its own SHT_RELA relocation sections in place of dynrela sections, and the symbols that the relas reference are special livepatch symbols (see section 2 and 3). The arch-specific livepatch relocation code is replaced by a call to apply_relocate_add().}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK&hjhhubeh}(h]jah ]h"]5why does livepatch need to write its own relocations?ah$]h&]uh1hhjhhhhhK%ubeh}(h]hah ]h"]1. background and motivationah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h2. Livepatch modinfo fieldh]h2. Livepatch modinfo field}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjCuh1hhjhhhhhK9ubh)}(hLivepatch modules are required to have the "livepatch" modinfo attribute. See the sample livepatch module in samples/livepatch/ for how this is done.h]hLivepatch modules are required to have the “livepatch” modinfo attribute. See the sample livepatch module in samples/livepatch/ for how this is done.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK;hjhhubh)}(hLivepatch modules can be identified by users by using the 'modinfo' command and looking for the presence of the "livepatch" field. This field is also used by the kernel module loader to identify livepatch modules.h]hLivepatch modules can be identified by users by using the ‘modinfo’ command and looking for the presence of the “livepatch” field. This field is also used by the kernel module loader to identify livepatch modules.}(hj-hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hjhhubh)}(hhh](h)}(hExample:h]hExample:}(hj>hhhNhNubah}(h]h ]h"]h$]h&]jjbuh1hhj;hhhhhKCubh)}(h**Modinfo output:**h]hstrong)}(hjNh]hModinfo output:}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1jPhjLubah}(h]h ]h"]h$]h&]uh1hhhhKEhj;hhubh literal_block)}(h% modinfo livepatch-meminfo.ko filename: livepatch-meminfo.ko livepatch: Y license: GPL depends: vermagic: 4.3.0+ SMP mod_unloadh]h% modinfo livepatch-meminfo.ko filename: livepatch-meminfo.ko livepatch: Y license: GPL depends: vermagic: 4.3.0+ SMP mod_unload}hjgsbah}(h]h ]h"]h$]h&]hhuh1jehhhKIhj;hhubeh}(h]jhah ]h"]example:ah$]h&]uh1hhjhhhhhKCubeh}(h]jIah ]h"]2. livepatch modinfo fieldah$]h&]uh1hhhhhhhhK9ubh)}(hhh](h)}(h 3. Livepatch relocation sectionsh]h 3. Livepatch relocation sections}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKQubh)}(hXHA livepatch module manages its own ELF relocation sections to apply relocations to modules as well as to the kernel (vmlinux) at the appropriate time. For example, if a patch module patches a driver that is not currently loaded, livepatch will apply the corresponding livepatch relocation section(s) to the driver once it loads.h]hXHA livepatch module manages its own ELF relocation sections to apply relocations to modules as well as to the kernel (vmlinux) at the appropriate time. For example, if a patch module patches a driver that is not currently loaded, livepatch will apply the corresponding livepatch relocation section(s) to the driver once it loads.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKShjhhubh)}(hXEach "object" (e.g. vmlinux, or a module) within a patch module may have multiple livepatch relocation sections associated with it (e.g. patches to multiple functions within the same object). There is a 1-1 correspondence between a livepatch relocation section and the target section (usually the text section of a function) to which the relocation(s) apply. It is also possible for a livepatch module to have no livepatch relocation sections, as in the case of the sample livepatch module (see samples/livepatch).h]hXEach “object” (e.g. vmlinux, or a module) within a patch module may have multiple livepatch relocation sections associated with it (e.g. patches to multiple functions within the same object). There is a 1-1 correspondence between a livepatch relocation section and the target section (usually the text section of a function) to which the relocation(s) apply. It is also possible for a livepatch module to have no livepatch relocation sections, as in the case of the sample livepatch module (see samples/livepatch).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKYhjhhubh)}(hXSince ELF information is preserved for livepatch modules (see Section 5), a livepatch relocation section can be applied simply by passing in the appropriate section index to apply_relocate_add(), which then uses it to access the relocation section and apply the relocations.h]hXSince ELF information is preserved for livepatch modules (see Section 5), a livepatch relocation section can be applied simply by passing in the appropriate section index to apply_relocate_add(), which then uses it to access the relocation section and apply the relocations.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKbhjhhubh)}(hEvery symbol referenced by a rela in a livepatch relocation section is a livepatch symbol. These must be resolved before livepatch can call apply_relocate_add(). See Section 3 for more information.h]hEvery symbol referenced by a rela in a livepatch relocation section is a livepatch symbol. These must be resolved before livepatch can call apply_relocate_add(). See Section 3 for more information.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKghjhhubeh}(h]jah ]h"] 3. livepatch relocation sectionsah$]h&]uh1hhhhhhhhKQubh)}(hhh](h)}(h'3.1 Livepatch relocation section formath]h'3.1 Livepatch relocation section format}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKlubh)}(hXLivepatch relocation sections must be marked with the SHF_RELA_LIVEPATCH section flag. See include/uapi/linux/elf.h for the definition. The module loader recognizes this flag and will avoid applying those relocation sections at patch module load time. These sections must also be marked with SHF_ALLOC, so that the module loader doesn't discard them on module load (i.e. they will be copied into memory along with the other SHF_ALLOC sections).h]hXLivepatch relocation sections must be marked with the SHF_RELA_LIVEPATCH section flag. See include/uapi/linux/elf.h for the definition. The module loader recognizes this flag and will avoid applying those relocation sections at patch module load time. These sections must also be marked with SHF_ALLOC, so that the module loader doesn’t discard them on module load (i.e. they will be copied into memory along with the other SHF_ALLOC sections).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKnhjhhubh)}(hQThe name of a livepatch relocation section must conform to the following format::h]hPThe name of a livepatch relocation section must conform to the following format:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKuhjhhubjf)}(hw.klp.rela.objname.section_name ^ ^^ ^ ^ ^ |________||_____| |__________| [A] [B] [C]h]hw.klp.rela.objname.section_name ^ ^^ ^ ^ ^ |________||_____| |__________| [A] [B] [C]}hjsbah}(h]h ]h"]h$]h&]hhuh1jehhhKxhjhhubhdefinition_list)}(hhh](hdefinition_list_item)}(hI[A] The relocation section name is prefixed with the string ".klp.rela." h](hterm)}(h[A]h]h[A]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhK~hjubh definition)}(hhh]h)}(hDThe relocation section name is prefixed with the string ".klp.rela."h]hHThe relocation section name is prefixed with the string “.klp.rela.”}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK~hj+ubah}(h]h ]h"]h$]h&]uh1j)hjubeh}(h]h ]h"]h$]h&]uh1jhhhK~hjubj)}(h[B] The name of the object (i.e. "vmlinux" or name of module) to which the relocation section belongs follows immediately after the prefix. h](j)}(h[B]h]h[B]}(hjLhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhKhjHubj*)}(hhh]h)}(hThe name of the object (i.e. "vmlinux" or name of module) to which the relocation section belongs follows immediately after the prefix.h]hThe name of the object (i.e. “vmlinux” or name of module) to which the relocation section belongs follows immediately after the prefix.}(hj]hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjZubah}(h]h ]h"]h$]h&]uh1j)hjHubeh}(h]h ]h"]h$]h&]uh1jhhhKhjhhubj)}(hM[C] The actual name of the section to which this relocation section applies. h](j)}(h[C]h]h[C]}(hj{hhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhKhjwubj*)}(hhh]h)}(hHThe actual name of the section to which this relocation section applies.h]hHThe actual name of the section to which this relocation section applies.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j)hjwubeh}(h]h ]h"]h$]h&]uh1jhhhKhjhhubeh}(h]h ]h"]h$]h&]uh1jhjhhhhhNubh)}(hhh](h)}(h Examples:h]h Examples:}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKubh)}(h'**Livepatch relocation section names:**h]jQ)}(hjh]h#Livepatch relocation section names:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jPhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubjf)}(hL.klp.rela.ext4.text.ext4_attr_store .klp.rela.vmlinux.text.cmdline_proc_showh]hL.klp.rela.ext4.text.ext4_attr_store .klp.rela.vmlinux.text.cmdline_proc_show}hjsbah}(h]h ]h"]h$]h&]hhuh1jehhhKhjhhubh)}(hd**`readelf --sections` output for a patch module that patches vmlinux and modules 9p, btrfs, ext4:**h]jQ)}(hjh]h``readelf --sections` output for a patch module that patches vmlinux and modules 9p, btrfs, ext4:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jPhjubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubjf)}(hX-Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ snip ] [29] .klp.rela.9p.text.caches.show RELA 0000000000000000 002d58 0000c0 18 AIo 64 9 8 [30] .klp.rela.btrfs.text.btrfs.feature.attr.show RELA 0000000000000000 002e18 000060 18 AIo 64 11 8 [ snip ] [34] .klp.rela.ext4.text.ext4.attr.store RELA 0000000000000000 002fd8 0000d8 18 AIo 64 13 8 [35] .klp.rela.ext4.text.ext4.attr.show RELA 0000000000000000 0030b0 000150 18 AIo 64 15 8 [36] .klp.rela.vmlinux.text.cmdline.proc.show RELA 0000000000000000 003200 000018 18 AIo 64 17 8 [37] .klp.rela.vmlinux.text.meminfo.proc.show RELA 0000000000000000 003218 0000f0 18 AIo 64 19 8 [ snip ] ^ ^ | | [*] [*]h]hX-Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ snip ] [29] .klp.rela.9p.text.caches.show RELA 0000000000000000 002d58 0000c0 18 AIo 64 9 8 [30] .klp.rela.btrfs.text.btrfs.feature.attr.show RELA 0000000000000000 002e18 000060 18 AIo 64 11 8 [ snip ] [34] .klp.rela.ext4.text.ext4.attr.store RELA 0000000000000000 002fd8 0000d8 18 AIo 64 13 8 [35] .klp.rela.ext4.text.ext4.attr.show RELA 0000000000000000 0030b0 000150 18 AIo 64 15 8 [36] .klp.rela.vmlinux.text.cmdline.proc.show RELA 0000000000000000 003200 000018 18 AIo 64 17 8 [37] .klp.rela.vmlinux.text.meminfo.proc.show RELA 0000000000000000 003218 0000f0 18 AIo 64 19 8 [ snip ] ^ ^ | | [*] [*]}hjsbah}(h]h ]h"]h$]h&]hhuh1jehhhKhjhhubj)}(hhh]j)}(hX[*] Livepatch relocation sections are SHT_RELA sections but with a few special characteristics. Notice that they are marked SHF_ALLOC ("A") so that they will not be discarded when the module is loaded into memory, as well as with the SHF_RELA_LIVEPATCH flag ("o" - for OS-specific). h](j)}(h[*]h]h[*]}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhKhj ubj*)}(hhh]h)}(hXLivepatch relocation sections are SHT_RELA sections but with a few special characteristics. Notice that they are marked SHF_ALLOC ("A") so that they will not be discarded when the module is loaded into memory, as well as with the SHF_RELA_LIVEPATCH flag ("o" - for OS-specific).h]hXLivepatch relocation sections are SHT_RELA sections but with a few special characteristics. Notice that they are marked SHF_ALLOC (“A”) so that they will not be discarded when the module is loaded into memory, as well as with the SHF_RELA_LIVEPATCH flag (“o” - for OS-specific).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1j)hj ubeh}(h]h ]h"]h$]h&]uh1jhhhKhjubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubh)}(h1**`readelf --relocs` output for a patch module:**h]jQ)}(hjAh]h-`readelf --relocs` output for a patch module:}(hjChhhNhNubah}(h]h ]h"]h$]h&]uh1jPhj?ubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubjf)}(hXjRelocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4 0000000000000028 0000003d0000000b R_X86_64_32S 0000000000000000 .klp.sym.btrfs.btrfs_ktype,0 + 0 0000000000000036 0000003b00000002 R_X86_64_PC32 0000000000000000 .klp.sym.btrfs.can_modify_feature.isra.3,0 - 4 000000000000004c 0000004900000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.snprintf,0 - 4 [ snip ] ^ | [*]h]hXjRelocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4 0000000000000028 0000003d0000000b R_X86_64_32S 0000000000000000 .klp.sym.btrfs.btrfs_ktype,0 + 0 0000000000000036 0000003b00000002 R_X86_64_PC32 0000000000000000 .klp.sym.btrfs.can_modify_feature.isra.3,0 - 4 000000000000004c 0000004900000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.snprintf,0 - 4 [ snip ] ^ | [*]}hjVsbah}(h]h ]h"]h$]h&]hhuh1jehhhKhjhhubj)}(hhh]j)}(hC[*] Every symbol referenced by a relocation is a livepatch symbol. h](j)}(h[*]h]h[*]}(hjkhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhhKhjgubj*)}(hhh]h)}(h>Every symbol referenced by a relocation is a livepatch symbol.h]h>Every symbol referenced by a relocation is a livepatch symbol.}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjyubah}(h]h ]h"]h$]h&]uh1j)hjgubeh}(h]h ]h"]h$]h&]uh1jhhhKhjdubah}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]jah ]h"]h$] examples:ah&]uh1hhjhhhhhK referencedKubeh}(h]jah ]h"]'3.1 livepatch relocation section formatah$]h&]uh1hhhhhhhhKlubh)}(hhh](h)}(h4. Livepatch symbolsh]h4. Livepatch symbols}(hjhhhNhNubah}(h]h ]h"]h$]h&]jjuh1hhjhhhhhKubh)}(hXLivepatch symbols are symbols referred to by livepatch relocation sections. These are symbols accessed from new versions of functions for patched objects, whose addresses cannot be resolved by the module loader (because they are local or unexported global syms). Since the module loader only resolves exported syms, and not every symbol referenced by the new patched functions is exported, livepatch symbols were introduced. They are used also in cases where we cannot immediately know the address of a symbol when a patch module loads. For example, this is the case when livepatch patches a module that is not loaded yet. In this case, the relevant livepatch symbols are resolved simply when the target module loads. In any case, for any livepatch relocation section, all livepatch symbols referenced by that section must be resolved before livepatch can call apply_relocate_add() for that reloc section.h]hXLivepatch symbols are symbols referred to by livepatch relocation sections. These are symbols accessed from new versions of functions for patched objects, whose addresses cannot be resolved by the module loader (because they are local or unexported global syms). Since the module loader only resolves exported syms, and not every symbol referenced by the new patched functions is exported, livepatch symbols were introduced. They are used also in cases where we cannot immediately know the address of a symbol when a patch module loads. For example, this is the case when livepatch patches a module that is not loaded yet. In this case, the relevant livepatch symbols are resolved simply when the target module loads. In any case, for any livepatch relocation section, all livepatch symbols referenced by that section must be resolved before livepatch can call apply_relocate_add() for that reloc section.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hLivepatch symbols must be marked with SHN_LIVEPATCH so that the module loader can identify and ignore them. Livepatch modules keep these symbols in their symbol tables, and the symbol table is made accessible through module->symtab.h]hLivepatch symbols must be marked with SHN_LIVEPATCH so that the module loader can identify and ignore them. Livepatch modules keep these symbols in their symbol tables, and the symbol table is made accessible through module->symtab.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h]jah ]h"]4. livepatch symbolsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h%4.1 A livepatch module's symbol tableh]h'4.1 A livepatch module’s symbol table}(hjhhhNhNubah}(h]h ]h"]h$]h&]jj!uh1hhjhhhhhKubh)}(hXiNormally, a stripped down copy of a module's symbol table (containing only "core" symbols) is made available through module->symtab (See layout_symtab() in kernel/module/kallsyms.c). For livepatch modules, the symbol table copied into memory on module load must be exactly the same as the symbol table produced when the patch module was compiled. This is because the relocations in each livepatch relocation section refer to their respective symbols with their symbol indices, and the original symbol indices (and thus the symtab ordering) must be preserved in order for apply_relocate_add() to find the right symbol.h]hXoNormally, a stripped down copy of a module’s symbol table (containing only “core” symbols) is made available through module->symtab (See layout_symtab() in kernel/module/kallsyms.c). For livepatch modules, the symbol table copied into memory on module load must be exactly the same as the symbol table produced when the patch module was compiled. This is because the relocations in each livepatch relocation section refer to their respective symbols with their symbol indices, and the original symbol indices (and thus the symtab ordering) must be preserved in order for apply_relocate_add() to find the right symbol.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h@For example, take this particular rela from a livepatch module::h]h?For example, take this particular rela from a livepatch module:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubjf)}(hX1Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4h]hX1Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: Offset Info Type Symbol's Value Symbol's Name + Addend 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4}hj sbah}(h]h ]h"]h$]h&]hhuh1jehhhKhjhhubh)}(hThis rela refers to the symbol '.klp.sym.vmlinux.printk,0', and the symbol index is encoded in 'Info'. Here its symbol index is 0x5e, which is 94 in decimal, which refers to the symbol index 94.h]hThis rela refers to the symbol ‘.klp.sym.vmlinux.printk,0’, and the symbol index is encoded in ‘Info’. Here its symbol index is 0x5e, which is 94 in decimal, which refers to the symbol index 94.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hcAnd in this patch module's corresponding symbol table, symbol index 94 refers to that very symbol::h]hdAnd in this patch module’s corresponding symbol table, symbol index 94 refers to that very symbol:}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubjf)}(hi[ snip ] 94: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.printk,0 [ snip ]h]hi[ snip ] 94: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.printk,0 [ snip ]}hj6sbah}(h]h ]h"]h$]h&]hhuh1jehhhKhjhhubeh}(h]j'ah ]h"]%4.1 a livepatch module's symbol tableah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h4.2 Livepatch symbol formath]h4.2 Livepatch symbol format}(hjNhhhNhNubah}(h]h ]h"]h$]h&]jjCuh1hhjKhhhhhKubh)}(hLivepatch symbols must have their section index marked as SHN_LIVEPATCH, so that the module loader can identify them and not attempt to resolve them. See include/uapi/linux/elf.h for the actual definitions.h]hLivepatch symbols must have their section index marked as SHN_LIVEPATCH, so that the module loader can identify them and not attempt to resolve them. See include/uapi/linux/elf.h for the actual definitions.}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjKhhubh)}(h=Livepatch symbol names must conform to the following format::h]hsymtab.h]hIA livepatch module’s symbol table is accessible through module->symtab.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM+hjhhubh)}(hXgSince apply_relocate_add() requires access to a module's section headers, symbol table, and relocation section indices, ELF information is preserved for livepatch modules and is made accessible by the module loader through module->klp_info, which is a :c:type:`klp_modinfo` struct. When a livepatch module loads, this struct is filled in by the module loader.h](hSince apply_relocate_add() requires access to a module’s section headers, symbol table, and relocation section indices, ELF information is preserved for livepatch modules and is made accessible by the module loader through module->klp_info, which is a }(hj hhhNhNubh)}(h:c:type:`klp_modinfo`h]hliteral)}(hjh]h klp_modinfo}(hjhhhNhNubah}(h]h ](xrefcc-typeeh"]h$]h&]uh1jhjubah}(h]h ]h"]h$]h&]refdoclivepatch/module-elf-format refdomainj#reftypetype refexplicitrefwarn reftarget klp_modinfouh1hhhhM-hj ubhV struct. When a livepatch module loads, this struct is filled in by the module loader.}(hj hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhM-hjhhubeh}(h]jah ]h"]&5. symbol table and elf section accessah$]h&]uh1hhhhhhhhM*ubeh}(h]livepatch-module-elf-formatah ]h"]livepatch module elf formatah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjserror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jMjJjjj hjjjjIjyjhjjjj examples:NjjjHj'jjIjEju nametypes}(jMjj jjjyjjjjjHjjEuh}(jJhjhhjjjjIjjhj;jjjjjjjjj'jjIjKjhjKjjhhjj jCj:jbjYjjjjjjjjj!jjCj:jbjYjju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}jK sRparse_messages]hsystem_message)}(hhh]h)}(h,Duplicate implicit target name: "examples:".h]h0Duplicate implicit target name: “examples:”.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubah}(h]h ]h"]h$]h&]jhalevelKtypeINFOsourcehlineM uh1jhjKhhhhhM ubatransform_messages] transformerN include_log] decorationNhhub.