Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3500800pxb; Mon, 18 Oct 2021 17:02:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNA9p4nlncCUUx/YbDFwE8FzOCLJf9eHQ3xZDPnA9kPij2oP/1Becgf3w+SCNaiNm1oYJa X-Received: by 2002:aa7:cac2:: with SMTP id l2mr48560922edt.168.1634601724521; Mon, 18 Oct 2021 17:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634601724; cv=none; d=google.com; s=arc-20160816; b=rw/eniNY1Rus1ZGAgvO8vD7H9zVmnIO9O5tF6Fih/9dr8jm/tmN9ztyt7yTFwqHSf8 Y6Nb6tWdJAW1D3RtIBgwff923UifgYQeazDig3l3Hbp5SQk8CLyNrLKR4O1ftxmvpiv3 wmv2dU7AjcOZ3U0Mq1MbT30lWSF8CQDGeA05OO9QqZDZVVhZHjD1dDQRilxgOblqUuKN tCjDRqcTXA+UTDP0JikJF+6eAzETohcv98bvL8+7BCAKw7d4J1TC0YIc6xJJHVLYJrDw H3RKhc+jpzsRVaeq6rum840/x/TahfD0I0AaSKxIdkFxXDlRXL45ZNEmZTU2VZAPoXX8 mFxg== 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; bh=jQip/ciDj9LiDsKIIEke39SlCkp4EOSDBbE2zk3UC1k=; b=GW8y3NQAVw2xz0nqv3G7Sd386URGNQKZRRJMu9Lbm8XYgHfuXv5+gT0+gjWCG5kDE3 yOe4srJOpJzitDtr/yPZ5u2BtgEoKeW4e/mutHIJ+ruSy8vR4TKse9gjReM2SUVFvPj8 Mf3IPyKPh842SxKmino/y+/1w5wROjDaNJ+nTzJNQQmbBM8ZbgMLKvxR6dpRQ/5I/P5v oIIUbQnJOT1aWK7RburJ2JXGoAH9EDXeQBt+JomlLYWgRYZh52qQXPH11FlkKFxAkN3j IFHn/rE2F+Cov51Q9wtMPRf2j5rNdU//kMnIzeqWhRzg8DM2/yggClbMWNFyPbSXPD6z HXxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n26si22938089ejz.9.2021.10.18.17.01.40; Mon, 18 Oct 2021 17:02:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233746AbhJSADU (ORCPT + 99 others); Mon, 18 Oct 2021 20:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbhJSADU (ORCPT ); Mon, 18 Oct 2021 20:03:20 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6411FC06161C; Mon, 18 Oct 2021 17:01:08 -0700 (PDT) Received: from localhost (unknown [IPv6:2804:14c:124:8a08::1007]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id B888F1F41A9C; Tue, 19 Oct 2021 01:01:06 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, david@fromorbit.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v8 06/32] fanotify: Split fsid check from other fid mode checks Date: Mon, 18 Oct 2021 20:59:49 -0300 Message-Id: <20211019000015.1666608-7-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211019000015.1666608-1-krisman@collabora.com> References: <20211019000015.1666608-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org FAN_FS_ERROR will require fsid, but not necessarily require the filesystem to expose a file handle. Split those checks into different functions, so they can be used separately when setting up an event. While there, update a comment about tmpfs having 0 fsid, which is no longer true. Reviewed-by: Amir Goldstein Reviewed-by: Jan Kara Signed-off-by: Gabriel Krisman Bertazi --- Changes since v2: - FAN_ERROR -> FAN_FS_ERROR (Amir) - Update comment (Amir) Changes since v1: (Amir) - Sort hunks to simplify diff. Changes since RFC: (Amir) - Rename fanotify_check_path_fsid -> fanotify_test_fsid. - Use dentry directly instead of path. --- fs/notify/fanotify/fanotify_user.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 6895ec310b5d..adeae6d65e35 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1300,16 +1300,15 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) return fd; } -/* Check if filesystem can encode a unique fid */ -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) +static int fanotify_test_fsid(struct dentry *dentry, __kernel_fsid_t *fsid) { __kernel_fsid_t root_fsid; int err; /* - * Make sure path is not in filesystem with zero fsid (e.g. tmpfs). + * Make sure dentry is not of a filesystem with zero fsid (e.g. fuse). */ - err = vfs_get_fsid(path->dentry, fsid); + err = vfs_get_fsid(dentry, fsid); if (err) return err; @@ -1317,10 +1316,10 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) return -ENODEV; /* - * Make sure path is not inside a filesystem subvolume (e.g. btrfs) + * Make sure dentry is not of a filesystem subvolume (e.g. btrfs) * which uses a different fsid than sb root. */ - err = vfs_get_fsid(path->dentry->d_sb->s_root, &root_fsid); + err = vfs_get_fsid(dentry->d_sb->s_root, &root_fsid); if (err) return err; @@ -1328,6 +1327,12 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) root_fsid.val[1] != fsid->val[1]) return -EXDEV; + return 0; +} + +/* Check if filesystem can encode a unique fid */ +static int fanotify_test_fid(struct dentry *dentry) +{ /* * We need to make sure that the file system supports at least * encoding a file handle so user can use name_to_handle_at() to @@ -1335,8 +1340,8 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) * objects. However, name_to_handle_at() requires that the * filesystem also supports decoding file handles. */ - if (!path->dentry->d_sb->s_export_op || - !path->dentry->d_sb->s_export_op->fh_to_dentry) + if (!dentry->d_sb->s_export_op || + !dentry->d_sb->s_export_op->fh_to_dentry) return -EOPNOTSUPP; return 0; @@ -1487,7 +1492,11 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, } if (fid_mode) { - ret = fanotify_test_fid(&path, &__fsid); + ret = fanotify_test_fsid(path.dentry, &__fsid); + if (ret) + goto path_put_and_out; + + ret = fanotify_test_fid(path.dentry); if (ret) goto path_put_and_out; -- 2.33.0