From patchwork Sun Dec 17 23:53:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10118015 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 3ED75601C8 for ; Sun, 17 Dec 2017 23:54:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32BCE2904D for ; Sun, 17 Dec 2017 23:54:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 276C229050; Sun, 17 Dec 2017 23:54:25 +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 2CF7B29060 for ; Sun, 17 Dec 2017 23:54:24 +0000 (UTC) Received: (qmail 26339 invoked by uid 550); 17 Dec 2017 23:54:10 -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 26196 invoked from network); 17 Dec 2017 23:54:09 -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=zxNtm9gAUcU/benW0 zdQ3UnutO1bdXMPyHB3RmH7zG0=; b=bPZV4T30rL4tJpSW2+vRq3ICwy/Z7d/wh o8mm9TdOKA+nVdYXXJIcvPKuziG5tembKdYzL7UBMaEy2ySAypueP1D+Dql+ZG06 zvkhqdcZPOWAi8H0N/KA9MD8sy3t5TdmK8yHezVqdXp+JlKJBn2RbnHCJRbS/JLP ac2JNbE4ydpnmGvW+UJVruJRioy6WoLkA2snWpwJdEBTy+wsvRPkCvwXX2e69ZGd puR/FnQr/d26w0yQ/4J5QG1Pp9wHQw9zcFaqbcv75Kyn5qQ6yL/7kBAk4HmKzekg OanO2q3uSNcJIBaq690B8tIBreeZGMetZQzhO8Ez0zVC97htRJWSw== 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=zxNtm9gAUcU/benW0zdQ3UnutO1bdXMPyHB3RmH7zG0=; b=TYqYzP4R yKziVmvD6quxjkXWqKKh/Yzi9rEY9/p4JTJTUz2HiA5s6TevrJhe0qPgvtk9Viot mm+whR8S67QK40KnYsQpu0YNAXHbpyNJRaktXXj+hvfcRGsOIbOf1c6so7lL9af6 YhuezxukuSQFJRCuACXHRmCP4TTYLtp7La2UlgPvP4mluUtkUbDfm4YUuIhzJuLG cmFh4yle5N7I6KBxV3CMuYxkg07qLsNUyIRdQCYeFeTeMmodfF8d5eq8si8nvcP7 13AOw6y/dVKIXCA6Tm+df4WqBclWi9auaJHN4rxT78SEenNh0TAU4bI4b9O+DgZo cO9HP98THw7How== 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: Mon, 18 Dec 2017 10:53:32 +1100 Message-Id: <1513554812-13014-4-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513554812-13014-1-git-send-email-me@tobin.cc> References: <1513554812-13014-1-git-send-email-me@tobin.cc> Subject: [kernel-hardening] [PATCH 3/3] trace: print address if symbol not found X-Virus-Scanned: ClamAV using ClamSMTP Fixes behaviour modified by: commit bd6b239cdbb2 ("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 +++--- 2 files changed, 27 insertions(+), 3 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..3e28522a76f4 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_addr(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) {