From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761357AbdLSGSw (ORCPT ); Tue, 19 Dec 2017 01:18:52 -0500 Received: from smtprelay0194.hostedemail.com ([216.40.44.194]:53498 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1761338AbdLSGSt (ORCPT ); Tue, 19 Dec 2017 01:18:49 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 30,2,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:334:355:368:369:379:541:569:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3868:3870:3871:3874:4321:5007:6119:10004:10400:10848:11026:11232:11473:11658:11914:12296:12438:12555:12740:12760:12895:13095:13439:14096:14097:14181:14659:14721:21080:21433:21451:21627:30003:30054:30089:30091,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:error,Custom_rules:0:0:0,LFtime:2000,LUA_SUMMARY:none X-HE-Tag: pest56_2dab510769758 X-Filterd-Recvd-Size: 3277 Message-ID: <1513664307.1234.21.camel@perches.com> Subject: Re: [PATCH v2 2/3] vsprintf: print if symbol not found From: Joe Perches To: "Tobin C. Harding" , kernel-hardening@lists.openwall.com Cc: Steven Rostedt , Tycho Andersen , Linus Torvalds , Kees Cook , Andrew Morton , Daniel Borkmann , Masahiro Yamada , Alexei Starovoitov , linux-kernel@vger.kernel.org, Network Development In-Reply-To: <1513654094-16832-3-git-send-email-me@tobin.cc> References: <1513654094-16832-1-git-send-email-me@tobin.cc> <1513654094-16832-3-git-send-email-me@tobin.cc> Content-Type: text/plain; charset="ISO-8859-1" Date: Mon, 18 Dec 2017 22:18:27 -0800 Mime-Version: 1.0 X-Mailer: Evolution 3.26.1-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2017-12-19 at 14:28 +1100, Tobin C. Harding wrote: > 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 = ""; This will be reinitialized on every use. > + 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); This could avoid the unnecessary strcpy if sym_not_found was not used at all and this was used instead if (ret == -1) return string(buf, end, "", spec); return string(buf, end, sym, spec); or maybe return string(buf, end, ret == -1 ? "" : sum, spec); > > return string(buf, end, sym, spec); > #else