From patchwork Tue Dec 19 03:28:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10122139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 72B3C60390 for ; Tue, 19 Dec 2017 03:29:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6474D28EE5 for ; Tue, 19 Dec 2017 03:29:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 590B628F08; Tue, 19 Dec 2017 03:29:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 4BA3228EE5 for ; Tue, 19 Dec 2017 03:29:00 +0000 (UTC) Received: (qmail 17902 invoked by uid 550); 19 Dec 2017 03:28:52 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 17677 invoked from network); 19 Dec 2017 03:28:50 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tobin.cc; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=/BBbg2O9Lr9vZzUNW Sj8vogFnaVpUmobrSdGBQEbHY4=; b=c4YrZJV7qHGqJfn4t24zMnofkSjtk26xj WXNJ2SEm8N/UaijbKVc7nWHh+1VX0jmbYIy8gFTGyA8ReLU+gqCPfA9uacoLTow4 1XY3bJhBRIlAqxYF1QU4hkZH74zObjNnaxTsXXjW1ZCvbBTwDh0EsGuL6k+4vNnj K0QtsToeAzkrhn2NDZhTxpXPA6TjfjF8q7njUvS8NSNY/oAgeQgIXALWNchwPNCz sCSFjD3lZFNYJOtjoAB/T5ozw/2RKMlS45LPQq1bAcv7Gj0EmtzsED03veKj26It 759Z9hkc00v2ZjPun7DKDO0mCa5tPbl8I8oyfUsqyFOQsRGSI14Vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=/BBbg2O9Lr9vZzUNWSj8vogFnaVpUmobrSdGBQEbHY4=; b=C0VIn5fk WyC/s86vCvd7/nKyXvHBk7javBWtHwwrdSPUzeBs5l7Lu1bZ/vw4aSWEPqypaBYw bnA5RJfVFcllUVZTC1othbwF36D1mVTcmqEBexYFBbruEekxq6giu/R73Kcd3VGr UVX74Mceys4OXCNmqxdOHpHzo3LVvMgDJMFS6ZG3O6QMmyLwDYL/8nVmiWeqrHlo tLouqybQ0m496h1ecP1RqbX9K0HY2gbTU3de8GlnvMr9zh7nZTsODoN/e4+MzX6w Mo8fxQtyvJSfVPnXMhIz0ZvO8dK5uWp791Youwp7EShOXscOtebVb6FcBLBvyjIf hxAq1Ip6tjmcTg== X-ME-Sender: From: "Tobin C. Harding" To: kernel-hardening@lists.openwall.com Cc: "Tobin C. Harding" , Steven Rostedt , Tycho Andersen , Linus Torvalds , Kees Cook , Andrew Morton , Daniel Borkmann , Masahiro Yamada , Alexei Starovoitov , linux-kernel@vger.kernel.org, Network Development Date: Tue, 19 Dec 2017 14:28:14 +1100 Message-Id: <1513654094-16832-4-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513654094-16832-1-git-send-email-me@tobin.cc> References: <1513654094-16832-1-git-send-email-me@tobin.cc> Subject: [kernel-hardening] [PATCH v2 3/3] trace: print address if symbol not found X-Virus-Scanned: ClamAV using ClamSMTP Fixes behaviour modified by: commit 40eee173a35e ("kallsyms: don't leak address when symbol not found") Previous patch changed behaviour of kallsyms function sprint_symbol() to return an error code instead of printing the address if a symbol was not found. Ftrace relies on the original behaviour. We should not break tracing when applying the previous patch. We can maintain the original behaviour by checking the return code on calls to sprint_symbol() and friends. Check return code and print actual address on error (i.e symbol not found). Signed-off-by: Tobin C. Harding --- kernel/trace/trace.h | 24 ++++++++++++++++++++++++ kernel/trace/trace_events_hist.c | 6 +++--- kernel/trace/trace_output.c | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 2a6d0325a761..881b1a577d75 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1814,4 +1814,28 @@ static inline void trace_event_eval_update(struct trace_eval_map **map, int len) extern struct trace_iterator *tracepoint_print_iter; +static inline int +trace_sprint_symbol(char *buffer, unsigned long address) +{ + int ret; + + ret = sprint_symbol(buffer, address); + if (ret == -1) + ret = sprintf(buffer, "0x%lx", address); + + return ret; +} + +static inline int +trace_sprint_symbol_no_offset(char *buffer, unsigned long address) +{ + int ret; + + ret = sprint_symbol_no_offset(buffer, address); + if (ret == -1) + ret = sprintf(buffer, "0x%lx", address); + + return ret; +} + #endif /* _LINUX_KERNEL_TRACE_H */ diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 1e1558c99d56..ca523327c058 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -982,7 +982,7 @@ static void hist_trigger_stacktrace_print(struct seq_file *m, return; seq_printf(m, "%*c", 1 + spaces, ' '); - sprint_symbol(str, stacktrace_entries[i]); + trace_sprint_symbol(str, stacktrace_entries[i]); seq_printf(m, "%s\n", str); } } @@ -1014,12 +1014,12 @@ hist_trigger_entry_print(struct seq_file *m, seq_printf(m, "%s: %llx", field_name, uval); } else if (key_field->flags & HIST_FIELD_FL_SYM) { uval = *(u64 *)(key + key_field->offset); - sprint_symbol_no_offset(str, uval); + trace_sprint_symbol_no_offset(str, uval); seq_printf(m, "%s: [%llx] %-45s", field_name, uval, str); } else if (key_field->flags & HIST_FIELD_FL_SYM_OFFSET) { uval = *(u64 *)(key + key_field->offset); - sprint_symbol(str, uval); + trace_sprint_symbol(str, uval); seq_printf(m, "%s: [%llx] %-55s", field_name, uval, str); } else if (key_field->flags & HIST_FIELD_FL_EXECNAME) { diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 90db994ac900..f3c3a0a60f72 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -365,7 +365,7 @@ seq_print_sym_offset(struct trace_seq *s, const char *fmt, #ifdef CONFIG_KALLSYMS const char *name; - sprint_symbol(str, address); + trace_sprint_symbol(str, address); name = kretprobed(str); if (name && strlen(name)) {