Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5005251ybb; Tue, 24 Mar 2020 09:12:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsjwyTqHYIJ3taR4iLOmmrCxsEPA5Tjgre23eeG5hTQ+KtpmU+Hmwg+qrz51+UFD6RtmVsw X-Received: by 2002:a9d:6b98:: with SMTP id b24mr6877184otq.242.1585066368148; Tue, 24 Mar 2020 09:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585066368; cv=none; d=google.com; s=arc-20160816; b=Ifu6QPtaoTRaq2ygsUsnPp+jMHikSEhgJi8XAMURVNmc9YJI7Qr7U6sMQIupitmDuM 0exX+MCXgUbVQQs25qU2mcU0ssW76/Hde1Y/keGi95KM4CqFFh3niehg6h0Ymj8YZTUu W4iqGwONzk6pm0oTJZ08Cmf2Tw7sNPwCpAMiYupxxrRvNS21bqI4sf4ImgHReDGP0OO1 +5aqHIo77+6gyrUdTDoiJKRTb+cbEKPnJRPXy++dP7yqbFKrqLDMwTOxUjYIuqN7Ajc5 lGSUuPazmapmlkSBmDHOwy13h/mFRr4GpM4u57wOCKykqmgGGGGlFpQHnB/K+qsHnnME bcIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:subject:cc:to :from:date:user-agent:message-id:dkim-signature; bh=rz3mhFCgB9B328Fd0jWl9RwFxKfJYgfKzlf+U7z7giw=; b=CULbboQH+nCLsoUhdzs6/niVfCBT/omJeTaqCeLqOikD8aYVnh8UZhise9ipacoq9P J3kVWjggJqamxn4inb3cRRRgPFmU7wgh4HNXF2N9imiUBAi+J1s4ljr2ToVpIVbuxOk9 D/349y7yRBSUMx0QaE9XePlL76O/rKIqbXtg0YZlIz8uN80Tin7IUTWdSuZXwe9bv3dy YVy/cIYMteEvX7E9BQVP1Zu12GSg8XqTikBun4RLLAjWpQR1ajdRAoCnTr2vEcOLB2ML 8sNydVKz8Yo/du0VGgiUUSspNV3jlLCqK7E/OiUAjD1jr9cdMqASiS73jIOcydvFrG1G MOqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=e1L35+Fb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si8646447ota.103.2020.03.24.09.12.34; Tue, 24 Mar 2020 09:12:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=e1L35+Fb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727716AbgCXQLk (ORCPT + 99 others); Tue, 24 Mar 2020 12:11:40 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:51018 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728461AbgCXQLg (ORCPT ); Tue, 24 Mar 2020 12:11:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-Id:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=rz3mhFCgB9B328Fd0jWl9RwFxKfJYgfKzlf+U7z7giw=; b=e1L35+FbCnp/91ZxH9+zXaUoKP S+GXRVmZU1su2tWqGW7JONQ4F62WxIDpnnsA5UkpPylZGYr+jVqXVdzk+R9oQV6xof0RDof1t0oNM dwZH/g+P3LLUpKP+7NLEGLpmApPQa3FHaEzHLnhsE0lCm6gyTPFDiBa45GkY3bKD+QCCKHzjfHSrc 1n+ATALsOIQBic44jX9+8P1glEQh/d8yAkHcJUK85BJc3BjyynmFhl3f2ehmvxQO6tbRXh6XxR7Cm kU6Gi5PhKlAu83nuEC/nQ8aT1NNvr0N8PoRVKnTrO7mJ8HmCXKnKCMyVXlH9oJKmmauuORZR0jlag +mpw+t+Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jGm9K-0000BQ-9T; Tue, 24 Mar 2020 16:11:30 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2FFCD304D2B; Tue, 24 Mar 2020 17:11:28 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 19C1520250FC4; Tue, 24 Mar 2020 17:11:28 +0100 (CET) Message-Id: <20200324160923.963996225@infradead.org> User-Agent: quilt/0.65 Date: Tue, 24 Mar 2020 16:31:14 +0100 From: Peter Zijlstra To: tglx@linutronix.de, jpoimboe@redhat.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, peterz@infradead.org, mhiramat@kernel.org, mbenes@suse.cz, brgerst@gmail.com Subject: [PATCH v3 01/26] objtool: Introduce validate_return() References: <20200324153113.098167666@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Trivial 'cleanup' to save one indentation level and match validate_call(). Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf --- tools/objtool/check.c | 64 ++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1935,6 +1935,41 @@ static int validate_sibling_call(struct return validate_call(insn, state); } +static int validate_return(struct symbol *func, struct instruction *insn, struct insn_state *state) +{ + if (state->uaccess && !func_uaccess_safe(func)) { + WARN_FUNC("return with UACCESS enabled", + insn->sec, insn->offset); + return 1; + } + + if (!state->uaccess && func_uaccess_safe(func)) { + WARN_FUNC("return with UACCESS disabled from a UACCESS-safe function", + insn->sec, insn->offset); + return 1; + } + + if (state->df) { + WARN_FUNC("return with DF set", + insn->sec, insn->offset); + return 1; + } + + if (func && has_modified_stack_frame(state)) { + WARN_FUNC("return with modified stack frame", + insn->sec, insn->offset); + return 1; + } + + if (state->bp_scratch) { + WARN("%s uses BP as a scratch register", + func->name); + return 1; + } + + return 0; +} + /* * Follow the branch starting at the given instruction, and recursively follow * any other branches (jumps). Meanwhile, track the frame pointer state at @@ -2050,34 +2085,7 @@ static int validate_branch(struct objtoo switch (insn->type) { case INSN_RETURN: - if (state.uaccess && !func_uaccess_safe(func)) { - WARN_FUNC("return with UACCESS enabled", sec, insn->offset); - return 1; - } - - if (!state.uaccess && func_uaccess_safe(func)) { - WARN_FUNC("return with UACCESS disabled from a UACCESS-safe function", sec, insn->offset); - return 1; - } - - if (state.df) { - WARN_FUNC("return with DF set", sec, insn->offset); - return 1; - } - - if (func && has_modified_stack_frame(&state)) { - WARN_FUNC("return with modified stack frame", - sec, insn->offset); - return 1; - } - - if (state.bp_scratch) { - WARN("%s uses BP as a scratch register", - func->name); - return 1; - } - - return 0; + return validate_return(func, insn, &state); case INSN_CALL: case INSN_CALL_DYNAMIC: