Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp928052pxj; Fri, 21 May 2021 02:24:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOzKInBJBzMhmzcqQF5FeXSbSW0zs1wzWI7eqa+uxqQSK3CL+y6nSXYPcU5XSlKMIgNefp X-Received: by 2002:a17:907:1b20:: with SMTP id mp32mr9493455ejc.495.1621589045759; Fri, 21 May 2021 02:24:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621589045; cv=none; d=google.com; s=arc-20160816; b=NAaWm9QX8/bMmzRcwoI5BtUNfAksR3rqsuVMAf2zFqPh0Kww2a9Wu4/j8GRhuvdr/y I/Z47DNg72t+5cfaL2hF/PuBhdlAmPHgsDihA7tcAIUQEUStETo29UTH4Dk90nETGi3J WAHNZM3ZTpTj5WmhmkbZlsqkzODt21D1wal/NQYAgEeZx5Y7IH86v76XyL/S7JStA9Yw OUI/q+X2bnRcT8IVXS8z0C4EAwhSHbGvU5uZmjIDuTZiICgA+wDZn4etNcGILwYW0N7b b4qgWr1yf+ejAXf38n8+1peuu+ilbBfKwxXeOiXXpMiz1KI9+qscySRdglzJ42uVUA1x wIHA== 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=SZeID75/6l9MXCNnAo/WHr2SuUFYEzZlr/Nog7IcLcI=; b=dfFa+i6tA7cUOJFP7VWWzrI+PiwMPBqoqQsyccq/zlLycgrIS0SudyKmj85XieUsAG dynyGF9CjYY5KfYT3AUSMZDZsLFbGg4bH8BgSVKeJ8vJ3z2pDmLBcsr3xb1+E4W6ygAv D+mHuZx2nf4GGifKRoPomU2tcyRdZQQV/j/qNm3edPOaVPYUiQaKD92VitsDdnaUVLSZ KORTKqQtKnvrhVu7kFlb3/AI+jdlsa3qCWqCyU4ziqigBk7xqqBeKPhDt5/Z4q2UcWEl U6oVBRKENHlDYE5aqG4C4AAxJdFRSi0EGZTHUDHB3JZ9dahiA9g+fmVhI85w6TFVH9g1 +bWg== 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 c16si4618957edv.362.2021.05.21.02.23.42; Fri, 21 May 2021 02:24:05 -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 S236665AbhEUCn2 (ORCPT + 99 others); Thu, 20 May 2021 22:43:28 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:54852 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbhEUCn2 (ORCPT ); Thu, 20 May 2021 22:43:28 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 511461F43D41 From: Gabriel Krisman Bertazi To: amir73il@gmail.com Cc: Gabriel Krisman Bertazi , kernel@collabora.com, "Darrick J . Wong" , Theodore Ts'o , Dave Chinner , jack@suse.com, dhowells@redhat.com, khazhy@google.com, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org Subject: [PATCH 02/11] fanotify: Split fsid check from other fid mode checks Date: Thu, 20 May 2021 22:41:25 -0400 Message-Id: <20210521024134.1032503-3-krisman@collabora.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210521024134.1032503-1-krisman@collabora.com> References: <20210521024134.1032503-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_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. Signed-off-by: Gabriel Krisman Bertazi Changes since v1: (Amir) - Rename fanotify_check_path_fsid -> fanotify_test_fsid - Use dentry directly instead of path --- fs/notify/fanotify/fanotify_user.c | 43 ++++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 3ccdee3c9f1e..9cc6c8808ed5 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -1178,15 +1178,31 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) } /* Check if filesystem can encode a unique fid */ -static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) +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 + * compare fid returned with event to the file handle of watched + * objects. However, name_to_handle_at() requires that the + * filesystem also supports decoding file handles. + */ + if (!dentry->d_sb->s_export_op || + !dentry->d_sb->s_export_op->fh_to_dentry) + return -EOPNOTSUPP; + + return 0; +} + +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. tmpfs). */ - err = vfs_get_fsid(path->dentry, fsid); + err = vfs_get_fsid(dentry, fsid); if (err) return err; @@ -1194,10 +1210,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; @@ -1205,17 +1221,6 @@ static int fanotify_test_fid(struct path *path, __kernel_fsid_t *fsid) root_fsid.val[1] != fsid->val[1]) return -EXDEV; - /* - * 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 - * compare fid returned with event to the file handle of watched - * 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) - return -EOPNOTSUPP; - return 0; } @@ -1362,7 +1367,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.31.0