Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1812514iog; Thu, 16 Jun 2022 14:32:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sr3eIA6ehvnFWppd8oa2YhTcP59jBMuinmQaG+qy9Xr7nySD5faO/bnStjXkQLoa+FowHn X-Received: by 2002:a17:90a:be16:b0:1ea:e19f:b3a2 with SMTP id a22-20020a17090abe1600b001eae19fb3a2mr8145743pjs.191.1655415174033; Thu, 16 Jun 2022 14:32:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655415174; cv=none; d=google.com; s=arc-20160816; b=bLXe4saRYaGz/LeYHV5pEcmpv7uGwyq3bPblrlx5d5z4KpGPM2HoerWG6Q+Se8GFL9 iOYw6LMv3fqTUojJwFQCs+J/NR/MjrUom/fHUSNM0MTjaOWmmfJ2ZNDX/Gn0ngVxHXQV 7mByXVgwE1srgbKcnqrHC7iQVb35uCKGJkrQAJ0PSz7ROoX7ct/tmVe2f3xFU4QFSdYQ zDT8GBJK1y1kWbuJNS47H826SZqJJg/8244wrNGIdR3hLZqzHAsIupq5u7D3JHez2Uxu Gf4VR36hFSHDbB3PtytWvNxR0DTw5kfaw/ZZs9A/gR+tdv0GzC6dNZgj6NXLqrqSx9p3 8crg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=VbuObtaq/Xj/9czX/5l9zKA6V33YfeHnptJycN7lX/0=; b=ne+8xMt8sT9DwdHFLZ1X7eRXqDwzKU6TG+wtxDRSIFS+c6YAICNkpTBbruXvBWUeyT vf2S74BIwN6TlJ19v10JE482hhhxLgQPY8nHpwtPclmC/6CCsjQWCnw7xgLaGqMQyJFD 0VMSU3/OJs6a9dCKZGLPO49tZQu0ge/Ea36WTllMZevKvMNo5f+QSNNtObH7qDnkiJv3 EN+lSUR9afU5HAXkYpeSZC6tpdT1WnR0ynqkNAk9bRlvDCJZUnO3SMNXcOc8XoBqrzpV hKhO4fKQ36WF4rknseQw/nELiwYanzoSSW2+xBw50R0q5AQ9f9ezBwfk4pgj6UQEy+hn HXDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=w9YjB7ax; dkim=pass header.i=@codewreck.org header.s=2 header.b=t2KiccZz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pv14-20020a17090b3c8e00b001e0cc18c2d4si3115866pjb.33.2022.06.16.14.32.41; Thu, 16 Jun 2022 14:32:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@codewreck.org header.s=2 header.b=w9YjB7ax; dkim=pass header.i=@codewreck.org header.s=2 header.b=t2KiccZz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1379107AbiFPVKs (ORCPT + 99 others); Thu, 16 Jun 2022 17:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379098AbiFPVKr (ORCPT ); Thu, 16 Jun 2022 17:10:47 -0400 Received: from nautica.notk.org (ipv6.notk.org [IPv6:2001:41d0:1:7a93::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76EF060BB4; Thu, 16 Jun 2022 14:10:46 -0700 (PDT) Received: by nautica.notk.org (Postfix, from userid 108) id 16C50C009; Thu, 16 Jun 2022 23:10:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655413845; bh=VbuObtaq/Xj/9czX/5l9zKA6V33YfeHnptJycN7lX/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w9YjB7axwSR9K81mBACZ3+xb0RqogmbKoz1Zarpo4jnfhdMd9+hknehWfSnusNzJs hy23z8e0asKymmHwDcXWZSFGoGqtVHNpPQqM1G462vvXFuyl2OCVq0KqiiZoHQjA/H b1gjHYR6xSSnv3dRAcjGV7L4QcsWzChrczmvihwcF/iobah9gVlkCZ7o7vzZu3RtT7 kET1Z/JzV/KtORxSl0Ht50JO+c6bIyTjP7nWZP7vfFxM2ZHqaHN+gcW+jijVkmUSrW wsQI/iOdjpQon262la6/V3oZ+BXXFBNGIOaInOVbrqN8ijTRk+xOIv3Eewg5B/fvjj 4TbUUxjJUDAGA== X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from odin.codewreck.org (localhost [127.0.0.1]) by nautica.notk.org (Postfix) with ESMTPS id CF64FC009; Thu, 16 Jun 2022 23:10:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codewreck.org; s=2; t=1655413844; bh=VbuObtaq/Xj/9czX/5l9zKA6V33YfeHnptJycN7lX/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t2KiccZzHDi58sq19Fwuhtd4F403cMuN761fHNRg6hXigyHJboAPQwI7O5x1Z57UD D482Mur4sR6jjYakgtPMy9x0gOo5/0MQE4Xtyuy44OkR4yoCQtfiPEW6nsCmezVava RSCnUln2Y3AWxesnZNdwZ9/nBXw6OSMaq3VD4SpeC1Xg4nhkvVAgYwM26ASA4QoeMD K3OF0O/rH+ecN2JX8/Stp2tEOLkn5Fio0zhENLij0B2lmyDViQomBn/tjqLs4PDMiv 5zumaGfcJ94Ui6CUFXhzTlI0TjDNEEggruBpFXNlnWtx5GeqChYv/OtH4wT/jnka7o /axCjbS7g3ivQ== Received: from localhost (odin.codewreck.org [local]) by odin.codewreck.org (OpenSMTPD) with ESMTPA id ca77515f; Thu, 16 Jun 2022 21:10:39 +0000 (UTC) From: Dominique Martinet To: Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , David Howells Cc: stable@vger.kernel.org, v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v3] 9p: fix EBADF errors in cached mode Date: Fri, 17 Jun 2022 06:10:25 +0900 Message-Id: <20220616211025.1790171-1-asmadeus@codewreck.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <15767273.MGizftpLG7@silver> References: <15767273.MGizftpLG7@silver> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cached operations sometimes need to do invalid operations (e.g. read on a write only file) Historic fscache had added a "writeback fid", a special handle opened RW as root, for this. The conversion to new fscache missed that bit. This commit reinstates a slightly lesser variant of the original code that uses the writeback fid for partial pages backfills if the regular user fid had been open as WRONLY, and thus would lack read permissions. Link: https://lkml.kernel.org/r/20220614033802.1606738-1-asmadeus@codewreck.org Fixes: eb497943fa21 ("9p: Convert to using the netfs helper lib to do reads and caching") Cc: stable@vger.kernel.org Cc: David Howells Reported-By: Christian Schoenebeck Reviewed-by: Christian Schoenebeck Tested-by: Christian Schoenebeck Signed-off-by: Dominique Martinet --- v3: use the least permissive version of the patch that only uses writeback fid when really required If no problem shows up by then I'll post this patch around Wed 23 (next week) with the other stable fixes. fs/9p/vfs_addr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c index a8f512b44a85..d0833fa69faf 100644 --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -58,8 +58,21 @@ static void v9fs_issue_read(struct netfs_io_subrequest *subreq) */ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file) { + struct inode *inode = file_inode(file); + struct v9fs_inode *v9inode = V9FS_I(inode); struct p9_fid *fid = file->private_data; + BUG_ON(!fid); + + /* we might need to read from a fid that was opened write-only + * for read-modify-write of page cache, use the writeback fid + * for that */ + if (rreq->origin == NETFS_READ_FOR_WRITE && + (fid->mode & O_ACCMODE) == O_WRONLY) { + fid = v9inode->writeback_fid; + BUG_ON(!fid); + } + refcount_inc(&fid->count); rreq->netfs_priv = fid; return 0; -- 2.35.1