Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751598AbdCBX7R (ORCPT ); Thu, 2 Mar 2017 18:59:17 -0500 Received: from smtprelay0098.hostedemail.com ([216.40.44.98]:54157 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750910AbdCBX7N (ORCPT ); Thu, 2 Mar 2017 18:59:13 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::,RULES_HIT:41:355:379:541:599:973:981:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1543:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:4605:5007:6119:7808:8603:8660:10004:10400:10848:11026:11232:11473:11658:11914:12296:12438:12555:12679:12740:12760:12895:12986:13148:13230:13439:14181:14659:14721:21080:21324:21433:21434:21451:30054:30056:30060:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: slave68_e660ff6f4d13 X-Filterd-Recvd-Size: 4404 Message-ID: <1488499097.2179.27.camel@perches.com> Subject: Re: [PATCH 24/26] ocfs2: reduce stack size with KASAN From: Joe Perches To: Arnd Bergmann Cc: kasan-dev , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Networking , Linux Kernel Mailing List , linux-media@vger.kernel.org, linux-wireless , kernel-build-reports@lists.linaro.org, "David S . Miller" Date: Thu, 02 Mar 2017 15:58:17 -0800 In-Reply-To: References: <20170302163834.2273519-1-arnd@arndb.de> <20170302163834.2273519-25-arnd@arndb.de> <1488476770.2179.6.camel@perches.com> <1488494428.2179.23.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.3-0ubuntu0.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2926 Lines: 86 On Thu, 2017-03-02 at 23:59 +0100, Arnd Bergmann wrote: > KASAN decides that passing a pointer to _m into an extern function > (_mlog_printk) is potentially dangerous, as that function might > keep a reference to that pointer after it goes out of scope, > or it might not know the correct length of the stack object pointed to. > > We can see from looking at the __mlog_printk() function definition > that it's actually safe, but the compiler cannot see that when looking > at another source file. OK, thanks. btw: changing __mlog_printk can save ~11% (90+KB) of object text size by removing __func__ and __LINE__ and using vsprintf pointer extension %pS, __builtin_return_address(0) as it is already used in dlmmaster. (defconfig x86-64, with ocfs2) $ size fs/ocfs2/built-in.o* text data bss dec hex filename 759791 111373 105688 976852 ee7d4 fs/ocfs2/built-in.o.new 852959 111373 105688 1070020 1053c4 fs/ocfs2/built-in.o.old It's nearly the same output. --- fs/ocfs2/cluster/masklog.c | 8 ++++---- fs/ocfs2/cluster/masklog.h | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c index d331c2386b94..a3f080f37108 100644 --- a/fs/ocfs2/cluster/masklog.c +++ b/fs/ocfs2/cluster/masklog.c @@ -64,8 +64,7 @@ static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count) return count; } -void __mlog_printk(const u64 *mask, const char *func, int line, - const char *fmt, ...) +void __mlog_printk(const u64 *mask, const char *fmt, ...) { struct va_format vaf; va_list args; @@ -90,9 +89,10 @@ void __mlog_printk(const u64 *mask, const char *func, int line, vaf.fmt = fmt; vaf.va = &args; - printk("%s(%s,%u,%u):%s:%d %s%pV", + printk("%s(%s,%u,%u):%pS %s%pV", level, current->comm, task_pid_nr(current), - raw_smp_processor_id(), func, line, prefix, &vaf); + raw_smp_processor_id(), __builtin_return_address(0), + prefix, &vaf); va_end(args); } diff --git a/fs/ocfs2/cluster/masklog.h b/fs/ocfs2/cluster/masklog.h index 3c16da69605d..56ba5baf625b 100644 --- a/fs/ocfs2/cluster/masklog.h +++ b/fs/ocfs2/cluster/masklog.h @@ -162,9 +162,8 @@ extern struct mlog_bits mlog_and_bits, mlog_not_bits; #endif -__printf(4, 5) __nocapture(2) -void __mlog_printk(const u64 *m, const char *func, int line, - const char *fmt, ...); +__printf(2, 3) __nocapture(2) +void __mlog_printk(const u64 *m, const char *fmt, ...); /* * Testing before the __mlog_printk call lets the compiler eliminate the @@ -174,8 +173,7 @@ void __mlog_printk(const u64 *m, const char *func, int line, do { \ u64 _m = MLOG_MASK_PREFIX | (mask); \ if (_m & ML_ALLOWED_BITS) \ - __mlog_printk(&_m, __func__, __LINE__, fmt, \ - ##__VA_ARGS__); \ + __mlog_printk(&_m, fmt, ##__VA_ARGS__); \ } while (0) #define mlog_errno(st) ({ \