From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8107C54FD0 for ; Wed, 25 Mar 2020 14:02:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9969020722 for ; Wed, 25 Mar 2020 14:02:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727490AbgCYOCK (ORCPT ); Wed, 25 Mar 2020 10:02:10 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:48968 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727357AbgCYOCK (ORCPT ); Wed, 25 Mar 2020 10:02:10 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jH6bf-002WDe-9O; Wed, 25 Mar 2020 14:02:07 +0000 Date: Wed, 25 Mar 2020 14:02:07 +0000 From: Al Viro To: Qian Cai Cc: Linus Torvalds , linux-fsdevel@vger.kernel.org, LKML Subject: Re: Null-ptr-deref due to "sanitized pathwalk machinery (v4)" Message-ID: <20200325140207.GM23230@ZenIV.linux.org.uk> References: <4CBDE0F3-FB73-43F3-8535-6C75BA004233@lca.pw> <20200324214637.GI23230@ZenIV.linux.org.uk> <20200325021327.GJ23230@ZenIV.linux.org.uk> <5281297D-B66E-4A4C-9B41-D2242F6B7AE7@lca.pw> <20200325040359.GK23230@ZenIV.linux.org.uk> <20200325055830.GL23230@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200325055830.GL23230@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Mar 25, 2020 at 05:58:30AM +0000, Al Viro wrote: > On Wed, Mar 25, 2020 at 04:03:59AM +0000, Al Viro wrote: > > > Lovely. So > > * we really do get NULL nd->path.dentry there; I've not misread the > > trace. > > * on the entry into link_path_walk() nd->path.dentry is non-NULL. > > * *ALL* components should've been LAST_NORM ones > > * not a single symlink in sight, unless the setup is rather unusual > > * possibly not even a single mountpoint along the way (depending > > upon the userland used) > > OK, I see one place where that could occur, but I really don't see how that > could be triggered on this pathname, short of very odd symlink layout in > the filesystem on the testbox. ... which, apparently, is what you've got there (/var/run -> ../run), so stepping into that braino is not implausible. Could you check if the fix below fixes what you've observed? I am folding it in anyway (into "lift all calls of step_into() out of follow_dotdot/follow_dotdot_rcu") - it's an obvious braino introduced in the commit in question, but I'd like a confirmation that this _is_ what you've caught. > Does the following fix your reproducer? > > diff --git a/fs/namei.c b/fs/namei.c > index 311e33dbac63..4082b70f32ff 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -1805,6 +1805,8 @@ static const char *handle_dots(struct nameidata *nd, int type) > error = step_into(nd, WALK_NOFOLLOW, > parent, inode, seq); > } > + if (unlikely(error)) > + return ERR_PTR(error); > > if (unlikely(nd->flags & LOOKUP_IS_SCOPED)) { > /*