Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp413656pxb; Tue, 1 Feb 2022 02:42:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1G1gfiGqhWhoHA7QvktIAe602wAfah1JR23sGS8zpOoJYNgFmtdlcsU7YrFpIRgqb5OWp X-Received: by 2002:a17:907:c13:: with SMTP id ga19mr20070197ejc.634.1643712161207; Tue, 01 Feb 2022 02:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643712161; cv=none; d=google.com; s=arc-20160816; b=UxumQ1+VTSEU1x6xSrogEXu8iZGMns1vwV3+YB1WnMhDI0THJL8YJv9833ERFHFIQy TcK7nMSMVoTQYGSbY4GtxKn80autBmCUtEBY0z3upHQUQHg7L7g/OQCDGffu+lX3Eort 2Nf4Cm+c7E1vwiroQcdvCM/wBnUiu/e1AwlihS0JwwiymiJN9nlZK8vhNGLvFfXYq8Pc Uslh5ZfSJRovKef7i9sU3pcWxmLz6als/C0cpzAHbaQ5VFONvQRCSMTLEVzWoUSWAmHg h9JQWc8q41kZuXqOy8uVIDXnJ574U7woSUBO0MUwLl8r+TVlQmEWTLSUR3a12+M00Dd+ xgJg== 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 :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=WzIC+v4+UrPRQhCkj2dIOPEwY3tXxjMgRe2rgwvMEZY=; b=CyUnsducp8Cdc1rNj26jAuH5CKS9OO/uSg90y0NUwDpvNovmIK4uVtuqNA400/QfuS LkiUOxE/vx2Cd0BmPHwJAYnmQxuPQjOgCmhlFvi26O6ODyiVmVJKmPV/2+oIoD4gfsKk +QsZJRO2DhRf+w2akvHaG/47RzGaTvyi6A0hbcCqOlXsSMycxL3R5wWM22K9cv6pVEE6 AIJZK91KerkPBMDGdJtlhJDqukgjhH6eXkxxhEaOctREBW+MdZ3R+6/2cSuJGFdMPaAR ml9zDaFf3ra0uyPT5p/Jt7ZeE5sSlI8wAutnd2WzDNynh9KI0E/Q9VWJFkNu+7DUgKY9 68Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b="A/eTCDAY"; dkim=pass header.i=@codewreck.org header.s=2 header.b=f92Lnoe7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j6si8536120ejj.264.2022.02.01.02.42.16; Tue, 01 Feb 2022 02:42:41 -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=@codewreck.org header.s=2 header.b="A/eTCDAY"; dkim=pass header.i=@codewreck.org header.s=2 header.b=f92Lnoe7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codewreck.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347099AbiA3NHM (ORCPT + 99 others); Sun, 30 Jan 2022 08:07:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347045AbiA3NHK (ORCPT ); Sun, 30 Jan 2022 08:07:10 -0500 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0974C061714; Sun, 30 Jan 2022 05:07:09 -0800 (PST) Received: by nautica.notk.org (Postfix, from userid 108) id 2C4C9C01E; Sun, 30 Jan 2022 14:07:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1643548025; bh=WzIC+v4+UrPRQhCkj2dIOPEwY3tXxjMgRe2rgwvMEZY=; h=From:To:Cc:Subject:Date:From; b=A/eTCDAYeVJIxX5tbvB12/4/652HP6a+M3FpLRcse+Sc/SEjEpfTDPYqr1LDWJh1v mKGkEQeNIvKnL7zXo0of38hdfHCmurruuAq1RVuh/WRkZ29Azka74FfWZ2FMPKPa7E OFzMujNAmlWwYryiv62a1n0xCvaQolZw3yZ4TE8ZNDfbF1x4cKDIA1DmHKvN902c1R CHdTs98gR/dogx6TZ8YrpA42dOjVmuR57wwsv/Oe8z1gb3TAn8r2u07I6qF7QdICHx wkg7Bzw9y1kIem4Y6uVmScgtSqVubnftN4Gv2MpiYgmAfNmiW/4DcWSBnHarALyF7n aXKrUoaYdnxKQ== X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on nautica.notk.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=unavailable version=3.3.2 Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id C0393C01B; Sun, 30 Jan 2022 14:07:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1643548024; bh=WzIC+v4+UrPRQhCkj2dIOPEwY3tXxjMgRe2rgwvMEZY=; h=From:To:Cc:Subject:Date:From; b=f92Lnoe7HN1ufdYJSbNXcyVI/iMnA8btHbNuPezzvvhOQa41J/nJcEc7dibLwCS/G YeXUlLJlorVVVAc8ayShvappXCEwRTXw5F+AqipPbYGKmZx4rMs4qqDYrNN1VLfrGX 7MXSoeDVhEvNk6X/KUVxjalJXF/G5wdlvkpC3qhwkzyNBfkbF27SOy5jmqhZXFgqxK vFqD7IzAAuFQw0AF9Xnm5zcLo+PSxECkbrsiGK3GQGuYfpKbXdVW+/cyBgRvLoly8V I8r1O5bdT9amTUA81wljgpkQ72J2meQt5rJNlmxiy2rkVPoTm+p1o/tP2m6WtYBamU fmdHqvKGboAbA== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id b42ff00b; Sun, 30 Jan 2022 13:06:57 +0000 (UTC) From: Dominique Martinet To: v9fs-developer@lists.sourceforge.net, ericvh@gmail.com, lucho@ionkov.net Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Dominique Martinet , stable@vger.kernel.org, ron minnich , ng@0x80.stream Subject: [PATCH] Revert "fs/9p: search open fids first" Date: Sun, 30 Jan 2022 22:06:51 +0900 Message-Id: <20220130130651.712293-1-asmadeus@codewreck.org> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This reverts commit 478ba09edc1f2f2ee27180a06150cb2d1a686f9c. That commit was meant as a fix for setattrs with by fd (e.g. ftruncate) to use an open fid instead of the first fid it found on lookup. The proper fix for that is to use the fid associated with the open file struct, available in iattr->ia_file for such operations, and was actually done just before in 66246641609b ("9p: retrieve fid from file when file instance exist.") As such, this commit is no longer required. Furthermore, changing lookup to return open fids first had unwanted side effects, as it turns out the protocol forbids the use of open fids for further walks (e.g. clone_fid) and we broke mounts for some servers enforcing this rule. Note this only reverts to the old working behaviour, but it's still possible for lookup to return open fids if dentry->d_fsdata is not set, so more work is needed to make sure we respect this rule in the future, for example by adding a flag to the lookup functions to only match certain fid open modes depending on caller requirements. Fixes: 478ba09edc1f ("fs/9p: search open fids first") Cc: stable@vger.kernel.org # v5.11+ Reported-by: ron minnich Reported-by: ng@0x80.stream Signed-off-by: Dominique Martinet --- I'm sorry I didn't find time to check this properly fixes the clone open fid issues, but Ron reported it did so I'll assume it did for now. I'll try to find time to either implement the check in ganesha or use another server -- if you have a suggestion that'd run either a ramfs or export a local filesystem from linux I'm all ears, I couldn't get go9p to work in the very little time I tried. I did however check that Greg's original open/chmod 0/ftruncate pattern works (while truncate was refused). Also, before revert the truncate by path wasn't refused, and now is again, so that's definitely good. I've also tested open-unlink-ftruncate and it works properly with ganesha, but not with qemu -- it looks like qemu tries to access the file by path in setattr even if the fid has an associated fd, so that'd be a qemu bug, but it's unrelated to this patch anyway. Unless there are issues with this patch I'll send it to Linus around Friday fs/9p/fid.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 6aab046c98e2..79df61fe0e59 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -96,12 +96,8 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any) dentry, dentry, from_kuid(&init_user_ns, uid), any); ret = NULL; - - if (d_inode(dentry)) - ret = v9fs_fid_find_inode(d_inode(dentry), uid); - /* we'll recheck under lock if there's anything to look in */ - if (!ret && dentry->d_fsdata) { + if (dentry->d_fsdata) { struct hlist_head *h = (struct hlist_head *)&dentry->d_fsdata; spin_lock(&dentry->d_lock); @@ -113,6 +109,9 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, kuid_t uid, int any) } } spin_unlock(&dentry->d_lock); + } else { + if (dentry->d_inode) + ret = v9fs_fid_find_inode(dentry->d_inode, uid); } return ret; -- 2.34.1