Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2909474iog; Mon, 27 Jun 2022 05:34:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sl6Lhr9SUOcns+49Se+SSl5kaOgNp886WHAg4ajEyhnJ7VP27JLelNjLrcM+NFjecGL+RZ X-Received: by 2002:aa7:db47:0:b0:435:76e4:c6f4 with SMTP id n7-20020aa7db47000000b0043576e4c6f4mr16246319edt.351.1656333249554; Mon, 27 Jun 2022 05:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333249; cv=none; d=google.com; s=arc-20160816; b=kKl0BBXAtayT6XpcV/3R5gPdXqpcdJOYmwL94L5efYglDyE9O4Oh/3DEUwmHacpR0C VNMxthUpqBgQCAKT6+9e2GeC7Tv+zT/c65cdzlspYbJtMIHTSwc1qkH4NgS+J3oE/xlS fpyle1kbTKQ4ZK+ubvM6FffY2FukhA4QEutFRbAxpXfkqBaiJGdI91TJCVQzO4eHQyCM PlAKYB2PlXrsnwGBSR+w4vj846ijedO94yJ51hhjyfWu2wy+XrHTUpo8VAb759hWD3m+ Of56MdvJN2SXwcINDVFCUB1YfMBVVZwhFGd0/pK5OrMVN3dOa79pkH8lk1+YxBg6SLqs aGzg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=C+bCbcYzMdVD7uFBtrlBe+a9jBHBAfo+v7Q5ZR8gVso=; b=ptY2qXIvb5QFJCkvxb1zkWv1JvwoEWdyVJzCG3lfnkwR2oVt9MR9J96q6ES0jOQNH2 8SYS7IbA1t/v8Z6rJARsg3RJwHtiJ62ukl3H+TdgzS+q+AFikfODC74TQOgxt4aBxXRt 5heEbJ5A4SeBXIgXtWpNwJL/aB3ivsXu60BoYeF7yCv90bzRe3EaalwWWIahsdZbPQzy ucZxFW3ahhnUVI4QiBvx3OueKiUv2Hj6hVEOkftBfz4RcZJf8PYN04ZKs0SWGT4I+QaP Y/khl7f/m49pwErZmKjmLhj4kxSp3ULP0fDeToPYPXpSyWGTte5p2Gwdq6bXc2vDP6I6 hxUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IT+7hB30; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js4-20020a17090797c400b0070b70788697si11710250ejc.160.2022.06.27.05.33.44; Mon, 27 Jun 2022 05:34:09 -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=@linuxfoundation.org header.s=korg header.b=IT+7hB30; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237877AbiF0LrN (ORCPT + 99 others); Mon, 27 Jun 2022 07:47:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237467AbiF0Lmx (ORCPT ); Mon, 27 Jun 2022 07:42:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F6DF67; Mon, 27 Jun 2022 04:38:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 370126114D; Mon, 27 Jun 2022 11:38:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4864FC341C8; Mon, 27 Jun 2022 11:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656329898; bh=TiybJzSVz8izLkFtpH1FLS4k+JLx8oS7oe9r0JDSkBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IT+7hB30Lh3/VD/YHoC6cDlMXvDa6aKX/7eVUWV7mriJzVApdqFAlgAA2xlR52v20 fr4oAU23gC4n4MSgYFWWmAaUEJvpxPTxG6VBTJLbbDJa67cVV5+1znM4aD30yrHIdZ pfc0bTVumWRngx/YQ6+zDnuJOFgZY6vsudk14i/o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Christian Schoenebeck , Dominique Martinet Subject: [PATCH 5.18 017/181] 9p: fix EBADF errors in cached mode Date: Mon, 27 Jun 2022 13:19:50 +0200 Message-Id: <20220627111945.062546213@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dominique Martinet commit b0017602fdf6bd3f344dd49eaee8b6ffeed6dbac upstream. 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 Signed-off-by: Greg Kroah-Hartman --- fs/9p/vfs_addr.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/fs/9p/vfs_addr.c +++ b/fs/9p/vfs_addr.c @@ -58,8 +58,21 @@ static void v9fs_issue_read(struct netfs */ 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;