Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4447715pxb; Tue, 18 Jan 2022 20:08:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7A/+oII4Sy5ubil6X/mmtjkV9AcxhN6n7FI+RUQ4lfqjNYJVmlg30g92/skoEsuPHBDgY X-Received: by 2002:a63:3341:: with SMTP id z62mr25673957pgz.99.1642565314665; Tue, 18 Jan 2022 20:08:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642565314; cv=none; d=google.com; s=arc-20160816; b=yn8A9WaiFUpr+zDezqVy0xzB0FJbVi+kNLm91/MgzuMb44n7vjIu3PzC2JMua1GlgN 8gHv+safa5EoY8udbu9gdUd0IYHI3mId9CKY40l8tieQuKSlg6PwjfleAWz40BtNXSk+ 0u+7PPpDSX+54QbPW0p9TXUWDL0+79ME0zaESk5QYIi6mOhUqOGr581i0PM0I356zjem jMihWGY90ZN+f5tNjKIi24VK4o1o/rRdnzaMzpXGaNDQca0egxMJ7YihA8rihjT0QfNA PDHsosEgY+f6SJPrLzx9kcLrJpkyLtlcQc+yn9ywHS0QrAn06su15iP2wojsATZLrjoz w/rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature:dkim-signature; bh=3mRA+fAp1gnVKZsZvkvI9SKUFhnHcen/USfAGlZMD/8=; b=Vk9dXvYF9QYuwts2WEHuwq4qTzE0ZAtRNStPEIzj8rT/2wqhz2xapsqGO0HZaFvYH2 +4+W3zR6xy+Qn+MM/tx1ygoCHagmSflDT0bjSH21vcj0prPVtG4uRSIq9MZVD9ayaqMX zcWZ14DG92OMvrre81ZVne1e+v4OaMHa/r19c3T+MpWjtTPzt9WyZjXt7/8fG/YIM//8 ic4jRxH0F7ZgmK3Yn7DjR7vBH3vhGcVh5GlQRaeBFTbaw3OYmF/VGa0LBTq4raIO+E1e yOT5cdZ13xznxd4J5NasWPqTgItW4+3qqjhFNlLfoqixs+XrFg4Ql93skq+pS9dV6lJT DkFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@themaw.net header.s=fm2 header.b=J1u9Ac5V; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ITwNEwhu; 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 b2si4069695pfm.243.2022.01.18.20.08.22; Tue, 18 Jan 2022 20:08:34 -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; dkim=pass header.i=@themaw.net header.s=fm2 header.b=J1u9Ac5V; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=ITwNEwhu; 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 S1349317AbiARCt1 (ORCPT + 99 others); Mon, 17 Jan 2022 21:49:27 -0500 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:51353 "EHLO wout4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345807AbiARCcE (ORCPT ); Mon, 17 Jan 2022 21:32:04 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id D682C3200946; Mon, 17 Jan 2022 21:32:02 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 17 Jan 2022 21:32:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h= message-id:subject:from:to:cc:date:in-reply-to:references :content-type:mime-version:content-transfer-encoding; s=fm2; bh= 3mRA+fAp1gnVKZsZvkvI9SKUFhnHcen/USfAGlZMD/8=; b=J1u9Ac5VDXG/UgfA F8k48UeRsyAyOn/Y50lgKLzHMDZI+ShW7HwAVKNSeugYAhLsjh0BPxpo4JwDF2pg WsMLL8f78+K643A5XY4XJ08C0Qf+w6HqXYlEXsxdiGkwScq5s/aYjuvmvzuropJt fMkQeb1ceDG4lpxiTrkJFfYaQE6M6JekrwgAdCEutgAhGu8h2W613VZYncd7FGpp oKf7kXK0nHAYljf/n7RFFS/DPUiev4r8WaLzCN6suPwbInNAZ8iyYqu8IB+qIRxz dqUpXsr8BQfBjRaFPixaCT3VqjLWiKQCwMd0vLQwG0gw8iRMHrBkZKAfb8nwEJd3 d17PVA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=3mRA+fAp1gnVKZsZvkvI9SKUFhnHcen/USfAGlZMD /8=; b=ITwNEwhut6PP8iq1nNC8XPTdHIXmjj5o8W3zahgmGmZWysKwg2DduJy/V GwT5UF0fD2l2i6k0WrygOK4G2VwKEN49L1J5WauKkKDJQtliqirfUVbRMn56wxFi Ho1OiO0SCM49WtBBCm3toZQk98Z3Iscp4XSICloQ2qKxvjkFa8YPgh6m+jWe/nQh /uuPg3WeGDBUG/hDmA3cXs9FYBrHF0P//ah2NeVN8qoSx9ZCLkZ5pQacVcb51IP8 wvCcPgbhvS12RFAZQ6HFhQUAsNAVxEAuwX3rWBgL29DIKA0ezSmy3XDxAVrrYGzB sRjXjFUa9XoU72Iy4uwDsFwjov4Gw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddruddvgdegkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkuffhvfffjghftggfggfgsehtkeertddtredunecuhfhrohhmpefkrghnucfm vghnthcuoehrrghvvghnsehthhgvmhgrfidrnhgvtheqnecuggftrfgrthhtvghrnhepff elvddtleehveduvefhkeejfedvkeetffeujedtudevfedtveehueeviefhleffnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhgrvhgvnhesth hhvghmrgifrdhnvght X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Jan 2022 21:31:58 -0500 (EST) Message-ID: <0f6c2348dae2c47ea46a986884a75fc7d44bb6fb.camel@themaw.net> Subject: Re: [PATCH] vfs: check dentry is still valid in get_link() From: Ian Kent To: Al Viro , Brian Foster Cc: "Darrick J. Wong" , Christoph Hellwig , Miklos Szeredi , David Howells , Kernel Mailing List , linux-fsdevel , xfs , Linus Torvalds Date: Tue, 18 Jan 2022 10:31:53 +0800 In-Reply-To: References: <164180589176.86426.501271559065590169.stgit@mickey.themaw.net> <275358741c4ee64b5e4e008d514876ed4ec1071c.camel@themaw.net> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.4 (3.40.4-2.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2022-01-18 at 01:32 +0000, Al Viro wrote: > 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. Wouldn't that case be caught by the unlazy call since ->get_link() needs to return -ECHILD for the rcu case now (in xfs anyway)? > > 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?