Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753843AbdLTDvE (ORCPT ); Tue, 19 Dec 2017 22:51:04 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:33999 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630AbdLTDvB (ORCPT ); Tue, 19 Dec 2017 22:51:01 -0500 Date: Tue, 19 Dec 2017 19:50:43 -0800 From: Matthew Wilcox To: Al Viro Cc: Linus Torvalds , "Tobin C. Harding" , Dmitry Vyukov , Kees Cook , Tetsuo Handa , Linux-MM , syzbot , David Windsor , keun-o.park@darkmatter.ae, Laura Abbott , LKML , Mark Rutland , Ingo Molnar , syzkaller-bugs@googlegroups.com, Will Deacon Subject: Re: BUG: bad usercopy in memdup_user Message-ID: <20171220035043.GA14980@bombadil.infradead.org> References: <001a113e9ca8a3affd05609d7ccf@google.com> <6a50d160-56d0-29f9-cfed-6c9202140b43@I-love.SAKURA.ne.jp> <20171219083746.GR19604@eros> <20171219132246.GD13680@bombadil.infradead.org> <20171219214849.GU21978@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171219214849.GU21978@ZenIV.linux.org.uk> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1240 Lines: 31 On Tue, Dec 19, 2017 at 09:48:49PM +0000, Al Viro wrote: > Well, for example seeing a 0xfffffffffffffff4 where a pointer to object > must have been is a pretty strong hint to start looking for a way for > that ERR_PTR(-ENOMEM) having ended up there... Something like > 0x6e69622f7273752f is almost certainly a misplaced "/usr/bin", i.e. a > pathname overwriting whatever it ends up in, etc. And yes, I have run > into both of those in real life. > > Debugging the situation when crap value has ended up in place of a > pointer is certainly a case where you do want to see what exactly has > ended up in there... Linus, how would you feel about printing ERR_PTRs without molestation? It's not going to leak any information about the kernel address space layout. I'm a little less certain about trying to detect ASCII strings, but I think this is an improvement. diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 01c3957b2de6..c80c60b4b3ef 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1859,6 +1859,9 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, return string(buf, end, "(null)", spec); } + if (IS_ERR(ptr)) + return pointer_string(buf, end, ptr, spec); + switch (*fmt) { case 'F': case 'f':