Skip to content

Commit 81bfafc

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool: Prevent infinite recursion in noreturn detection
Ingo reported an infinite loop in objtool with a certain randconfig [1]. With the given config, two functions in crypto/ablkcipher.o contained sibling calls to each other, which threw the recursive call in dead_end_function() for a loop (literally!). Split the noreturn detection into two passes. In the first pass, check for return instructions. In the second pass, do the potentially recursive sibling call check. In most cases, the first pass will be good enough. In the rare case where a second pass is needed, recursion should hopefully no longer be possible. [1] https://lkml.kernel.org/r/20160308154909.GA20956@gmail.com Reported-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arnaldo Carvalho de Melo <acme@infradead.org> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Bernd Petrovitsch <bernd@petrovitsch.priv.at> Cc: Borislav Petkov <bp@alien8.de> Cc: Chris J Arges <chris.j.arges@canonical.com> Cc: Jiri Slaby <jslaby@suse.cz> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michal Marek <mmarek@suse.cz> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Pedro Alves <palves@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: live-patching@vger.kernel.org Link: http://lkml.kernel.org/r/16afb602640ef43b7782087d6cca17bf6fc13603.1457502970.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3b27a0c commit 81bfafc

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tools/objtool/builtin-check.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static bool ignore_func(struct objtool_file *file, struct symbol *func)
125125
static bool dead_end_function(struct objtool_file *file, struct symbol *func)
126126
{
127127
int i;
128-
struct instruction *insn;
128+
struct instruction *insn, *func_insn;
129129
bool empty = true;
130130

131131
/*
@@ -154,10 +154,11 @@ static bool dead_end_function(struct objtool_file *file, struct symbol *func)
154154
if (!func->sec)
155155
return false;
156156

157-
insn = find_instruction(file, func->sec, func->offset);
158-
if (!insn)
157+
func_insn = find_instruction(file, func->sec, func->offset);
158+
if (!func_insn)
159159
return false;
160160

161+
insn = func_insn;
161162
list_for_each_entry_from(insn, &file->insns, list) {
162163
if (insn->sec != func->sec ||
163164
insn->offset >= func->offset + func->len)
@@ -167,6 +168,21 @@ static bool dead_end_function(struct objtool_file *file, struct symbol *func)
167168

168169
if (insn->type == INSN_RETURN)
169170
return false;
171+
}
172+
173+
if (empty)
174+
return false;
175+
176+
/*
177+
* A function can have a sibling call instead of a return. In that
178+
* case, the function's dead-end status depends on whether the target
179+
* of the sibling call returns.
180+
*/
181+
insn = func_insn;
182+
list_for_each_entry_from(insn, &file->insns, list) {
183+
if (insn->sec != func->sec ||
184+
insn->offset >= func->offset + func->len)
185+
break;
170186

171187
if (insn->type == INSN_JUMP_UNCONDITIONAL) {
172188
struct instruction *dest = insn->jump_dest;
@@ -194,7 +210,7 @@ static bool dead_end_function(struct objtool_file *file, struct symbol *func)
194210
return false;
195211
}
196212

197-
return !empty;
213+
return true;
198214
}
199215

200216
/*

0 commit comments

Comments
 (0)