Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3380691pxb; Mon, 17 Jan 2022 19:07:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPd4tq2Qd8Z9kva5XYT+xsCbOtm9v3slDQsGiWCpw9NYjL2aXU1HdUfh4zyKbCLf27WpxW X-Received: by 2002:a62:c186:0:b0:4c1:232c:819d with SMTP id i128-20020a62c186000000b004c1232c819dmr23996801pfg.28.1642475255777; Mon, 17 Jan 2022 19:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642475255; cv=none; d=google.com; s=arc-20160816; b=kopPjvh1HM/utlxKXVdbW8LrpMu2PpVk+zmVx5sFv1k9bwHsOweUZrxNtVOHdt4nja o2UFkI4dGDQ+COVAbTXYcvicddoIK0lYm1bFMpAUXwCRXXws7Ut9jHkP73iKX218McJP yUGIyRy5N+j1ERLBQSKZNKbNnVdia2z1tWToo5XsZ7BNl0Ds22LNkKWgiNxzv6SgR7vq vsPkClJ99RDDlGFC2DwyPYUU+nIQ11y0/U+5353XmOjvYyG/SHUnICzAsm/tD4pjrXKg D/rc7FuvfTurTRu4YuDjMJ/PE9CqMwDm28pS4F5FiUrqt6fJCUk+dnenrAAP7BJFO7Ys idIA== 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=+5T9JRMff4BHSPnERcVPBSxRGSOt75eyUbTAdiJ6ZPM=; b=TTJBOhaLyutU924bcpuvDa0/pb5I7ByHhVAjyZKvKmNuxy+pZXDVWRfMHGMCb6XVU3 xVKWQpaGyuA4VNzZ3fWxh3GAeVwwq3Vk/y/zg8/P4lWYwAfIQZyx9JEPqr4JkZvyJifx fAwJKBL0VrhmnWHep2hZxi6zLziXiN51jqV2gD9bn2ARGUaJ43vkUbBgE9XjzktGn2Bq l7NZsURHGeFahFhajM6yjj7Swp8LR0b7Tg+mK1tVBD82tL1mP0MOzgMpe/FNncjXHwMx +I1SfFADiB9QloxyP6caDoCCUGkPXRmjSXGm6kzIa1eYMdOLQZ83VksXvRkh61boYTM6 ZSlg== 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 k19si15943257pfu.230.2022.01.17.19.07.24; Mon, 17 Jan 2022 19:07:35 -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 S238728AbiARBce (ORCPT + 99 others); Mon, 17 Jan 2022 20:32:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229705AbiARBcd (ORCPT ); Mon, 17 Jan 2022 20:32:33 -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 72DE6C061574; Mon, 17 Jan 2022 17:32:33 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9dMF-002gha-WE; Tue, 18 Jan 2022 01:32:24 +0000 Date: Tue, 18 Jan 2022 01:32:23 +0000 From: Al Viro To: Brian Foster Cc: Ian Kent , "Darrick J. Wong" , Christoph Hellwig , Miklos Szeredi , David Howells , Kernel Mailing List , linux-fsdevel , xfs , Linus Torvalds 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> 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 Mon, Jan 17, 2022 at 07:48:49PM +0000, Al Viro wrote: > > 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 > > wrong place, with nothing to tell us that it's happening. We could handle > > that by adding a check to fs/namei.c:put_link(), and propagating the error > > to callers. It's not impossible, but it won't be pretty. > > > > And that assumes we avoid oopsen on string changing under us in the first > > place. Which might or might not be true - I hadn't finished the audit yet. > > Note that it's *NOT* just fs/namei.c + fs/dcache.c + some fs methods - > > we need to make sure that e.g. everything called by ->d_hash() instances > > is OK with strings changing right under them. Including utf8_to_utf32(), > > crc32_le(), utf8_casefold_hash(), etc. > > And AFAICS, ext4, xfs and possibly ubifs (I'm unfamiliar with that one and > the call chains there are deep enough for me to miss something) have the > "bugger the contents of string returned by RCU ->get_link() if unlink() > happens" problem. > > I would very much prefer to have them deal with that crap, especially > since I don't see why does ext4_evict_inode() need to do that memset() - > can't we simply check ->i_op in ext4_can_truncate() and be done with > that? This reuse-without-delay has another fun side, AFAICS. Suppose the new use for inode comes with the same ->i_op (i.e. it's a symlink again) and it happens right after ->get_link() has returned the pointer to body. We are already past whatever checks we might add in pick_link(). And the pointer is still valid. So we end up quietly traversing the body of completely unrelated symlink that never had been anywhere near any directory we might be looking at. With no indication of anything going wrong - just a successful resolution with bogus result. Could XFS folks explain what exactly goes wrong if we make actual marking inode as ready for reuse RCU-delayed, by shifting just that into ->free_inode()? Why would we need any extra synchronize_rcu() anywhere?