Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5060818pxb; Thu, 14 Oct 2021 18:18:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwx5+ku+MseJP5W3FGWeRt3N9RgZoeGnckbkmZYRPZ/1apE74yVoF+AMy/5XyU6Y9DUaDk1 X-Received: by 2002:a17:902:b694:b0:138:a031:610d with SMTP id c20-20020a170902b69400b00138a031610dmr8382932pls.36.1634260724499; Thu, 14 Oct 2021 18:18:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634260724; cv=none; d=google.com; s=arc-20160816; b=wYX6npLK47KMzqPylCDW80pJUtywIqHOVyKdgHhaxHO4Y9M5auLfKHoaCh08JVnx4z 4wZmru2YNkS/QeffhxfAUr6+jeCS3pShkoPa+r2j7sQUmKyZ/e20tLtujg8rTFBVrH1c PUEX0FFY3uSu9+1DnhQubtxVKPMG7rpAh6cLdzjQDkURR8rnkR3YwogibxD+XL/hXh0P J96lVsGTlvhcB5KLWSrDVsLaBSNJi87+9LfoctS6yiSWEwP822LPcokH/v+8AU1pIdPE AymhFVwcWe/a9HC+8G77slLeF/dXSYCVXIlagJtDu0bV3UtjKYBZLBUKLhn24uKPAkaM fGZA== 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=oFTws/FsGy05i0y2DeR4EhHMJaym97fyopj1KucITrAuYIeuoF1LhA39QkwTr72kgQ 9LQsXb/qP/ehJbsz6m9Edh4nIeXPwKXi95xPDJql6tHIbI9uiwz0MUf79IfrHCat+ghg AzzVMGmerdx6mcxhXQKyiE2Ry8bbgWHHtqrfj7s5QwFzwNtrWu77DthxnOPR6dl3s2h2 VvPJxqKuX7gwae0azyVDb/q/l2jHZ/xWFCtcknVBYmnfDDpIAHhWW6iF7A9p2Tixy38O 9dZOO31gqd3Jp7SMbZ8Zs1QxfKBQBbEece9MJ9EhCW53tbva4PIjsuyu5y9GLg8HY3xR oAoQ== 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 t4si5894424pfd.103.2021.10.14.18.18.31; Thu, 14 Oct 2021 18:18:44 -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 S233374AbhJNVjw (ORCPT + 99 others); Thu, 14 Oct 2021 17:39:52 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54038 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbhJNVjv (ORCPT ); Thu, 14 Oct 2021 17:39:51 -0400 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 3A53B1F44F78; Thu, 14 Oct 2021 22:37:44 +0100 (BST) From: Gabriel Krisman Bertazi To: jack@suse.com, amir73il@gmail.com Cc: djwong@kernel.org, tytso@mit.edu, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-api@vger.kernel.org, repnop@google.com, Gabriel Krisman Bertazi , kernel@collabora.com, Jan Kara Subject: [PATCH v7 06/28] fanotify: Split fsid check from other fid mode checks Date: Thu, 14 Oct 2021 18:36:24 -0300 Message-Id: <20211014213646.1139469-7-krisman@collabora.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014213646.1139469-1-krisman@collabora.com> References: <20211014213646.1139469-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