Skip to content

Commit 6ebb05b

Browse files
committed
fhandle: pull CAP_DAC_READ_SEARCH check into may_decode_fh()
There's no point in keeping it outside of that helper. This way we have all the permission pieces in one place. Link: https://lore.kernel.org/r/20241129-work-pidfs-file_handle-v1-4-87d803a42495@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 50166d5 commit 6ebb05b

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

fs/fhandle.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,32 @@ static int do_handle_to_path(struct file_handle *handle, struct path *path,
279279
return 0;
280280
}
281281

282-
/*
283-
* Allow relaxed permissions of file handles if the caller has the
284-
* ability to mount the filesystem or create a bind-mount of the
285-
* provided @mountdirfd.
286-
*
287-
* In both cases the caller may be able to get an unobstructed way to
288-
* the encoded file handle. If the caller is only able to create a
289-
* bind-mount we need to verify that there are no locked mounts on top
290-
* of it that could prevent us from getting to the encoded file.
291-
*
292-
* In principle, locked mounts can prevent the caller from mounting the
293-
* filesystem but that only applies to procfs and sysfs neither of which
294-
* support decoding file handles.
295-
*/
296282
static inline bool may_decode_fh(struct handle_to_path_ctx *ctx,
297283
unsigned int o_flags)
298284
{
299285
struct path *root = &ctx->root;
300286

287+
if (capable(CAP_DAC_READ_SEARCH))
288+
return true;
289+
301290
/*
302-
* Restrict to O_DIRECTORY to provide a deterministic API that avoids a
303-
* confusing api in the face of disconnected non-dir dentries.
291+
* Allow relaxed permissions of file handles if the caller has
292+
* the ability to mount the filesystem or create a bind-mount of
293+
* the provided @mountdirfd.
294+
*
295+
* In both cases the caller may be able to get an unobstructed
296+
* way to the encoded file handle. If the caller is only able to
297+
* create a bind-mount we need to verify that there are no
298+
* locked mounts on top of it that could prevent us from getting
299+
* to the encoded file.
300+
*
301+
* In principle, locked mounts can prevent the caller from
302+
* mounting the filesystem but that only applies to procfs and
303+
* sysfs neither of which support decoding file handles.
304+
*
305+
* Restrict to O_DIRECTORY to provide a deterministic API that
306+
* avoids a confusing api in the face of disconnected non-dir
307+
* dentries.
304308
*
305309
* There's only one dentry for each directory inode (VFS rule)...
306310
*/
@@ -337,7 +341,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
337341
if (retval)
338342
goto out_err;
339343

340-
if (!capable(CAP_DAC_READ_SEARCH) && !may_decode_fh(&ctx, o_flags)) {
344+
if (!may_decode_fh(&ctx, o_flags)) {
341345
retval = -EPERM;
342346
goto out_path;
343347
}

0 commit comments

Comments
 (0)