From patchwork Tue Dec 19 03:28:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10122137 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 A8D5160390 for ; Tue, 19 Dec 2017 03:28:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99CE228EE5 for ; Tue, 19 Dec 2017 03:28:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E4E428F08; Tue, 19 Dec 2017 03:28:55 +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 9F44628EE5 for ; Tue, 19 Dec 2017 03:28:54 +0000 (UTC) Received: (qmail 17510 invoked by uid 550); 19 Dec 2017 03:28:48 -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 16278 invoked from network); 19 Dec 2017 03:28:46 -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=MXu/UZTRW63shZrEL 8iy2d1kZLfQrNKJomKramXquEI=; b=ISV4b5vKdu/XoZpNLv2akRzPXSS8Zo5nq YK2uQ484iXH7sbqjYfcvW94w8AZ2EEhxCdzgTYspI2foElVqRPUQs8zWyvBakQ2Z 3NvOGpdP2EArY1LtJsJEA1BlXQ7QglXz40h95PJsgmPEiO6DxJ2/BpAPs2wzJs+E qlVYC+CQtnM/KgEy5mLYRuxiAdPUFwFOzmlAhUszZD8N2qvTu24wxktVXeHvhVME R311zhBtAm9lB/QwrPSK7pEsnJqSjdp7IX545GGW/1VQrhY2mZnRq+6wjHU8VbJb dsvFshkqr/b1dEZFtQa8s4Yn2//M+N9e18Wearm+KXc/noGoYjQGw== 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=MXu/UZTRW63shZrEL8iy2d1kZLfQrNKJomKramXquEI=; b=LEpcG7QE egDiNuo2ewo0fHfrxKmdt3jX3ysmJWuchuT0AzLK6QrqA/YlT4azas38qVJQcjUj gLYmu04uOod8eEKSCKYQzWMoZUPv9z0mo0dR8BECk99/C0uwVxCpW9YGQfgvuTIi imn0uiHU2zgrkVkEYNj+h+nPd/wyW2oVyRJIJLIrSZV29+MZGH+qbJ9rKQhu6le4 ZLjQv3sOf7Foi1DIg5R+LE2u8GQS0WTsrDwn26VO/CkkrWz51gmXorsA0Ifm7xkU o6SD/qTvJh43B5WlMJ6G/+y/O8egL0CBIJc6SlDpSxAOt6MCOuho1T8XKlVSPAg4 5wIDZF27PJNApA== 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:13 +1100 Message-Id: <1513654094-16832-3-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 2/3] vsprintf: print if symbol not found X-Virus-Scanned: ClamAV using ClamSMTP Depends on: commit 40eee173a35e ("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 that 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 %p[sSB] if symbol look up fails. Signed-off-by: Tobin C. Harding --- lib/vsprintf.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 01c3957b2de6..820ed4fe6e6c 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -674,6 +674,8 @@ char *symbol_string(char *buf, char *end, void *ptr, unsigned long value; #ifdef CONFIG_KALLSYMS char sym[KSYM_SYMBOL_LEN]; + const char *sym_not_found = ""; + int ret; #endif if (fmt[1] == 'R') @@ -682,11 +684,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, sym_not_found); return string(buf, end, sym, spec); #else