Skip to content

Commit c9c8133

Browse files
committed
Merge branch 'for-6.4/doc' into for-linus
2 parents 1b47b80 + 6486a57 commit c9c8133

7 files changed

Lines changed: 36 additions & 34 deletions

File tree

Documentation/livepatch/module-elf-format.rst

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
===========================
2-
Livepatch module Elf format
2+
Livepatch module ELF format
33
===========================
44

5-
This document outlines the Elf format requirements that livepatch modules must follow.
5+
This document outlines the ELF format requirements that livepatch modules must follow.
66

77

88
.. Table of Contents
@@ -20,17 +20,17 @@ code. So, instead of duplicating code and re-implementing what the module
2020
loader can already do, livepatch leverages existing code in the module
2121
loader to perform the all the arch-specific relocation work. Specifically,
2222
livepatch reuses the apply_relocate_add() function in the module loader to
23-
write relocations. The patch module Elf format described in this document
23+
write relocations. The patch module ELF format described in this document
2424
enables livepatch to be able to do this. The hope is that this will make
2525
livepatch more easily portable to other architectures and reduce the amount
2626
of arch-specific code required to port livepatch to a particular
2727
architecture.
2828

2929
Since apply_relocate_add() requires access to a module's section header
30-
table, symbol table, and relocation section indices, Elf information is
30+
table, symbol table, and relocation section indices, ELF information is
3131
preserved for livepatch modules (see section 5). Livepatch manages its own
3232
relocation sections and symbols, which are described in this document. The
33-
Elf constants used to mark livepatch symbols and relocation sections were
33+
ELF constants used to mark livepatch symbols and relocation sections were
3434
selected from OS-specific ranges according to the definitions from glibc.
3535

3636
Why does livepatch need to write its own relocations?
@@ -43,7 +43,7 @@ reject the livepatch module. Furthermore, we cannot apply relocations that
4343
affect modules not yet loaded at patch module load time (e.g. a patch to a
4444
driver that is not loaded). Formerly, livepatch solved this problem by
4545
embedding special "dynrela" (dynamic rela) sections in the resulting patch
46-
module Elf output. Using these dynrela sections, livepatch could resolve
46+
module ELF output. Using these dynrela sections, livepatch could resolve
4747
symbols while taking into account its scope and what module the symbol
4848
belongs to, and then manually apply the dynamic relocations. However this
4949
approach required livepatch to supply arch-specific code in order to write
@@ -80,7 +80,7 @@ Example:
8080
3. Livepatch relocation sections
8181
================================
8282

83-
A livepatch module manages its own Elf relocation sections to apply
83+
A livepatch module manages its own ELF relocation sections to apply
8484
relocations to modules as well as to the kernel (vmlinux) at the
8585
appropriate time. For example, if a patch module patches a driver that is
8686
not currently loaded, livepatch will apply the corresponding livepatch
@@ -95,7 +95,7 @@ also possible for a livepatch module to have no livepatch relocation
9595
sections, as in the case of the sample livepatch module (see
9696
samples/livepatch).
9797

98-
Since Elf information is preserved for livepatch modules (see Section 5), a
98+
Since ELF information is preserved for livepatch modules (see Section 5), a
9999
livepatch relocation section can be applied simply by passing in the
100100
appropriate section index to apply_relocate_add(), which then uses it to
101101
access the relocation section and apply the relocations.
@@ -291,19 +291,12 @@ Examples:
291291
Note that the 'Ndx' (Section index) for these symbols is SHN_LIVEPATCH (0xff20).
292292
"OS" means OS-specific.
293293

294-
5. Symbol table and Elf section access
294+
5. Symbol table and ELF section access
295295
======================================
296296
A livepatch module's symbol table is accessible through module->symtab.
297297

298298
Since apply_relocate_add() requires access to a module's section headers,
299-
symbol table, and relocation section indices, Elf information is preserved for
299+
symbol table, and relocation section indices, ELF information is preserved for
300300
livepatch modules and is made accessible by the module loader through
301-
module->klp_info, which is a klp_modinfo struct. When a livepatch module loads,
302-
this struct is filled in by the module loader. Its fields are documented below::
303-
304-
struct klp_modinfo {
305-
Elf_Ehdr hdr; /* Elf header */
306-
Elf_Shdr *sechdrs; /* Section header table */
307-
char *secstrings; /* String table for the section headers */
308-
unsigned int symndx; /* The symbol table section index */
309-
};
301+
module->klp_info, which is a :c:type:`klp_modinfo` struct. When a livepatch module
302+
loads, this struct is filled in by the module loader.

include/linux/module.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ struct mod_kallsyms {
352352
};
353353

354354
#ifdef CONFIG_LIVEPATCH
355+
/**
356+
* struct klp_modinfo - ELF information preserved from the livepatch module
357+
*
358+
* @hdr: ELF header
359+
* @sechdrs: Section header table
360+
* @secstrings: String table for the section headers
361+
* @symndx: The symbol table section index
362+
*/
355363
struct klp_modinfo {
356364
Elf_Ehdr hdr;
357365
Elf_Shdr *sechdrs;
@@ -515,7 +523,7 @@ struct module {
515523
bool klp; /* Is this a livepatch module? */
516524
bool klp_alive;
517525

518-
/* Elf information */
526+
/* ELF information */
519527
struct klp_modinfo *klp_info;
520528
#endif
521529

kernel/module/livepatch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "internal.h"
1212

1313
/*
14-
* Persist Elf information about a module. Copy the Elf header,
14+
* Persist ELF information about a module. Copy the ELF header,
1515
* section header table, section string table, and symtab section
1616
* index from info to mod->klp_info.
1717
*/
@@ -25,27 +25,27 @@ int copy_module_elf(struct module *mod, struct load_info *info)
2525
if (!mod->klp_info)
2626
return -ENOMEM;
2727

28-
/* Elf header */
28+
/* ELF header */
2929
size = sizeof(mod->klp_info->hdr);
3030
memcpy(&mod->klp_info->hdr, info->hdr, size);
3131

32-
/* Elf section header table */
32+
/* ELF section header table */
3333
size = sizeof(*info->sechdrs) * info->hdr->e_shnum;
3434
mod->klp_info->sechdrs = kmemdup(info->sechdrs, size, GFP_KERNEL);
3535
if (!mod->klp_info->sechdrs) {
3636
ret = -ENOMEM;
3737
goto free_info;
3838
}
3939

40-
/* Elf section name string table */
40+
/* ELF section name string table */
4141
size = info->sechdrs[info->hdr->e_shstrndx].sh_size;
4242
mod->klp_info->secstrings = kmemdup(info->secstrings, size, GFP_KERNEL);
4343
if (!mod->klp_info->secstrings) {
4444
ret = -ENOMEM;
4545
goto free_sechdrs;
4646
}
4747

48-
/* Elf symbol section index */
48+
/* ELF symbol section index */
4949
symndx = info->index.sym;
5050
mod->klp_info->symndx = symndx;
5151

kernel/module/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/fs.h>
1818
#include <linux/kernel.h>
1919
#include <linux/kernel_read_file.h>
20+
#include <linux/kstrtox.h>
2021
#include <linux/slab.h>
2122
#include <linux/vmalloc.h>
2223
#include <linux/elf.h>
@@ -2675,7 +2676,7 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname,
26752676
int ret;
26762677

26772678
if (strcmp(param, "async_probe") == 0) {
2678-
if (strtobool(val, &mod->async_probe_requested))
2679+
if (kstrtobool(val, &mod->async_probe_requested))
26792680
mod->async_probe_requested = true;
26802681
return 0;
26812682
}

kernel/params.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
*/
66
#include <linux/kernel.h>
7+
#include <linux/kstrtox.h>
78
#include <linux/string.h>
89
#include <linux/errno.h>
910
#include <linux/module.h>
@@ -310,7 +311,7 @@ int param_set_bool(const char *val, const struct kernel_param *kp)
310311
if (!val) val = "1";
311312

312313
/* One of =[yYnN01] */
313-
return strtobool(val, kp->arg);
314+
return kstrtobool(val, kp->arg);
314315
}
315316
EXPORT_SYMBOL(param_set_bool);
316317

lib/test_kmod.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ static int num_test_devs;
5151

5252
/**
5353
* enum kmod_test_case - linker table test case
54-
*
55-
* If you add a test case, please be sure to review if you need to se
56-
* @need_mod_put for your tests case.
57-
*
5854
* @TEST_KMOD_DRIVER: stress tests request_module()
5955
* @TEST_KMOD_FS_TYPE: stress tests get_fs_type()
56+
*
57+
* If you add a test case, please be sure to review if you need to set
58+
* @need_mod_put for your tests case.
6059
*/
6160
enum kmod_test_case {
6261
__TEST_KMOD_INVALID = 0,
@@ -78,7 +77,7 @@ struct test_config {
7877
struct kmod_test_device;
7978

8079
/**
81-
* kmod_test_device_info - thread info
80+
* struct kmod_test_device_info - thread info
8281
*
8382
* @ret_sync: return value if request_module() is used, sync request for
8483
* @TEST_KMOD_DRIVER
@@ -101,7 +100,7 @@ struct kmod_test_device_info {
101100
};
102101

103102
/**
104-
* kmod_test_device - test device to help test kmod
103+
* struct kmod_test_device - test device to help test kmod
105104
*
106105
* @dev_idx: unique ID for test device
107106
* @config: configuration for the test

scripts/Makefile.modinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ modules := $(call read-file, $(MODORDER))
1414
ifeq ($(KBUILD_EXTMOD),)
1515
dst := $(MODLIB)/kernel
1616
else
17-
INSTALL_MOD_DIR ?= extra
17+
INSTALL_MOD_DIR ?= updates
1818
dst := $(MODLIB)/$(INSTALL_MOD_DIR)
1919
endif
2020

0 commit comments

Comments
 (0)