Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5905051pxb; Thu, 20 Jan 2022 06:58:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQyh72SN0byRkmam53sxExsOrryJzBo3RENUVRnNIrV/PVyjXpgo/2Hpl/n419/6zkgj5o X-Received: by 2002:a05:6a00:1595:b0:4c2:7c7c:f3df with SMTP id u21-20020a056a00159500b004c27c7cf3dfmr31273936pfk.71.1642690689622; Thu, 20 Jan 2022 06:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642690689; cv=none; d=google.com; s=arc-20160816; b=LSxih8WTXlTYSMDq4BZBGmTQ6VioR0dEvsUm4bsU9vWr/URe/y9iQF5pwmR7DMXSYn qdM+KSgc5lBZvYi1UK5iv6DGudpyUXyZaM4XeB8/sSI69ag8VYkiV97nz2SkyAuVRDra YY0Wvptfq2+tX60DMV7oc0T+seaFF3T9pLiTAY6ks0E9/9OboxKvwVW2XVWvoktGvj4n l5uW4tGW2fyRoY8xH04AtzSY0ayWDyYOFPzClRP/0H9YfgxhIqL1ZPQE39zpXTGrKN0Y PBc3OUV/DF3Mpy8HjgeoxsIaUuzTR8MWBJYzfqxBfyWINzc/D1h0qe/cU/PWcpz/SPkI 89Aw== 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=8x48MiZFRbV94zjE736KjA2TBA0wQtq/rVhtpq8/VMI=; b=qXpD4p7XqEx50AmDlXNtf8b+/dvyyayCqgb97lqOTXMda7a3EtI9VGo7Qluo2PZRr1 4/9iBxP4jASN7W82R5KrcDfmZ06lLY1CCmAKlDReyibn/1XFjKffmrLmOfVOol6h4UYP UXVPrMuZtdc9jXEM4lK3KVWrxuNW/B/kMbSSi4iatJjOni6ZbCv/IRdBdSsRqDNCSDti xdlE7/F1Pwf3QxrnP8AJVMRQIUephePOacAliowPrbSSKaBZd28+LKPg68g5+Afmg1Ii ZgR+oY+HFm/RaFO4Y+eHFgov5hF440XSHHgYR+/fSB6m4c4N4Ik1wKsNlhbUAPPWYGkj Su6g== 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 l2si1279600pfl.56.2022.01.20.06.57.58; Thu, 20 Jan 2022 06:58:09 -0800 (PST) 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 S1346192AbiARQE6 (ORCPT + 99 others); Tue, 18 Jan 2022 11:04:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241152AbiARQE5 (ORCPT ); Tue, 18 Jan 2022 11:04:57 -0500 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 A0414C061574; Tue, 18 Jan 2022 08:04:57 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9qyY-002r1e-4y; Tue, 18 Jan 2022 16:04:50 +0000 Date: Tue, 18 Jan 2022 16:04:50 +0000 From: Al Viro To: Christian Brauner Cc: Brian Foster , Ian Kent , "Darrick J. Wong" , Christoph Hellwig , Miklos Szeredi , David Howells , Kernel Mailing List , linux-fsdevel , xfs Subject: Re: [PATCH] vfs: check dentry is still valid in get_link() Message-ID: References: <164180589176.86426.501271559065590169.stgit@mickey.themaw.net> <275358741c4ee64b5e4e008d514876ed4ec1071c.camel@themaw.net> <20220118082911.rsmv5m2pjeyt6wpg@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220118082911.rsmv5m2pjeyt6wpg@wittgenstein> Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 18, 2022 at 09:29:11AM +0100, Christian Brauner wrote: > On Mon, Jan 17, 2022 at 06:10:36PM +0000, Al Viro wrote: > > On Mon, Jan 17, 2022 at 04:28:52PM +0000, Al Viro wrote: > > > > > IOW, ->free_inode() is RCU-delayed part of ->destroy_inode(). If both > > > are present, ->destroy_inode() will be called synchronously, followed > > > by ->free_inode() from RCU callback, so you can have both - moving just > > > the "finally mark for reuse" part into ->free_inode() would be OK. > > > Any blocking stuff (if any) can be left in ->destroy_inode()... > > > > BTW, we *do* have a problem with ext4 fast symlinks. Pathwalk assumes that > > strings it parses are not changing under it. There are rather delicate > > dances in dcache lookups re possibility of ->d_name contents changing under > > it, but the search key is assumed to be stable. > > > > What's more, there's a correctness issue even if we do not oops. Currently > > we do not recheck ->d_seq of symlink dentry when we dismiss the symlink from > > the stack. After all, we'd just finished traversing what used to be the > > contents of a symlink that used to be in the right place. It might have been > > unlinked while we'd been traversing it, but that's not a correctness issue. > > > > But that critically depends upon the contents not getting mangled. If it > > *can* be screwed by such unlink, we risk successful lookup leading to the > > Out of curiosity: whether or not it can get mangled depends on the > filesystem and how it implements fast symlinks or do fast symlinks > currently guarantee that contents are mangled? Not sure if I understand your question correctly... Filesystems should guarantee that the contents of string returned by ->get_link() (or pointed to by ->i_link) remains unchanged for as long as we are looking at it (until fs/namei.c:put_link() that drops it or fs/namei.c:drop_links() in the end of pathwalk). Fast symlinks or not - doesn't matter. The only cases where that does not hold (there are two of them in the entire kernel) happen to be fast symlinks. Both cases are bugs. ext4 case is actually easy to fix - the only reason it ends up mangling the string is the way ext4_truncate() implements its check for victim being a fast symlink (and thus needing no work). It gets disrupted by zeroing ->i_size, which we need to do in this case (inode removal). That's not hard to get right. A plenty of other fast symlink variants (starting with ext2 ones, BTW) do not step into anything of that sort. IIRC, we used to have at least some cases (orangefs, perhaps?) where revalidate on a symlink might (with confused or malicious server) end up modifying the contents, possibly right under somebody else walking that symlink. Also a bug...