From patchwork Sun Dec 17 23:53:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10118011 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 6F3C6601C8 for ; Sun, 17 Dec 2017 23:54:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 628022904D for ; Sun, 17 Dec 2017 23:54:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5726129060; Sun, 17 Dec 2017 23:54:18 +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 7C7AB2904D for ; Sun, 17 Dec 2017 23:54:17 +0000 (UTC) Received: (qmail 26078 invoked by uid 550); 17 Dec 2017 23:54:08 -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 26024 invoked from network); 17 Dec 2017 23:54: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=W0/70Jt4wydvsPrPr XT/qT3HtkhWHysmgMbFTm17vlo=; b=KEiWxmN3ocZUKn7TJAOxkkZdNLM9J8EJh oR4Wx6bi2+vYofJII1h+JZvhcmK020XPdT1/oAg4QGeL8gEpqnBdNEOu5AytdKhD o4LfMLiuzn/JZZ263ON8aL3qrNmOVgxOSk4a3guRdTWPYqK2WvadJUrPrqYxj8fC G7iZ7WUPXm90wVWn0npFj/FJCiC0Uqh+AAQ5ewZnbH6cw3JsC4/wkjcA2SDuiE1j zB6ZgC+fk6EboRcjM7iPvgEnytokVOauaCPmr7EScrytp6OLDDvWChaf/K9DyGg+ BCsBWJEZzf0nCk8DSF7A0C7V4GOZDXlpPCNhNJv3HHCDphRdIvIFQ== 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=W0/70Jt4wydvsPrPrXT/qT3HtkhWHysmgMbFTm17vlo=; b=pSMsRonQ ojyZmhDx8bShVyrLOWRK3z+fWAZzv9y4SbykE5BXxciR616F/D0CtSNPA08oMEYI b1345pjWNWNMZdNfMyKY4/C8rC7IKw9+PQEIzkENEqlBWr+UlVGuXshLbQybvgS+ 204EWFAA0yY0mQcMs9UC6FzEgTp/G/f6MSJUxnMr1ECS0lc1+vFO1hNnGDs8/B8u rRLQIlirt/i1DIagXDOKimjRLqsmROG8xLell6GHIfL5e1ASrTOAoQneMSPadqIi aRKLWr2utVvOY5+L06ABkQdVJfk0v+R8eqpZ13tD9kvDg4Lqh8XLRnD8hg1ayiDL 8b3oLiH4n16MIw== 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:31 +1100 Message-Id: <1513554812-13014-3-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 2/3] vsprintf: print if symbol not found X-Virus-Scanned: ClamAV using ClamSMTP Depends on: commit bd6b239cdbb2 ("kallsyms: don't leak address when symbol not found") Currently vsprintf for specifiers %p[SsB] relies on the behaviour of kallsyms (sprint_symbol()) and prints the actual address if a symbol is not found. Previous patch changes this behaviour so tha sprint_symbol() returns an error if symbol not found. With this patch in place we can print a sanitized message '' instead of leaking the address. Print '' for printk specifier %s[sSB] if no symbol is found. Signed-off-by: Tobin C. Harding --- include/linux/kernel.h | 2 ++ lib/vsprintf.c | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index ce51455e2adf..89e8ce79c2d1 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -460,6 +460,8 @@ char *kvasprintf(gfp_t gfp, const char *fmt, va_list args); extern __printf(2, 0) const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args); +extern int string_is_no_symbol(const char *s); + extern __scanf(2, 3) int sscanf(const char *, const char *, ...); extern __scanf(2, 0) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 01c3957b2de6..c112b0980ead 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -667,6 +667,8 @@ char *bdev_name(char *buf, char *end, struct block_device *bdev, } #endif +#define PRINTK_NO_SYMBOL_STR "" + static noinline_for_stack char *symbol_string(char *buf, char *end, void *ptr, struct printf_spec spec, const char *fmt) @@ -674,6 +676,7 @@ char *symbol_string(char *buf, char *end, void *ptr, unsigned long value; #ifdef CONFIG_KALLSYMS char sym[KSYM_SYMBOL_LEN]; + int ret; #endif if (fmt[1] == 'R') @@ -682,11 +685,14 @@ char *symbol_string(char *buf, char *end, void *ptr, #ifdef CONFIG_KALLSYMS if (*fmt == 'B') - sprint_backtrace(sym, value); + ret = sprint_backtrace(sym, value); else if (*fmt != 'f' && *fmt != 's') - sprint_symbol(sym, value); + ret = sprint_symbol(sym, value); else - sprint_symbol_no_offset(sym, value); + ret = sprint_symbol_no_offset(sym, value); + + if (ret == -1) + strcpy(sym, PRINTK_NO_SYMBOL_STR); return string(buf, end, sym, spec); #else @@ -694,6 +700,12 @@ char *symbol_string(char *buf, char *end, void *ptr, #endif } +int string_is_no_symbol(const char *s) +{ + return !!strstr(s, PRINTK_NO_SYMBOL_STR); +} +EXPORT_SYMBOL(string_is_no_symbol); + static noinline_for_stack char *resource_string(char *buf, char *end, struct resource *res, struct printf_spec spec, const char *fmt)