Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1740665ioo; Fri, 27 May 2022 16:09:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxZa59sszRz2EX8rFsWeGoXgC89evM68innrq6v637Y4wyV/dJX564GxfOs74sgjlSUBAm X-Received: by 2002:a62:5a07:0:b0:519:38ef:cc72 with SMTP id o7-20020a625a07000000b0051938efcc72mr4981564pfb.82.1653692966724; Fri, 27 May 2022 16:09:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653692966; cv=none; d=google.com; s=arc-20160816; b=t44FGvDuLgwfwsjgUNIYiiwUtKA8q8azd/FuZHlC9YtbBhVLRq45Wqd40pVj/F7Iiz pAumGWG4puESxY0FIDSVpmn5Xf0Y5RMc87/jWPiXyXAHA4x7cYR11PAtFae7G/v/e9Wq dEppZYThmbuw3aQJDbWBWH92I0RtVp71hXYvwkTyeO+8A+bjtV/eYRmudhQVQmv8E0MK V3eh6bMP/lSIZVQAfoVi/bwhzeLGoRY/xt5eI2Q9lM6QcZDSkzCiQ/cyIEzm/+ImTVPG /HTB9YRapOD3n7Mucjqzktq+1Zo2MVlVaNrDbeSWumvUOaUT82/+LWRaAUthodeUMRXM gRPg== 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-filter; bh=NhuOrFwDQW9Q1UcmxsEGyGirwZwzRLJvKVIm4Dfq7Go=; b=kw3yxsiFgKjKKxGSm/IXclFTzXi4rKGSuJfOos4A2XWBMsm4kriUcgp/lvSppBAwew bzmY0JA75PT3cxknruhYkEKYwTCaMYga1tmh4gmof3GSJ6hft+jnMr9QhAsoObDPxZn9 3srLw/QMfuKz+37EIRZLJKhyYiYR/koqgFAIm3eFcP5wP3wZqJ4CzluZj1OXLSE3qOuX mmx4Msu4M2St0IySwVYVJNU5PD+zkWoWYYy1VbryqkZvjy3mvvPlDgNPDXP41+EKw9jH fsOUuy12iNyG+j+n+1DJVfCg+pmRYao6TjKTVonhMeIrT9LKHyQPDLXwEAT4WkSec0c8 S0oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=VEOVZWTZ; 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=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a631c4f000000b003c61ee0c7f6si7218885pgm.552.2022.05.27.16.09.15; Fri, 27 May 2022 16:09:26 -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=@linux.microsoft.com header.s=default header.b=VEOVZWTZ; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345520AbiE0AAc (ORCPT + 99 others); Thu, 26 May 2022 20:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343755AbiE0AA2 (ORCPT ); Thu, 26 May 2022 20:00:28 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0D2B58BD06 for ; Thu, 26 May 2022 17:00:28 -0700 (PDT) Received: from sequoia.corp.microsoft.com (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 45BEC20B6C7C; Thu, 26 May 2022 17:00:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 45BEC20B6C7C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1653609627; bh=NhuOrFwDQW9Q1UcmxsEGyGirwZwzRLJvKVIm4Dfq7Go=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VEOVZWTZwwz+nwhUfw74fZ7F3of6fGhlZoWIXbWcxkU78Awwb/9fML91xtfZe7p/f RIbWgoXWZo9vACbaM7OyykfAa/A3MuHmUQEowMPqZFfQQSv1WOtIdkAy6GufgktV7c XkXbq+bxVDYr4IYAtUiy1VXIb1ET8Qj2hmlVlS4M= From: Tyler Hicks To: Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet Cc: Christian Schoenebeck , Jianyong Wu , v9fs-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/5] 9p: Fix refcounting during full path walks for fid lookups Date: Thu, 26 May 2022 18:59:59 -0500 Message-Id: <20220527000003.355812-2-tyhicks@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220527000003.355812-1-tyhicks@linux.microsoft.com> References: <20220527000003.355812-1-tyhicks@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 Decrement the refcount of the parent dentry's fid after walking each path component during a full path walk for a lookup. Failure to do so can lead to fids that are not clunked until the filesystem is unmounted, as indicated by this warning: 9pnet: found fid 3 not clunked The improper refcounting after walking resulted in open(2) returning -EIO on any directories underneath the mount point when using the virtio transport. When using the fd transport, there's no apparent issue until the filesytem is unmounted and the warning above is emitted to the logs. In some cases, the user may not yet be attached to the filesystem and a new root fid, associated with the user, is created and attached to the root dentry before the full path walk is performed. Increment the new root fid's refcount to two in that situation so that it can be safely decremented to one after it is used for the walk operation. The new fid will still be attached to the root dentry when v9fs_fid_lookup_with_uid() returns so a final refcount of one is correct/expected. Fixes: 6636b6dcc3db ("9p: add refcount to p9_fid struct") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks --- fs/9p/fid.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/fs/9p/fid.c b/fs/9p/fid.c index 79df61fe0e59..5a469b79c1ee 100644 --- a/fs/9p/fid.c +++ b/fs/9p/fid.c @@ -152,7 +152,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry, const unsigned char **wnames, *uname; int i, n, l, clone, access; struct v9fs_session_info *v9ses; - struct p9_fid *fid, *old_fid = NULL; + struct p9_fid *fid, *old_fid; v9ses = v9fs_dentry2v9ses(dentry); access = v9ses->flags & V9FS_ACCESS_MASK; @@ -194,13 +194,12 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry, if (IS_ERR(fid)) return fid; + refcount_inc(&fid->count); v9fs_fid_add(dentry->d_sb->s_root, fid); } /* If we are root ourself just return that */ - if (dentry->d_sb->s_root == dentry) { - refcount_inc(&fid->count); + if (dentry->d_sb->s_root == dentry) return fid; - } /* * Do a multipath walk with attached root. * When walking parent we need to make sure we @@ -212,6 +211,7 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry, fid = ERR_PTR(n); goto err_out; } + old_fid = fid; clone = 1; i = 0; while (i < n) { @@ -221,15 +221,8 @@ static struct p9_fid *v9fs_fid_lookup_with_uid(struct dentry *dentry, * walk to ensure none of the patch component change */ fid = p9_client_walk(fid, l, &wnames[i], clone); + p9_client_clunk(old_fid); if (IS_ERR(fid)) { - if (old_fid) { - /* - * If we fail, clunk fid which are mapping - * to path component and not the last component - * of the path. - */ - p9_client_clunk(old_fid); - } kfree(wnames); goto err_out; } -- 2.25.1