@@ -28,6 +28,15 @@ Objtool has the following features:
28
28
sites, enabling the kernel to patch them inline, to prevent "thunk
29
29
funneling" for both security and performance reasons
30
30
31
+ - Return thunk validation -- validates return thunks are used for
32
+ certain CPU mitigations including Retbleed and SRSO
33
+
34
+ - Return thunk annotation -- annotates all return thunk sites so kernel
35
+ can patch them inline, depending on enabled mitigations
36
+
37
+ - Return thunk training valiation -- validate that all entry paths
38
+ untrain a "safe return" before the first return (or call)
39
+
31
40
- Non-instrumentation validation -- validates non-instrumentable
32
41
("noinstr") code rules, preventing instrumentation in low-level C
33
42
entry code
@@ -53,6 +62,9 @@ Objtool has the following features:
53
62
- Function entry annotation -- annotates function entries, enabling
54
63
kernel function tracing
55
64
65
+ - Function preamble (prefix) annotation and/or symbol generation -- used
66
+ for FineIBT and call depth tracking
67
+
56
68
- Other toolchain hacks which will go unmentioned at this time...
57
69
58
70
Each feature can be enabled individually or in combination using the
@@ -197,19 +209,17 @@ To achieve the validation, objtool enforces the following rules:
197
209
198
210
1. Each callable function must be annotated as such with the ELF
199
211
function type. In asm code, this is typically done using the
200
- ENTRY/ENDPROC macros. If objtool finds a return instruction
212
+ SYM_FUNC_{START,END} macros. If objtool finds a return instruction
201
213
outside of a function, it flags an error since that usually indicates
202
214
callable code which should be annotated accordingly.
203
215
204
216
This rule is needed so that objtool can properly identify each
205
217
callable function in order to analyze its stack metadata.
206
218
207
- 2. Conversely, each section of code which is *not* callable should *not*
208
- be annotated as an ELF function. The ENDPROC macro shouldn't be used
209
- in this case.
210
-
211
- This rule is needed so that objtool can ignore non-callable code.
212
- Such code doesn't have to follow any of the other rules.
219
+ 2. Conversely, each section of code which is *not* callable, or is
220
+ otherwise doing funny things with the stack or registers, should
221
+ *not* be annotated as an ELF function. Rather, SYM_CODE_{START,END}
222
+ should be used along with unwind hints.
213
223
214
224
3. Each callable function which calls another function must have the
215
225
correct frame pointer logic, if required by CONFIG_FRAME_POINTER or
@@ -221,7 +231,7 @@ To achieve the validation, objtool enforces the following rules:
221
231
function B, the _caller_ of function A will be skipped on the stack
222
232
trace.
223
233
224
- 4. Dynamic jumps and jumps to undefined symbols are only allowed if:
234
+ 4. Indirect jumps and jumps to undefined symbols are only allowed if:
225
235
226
236
a) the jump is part of a switch statement; or
227
237
@@ -304,20 +314,21 @@ the objtool maintainers.
304
314
001e 2823e: 80 ce 02 or $0x2,%dh
305
315
...
306
316
317
+
307
318
2. file.o: warning: objtool: .text+0x53: unreachable instruction
308
319
309
320
Objtool couldn't find a code path to reach the instruction.
310
321
311
322
If the error is for an asm file, and the instruction is inside (or
312
323
reachable from) a callable function, the function should be annotated
313
- with the ENTRY/ENDPROC macros (ENDPROC is the important one).
314
- Otherwise, the code should probably be annotated with the unwind hint
315
- macros in asm/unwind_hints.h so objtool and the unwinder can know the
316
- stack state associated with the code.
324
+ with the SYM_FUNC_START and SYM_FUNC_END macros.
325
+
326
+ Otherwise, SYM_CODE_START can be used. In that case the code needs
327
+ to be annotated with unwind hint macros.
328
+
329
+ If you're sure the code won't affect the reliability of runtime stack
330
+ traces and want objtool to ignore it, see "Adding exceptions" below.
317
331
318
- If you're 100% sure the code won't affect stack traces, or if you're
319
- a just a bad person, you can tell objtool to ignore it. See the
320
- "Adding exceptions" section below.
321
332
322
333
3. file.o: warning: objtool: foo+0x48c: bar() missing __noreturn in .c/.h or NORETURN() in noreturns.h
323
334
@@ -326,6 +337,7 @@ the objtool maintainers.
326
337
declaration and its definition, and must have a NORETURN() annotation
327
338
in tools/objtool/noreturns.h.
328
339
340
+
329
341
4. file.o: warning: objtool: func(): can't find starting instruction
330
342
or
331
343
file.o: warning: objtool: func()+0x11dd: can't decode instruction
@@ -339,23 +351,21 @@ the objtool maintainers.
339
351
340
352
This is a kernel entry/exit instruction like sysenter or iret. Such
341
353
instructions aren't allowed in a callable function, and are most
342
- likely part of the kernel entry code. They should usually not have
343
- the callable function annotation (ENDPROC) and should always be
344
- annotated with the unwind hint macros in asm/unwind_hints.h.
354
+ likely part of the kernel entry code. Such code should probably be
355
+ placed in a SYM_FUNC_CODE block with unwind hints.
345
356
346
357
347
358
6. file.o: warning: objtool: func()+0x26: sibling call from callable instruction with modified stack frame
348
359
349
- This is a dynamic jump or a jump to an undefined symbol. Objtool
350
- assumed it's a sibling call and detected that the frame pointer
351
- wasn't first restored to its original state.
360
+ This is a branch to an UNDEF symbol. Objtool assumed it's a
361
+ sibling call and detected that the stack wasn't first restored to its
362
+ original state.
352
363
353
- If it's not really a sibling call, you may need to move the
354
- destination code to the local file.
364
+ If it's not really a sibling call, you may need to use unwind hints
365
+ and/or move the destination code to the local file.
355
366
356
367
If the instruction is not actually in a callable function (e.g.
357
- kernel entry code), change ENDPROC to END and annotate manually with
358
- the unwind hint macros in asm/unwind_hints.h.
368
+ kernel entry code), use SYM_CODE_{START,END} and unwind hints.
359
369
360
370
361
371
7. file: warning: objtool: func()+0x5c: stack state mismatch
@@ -371,8 +381,8 @@ the objtool maintainers.
371
381
372
382
Another possibility is that the code has some asm or inline asm which
373
383
does some unusual things to the stack or the frame pointer. In such
374
- cases it's probably appropriate to use the unwind hint macros in
375
- asm/unwind_hints.h .
384
+ cases it's probably appropriate to use SYM_FUNC_CODE with unwind
385
+ hints .
376
386
377
387
378
388
8. file.o: warning: objtool: funcA() falls through to next function funcB()
@@ -382,17 +392,16 @@ the objtool maintainers.
382
392
can fall through into the next function. There could be different
383
393
reasons for this:
384
394
385
- 1 ) funcA()'s last instruction is a call to a "noreturn" function like
395
+ a ) funcA()'s last instruction is a call to a "noreturn" function like
386
396
panic(). In this case the noreturn function needs to be added to
387
397
objtool's hard-coded global_noreturns array. Feel free to bug the
388
398
objtool maintainer, or you can submit a patch.
389
399
390
- 2 ) funcA() uses the unreachable() annotation in a section of code
400
+ b ) funcA() uses the unreachable() annotation in a section of code
391
401
that is actually reachable.
392
402
393
- 3) If funcA() calls an inline function, the object code for funcA()
394
- might be corrupt due to a gcc bug. For more details, see:
395
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70646
403
+ c) Some undefined behavior like divide by zero.
404
+
396
405
397
406
9. file.o: warning: objtool: funcA() call to funcB() with UACCESS enabled
398
407
@@ -430,24 +439,26 @@ the objtool maintainers.
430
439
This limitation can be overcome by massaging the alternatives with
431
440
NOPs to shift the stack changes around so they no longer conflict.
432
441
442
+
433
443
11. file.o: warning: unannotated intra-function call
434
444
435
- This warning means that a direct call is done to a destination which
436
- is not at the beginning of a function. If this is a legit call, you
437
- can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL
438
- directive right before the call.
445
+ This warning means that a direct call is done to a destination which
446
+ is not at the beginning of a function. If this is a legit call, you
447
+ can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL
448
+ directive right before the call.
449
+
439
450
440
451
12. file.o: warning: func(): not an indirect call target
441
452
442
- This means that objtool is running with --ibt and a function expected
443
- to be an indirect call target is not. In particular, this happens for
444
- init_module() or cleanup_module() if a module relies on these special
445
- names and does not use module_init() / module_exit() macros to create
446
- them.
453
+ This means that objtool is running with --ibt and a function
454
+ expected to be an indirect call target is not. In particular, this
455
+ happens for init_module() or cleanup_module() if a module relies on
456
+ these special names and does not use module_init() / module_exit()
457
+ macros to create them.
447
458
448
459
449
460
If the error doesn't seem to make sense, it could be a bug in objtool.
450
- Feel free to ask the objtool maintainer for help.
461
+ Feel free to ask objtool maintainers for help.
451
462
452
463
453
464
Adding exceptions
0 commit comments