From patchwork Mon Nov 27 22:30:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10078295 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 60C7F602BD for ; Mon, 27 Nov 2017 22:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5433C28FCF for ; Mon, 27 Nov 2017 22:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49310290B0; Mon, 27 Nov 2017 22:31:08 +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 5BAB528FCF for ; Mon, 27 Nov 2017 22:31:07 +0000 (UTC) Received: (qmail 13562 invoked by uid 550); 27 Nov 2017 22:30:58 -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 13473 invoked from network); 27 Nov 2017 22:30:57 -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=NUpUkZ2H8jAIbhu61dQpZfOayCFn/X+xg bwdUtLSV7ho6cQ+H+3yv1wDCK81N1c7/C6dc7dkjJPk0lwUaf/ZbQbR+YNsmj+Ig 72CLxY0dQKs5vOlnpWfG0kpDPBGm3wmW6cQmOhNMPODLtRdKlUUbcb8433KlvgDE 5Jmo7CoF8IwRANt/2tRH3wQlbcP0S82cC3e1eeRfRdyAd1oN8C25iVrnrBplvFaJ PlclFqnYdyTdNj4oFP6gveAiYZgi5CWVkDe+BXEJ6pFKrGzMoEjn+5die+chIuCu Bp5lg/fFos37VvxYaT6Nu+AJgPGgQAxC7t5/Y+YrApaY5qFjSDz4g== 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=XjKG2gUy QAp1Mhb8jEjjx23/R6ENIWRrwIVbYn2nbgNjKYmCmSVcU5dfNZlLrKfLpu/TWzNg B8yAZcER8/yf3EyGKSQKHlkcsmGM8DLDkCOZ5RvtCbMA/AsixCBBn2ozgZQ5WzOq bptRY8kpDePt4fQDV36OiljAUCgImFw1QHH9kLX3vawqGrZgDHXAHJdXNVbwPtIJ r6wYGiyxUV043al0fd8XWVakcVtbfYML2vh3/koN510V6H5yYjETt7NKkEMgKDqI CQNhFw197aFZDGJbSoanBsM0u+5AJpG1QNy/XmKhvakN4ffCDA+r3d1w+DRJSmJ1 kmUaRtMDcsttdQ== X-ME-Sender: From: "Tobin C. Harding" To: kernel-hardening@lists.openwall.com Cc: "Tobin C. Harding" , linux-kernel@vger.kernel.org, Network Development , Steven Rostedt , Tycho Andersen , Ingo Molnar Date: Tue, 28 Nov 2017 09:30:19 +1100 Message-Id: <1511821819-5496-4-git-send-email-me@tobin.cc> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511821819-5496-1-git-send-email-me@tobin.cc> References: <1511821819-5496-1-git-send-email-me@tobin.cc> Subject: [kernel-hardening] [RFC 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) {