From patchwork Tue Dec 19 21:39:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobin Harding X-Patchwork-Id: 10124527 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 8985D60390 for ; Tue, 19 Dec 2017 21:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C6CA28A46 for ; Tue, 19 Dec 2017 21:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7165C28A5B; Tue, 19 Dec 2017 21:40:13 +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 B1A3E28A46 for ; Tue, 19 Dec 2017 21:40:12 +0000 (UTC) Received: (qmail 22002 invoked by uid 550); 19 Dec 2017 21:40:03 -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 21865 invoked from network); 19 Dec 2017 21:40:02 -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=tJKL5e0fIwbTFdCHe ql5Gvg2khxQYEidoy/Ohkxe6Uo=; b=YhWpoxgT4VBl+P8RJj8eaHTNAOTXBYlnj vvPpF1tGzlzdbM/URewVurWNcOFmo32Xs4AryO/g8rSMQ/n2vQ0h7QoyPP9x0n3B G/aZYUzaTP/1AaWgOvs1ZfgAdgwKFEkt8JZOeVDkIjAU0dy+M5gVYEfI6xXHrBhs rqAP/escH6WyCJIjrETs9ET3GI18wJc8SOkpLTAIBM8yqKHh6d+CPo8QM9uutc5C dCXg18jLFr2tWLpSamX9hFnBrDkH6UwhTldQDYcjpR4ucdIsvtpG6DKYDLQ4v8Kw It5ACghhCAbbYza5mYQTUnSDHhHKb8GFcBxT+vRWM13BsVwSskOjg== 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=tJKL5e0fIwbTFdCHeql5Gvg2khxQYEidoy/Ohkxe6Uo=; b=lLcQrHnE hT0BXLpVriYpD/mXGkc/nbCJYv46S3h175zp7RYSz2kc7l/aYj5406yfHOA9Nsv2 joJyRrO1v/+3+E0P3JrP3xH7DsvsVBvEwkunpVLcZFTKqDFK4LYX7XJaUlI2cbhz LAb04aN1Q4crHEkG4JKahoE3XXFCtEPJdPV9uad7oLamIRqOCLnK2fdsoATyVRRz WmHmvhX5NaGZ8RCgnAaPdeAmXveOrKagtxsoeqDyU9C+qfLYVcwdSUTLFZ7hJY6R AeQXzUp1kTmV/YWtTKzYMCpEXJ7Xg4NogWrh7cmejGwC9nN8HOFSAxrq87OT/nGw 4NlIAub5AG0bnQ== 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:23 +1100 Message-Id: <1513719564-13249-3-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 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 01c3957b2de6..503402a44ffe 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -674,6 +674,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,13 +683,13 @@ 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); - return string(buf, end, sym, spec); + return string(buf, end, ret == -1 ? "" : sym, spec); #else return special_hex_number(buf, end, value, sizeof(void *)); #endif