Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp5470180rdb; Sun, 31 Dec 2023 02:45:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7DjAjQaMbJ7uDrlXtNk9Ox1eINNWfHQc7kI0MnZUkcHXCSz3zIzw3wXKEyRg3fBuUpgl8 X-Received: by 2002:a17:902:e881:b0:1d4:4c3a:3ee3 with SMTP id w1-20020a170902e88100b001d44c3a3ee3mr14344421plg.106.1704019519027; Sun, 31 Dec 2023 02:45:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704019519; cv=none; d=google.com; s=arc-20160816; b=w2oTfg95Nk2fosn09EmwLqjL0drhFrrc2HEDh0Fq7wfjEPBH8JjjxNjgPg9yhJgIdH W/tjPXaCfqr1B7Hxhun7NbNwrtRO9rInx044WovlFTYkXzE9Ou+t3BmqKU9ZFapy3Mlr 7QpaBf3PlqyJ2I2G7UjNqXbcUnicAmpJjWcvRhCSEqwufnU93bP9tPJcy41fjs14So5E 85bQ1AIGiTIDsqcJt77yhjbfBEIf/AOQ1zKa0uDdJ2lCwkPvvOhsIjeygmJ13esPA75H 86uQ5SnwJAK1fYXRs5wlwQMRhvyHGFA43Ykb3vL41GVW8fAebYAGc8aOKsvIqZg1O/ua gUxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ym5PQGYqMktC4T1S3eQaZFoa+im01ZODGDdyF9/BuxA=; fh=rwiaHyY90Ka0dv121XHQKS8Ghig5+12psWf/wF0vE1o=; b=baF9VtzAso82UdAYw3LRbx07JFuLI4NtHSoO/hYn5qPCvLKjP+PQ6+4ukvwpA2mm5D Gg09rWbaXW7dm0v2qzbGqEDrtXQJmNT/809s2gPPG38UiOM72Ez3/uhaJhTj1WKfsgYd L8x3iqfUC00Ky00J2Yb+YhBG7uagOHcT0ClOB0BJEYu+3OylxFwQpGpIjAFpng88w9CJ wwKMmT/OPygx3XJYniLJ3mUXX6ftk8Xy9rAI8XeYULoAWe4SW6t4vOhkqES67QFK/4Xi bn23S2jvy+9+iYdpDnLvAHBAPZ/vpHzbFPlVHJq/8FChvAwOpwIisWD/i296ytsnmD1P AIQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ve3Pfsvz; spf=pass (google.com: domain of linux-nfs+bounces-847-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-847-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r22-20020a170902be1600b001d43b2fcba1si12861213pls.532.2023.12.31.02.45.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Dec 2023 02:45:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-847-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Ve3Pfsvz; spf=pass (google.com: domain of linux-nfs+bounces-847-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-847-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 54976B20E48 for ; Sun, 31 Dec 2023 10:45:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C02133D3; Sun, 31 Dec 2023 10:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ve3Pfsvz" X-Original-To: linux-nfs@vger.kernel.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B386833D1; Sun, 31 Dec 2023 10:45:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-67f911e9ac4so65798606d6.3; Sun, 31 Dec 2023 02:45:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704019508; x=1704624308; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ym5PQGYqMktC4T1S3eQaZFoa+im01ZODGDdyF9/BuxA=; b=Ve3PfsvzUsTHJI3c/x2xgvro9H7NU8ZzEwnvzDMrhspbTRmdna/5Hcslk/XxrFB5WK yLvt9W4LYd0vKfc3ktpy3QITtjEj1RGlpR3H4Vl+VMQHJXvb/Dx2yWe8nqxlxdLkgsy8 PNmd7I6IuXKFxzGDYgIKNJiJrWrIj1Nka3ATUWr//j6up2mbS4smMTN06M9BCrIq1jnR aFE+Mns0/xcK97sA1GTHYIp/+bvJWw26tcwWiT6gUI33lU3iyTZBAQMAAlkMayFHhKFV HNcshbq4IXlarHPyWJk1Vr3ZrT/j7So/aY4rXhkZh7g24yEeut5MWcUZRC7PzCcJTEq8 wi/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704019508; x=1704624308; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ym5PQGYqMktC4T1S3eQaZFoa+im01ZODGDdyF9/BuxA=; b=nCjr5oISNVSc7ERBwVwZWxjG5jIo3XuXb2QomKnP8bB2USo4c1fxr/rsxhRKmVJDio hy8/B96OYna6XWPwzV8kuw0IlFQJwn4nok8hcxf2xOPaZEZGiYIzFk0N6N68dZi8dmgE h6+UwG+5MW9shaL+iU1KOnpstHjR/2caMDxkbHMKoAOgwtTPuoP1+YHIfYAQELjd685r zVok71YyO6ti8lMp+jPxHaCz/sOfAlVk+i/VXrRcj4ZMbow0n5I5H/UvvNpir5q9fq8T u2QRVVDISqE1CU/ocKPbiaZ8jA0IMhXDgB+v/WjOJJrGHKEAWamlJtD7rFen02DJVfWW uRgQ== X-Gm-Message-State: AOJu0YxbmkjvK+NWyGrbq79h8jww5/mPtaHDOA+Z2zr8scLbRZBv17/J eQwBPWIfzHAIGIQzsv+BvtPnR2MsQnoKWkSSd0aqlEy/3U8= X-Received: by 2002:a05:6214:2128:b0:67f:c76:e9e8 with SMTP id r8-20020a056214212800b0067f0c76e9e8mr28339330qvc.16.1704019508461; Sun, 31 Dec 2023 02:45:08 -0800 (PST) Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231228201510.985235-1-trondmy@kernel.org> <9c4867cf1f94a8e46c2271bfd5a91d30d49ada70.camel@hammerspace.com> In-Reply-To: <9c4867cf1f94a8e46c2271bfd5a91d30d49ada70.camel@hammerspace.com> From: Amir Goldstein Date: Sun, 31 Dec 2023 12:44:57 +0200 Message-ID: Subject: Re: [PATCH] knfsd: fix the fallback implementation of the get_name export operation To: Trond Myklebust Cc: "linux-nfs@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "viro@zeniv.linux.org.uk" , "chuck.lever@oracle.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Dec 30, 2023 at 9:36=E2=80=AFPM Trond Myklebust wrote: > > On Sat, 2023-12-30 at 08:23 +0200, Amir Goldstein wrote: > > On Sat, Dec 30, 2023 at 1:50=E2=80=AFAM Trond Myklebust > > wrote: > > > > > > On Fri, 2023-12-29 at 18:29 -0500, Chuck Lever wrote: > > > > On Fri, Dec 29, 2023 at 07:44:20PM +0200, Amir Goldstein wrote: > > > > > On Fri, Dec 29, 2023 at 4:35=E2=80=AFPM Chuck Lever > > > > > wrote: > > > > > > > > > > > > On Fri, Dec 29, 2023 at 07:46:54AM +0200, Amir Goldstein > > > > > > wrote: > > > > > > > [CC: fsdevel, viro] > > > > > > > > > > > > Thanks for picking this up, Amir, and for copying > > > > > > viro/fsdevel. I > > > > > > was planning to repost this next week when more folks are > > > > > > back, > > > > > > but > > > > > > this works too. > > > > > > > > > > > > Trond, if you'd like, I can handle review changes if you > > > > > > don't > > > > > > have > > > > > > time to follow up. > > > > > > > > > > > > > > > > > > > On Thu, Dec 28, 2023 at 10:22=E2=80=AFPM > > > > > > > wrote: > > > > > > > > > > > > > > > > From: Trond Myklebust > > > > > > > > > > > > > > > > The fallback implementation for the get_name export > > > > > > > > operation > > > > > > > > uses > > > > > > > > readdir() to try to match the inode number to a filename. > > > > > > > > That filename > > > > > > > > is then used together with lookup_one() to produce a > > > > > > > > dentry. > > > > > > > > A problem arises when we match the '.' or '..' entries, > > > > > > > > since > > > > > > > > that > > > > > > > > causes lookup_one() to fail. This has sometimes been seen > > > > > > > > to > > > > > > > > occur for > > > > > > > > filesystems that violate POSIX requirements around > > > > > > > > uniqueness > > > > > > > > of inode > > > > > > > > numbers, something that is common for snapshot > > > > > > > > directories. > > > > > > > > > > > > > > Ouch. Nasty. > > > > > > > > > > > > > > Looks to me like the root cause is "filesystems that > > > > > > > violate > > > > > > > POSIX > > > > > > > requirements around uniqueness of inode numbers". > > > > > > > This violation can cause any of the parent's children to > > > > > > > wrongly match > > > > > > > get_name() not only '.' and '..' and fail the d_inode > > > > > > > sanity > > > > > > > check after > > > > > > > lookup_one(). > > > > > > > > > > > > > > I understand why this would be common with parent of > > > > > > > snapshot > > > > > > > dir, > > > > > > > but the only fs that support snapshots that I know of > > > > > > > (btrfs, > > > > > > > bcachefs) > > > > > > > do implement ->get_name(), so which filesystem did you > > > > > > > encounter > > > > > > > this behavior with? can it be fixed by implementing a > > > > > > > snapshot > > > > > > > aware ->get_name()? > > > > > > > > > > > > > > > This patch just ensures that we skip '.' and '..' rather > > > > > > > > than > > > > > > > > allowing a > > > > > > > > match. > > > > > > > > > > > > > > I agree that skipping '.' and '..' makes sense, but... > > > > > > > > > > > > Does skipping '.' and '..' make sense for file systems that > > > > > > do > > > > > > > > > > It makes sense because if the child's name in its parent would > > > > > have been "." or ".." it would have been its own parent or its > > > > > own > > > > > grandparent (ELOOP situation). > > > > > IOW, we can safely skip "." and "..", regardless of anything > > > > > else. > > > > > > > > This new comment: > > > > > > > > + /* Ignore the '.' and '..' entries */ > > > > > > > > then seems inadequate to explain why dot and dot-dot are now > > > > never > > > > matched. Perhaps the function's documenting comment could expand > > > > on > > > > this a little. I'll give it some thought. > > > > > > The point of this code is to attempt to create a valid path that > > > connects the inode found by the filehandle to the export point. The > > > readdir() must determine a valid name for a dentry that is a > > > component > > > of that path, which is why '.' and '..' can never be acceptable. > > > > > > This is why I think we should keep the 'Fixes:' line. The commit it > > > points to explains quite concisely why this patch is needed. > > > > > > > By all means, mention this commit, just not with a fixed tag please. > > IIUC, commit 21d8a15ac333 did not introduce a regression that this > > patch fixes. Right? > > So why insist on abusing Fixes: tag instead of a mention? > > I don't see it as being that straightforward. > > Prior to commit 21d8a15ac333, the call to lookup_one_len() could return > a dentry (albeit one with an invalid name) depending on whether or not > the filesystem lookup succeeds. Note that knfsd does support a lookup > of "." and "..", as do several other NFS servers. > > With commit 21d8a15ac333 applied, however, lookup_one_len() > automatically returns an EACCES error. > > So while I agree that there are good reasons for introducing commit > 21d8a15ac333, it does change the behaviour in this code path. > I feel that we are miscommunicating. Let me explain how I understand the code and please tell me where I am wron= g. The way I see it, before 21d8a15ac333, exportfs_decode_fh_raw() would call lookup_one() and may get a dentry (with invalid name), but then the sanity check following lookup_one() would surely fail, because no fs should allow a directory to be its own parent/grandparent: if (unlikely(nresult->d_inode !=3D result->d_inode)= ) { dput(nresult); nresult =3D ERR_PTR(-ESTALE); } The way I see it, the only thing that commit 21d8a15ac333 changed in this code is the return value of exportfs_decode_fh_raw() from -ESTALE to -EACCES. exportfs_decode_fh() converts both these errors to -ESTALE and so does nfsd_set_fh_dentry(). Bottom line, if I am reading the code correctly, commit 21d8a15ac333 did not change the behaviour for knfsd nor any user visible behavior for open_by_handle_at() for userspace nfsd. Your fix is good because: 1. It saves an unneeded call to lookup_one() 2. skipping "." and ".." increases the chance of finding the correct child name in the case of non-unique ino So I have no objection to your fix in generic code, but I do not see it being a regression fix. Where are we miscommunicating? What am I missing? Thanks, Amir.