diff options
-rw-r--r-- | Documentation/ABI/testing/sysfs-kernel-livepatch | 2 | ||||
-rw-r--r-- | Documentation/livepatch/callbacks.rst (renamed from Documentation/livepatch/callbacks.txt) | 12 | ||||
-rw-r--r-- | Documentation/livepatch/cumulative-patches.rst (renamed from Documentation/livepatch/cumulative-patches.txt) | 14 | ||||
-rw-r--r-- | Documentation/livepatch/index.rst | 21 | ||||
-rw-r--r-- | Documentation/livepatch/livepatch.rst (renamed from Documentation/livepatch/livepatch.txt) | 62 | ||||
-rw-r--r-- | Documentation/livepatch/module-elf-format.rst (renamed from Documentation/livepatch/module-elf-format.txt) | 217 | ||||
-rw-r--r-- | Documentation/livepatch/shadow-vars.rst (renamed from Documentation/livepatch/shadow-vars.txt) | 65 | ||||
-rw-r--r-- | tools/objtool/Documentation/stack-validation.txt | 2 |
8 files changed, 228 insertions, 167 deletions
diff --git a/Documentation/ABI/testing/sysfs-kernel-livepatch b/Documentation/ABI/testing/sysfs-kernel-livepatch index 85db352f68f9..bea7bd5a1d5f 100644 --- a/Documentation/ABI/testing/sysfs-kernel-livepatch +++ b/Documentation/ABI/testing/sysfs-kernel-livepatch | |||
@@ -45,7 +45,7 @@ Description: | |||
45 | use this feature without a clearance from a patch | 45 | use this feature without a clearance from a patch |
46 | distributor. Removal (rmmod) of patch modules is permanently | 46 | distributor. Removal (rmmod) of patch modules is permanently |
47 | disabled when the feature is used. See | 47 | disabled when the feature is used. See |
48 | Documentation/livepatch/livepatch.txt for more information. | 48 | Documentation/livepatch/livepatch.rst for more information. |
49 | 49 | ||
50 | What: /sys/kernel/livepatch/<patch>/<object> | 50 | What: /sys/kernel/livepatch/<patch>/<object> |
51 | Date: Nov 2014 | 51 | Date: Nov 2014 |
diff --git a/Documentation/livepatch/callbacks.txt b/Documentation/livepatch/callbacks.rst index 182e31d4abce..d76d1f0d9fcf 100644 --- a/Documentation/livepatch/callbacks.txt +++ b/Documentation/livepatch/callbacks.rst | |||
@@ -30,16 +30,20 @@ be patched, irrespective of the target klp_object's current state. | |||
30 | 30 | ||
31 | Callbacks can be registered for the following livepatch actions: | 31 | Callbacks can be registered for the following livepatch actions: |
32 | 32 | ||
33 | * Pre-patch - before a klp_object is patched | 33 | * Pre-patch |
34 | - before a klp_object is patched | ||
34 | 35 | ||
35 | * Post-patch - after a klp_object has been patched and is active | 36 | * Post-patch |
37 | - after a klp_object has been patched and is active | ||
36 | across all tasks | 38 | across all tasks |
37 | 39 | ||
38 | * Pre-unpatch - before a klp_object is unpatched (ie, patched code is | 40 | * Pre-unpatch |
41 | - before a klp_object is unpatched (ie, patched code is | ||
39 | active), used to clean up post-patch callback | 42 | active), used to clean up post-patch callback |
40 | resources | 43 | resources |
41 | 44 | ||
42 | * Post-unpatch - after a klp_object has been patched, all code has | 45 | * Post-unpatch |
46 | - after a klp_object has been patched, all code has | ||
43 | been restored and no tasks are running patched code, | 47 | been restored and no tasks are running patched code, |
44 | used to cleanup pre-patch callback resources | 48 | used to cleanup pre-patch callback resources |
45 | 49 | ||
diff --git a/Documentation/livepatch/cumulative-patches.txt b/Documentation/livepatch/cumulative-patches.rst index 0012808e8d44..1931f318976a 100644 --- a/Documentation/livepatch/cumulative-patches.txt +++ b/Documentation/livepatch/cumulative-patches.rst | |||
@@ -18,7 +18,7 @@ Usage | |||
18 | ----- | 18 | ----- |
19 | 19 | ||
20 | The atomic replace can be enabled by setting "replace" flag in struct klp_patch, | 20 | The atomic replace can be enabled by setting "replace" flag in struct klp_patch, |
21 | for example: | 21 | for example:: |
22 | 22 | ||
23 | static struct klp_patch patch = { | 23 | static struct klp_patch patch = { |
24 | .mod = THIS_MODULE, | 24 | .mod = THIS_MODULE, |
@@ -49,19 +49,19 @@ Features | |||
49 | 49 | ||
50 | The atomic replace allows: | 50 | The atomic replace allows: |
51 | 51 | ||
52 | + Atomically revert some functions in a previous patch while | 52 | - Atomically revert some functions in a previous patch while |
53 | upgrading other functions. | 53 | upgrading other functions. |
54 | 54 | ||
55 | + Remove eventual performance impact caused by core redirection | 55 | - Remove eventual performance impact caused by core redirection |
56 | for functions that are no longer patched. | 56 | for functions that are no longer patched. |
57 | 57 | ||
58 | + Decrease user confusion about dependencies between livepatches. | 58 | - Decrease user confusion about dependencies between livepatches. |
59 | 59 | ||
60 | 60 | ||
61 | Limitations: | 61 | Limitations: |
62 | ------------ | 62 | ------------ |
63 | 63 | ||
64 | + Once the operation finishes, there is no straightforward way | 64 | - Once the operation finishes, there is no straightforward way |
65 | to reverse it and restore the replaced patches atomically. | 65 | to reverse it and restore the replaced patches atomically. |
66 | 66 | ||
67 | A good practice is to set .replace flag in any released livepatch. | 67 | A good practice is to set .replace flag in any released livepatch. |
@@ -74,7 +74,7 @@ Limitations: | |||
74 | only when the transition was not forced. | 74 | only when the transition was not forced. |
75 | 75 | ||
76 | 76 | ||
77 | + Only the (un)patching callbacks from the _new_ cumulative livepatch are | 77 | - Only the (un)patching callbacks from the _new_ cumulative livepatch are |
78 | executed. Any callbacks from the replaced patches are ignored. | 78 | executed. Any callbacks from the replaced patches are ignored. |
79 | 79 | ||
80 | In other words, the cumulative patch is responsible for doing any actions | 80 | In other words, the cumulative patch is responsible for doing any actions |
@@ -93,7 +93,7 @@ Limitations: | |||
93 | enabled patches were called. | 93 | enabled patches were called. |
94 | 94 | ||
95 | 95 | ||
96 | + There is no special handling of shadow variables. Livepatch authors | 96 | - There is no special handling of shadow variables. Livepatch authors |
97 | must create their own rules how to pass them from one cumulative | 97 | must create their own rules how to pass them from one cumulative |
98 | patch to the other. Especially that they should not blindly remove | 98 | patch to the other. Especially that they should not blindly remove |
99 | them in module_exit() functions. | 99 | them in module_exit() functions. |
diff --git a/Documentation/livepatch/index.rst b/Documentation/livepatch/index.rst new file mode 100644 index 000000000000..edd291d51847 --- /dev/null +++ b/Documentation/livepatch/index.rst | |||
@@ -0,0 +1,21 @@ | |||
1 | :orphan: | ||
2 | |||
3 | =================== | ||
4 | Kernel Livepatching | ||
5 | =================== | ||
6 | |||
7 | .. toctree:: | ||
8 | :maxdepth: 1 | ||
9 | |||
10 | livepatch | ||
11 | callbacks | ||
12 | cumulative-patches | ||
13 | module-elf-format | ||
14 | shadow-vars | ||
15 | |||
16 | .. only:: subproject and html | ||
17 | |||
18 | Indices | ||
19 | ======= | ||
20 | |||
21 | * :ref:`genindex` | ||
diff --git a/Documentation/livepatch/livepatch.txt b/Documentation/livepatch/livepatch.rst index 4627b41ff02e..c2c598c4ead8 100644 --- a/Documentation/livepatch/livepatch.txt +++ b/Documentation/livepatch/livepatch.rst | |||
@@ -4,22 +4,22 @@ Livepatch | |||
4 | 4 | ||
5 | This document outlines basic information about kernel livepatching. | 5 | This document outlines basic information about kernel livepatching. |
6 | 6 | ||
7 | Table of Contents: | 7 | .. Table of Contents: |
8 | 8 | ||
9 | 1. Motivation | 9 | 1. Motivation |
10 | 2. Kprobes, Ftrace, Livepatching | 10 | 2. Kprobes, Ftrace, Livepatching |
11 | 3. Consistency model | 11 | 3. Consistency model |
12 | 4. Livepatch module | 12 | 4. Livepatch module |
13 | 4.1. New functions | 13 | 4.1. New functions |
14 | 4.2. Metadata | 14 | 4.2. Metadata |
15 | 5. Livepatch life-cycle | 15 | 5. Livepatch life-cycle |
16 | 5.1. Loading | 16 | 5.1. Loading |
17 | 5.2. Enabling | 17 | 5.2. Enabling |
18 | 5.3. Replacing | 18 | 5.3. Replacing |
19 | 5.4. Disabling | 19 | 5.4. Disabling |
20 | 5.5. Removing | 20 | 5.5. Removing |
21 | 6. Sysfs | 21 | 6. Sysfs |
22 | 7. Limitations | 22 | 7. Limitations |
23 | 23 | ||
24 | 24 | ||
25 | 1. Motivation | 25 | 1. Motivation |
@@ -40,14 +40,14 @@ There are multiple mechanisms in the Linux kernel that are directly related | |||
40 | to redirection of code execution; namely: kernel probes, function tracing, | 40 | to redirection of code execution; namely: kernel probes, function tracing, |
41 | and livepatching: | 41 | and livepatching: |
42 | 42 | ||
43 | + The kernel probes are the most generic. The code can be redirected by | 43 | - The kernel probes are the most generic. The code can be redirected by |
44 | putting a breakpoint instruction instead of any instruction. | 44 | putting a breakpoint instruction instead of any instruction. |
45 | 45 | ||
46 | + The function tracer calls the code from a predefined location that is | 46 | - The function tracer calls the code from a predefined location that is |
47 | close to the function entry point. This location is generated by the | 47 | close to the function entry point. This location is generated by the |
48 | compiler using the '-pg' gcc option. | 48 | compiler using the '-pg' gcc option. |
49 | 49 | ||
50 | + Livepatching typically needs to redirect the code at the very beginning | 50 | - Livepatching typically needs to redirect the code at the very beginning |
51 | of the function entry before the function parameters or the stack | 51 | of the function entry before the function parameters or the stack |
52 | are in any way modified. | 52 | are in any way modified. |
53 | 53 | ||
@@ -249,7 +249,7 @@ The patch contains only functions that are really modified. But they | |||
249 | might want to access functions or data from the original source file | 249 | might want to access functions or data from the original source file |
250 | that may only be locally accessible. This can be solved by a special | 250 | that may only be locally accessible. This can be solved by a special |
251 | relocation section in the generated livepatch module, see | 251 | relocation section in the generated livepatch module, see |
252 | Documentation/livepatch/module-elf-format.txt for more details. | 252 | Documentation/livepatch/module-elf-format.rst for more details. |
253 | 253 | ||
254 | 254 | ||
255 | 4.2. Metadata | 255 | 4.2. Metadata |
@@ -258,7 +258,7 @@ Documentation/livepatch/module-elf-format.txt for more details. | |||
258 | The patch is described by several structures that split the information | 258 | The patch is described by several structures that split the information |
259 | into three levels: | 259 | into three levels: |
260 | 260 | ||
261 | + struct klp_func is defined for each patched function. It describes | 261 | - struct klp_func is defined for each patched function. It describes |
262 | the relation between the original and the new implementation of a | 262 | the relation between the original and the new implementation of a |
263 | particular function. | 263 | particular function. |
264 | 264 | ||
@@ -275,7 +275,7 @@ into three levels: | |||
275 | only for a particular object ( vmlinux or a kernel module ). Note that | 275 | only for a particular object ( vmlinux or a kernel module ). Note that |
276 | kallsyms allows for searching symbols according to the object name. | 276 | kallsyms allows for searching symbols according to the object name. |
277 | 277 | ||
278 | + struct klp_object defines an array of patched functions (struct | 278 | - struct klp_object defines an array of patched functions (struct |
279 | klp_func) in the same object. Where the object is either vmlinux | 279 | klp_func) in the same object. Where the object is either vmlinux |
280 | (NULL) or a module name. | 280 | (NULL) or a module name. |
281 | 281 | ||
@@ -285,7 +285,7 @@ into three levels: | |||
285 | only when they are available. | 285 | only when they are available. |
286 | 286 | ||
287 | 287 | ||
288 | + struct klp_patch defines an array of patched objects (struct | 288 | - struct klp_patch defines an array of patched objects (struct |
289 | klp_object). | 289 | klp_object). |
290 | 290 | ||
291 | This structure handles all patched functions consistently and eventually, | 291 | This structure handles all patched functions consistently and eventually, |
@@ -337,14 +337,16 @@ operation fails. | |||
337 | Second, livepatch enters into a transition state where tasks are converging | 337 | Second, livepatch enters into a transition state where tasks are converging |
338 | to the patched state. If an original function is patched for the first | 338 | to the patched state. If an original function is patched for the first |
339 | time, a function specific struct klp_ops is created and an universal | 339 | time, a function specific struct klp_ops is created and an universal |
340 | ftrace handler is registered[*]. This stage is indicated by a value of '1' | 340 | ftrace handler is registered\ [#]_. This stage is indicated by a value of '1' |
341 | in /sys/kernel/livepatch/<name>/transition. For more information about | 341 | in /sys/kernel/livepatch/<name>/transition. For more information about |
342 | this process, see the "Consistency model" section. | 342 | this process, see the "Consistency model" section. |
343 | 343 | ||
344 | Finally, once all tasks have been patched, the 'transition' value changes | 344 | Finally, once all tasks have been patched, the 'transition' value changes |
345 | to '0'. | 345 | to '0'. |
346 | 346 | ||
347 | [*] Note that functions might be patched multiple times. The ftrace handler | 347 | .. [#] |
348 | |||
349 | Note that functions might be patched multiple times. The ftrace handler | ||
348 | is registered only once for a given function. Further patches just add | 350 | is registered only once for a given function. Further patches just add |
349 | an entry to the list (see field `func_stack`) of the struct klp_ops. | 351 | an entry to the list (see field `func_stack`) of the struct klp_ops. |
350 | The right implementation is selected by the ftrace handler, see | 352 | The right implementation is selected by the ftrace handler, see |
@@ -368,7 +370,7 @@ the ftrace handler is unregistered and the struct klp_ops is | |||
368 | freed when the related function is not modified by the new patch | 370 | freed when the related function is not modified by the new patch |
369 | and func_stack list becomes empty. | 371 | and func_stack list becomes empty. |
370 | 372 | ||
371 | See Documentation/livepatch/cumulative-patches.txt for more details. | 373 | See Documentation/livepatch/cumulative-patches.rst for more details. |
372 | 374 | ||
373 | 375 | ||
374 | 5.4. Disabling | 376 | 5.4. Disabling |
@@ -421,7 +423,7 @@ See Documentation/ABI/testing/sysfs-kernel-livepatch for more details. | |||
421 | 423 | ||
422 | The current Livepatch implementation has several limitations: | 424 | The current Livepatch implementation has several limitations: |
423 | 425 | ||
424 | + Only functions that can be traced could be patched. | 426 | - Only functions that can be traced could be patched. |
425 | 427 | ||
426 | Livepatch is based on the dynamic ftrace. In particular, functions | 428 | Livepatch is based on the dynamic ftrace. In particular, functions |
427 | implementing ftrace or the livepatch ftrace handler could not be | 429 | implementing ftrace or the livepatch ftrace handler could not be |
@@ -431,7 +433,7 @@ The current Livepatch implementation has several limitations: | |||
431 | 433 | ||
432 | 434 | ||
433 | 435 | ||
434 | + Livepatch works reliably only when the dynamic ftrace is located at | 436 | - Livepatch works reliably only when the dynamic ftrace is located at |
435 | the very beginning of the function. | 437 | the very beginning of the function. |
436 | 438 | ||
437 | The function need to be redirected before the stack or the function | 439 | The function need to be redirected before the stack or the function |
@@ -445,7 +447,7 @@ The current Livepatch implementation has several limitations: | |||
445 | this is handled on the ftrace level. | 447 | this is handled on the ftrace level. |
446 | 448 | ||
447 | 449 | ||
448 | + Kretprobes using the ftrace framework conflict with the patched | 450 | - Kretprobes using the ftrace framework conflict with the patched |
449 | functions. | 451 | functions. |
450 | 452 | ||
451 | Both kretprobes and livepatches use a ftrace handler that modifies | 453 | Both kretprobes and livepatches use a ftrace handler that modifies |
@@ -453,7 +455,7 @@ The current Livepatch implementation has several limitations: | |||
453 | is rejected when the handler is already in use by the other. | 455 | is rejected when the handler is already in use by the other. |
454 | 456 | ||
455 | 457 | ||
456 | + Kprobes in the original function are ignored when the code is | 458 | - Kprobes in the original function are ignored when the code is |
457 | redirected to the new implementation. | 459 | redirected to the new implementation. |
458 | 460 | ||
459 | There is a work in progress to add warnings about this situation. | 461 | There is a work in progress to add warnings about this situation. |
diff --git a/Documentation/livepatch/module-elf-format.txt b/Documentation/livepatch/module-elf-format.rst index f21a5289a09c..7f557c6f6deb 100644 --- a/Documentation/livepatch/module-elf-format.txt +++ b/Documentation/livepatch/module-elf-format.rst | |||
@@ -4,29 +4,29 @@ Livepatch module Elf format | |||
4 | 4 | ||
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. |
6 | 6 | ||
7 | ----------------- | 7 | |
8 | Table of Contents | 8 | .. Table of Contents |
9 | ----------------- | 9 | |
10 | 0. Background and motivation | 10 | 0. Background and motivation |
11 | 1. Livepatch modinfo field | 11 | 1. Livepatch modinfo field |
12 | 2. Livepatch relocation sections | 12 | 2. Livepatch relocation sections |
13 | 2.1 What are livepatch relocation sections? | 13 | 2.1 What are livepatch relocation sections? |
14 | 2.2 Livepatch relocation section format | 14 | 2.2 Livepatch relocation section format |
15 | 2.2.1 Required flags | 15 | 2.2.1 Required flags |
16 | 2.2.2 Required name format | 16 | 2.2.2 Required name format |
17 | 2.2.3 Example livepatch relocation section names | 17 | 2.2.3 Example livepatch relocation section names |
18 | 2.2.4 Example `readelf --sections` output | 18 | 2.2.4 Example `readelf --sections` output |
19 | 2.2.5 Example `readelf --relocs` output | 19 | 2.2.5 Example `readelf --relocs` output |
20 | 3. Livepatch symbols | 20 | 3. Livepatch symbols |
21 | 3.1 What are livepatch symbols? | 21 | 3.1 What are livepatch symbols? |
22 | 3.2 A livepatch module's symbol table | 22 | 3.2 A livepatch module's symbol table |
23 | 3.3 Livepatch symbol format | 23 | 3.3 Livepatch symbol format |
24 | 3.3.1 Required flags | 24 | 3.3.1 Required flags |
25 | 3.3.2 Required name format | 25 | 3.3.2 Required name format |
26 | 3.3.3 Example livepatch symbol names | 26 | 3.3.3 Example livepatch symbol names |
27 | 3.3.4 Example `readelf --symbols` output | 27 | 3.3.4 Example `readelf --symbols` output |
28 | 4. Architecture-specific sections | 28 | 4. Architecture-specific sections |
29 | 5. Symbol table and Elf section access | 29 | 5. Symbol table and Elf section access |
30 | 30 | ||
31 | ---------------------------- | 31 | ---------------------------- |
32 | 0. Background and motivation | 32 | 0. Background and motivation |
@@ -89,12 +89,15 @@ used by the kernel module loader to identify livepatch modules. | |||
89 | 89 | ||
90 | Example modinfo output: | 90 | Example modinfo output: |
91 | ----------------------- | 91 | ----------------------- |
92 | % modinfo livepatch-meminfo.ko | 92 | |
93 | filename: livepatch-meminfo.ko | 93 | :: |
94 | livepatch: Y | 94 | |
95 | license: GPL | 95 | % modinfo livepatch-meminfo.ko |
96 | depends: | 96 | filename: livepatch-meminfo.ko |
97 | vermagic: 4.3.0+ SMP mod_unload | 97 | livepatch: Y |
98 | license: GPL | ||
99 | depends: | ||
100 | vermagic: 4.3.0+ SMP mod_unload | ||
98 | 101 | ||
99 | -------------------------------- | 102 | -------------------------------- |
100 | 2. Livepatch relocation sections | 103 | 2. Livepatch relocation sections |
@@ -142,17 +145,18 @@ be copied into memory along with the other SHF_ALLOC sections). | |||
142 | 145 | ||
143 | 2.2.2 Required name format | 146 | 2.2.2 Required name format |
144 | -------------------------- | 147 | -------------------------- |
145 | The name of a livepatch relocation section must conform to the following format: | 148 | The name of a livepatch relocation section must conform to the following |
149 | format:: | ||
146 | 150 | ||
147 | .klp.rela.objname.section_name | 151 | .klp.rela.objname.section_name |
148 | ^ ^^ ^ ^ ^ | 152 | ^ ^^ ^ ^ ^ |
149 | |________||_____| |__________| | 153 | |________||_____| |__________| |
150 | [A] [B] [C] | 154 | [A] [B] [C] |
151 | 155 | ||
152 | [A] The relocation section name is prefixed with the string ".klp.rela." | 156 | [A] The relocation section name is prefixed with the string ".klp.rela." |
153 | [B] The name of the object (i.e. "vmlinux" or name of module) to | 157 | [B] The name of the object (i.e. "vmlinux" or name of module) to |
154 | which the relocation section belongs follows immediately after the prefix. | 158 | which the relocation section belongs follows immediately after the prefix. |
155 | [C] The actual name of the section to which this relocation section applies. | 159 | [C] The actual name of the section to which this relocation section applies. |
156 | 160 | ||
157 | 2.2.3 Example livepatch relocation section names: | 161 | 2.2.3 Example livepatch relocation section names: |
158 | ------------------------------------------------- | 162 | ------------------------------------------------- |
@@ -162,6 +166,9 @@ The name of a livepatch relocation section must conform to the following format: | |||
162 | 2.2.4 Example `readelf --sections` output for a patch | 166 | 2.2.4 Example `readelf --sections` output for a patch |
163 | module that patches vmlinux and modules 9p, btrfs, ext4: | 167 | module that patches vmlinux and modules 9p, btrfs, ext4: |
164 | -------------------------------------------------------- | 168 | -------------------------------------------------------- |
169 | |||
170 | :: | ||
171 | |||
165 | Section Headers: | 172 | Section Headers: |
166 | [Nr] Name Type Address Off Size ES Flg Lk Inf Al | 173 | [Nr] Name Type Address Off Size ES Flg Lk Inf Al |
167 | [ snip ] | 174 | [ snip ] |
@@ -175,23 +182,26 @@ module that patches vmlinux and modules 9p, btrfs, ext4: | |||
175 | [ snip ] ^ ^ | 182 | [ snip ] ^ ^ |
176 | | | | 183 | | | |
177 | [*] [*] | 184 | [*] [*] |
178 | [*] Livepatch relocation sections are SHT_RELA sections but with a few special | 185 | [*] Livepatch relocation sections are SHT_RELA sections but with a few special |
179 | characteristics. Notice that they are marked SHF_ALLOC ("A") so that they will | 186 | characteristics. Notice that they are marked SHF_ALLOC ("A") so that they will |
180 | not be discarded when the module is loaded into memory, as well as with the | 187 | not be discarded when the module is loaded into memory, as well as with the |
181 | SHF_RELA_LIVEPATCH flag ("o" - for OS-specific). | 188 | SHF_RELA_LIVEPATCH flag ("o" - for OS-specific). |
182 | 189 | ||
183 | 2.2.5 Example `readelf --relocs` output for a patch module: | 190 | 2.2.5 Example `readelf --relocs` output for a patch module: |
184 | ----------------------------------------------------------- | 191 | ----------------------------------------------------------- |
185 | Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: | 192 | |
186 | Offset Info Type Symbol's Value Symbol's Name + Addend | 193 | :: |
187 | 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4 | 194 | |
188 | 0000000000000028 0000003d0000000b R_X86_64_32S 0000000000000000 .klp.sym.btrfs.btrfs_ktype,0 + 0 | 195 | Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: |
189 | 0000000000000036 0000003b00000002 R_X86_64_PC32 0000000000000000 .klp.sym.btrfs.can_modify_feature.isra.3,0 - 4 | 196 | Offset Info Type Symbol's Value Symbol's Name + Addend |
190 | 000000000000004c 0000004900000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.snprintf,0 - 4 | 197 | 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4 |
191 | [ snip ] ^ | 198 | 0000000000000028 0000003d0000000b R_X86_64_32S 0000000000000000 .klp.sym.btrfs.btrfs_ktype,0 + 0 |
192 | | | 199 | 0000000000000036 0000003b00000002 R_X86_64_PC32 0000000000000000 .klp.sym.btrfs.can_modify_feature.isra.3,0 - 4 |
200 | 000000000000004c 0000004900000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.snprintf,0 - 4 | ||
201 | [ snip ] ^ | ||
202 | | | ||
193 | [*] | 203 | [*] |
194 | [*] Every symbol referenced by a relocation is a livepatch symbol. | 204 | [*] Every symbol referenced by a relocation is a livepatch symbol. |
195 | 205 | ||
196 | -------------------- | 206 | -------------------- |
197 | 3. Livepatch symbols | 207 | 3. Livepatch symbols |
@@ -231,18 +241,19 @@ relocation section refer to their respective symbols with their symbol indices, | |||
231 | and the original symbol indices (and thus the symtab ordering) must be | 241 | and the original symbol indices (and thus the symtab ordering) must be |
232 | preserved in order for apply_relocate_add() to find the right symbol. | 242 | preserved in order for apply_relocate_add() to find the right symbol. |
233 | 243 | ||
234 | For example, take this particular rela from a livepatch module: | 244 | For example, take this particular rela from a livepatch module::: |
235 | Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: | ||
236 | Offset Info Type Symbol's Value Symbol's Name + Addend | ||
237 | 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4 | ||
238 | 245 | ||
239 | This rela refers to the symbol '.klp.sym.vmlinux.printk,0', and the symbol index is encoded | 246 | Relocation section '.klp.rela.btrfs.text.btrfs_feature_attr_show' at offset 0x2ba0 contains 4 entries: |
240 | in 'Info'. Here its symbol index is 0x5e, which is 94 in decimal, which refers to the | 247 | Offset Info Type Symbol's Value Symbol's Name + Addend |
241 | symbol index 94. | 248 | 000000000000001f 0000005e00000002 R_X86_64_PC32 0000000000000000 .klp.sym.vmlinux.printk,0 - 4 |
242 | And in this patch module's corresponding symbol table, symbol index 94 refers to that very symbol: | 249 | |
243 | [ snip ] | 250 | This rela refers to the symbol '.klp.sym.vmlinux.printk,0', and the symbol index is encoded |
244 | 94: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.printk,0 | 251 | in 'Info'. Here its symbol index is 0x5e, which is 94 in decimal, which refers to the |
245 | [ snip ] | 252 | symbol index 94. |
253 | And in this patch module's corresponding symbol table, symbol index 94 refers to that very symbol: | ||
254 | [ snip ] | ||
255 | 94: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.printk,0 | ||
256 | [ snip ] | ||
246 | 257 | ||
247 | --------------------------- | 258 | --------------------------- |
248 | 3.3 Livepatch symbol format | 259 | 3.3 Livepatch symbol format |
@@ -256,42 +267,48 @@ See include/uapi/linux/elf.h for the actual definitions. | |||
256 | 267 | ||
257 | 3.3.2 Required name format | 268 | 3.3.2 Required name format |
258 | -------------------------- | 269 | -------------------------- |
259 | Livepatch symbol names must conform to the following format: | 270 | Livepatch symbol names must conform to the following format:: |
260 | 271 | ||
261 | .klp.sym.objname.symbol_name,sympos | 272 | .klp.sym.objname.symbol_name,sympos |
262 | ^ ^^ ^ ^ ^ ^ | 273 | ^ ^^ ^ ^ ^ ^ |
263 | |_______||_____| |_________| | | 274 | |_______||_____| |_________| | |
264 | [A] [B] [C] [D] | 275 | [A] [B] [C] [D] |
265 | 276 | ||
266 | [A] The symbol name is prefixed with the string ".klp.sym." | 277 | [A] The symbol name is prefixed with the string ".klp.sym." |
267 | [B] The name of the object (i.e. "vmlinux" or name of module) to | 278 | [B] The name of the object (i.e. "vmlinux" or name of module) to |
268 | which the symbol belongs follows immediately after the prefix. | 279 | which the symbol belongs follows immediately after the prefix. |
269 | [C] The actual name of the symbol. | 280 | [C] The actual name of the symbol. |
270 | [D] The position of the symbol in the object (as according to kallsyms) | 281 | [D] The position of the symbol in the object (as according to kallsyms) |
271 | This is used to differentiate duplicate symbols within the same | 282 | This is used to differentiate duplicate symbols within the same |
272 | object. The symbol position is expressed numerically (0, 1, 2...). | 283 | object. The symbol position is expressed numerically (0, 1, 2...). |
273 | The symbol position of a unique symbol is 0. | 284 | The symbol position of a unique symbol is 0. |
274 | 285 | ||
275 | 3.3.3 Example livepatch symbol names: | 286 | 3.3.3 Example livepatch symbol names: |
276 | ------------------------------------- | 287 | ------------------------------------- |
277 | .klp.sym.vmlinux.snprintf,0 | 288 | |
278 | .klp.sym.vmlinux.printk,0 | 289 | :: |
279 | .klp.sym.btrfs.btrfs_ktype,0 | 290 | |
291 | .klp.sym.vmlinux.snprintf,0 | ||
292 | .klp.sym.vmlinux.printk,0 | ||
293 | .klp.sym.btrfs.btrfs_ktype,0 | ||
280 | 294 | ||
281 | 3.3.4 Example `readelf --symbols` output for a patch module: | 295 | 3.3.4 Example `readelf --symbols` output for a patch module: |
282 | ------------------------------------------------------------ | 296 | ------------------------------------------------------------ |
283 | Symbol table '.symtab' contains 127 entries: | 297 | |
284 | Num: Value Size Type Bind Vis Ndx Name | 298 | :: |
285 | [ snip ] | 299 | |
286 | 73: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.snprintf,0 | 300 | Symbol table '.symtab' contains 127 entries: |
287 | 74: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.capable,0 | 301 | Num: Value Size Type Bind Vis Ndx Name |
288 | 75: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.find_next_bit,0 | 302 | [ snip ] |
289 | 76: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.si_swapinfo,0 | 303 | 73: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.snprintf,0 |
290 | [ snip ] ^ | 304 | 74: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.capable,0 |
291 | | | 305 | 75: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.find_next_bit,0 |
292 | [*] | 306 | 76: 0000000000000000 0 NOTYPE GLOBAL DEFAULT OS [0xff20] .klp.sym.vmlinux.si_swapinfo,0 |
293 | [*] Note that the 'Ndx' (Section index) for these symbols is SHN_LIVEPATCH (0xff20). | 307 | [ snip ] ^ |
294 | "OS" means OS-specific. | 308 | | |
309 | [*] | ||
310 | [*] Note that the 'Ndx' (Section index) for these symbols is SHN_LIVEPATCH (0xff20). | ||
311 | "OS" means OS-specific. | ||
295 | 312 | ||
296 | --------------------------------- | 313 | --------------------------------- |
297 | 4. Architecture-specific sections | 314 | 4. Architecture-specific sections |
@@ -313,11 +330,11 @@ Since apply_relocate_add() requires access to a module's section headers, | |||
313 | symbol table, and relocation section indices, Elf information is preserved for | 330 | symbol table, and relocation section indices, Elf information is preserved for |
314 | livepatch modules and is made accessible by the module loader through | 331 | livepatch modules and is made accessible by the module loader through |
315 | module->klp_info, which is a klp_modinfo struct. When a livepatch module loads, | 332 | module->klp_info, which is a klp_modinfo struct. When a livepatch module loads, |
316 | this struct is filled in by the module loader. Its fields are documented below: | 333 | this struct is filled in by the module loader. Its fields are documented below:: |
317 | 334 | ||
318 | struct klp_modinfo { | 335 | struct klp_modinfo { |
319 | Elf_Ehdr hdr; /* Elf header */ | 336 | Elf_Ehdr hdr; /* Elf header */ |
320 | Elf_Shdr *sechdrs; /* Section header table */ | 337 | Elf_Shdr *sechdrs; /* Section header table */ |
321 | char *secstrings; /* String table for the section headers */ | 338 | char *secstrings; /* String table for the section headers */ |
322 | unsigned int symndx; /* The symbol table section index */ | 339 | unsigned int symndx; /* The symbol table section index */ |
323 | }; | 340 | }; |
diff --git a/Documentation/livepatch/shadow-vars.txt b/Documentation/livepatch/shadow-vars.rst index ecc09a7be5dd..c05715aeafa4 100644 --- a/Documentation/livepatch/shadow-vars.txt +++ b/Documentation/livepatch/shadow-vars.rst | |||
@@ -27,10 +27,13 @@ A hashtable references all shadow variables. These references are | |||
27 | stored and retrieved through a <obj, id> pair. | 27 | stored and retrieved through a <obj, id> pair. |
28 | 28 | ||
29 | * The klp_shadow variable data structure encapsulates both tracking | 29 | * The klp_shadow variable data structure encapsulates both tracking |
30 | meta-data and shadow-data: | 30 | meta-data and shadow-data: |
31 | |||
31 | - meta-data | 32 | - meta-data |
33 | |||
32 | - obj - pointer to parent object | 34 | - obj - pointer to parent object |
33 | - id - data identifier | 35 | - id - data identifier |
36 | |||
34 | - data[] - storage for shadow data | 37 | - data[] - storage for shadow data |
35 | 38 | ||
36 | It is important to note that the klp_shadow_alloc() and | 39 | It is important to note that the klp_shadow_alloc() and |
@@ -47,31 +50,43 @@ to do actions that can be done only once when a new variable is allocated. | |||
47 | 50 | ||
48 | * klp_shadow_alloc() - allocate and add a new shadow variable | 51 | * klp_shadow_alloc() - allocate and add a new shadow variable |
49 | - search hashtable for <obj, id> pair | 52 | - search hashtable for <obj, id> pair |
53 | |||
50 | - if exists | 54 | - if exists |
55 | |||
51 | - WARN and return NULL | 56 | - WARN and return NULL |
57 | |||
52 | - if <obj, id> doesn't already exist | 58 | - if <obj, id> doesn't already exist |
59 | |||
53 | - allocate a new shadow variable | 60 | - allocate a new shadow variable |
54 | - initialize the variable using a custom constructor and data when provided | 61 | - initialize the variable using a custom constructor and data when provided |
55 | - add <obj, id> to the global hashtable | 62 | - add <obj, id> to the global hashtable |
56 | 63 | ||
57 | * klp_shadow_get_or_alloc() - get existing or alloc a new shadow variable | 64 | * klp_shadow_get_or_alloc() - get existing or alloc a new shadow variable |
58 | - search hashtable for <obj, id> pair | 65 | - search hashtable for <obj, id> pair |
66 | |||
59 | - if exists | 67 | - if exists |
68 | |||
60 | - return existing shadow variable | 69 | - return existing shadow variable |
70 | |||
61 | - if <obj, id> doesn't already exist | 71 | - if <obj, id> doesn't already exist |
72 | |||
62 | - allocate a new shadow variable | 73 | - allocate a new shadow variable |
63 | - initialize the variable using a custom constructor and data when provided | 74 | - initialize the variable using a custom constructor and data when provided |
64 | - add <obj, id> pair to the global hashtable | 75 | - add <obj, id> pair to the global hashtable |
65 | 76 | ||
66 | * klp_shadow_free() - detach and free a <obj, id> shadow variable | 77 | * klp_shadow_free() - detach and free a <obj, id> shadow variable |
67 | - find and remove a <obj, id> reference from global hashtable | 78 | - find and remove a <obj, id> reference from global hashtable |
79 | |||
68 | - if found | 80 | - if found |
81 | |||
69 | - call destructor function if defined | 82 | - call destructor function if defined |
70 | - free shadow variable | 83 | - free shadow variable |
71 | 84 | ||
72 | * klp_shadow_free_all() - detach and free all <*, id> shadow variables | 85 | * klp_shadow_free_all() - detach and free all <*, id> shadow variables |
73 | - find and remove any <*, id> references from global hashtable | 86 | - find and remove any <*, id> references from global hashtable |
87 | |||
74 | - if found | 88 | - if found |
89 | |||
75 | - call destructor function if defined | 90 | - call destructor function if defined |
76 | - free shadow variable | 91 | - free shadow variable |
77 | 92 | ||
@@ -102,12 +117,12 @@ parent "goes live" (ie, any shadow variable get-API requests are made | |||
102 | for this <obj, id> pair.) | 117 | for this <obj, id> pair.) |
103 | 118 | ||
104 | For commit 1d147bfa6429, when a parent sta_info structure is allocated, | 119 | For commit 1d147bfa6429, when a parent sta_info structure is allocated, |
105 | allocate a shadow copy of the ps_lock pointer, then initialize it: | 120 | allocate a shadow copy of the ps_lock pointer, then initialize it:: |
106 | 121 | ||
107 | #define PS_LOCK 1 | 122 | #define PS_LOCK 1 |
108 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, | 123 | struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, |
109 | const u8 *addr, gfp_t gfp) | 124 | const u8 *addr, gfp_t gfp) |
110 | { | 125 | { |
111 | struct sta_info *sta; | 126 | struct sta_info *sta; |
112 | spinlock_t *ps_lock; | 127 | spinlock_t *ps_lock; |
113 | 128 | ||
@@ -123,10 +138,10 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, | |||
123 | ... | 138 | ... |
124 | 139 | ||
125 | When requiring a ps_lock, query the shadow variable API to retrieve one | 140 | When requiring a ps_lock, query the shadow variable API to retrieve one |
126 | for a specific struct sta_info: | 141 | for a specific struct sta_info::: |
127 | 142 | ||
128 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) | 143 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
129 | { | 144 | { |
130 | spinlock_t *ps_lock; | 145 | spinlock_t *ps_lock; |
131 | 146 | ||
132 | /* sync with ieee80211_tx_h_unicast_ps_buf */ | 147 | /* sync with ieee80211_tx_h_unicast_ps_buf */ |
@@ -136,10 +151,10 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) | |||
136 | ... | 151 | ... |
137 | 152 | ||
138 | When the parent sta_info structure is freed, first free the shadow | 153 | When the parent sta_info structure is freed, first free the shadow |
139 | variable: | 154 | variable:: |
140 | 155 | ||
141 | void sta_info_free(struct ieee80211_local *local, struct sta_info *sta) | 156 | void sta_info_free(struct ieee80211_local *local, struct sta_info *sta) |
142 | { | 157 | { |
143 | klp_shadow_free(sta, PS_LOCK, NULL); | 158 | klp_shadow_free(sta, PS_LOCK, NULL); |
144 | kfree(sta); | 159 | kfree(sta); |
145 | ... | 160 | ... |
@@ -155,19 +170,19 @@ these cases, the klp_shadow_get_or_alloc() call can be used to attach | |||
155 | shadow variables to parents already in-flight. | 170 | shadow variables to parents already in-flight. |
156 | 171 | ||
157 | For commit 1d147bfa6429, a good spot to allocate a shadow spinlock is | 172 | For commit 1d147bfa6429, a good spot to allocate a shadow spinlock is |
158 | inside ieee80211_sta_ps_deliver_wakeup(): | 173 | inside ieee80211_sta_ps_deliver_wakeup():: |
159 | 174 | ||
160 | int ps_lock_shadow_ctor(void *obj, void *shadow_data, void *ctor_data) | 175 | int ps_lock_shadow_ctor(void *obj, void *shadow_data, void *ctor_data) |
161 | { | 176 | { |
162 | spinlock_t *lock = shadow_data; | 177 | spinlock_t *lock = shadow_data; |
163 | 178 | ||
164 | spin_lock_init(lock); | 179 | spin_lock_init(lock); |
165 | return 0; | 180 | return 0; |
166 | } | 181 | } |
167 | 182 | ||
168 | #define PS_LOCK 1 | 183 | #define PS_LOCK 1 |
169 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) | 184 | void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) |
170 | { | 185 | { |
171 | spinlock_t *ps_lock; | 186 | spinlock_t *ps_lock; |
172 | 187 | ||
173 | /* sync with ieee80211_tx_h_unicast_ps_buf */ | 188 | /* sync with ieee80211_tx_h_unicast_ps_buf */ |
@@ -200,10 +215,12 @@ suggests how to handle the parent object. | |||
200 | ============= | 215 | ============= |
201 | 216 | ||
202 | * https://github.com/dynup/kpatch | 217 | * https://github.com/dynup/kpatch |
203 | The livepatch implementation is based on the kpatch version of shadow | 218 | |
204 | variables. | 219 | The livepatch implementation is based on the kpatch version of shadow |
220 | variables. | ||
205 | 221 | ||
206 | * http://files.mkgnu.net/files/dynamos/doc/papers/dynamos_eurosys_07.pdf | 222 | * http://files.mkgnu.net/files/dynamos/doc/papers/dynamos_eurosys_07.pdf |
207 | Dynamic and Adaptive Updates of Non-Quiescent Subsystems in Commodity | 223 | |
208 | Operating System Kernels (Kritis Makris, Kyung Dong Ryu 2007) presented | 224 | Dynamic and Adaptive Updates of Non-Quiescent Subsystems in Commodity |
209 | a datatype update technique called "shadow data structures". | 225 | Operating System Kernels (Kritis Makris, Kyung Dong Ryu 2007) presented |
226 | a datatype update technique called "shadow data structures". | ||
diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objtool/Documentation/stack-validation.txt index 3995735a878f..8df526c80b65 100644 --- a/tools/objtool/Documentation/stack-validation.txt +++ b/tools/objtool/Documentation/stack-validation.txt | |||
@@ -111,7 +111,7 @@ c) Higher live patching compatibility rate | |||
111 | be detectable). Objtool makes that possible. | 111 | be detectable). Objtool makes that possible. |
112 | 112 | ||
113 | For more details, see the livepatch documentation in the Linux kernel | 113 | For more details, see the livepatch documentation in the Linux kernel |
114 | source tree at Documentation/livepatch/livepatch.txt. | 114 | source tree at Documentation/livepatch/livepatch.rst. |
115 | 115 | ||
116 | Rules | 116 | Rules |
117 | ----- | 117 | ----- |