summaryrefslogtreecommitdiffstats
path: root/Documentation/livepatch
diff options
context:
space:
mode:
authorMiroslav Benes <mbenes@suse.cz>2018-01-10 05:01:28 -0500
committerJiri Kosina <jkosina@suse.cz>2018-01-11 04:58:03 -0500
commitd0807da78e11d46f18399cbf8c4028c731346766 (patch)
tree7421d9d68ae0d159c816995564984a0c0cfcc26a /Documentation/livepatch
parentc99a2be790b07752d8cc694434d3450afd4c5a00 (diff)
livepatch: Remove immediate feature
Immediate flag has been used to disable per-task consistency and patch all tasks immediately. It could be useful if the patch doesn't change any function or data semantics. However, it causes problems on its own. The consistency problem is currently broken with respect to immediate patches. func a patches 1i 2i 3 When the patch 3 is applied, only 2i function is checked (by stack checking facility). There might be a task sleeping in 1i though. Such task is migrated to 3, because we do not check 1i in klp_check_stack_func() at all. Coming atomic replace feature would be easier to implement and more reliable without immediate. Thus, remove immediate feature completely and save us from the problems. Note that force feature has the similar problem. However it is considered as a last resort. If used, administrator should not apply any new live patches and should plan for reboot into an updated kernel. The architectures would now need to provide HAVE_RELIABLE_STACKTRACE to fully support livepatch. Signed-off-by: Miroslav Benes <mbenes@suse.cz> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'Documentation/livepatch')
-rw-r--r--Documentation/livepatch/livepatch.txt89
1 files changed, 27 insertions, 62 deletions
diff --git a/Documentation/livepatch/livepatch.txt b/Documentation/livepatch/livepatch.txt
index 896ba8941702..1ae2de758c08 100644
--- a/Documentation/livepatch/livepatch.txt
+++ b/Documentation/livepatch/livepatch.txt
@@ -72,8 +72,7 @@ example, they add a NULL pointer or a boundary check, fix a race by adding
72a missing memory barrier, or add some locking around a critical section. 72a missing memory barrier, or add some locking around a critical section.
73Most of these changes are self contained and the function presents itself 73Most of these changes are self contained and the function presents itself
74the same way to the rest of the system. In this case, the functions might 74the same way to the rest of the system. In this case, the functions might
75be updated independently one by one. (This can be done by setting the 75be updated independently one by one.
76'immediate' flag in the klp_patch struct.)
77 76
78But there are more complex fixes. For example, a patch might change 77But there are more complex fixes. For example, a patch might change
79ordering of locking in multiple functions at the same time. Or a patch 78ordering of locking in multiple functions at the same time. Or a patch
@@ -125,12 +124,6 @@ safe to patch tasks:
125 b) Patching CPU-bound user tasks. If the task is highly CPU-bound 124 b) Patching CPU-bound user tasks. If the task is highly CPU-bound
126 then it will get patched the next time it gets interrupted by an 125 then it will get patched the next time it gets interrupted by an
127 IRQ. 126 IRQ.
128 c) In the future it could be useful for applying patches for
129 architectures which don't yet have HAVE_RELIABLE_STACKTRACE. In
130 this case you would have to signal most of the tasks on the
131 system. However this isn't supported yet because there's
132 currently no way to patch kthreads without
133 HAVE_RELIABLE_STACKTRACE.
134 127
1353. For idle "swapper" tasks, since they don't ever exit the kernel, they 1283. For idle "swapper" tasks, since they don't ever exit the kernel, they
136 instead have a klp_update_patch_state() call in the idle loop which 129 instead have a klp_update_patch_state() call in the idle loop which
@@ -138,27 +131,16 @@ safe to patch tasks:
138 131
139 (Note there's not yet such an approach for kthreads.) 132 (Note there's not yet such an approach for kthreads.)
140 133
141All the above approaches may be skipped by setting the 'immediate' flag 134Architectures which don't have HAVE_RELIABLE_STACKTRACE solely rely on
142in the 'klp_patch' struct, which will disable per-task consistency and 135the second approach. It's highly likely that some tasks may still be
143patch all tasks immediately. This can be useful if the patch doesn't 136running with an old version of the function, until that function
144change any function or data semantics. Note that, even with this flag 137returns. In this case you would have to signal the tasks. This
145set, it's possible that some tasks may still be running with an old 138especially applies to kthreads. They may not be woken up and would need
146version of the function, until that function returns. 139to be forced. See below for more information.
147 140
148There's also an 'immediate' flag in the 'klp_func' struct which allows 141Unless we can come up with another way to patch kthreads, architectures
149you to specify that certain functions in the patch can be applied 142without HAVE_RELIABLE_STACKTRACE are not considered fully supported by
150without per-task consistency. This might be useful if you want to patch 143the kernel livepatching.
151a common function like schedule(), and the function change doesn't need
152consistency but the rest of the patch does.
153
154For architectures which don't have HAVE_RELIABLE_STACKTRACE, the user
155must set patch->immediate which causes all tasks to be patched
156immediately. This option should be used with care, only when the patch
157doesn't change any function or data semantics.
158
159In the future, architectures which don't have HAVE_RELIABLE_STACKTRACE
160may be allowed to use per-task consistency if we can come up with
161another way to patch kthreads.
162 144
163The /sys/kernel/livepatch/<patch>/transition file shows whether a patch 145The /sys/kernel/livepatch/<patch>/transition file shows whether a patch
164is in transition. Only a single patch (the topmost patch on the stack) 146is in transition. Only a single patch (the topmost patch on the stack)
@@ -197,6 +179,11 @@ modules is permanently disabled when the force feature is used. It cannot be
197guaranteed there is no task sleeping in such module. It implies unbounded 179guaranteed there is no task sleeping in such module. It implies unbounded
198reference count if a patch module is disabled and enabled in a loop. 180reference count if a patch module is disabled and enabled in a loop.
199 181
182Moreover, the usage of force may also affect future applications of live
183patches and cause even more harm to the system. Administrator should first
184consider to simply cancel a transition (see above). If force is used, reboot
185should be planned and no more live patches applied.
186
2003.1 Adding consistency model support to new architectures 1873.1 Adding consistency model support to new architectures
201--------------------------------------------------------- 188---------------------------------------------------------
202 189
@@ -234,13 +221,6 @@ few options:
234 a good backup option for those architectures which don't have 221 a good backup option for those architectures which don't have
235 reliable stack traces yet. 222 reliable stack traces yet.
236 223
237In the meantime, patches for such architectures can bypass the
238consistency model by setting klp_patch.immediate to true. This option
239is perfectly fine for patches which don't change the semantics of the
240patched functions. In practice, this is usable for ~90% of security
241fixes. Use of this option also means the patch can't be unloaded after
242it has been disabled.
243
244 224
2454. Livepatch module 2254. Livepatch module
246=================== 226===================
@@ -296,9 +276,6 @@ into three levels:
296 only for a particular object ( vmlinux or a kernel module ). Note that 276 only for a particular object ( vmlinux or a kernel module ). Note that
297 kallsyms allows for searching symbols according to the object name. 277 kallsyms allows for searching symbols according to the object name.
298 278
299 There's also an 'immediate' flag which, when set, patches the
300 function immediately, bypassing the consistency model safety checks.
301
302 + struct klp_object defines an array of patched functions (struct 279 + struct klp_object defines an array of patched functions (struct
303 klp_func) in the same object. Where the object is either vmlinux 280 klp_func) in the same object. Where the object is either vmlinux
304 (NULL) or a module name. 281 (NULL) or a module name.
@@ -317,9 +294,6 @@ into three levels:
317 symbols are found. The only exception are symbols from objects 294 symbols are found. The only exception are symbols from objects
318 (kernel modules) that have not been loaded yet. 295 (kernel modules) that have not been loaded yet.
319 296
320 Setting the 'immediate' flag applies the patch to all tasks
321 immediately, bypassing the consistency model safety checks.
322
323 For more details on how the patch is applied on a per-task basis, 297 For more details on how the patch is applied on a per-task basis,
324 see the "Consistency model" section. 298 see the "Consistency model" section.
325 299
@@ -334,14 +308,12 @@ section "Livepatch life-cycle" below for more details about these
334two operations. 308two operations.
335 309
336Module removal is only safe when there are no users of the underlying 310Module removal is only safe when there are no users of the underlying
337functions. The immediate consistency model is not able to detect this. The 311functions. This is the reason why the force feature permanently disables
338code just redirects the functions at the very beginning and it does not 312the removal. The forced tasks entered the functions but we cannot say
339check if the functions are in use. In other words, it knows when the 313that they returned back. Therefore it cannot be decided when the
340functions get called but it does not know when the functions return. 314livepatch module can be safely removed. When the system is successfully
341Therefore it cannot be decided when the livepatch module can be safely 315transitioned to a new patch state (patched/unpatched) without being
342removed. This is solved by a hybrid consistency model. When the system is 316forced it is guaranteed that no task sleeps or runs in the old code.
343transitioned to a new patch state (patched/unpatched) it is guaranteed that
344no task sleeps or runs in the old code.
345 317
346 318
3475. Livepatch life-cycle 3195. Livepatch life-cycle
@@ -355,19 +327,12 @@ First, the patch is applied only when all patched symbols for already
355loaded objects are found. The error handling is much easier if this 327loaded objects are found. The error handling is much easier if this
356check is done before particular functions get redirected. 328check is done before particular functions get redirected.
357 329
358Second, the immediate consistency model does not guarantee that anyone is not 330Second, it might take some time until the entire system is migrated with
359sleeping in the new code after the patch is reverted. This means that the new 331the hybrid consistency model being used. The patch revert might block
360code needs to stay around "forever". If the code is there, one could apply it 332the livepatch module removal for too long. Therefore it is useful to
361again. Therefore it makes sense to separate the operations that might be done 333revert the patch using a separate operation that might be called
362once and those that need to be repeated when the patch is enabled (applied) 334explicitly. But it does not make sense to remove all information until
363again. 335the livepatch module is really removed.
364
365Third, it might take some time until the entire system is migrated
366when a more complex consistency model is used. The patch revert might
367block the livepatch module removal for too long. Therefore it is useful
368to revert the patch using a separate operation that might be called
369explicitly. But it does not make sense to remove all information
370until the livepatch module is really removed.
371 336
372 337
3735.1. Registration 3385.1. Registration