From patchwork Thu Mar 2 23:58:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 9601807 X-Patchwork-Delegate: kvalo@adurom.com 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 92B8860429 for ; Fri, 3 Mar 2017 00:00:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8527F28608 for ; Fri, 3 Mar 2017 00:00:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7868D28617; Fri, 3 Mar 2017 00:00:08 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A5DD28608 for ; Fri, 3 Mar 2017 00:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751487AbdCBX7P (ORCPT ); Thu, 2 Mar 2017 18:59:15 -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 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay02.hostedemail.com (Postfix) with ESMTP id C577812BA12; Thu, 2 Mar 2017 23:58:20 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: slave68_e660ff6f4d13 X-Filterd-Recvd-Size: 4404 Received: from XPS-9350 (unknown [47.151.132.55]) (Authenticated sender: joe@perches.com) by omf05.hostedemail.com (Postfix) with ESMTPA; Thu, 2 Mar 2017 23:58:18 +0000 (UTC) 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> X-Mailer: Evolution 3.22.3-0ubuntu0.1 Mime-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) ({ \