Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4082991pxf; Tue, 6 Apr 2021 07:34:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf8EseuFzZXMJODg+QZN8frDQuBpaHI5ectSBWLpl3kx4uwm/cO+YLgilBUAsSle6LCTWp X-Received: by 2002:a5d:9449:: with SMTP id x9mr25119028ior.157.1617719673722; Tue, 06 Apr 2021 07:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617719673; cv=none; d=google.com; s=arc-20160816; b=JVmpFTCAxuh0bRU6Zw7l5chC6+20odzRh3N+FxvUtBOJ2q+kZAcpoHa4JwqN91z3Ea YYkzRrdlsjEzUgw9vvNaA676miqV96w3qmLSezqlzdrarieGZ81gWzBfNHfIFnIahpCe RX8l8XiNIABHp+wlly8y988LsDd6HSLV+86MpmZViUKBy89P4aqutss0xoG4u1m0vKR8 whWOTRPdDIgjLDWSd5idoItumRL7MqRY87mYJrS6BPbBAtVTictJRPCegV328LQJX73W 8ia4D4TKEy6B3pCBXs8wmanW4+yBdIvPL5n5g34e88RoxizHOXRlWFABpO3QCiXHohvr pRqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=nECBYA4y3uj9+dqWCIh1x/AASsJi+BQOpQZ44aOFqKk=; b=P+z0XaszEEAe0zaXzMRlSsff6gE0fXlSY0uHdczEv9vD3tjIz244yPu7XIZ1VuxAlz NU8kOj/YZcMw3nPKBKS0N8vtKRh1o4AWIDEOkjnzWQcQokgHiOifhuz01mkNO8RsmZY1 hYoaArNt32GojMUoQ3UMURc96b2W/RlKkKlxfhjVxbn3HWW6KBFoDhsaOVNSOagmvOJh 3mGZ9QKd1N/vWrXVIdaXaMsty8QGtYol1C0MX1sCjb+J+8pKaJpAQhiVlhQcpPtGPA33 RdVzH3xWlx1uM/ItOkn17gYg1gmZMcCmqC5dOWYnNESdJ2B5maSZYRoErZ22LVrzl1SX MQ7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si18888083jaj.23.2021.04.06.07.34.20; Tue, 06 Apr 2021 07:34:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238828AbhDFCYT (ORCPT + 99 others); Mon, 5 Apr 2021 22:24:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243371AbhDFCYR (ORCPT ); Mon, 5 Apr 2021 22:24:17 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64324C06174A; Mon, 5 Apr 2021 19:24:10 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lTbNw-002t98-0J; Tue, 06 Apr 2021 02:24:08 +0000 Date: Tue, 6 Apr 2021 02:24:07 +0000 From: Al Viro To: Christian Brauner Cc: Jens Axboe , syzbot , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, io-uring@vger.kernel.org Subject: Re: [syzbot] WARNING in mntput_no_expire (2) Message-ID: References: <20210404170513.mfl5liccdaxjnpls@wittgenstein> <20210405114437.hjcojekyp5zt6huu@wittgenstein> <20210405170801.zrdhnon6g4ggb6c7@wittgenstein> <20210405200737.qurhkqitoxweousx@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 06, 2021 at 01:38:39AM +0000, Al Viro wrote: > On Mon, Apr 05, 2021 at 10:07:37PM +0200, Christian Brauner wrote: > > > > diff --git a/fs/namei.c b/fs/namei.c > > > index 216f16e74351..82344f1139ff 100644 > > > --- a/fs/namei.c > > > +++ b/fs/namei.c > > > @@ -2289,6 +2289,9 @@ static const char *path_init(struct nameidata *nd, unsigned flags) > > > int error; > > > const char *s = nd->name->name; > > > > > > + nd->path.mnt = NULL; > > > + nd->path.dentry = NULL; > > > + > > > /* LOOKUP_CACHED requires RCU, ask caller to retry */ > > > if ((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED) > > > return ERR_PTR(-EAGAIN); > > > @@ -2322,8 +2325,6 @@ static const char *path_init(struct nameidata *nd, unsigned flags) > > > } > > > > > > nd->root.mnt = NULL; > > > - nd->path.mnt = NULL; > > > - nd->path.dentry = NULL; > > > > > > /* Absolute pathname -- fetch the root (LOOKUP_IN_ROOT uses nd->dfd). */ > > > if (*s == '/' && !(flags & LOOKUP_IN_ROOT)) { > > > > Bingo. That fixes it. > > *grumble* > > OK, I suppose it'll do for backports, but longer term... I don't like how > convoluted the rules for nameidata fields' validity are. In particular, > for nd->path I would rather have it > * cleared in set_nameidata() > * cleared when it become invalid. That would be > * places that drop rcu_read_lock() without having legitimized the sucker > (already done, except for terminate_walk()) > * terminate_walk() in non-RCU case after path_put(&nd->path) > > OTOH... wait a sec - the whole thing is this cycle regression, so... BTW, there's another piece of brittleness that almost accidentally doesn't end up biting us - nd->depth should be cleared in set_nameidata(), not in path_init(). In this case we are saved by the fact that the only really early failure in path_init() can't happen on the first call, so if we do leave the sucker before zeroing nd->depth, we are saved by the fact that terminate_walk() has just been called and it *does* clear nd->depth. It's obviously cleaner to have it initialized from the very beginning and not bother with it in path_init() at all. Separate patch, though - this is not, strictly speaking, a bug.