From patchwork Tue Dec 19 21:39:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10124529 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 4460360390 for ; Tue, 19 Dec 2017 21:40:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36E1028A46 for ; Tue, 19 Dec 2017 21:40:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B9B728A5B; Tue, 19 Dec 2017 21:40:21 +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 2B32728A46 for ; Tue, 19 Dec 2017 21:40:19 +0000 (UTC) Received: (qmail 22317 invoked by uid 550); 19 Dec 2017 21:40:06 -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 22184 invoked from network); 19 Dec 2017 21:40:05 -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=Y6Kty0glnA1yqFzTMNnh+g/C/Zbupken9 7zpE5H03SZugAPmeoaiqZQQQuKnWHLOTgVIE9PFRDLIk577Jq1T7Cdwe5ltRxnlN 5ErqW8XldfgrR4V0XTTLHPxwIrSEShFpnW8izoxB9h0tKFpo898dhaWDCd8dI54v j0LXRL4u/0/J65dMieS6oloSubZoNA97EutMol4yAvz+wV4U2I46VqLvrkOcXFsD DRhTeP37aWTGVP/LDdNVicoeAQpJVygwkG64PiS48o+KuTYskNrbXv8zTHm7nIvC cZWO9q0oIHU2Ci0TA5/P1yzU7y5dNFYtkRFePY/6g/vt4zGaHpnAw== 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=oksUkl2Q SIvOnQx64iZ/Ajk7h2eS6wRNZZC4Dkrgn74vkgcxj8nGxOsoexWxrry+6aPo3mOF CyRBfAnnPWCyRiEeSUo/Xl1SWURzXMGlVU5xywZGzgYliQT1+/PrG1RR5iLhnImH /510SK8j79fesUru9R/uNIh1gn3xg3JY+wM/nC4y3Wr8joKI1R34WATaKQH/6Vg7 hM09mTIjFNP59TC2czaLa5ooNtKFG0Yu9hFdmlIc+VW96aqwTYxRAR4IPbthcOqP gduxLgZnepO+NS+reeFR0LlzetIULsanxbgvLnhNWetDWtpDVCRrodyqLwl9tZ5b vwZGEG0rvNGtCQ== 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 , Joe Perches Date: Wed, 20 Dec 2017 08:39:24 +1100 Message-Id: <1513719564-13249-4-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513719564-13249-1-git-send-email-me@tobin.cc> References: <1513719564-13249-1-git-send-email-me@tobin.cc> Subject: [kernel-hardening] [PATCH v3 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)) {