From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932250AbcCILom (ORCPT ); Wed, 9 Mar 2016 06:44:42 -0500 Received: from torg.zytor.com ([198.137.202.12]:37712 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753452AbcCILoX (ORCPT ); Wed, 9 Mar 2016 06:44:23 -0500 Date: Wed, 9 Mar 2016 03:42:41 -0800 From: tip-bot for Josh Poimboeuf Message-ID: Cc: akpm@linux-foundation.org, bernd@petrovitsch.priv.at, mingo@kernel.org, tglx@linutronix.de, namhyung@gmail.com, hpa@zytor.com, acme@kernel.org, jslaby@suse.cz, jpoimboe@redhat.com, mmarek@suse.cz, palves@redhat.com, luto@kernel.org, torvalds@linux-foundation.org, bp@alien8.de, chris.j.arges@canonical.com, linux-kernel@vger.kernel.org, peterz@infradead.org, acme@infradead.org Reply-To: chris.j.arges@canonical.com, torvalds@linux-foundation.org, bp@alien8.de, palves@redhat.com, luto@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, acme@infradead.org, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, namhyung@gmail.com, akpm@linux-foundation.org, bernd@petrovitsch.priv.at, jslaby@suse.cz, mmarek@suse.cz, jpoimboe@redhat.com, acme@kernel.org In-Reply-To: <16afb602640ef43b7782087d6cca17bf6fc13603.1457502970.git.jpoimboe@redhat.com> References: <16afb602640ef43b7782087d6cca17bf6fc13603.1457502970.git.jpoimboe@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:core/objtool] objtool: Prevent infinite recursion in noreturn detection Git-Commit-ID: 81bfafca1332869160e9da789252276e2f34a14e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 81bfafca1332869160e9da789252276e2f34a14e Gitweb: http://git.kernel.org/tip/81bfafca1332869160e9da789252276e2f34a14e Author: Josh Poimboeuf AuthorDate: Wed, 9 Mar 2016 00:06:51 -0600 Committer: Ingo Molnar CommitDate: Wed, 9 Mar 2016 10:48:07 +0100 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 Signed-off-by: Josh Poimboeuf Cc: Andrew Morton Cc: Andy Lutomirski Cc: Arnaldo Carvalho de Melo Cc: Arnaldo Carvalho de Melo Cc: Bernd Petrovitsch Cc: Borislav Petkov Cc: Chris J Arges Cc: Jiri Slaby Cc: Linus Torvalds Cc: Michal Marek Cc: Namhyung Kim Cc: Pedro Alves Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: live-patching@vger.kernel.org Link: http://lkml.kernel.org/r/16afb602640ef43b7782087d6cca17bf6fc13603.1457502970.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar --- tools/objtool/builtin-check.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index f7e0eba..80d9ed9 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -125,7 +125,7 @@ static bool ignore_func(struct objtool_file *file, struct symbol *func) static bool dead_end_function(struct objtool_file *file, struct symbol *func) { int i; - struct instruction *insn; + struct instruction *insn, *func_insn; bool empty = true; /* @@ -154,10 +154,11 @@ static bool dead_end_function(struct objtool_file *file, struct symbol *func) if (!func->sec) return false; - insn = find_instruction(file, func->sec, func->offset); - if (!insn) + func_insn = find_instruction(file, func->sec, func->offset); + if (!func_insn) return false; + insn = func_insn; list_for_each_entry_from(insn, &file->insns, list) { if (insn->sec != func->sec || insn->offset >= func->offset + func->len) @@ -167,6 +168,21 @@ static bool dead_end_function(struct objtool_file *file, struct symbol *func) if (insn->type == INSN_RETURN) return false; + } + + if (empty) + return false; + + /* + * A function can have a sibling call instead of a return. In that + * case, the function's dead-end status depends on whether the target + * of the sibling call returns. + */ + insn = func_insn; + list_for_each_entry_from(insn, &file->insns, list) { + if (insn->sec != func->sec || + insn->offset >= func->offset + func->len) + break; if (insn->type == INSN_JUMP_UNCONDITIONAL) { struct instruction *dest = insn->jump_dest; @@ -194,7 +210,7 @@ static bool dead_end_function(struct objtool_file *file, struct symbol *func) return false; } - return !empty; + return true; } /*