Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/fs_struct.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/fsnotify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static long do_sys_name_to_handle(struct path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 				  struct file_handle __user *ufh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 				  int __user *mnt_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	long retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct file_handle f_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int handle_dwords, handle_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct file_handle *handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	 * We need to make sure whether the file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	 * support decoding of the file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (!path->dentry->d_sb->s_export_op ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	    !path->dentry->d_sb->s_export_op->fh_to_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (f_handle.handle_bytes > MAX_HANDLE_SZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (!handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	/* convert handle size to multiple of sizeof(u32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	handle_dwords = f_handle.handle_bytes >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/* we ask for a non connected handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	retval = exportfs_encode_fh(path->dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				    (struct fid *)handle->f_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 				    &handle_dwords,  0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	handle->handle_type = retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/* convert handle size to bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	handle_bytes = handle_dwords * sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	handle->handle_bytes = handle_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if ((handle->handle_bytes > f_handle.handle_bytes) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	    (retval == FILEID_INVALID) || (retval == -ENOSPC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		/* As per old exportfs_encode_fh documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		 * we could return ENOSPC to indicate overflow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		 * But file system returned 255 always. So handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 * both the values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		 * set the handle size to zero so we copy only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 * non variable part of the file_handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		handle_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		retval = -EOVERFLOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* copy the mount id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	    copy_to_user(ufh, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			 sizeof(struct file_handle) + handle_bytes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	kfree(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * sys_name_to_handle_at: convert name to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * @dfd: directory relative to which name is interpreted if not absolute
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * @name: name that should be converted to handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * @handle: resulting file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * @mnt_id: mount id of the file system containing the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @flag: flag value to indicate whether to follow symlink or not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @handle->handle_size indicate the space available to store the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  * variable part of the file handle in bytes. If there is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)  * enough space, the field is updated to return the minimum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)  * value required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		struct file_handle __user *, handle, int __user *, mnt_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		int, flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	int lookup_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if ((flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	lookup_flags = (flag & AT_SYMLINK_FOLLOW) ? LOOKUP_FOLLOW : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (flag & AT_EMPTY_PATH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		lookup_flags |= LOOKUP_EMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	err = user_path_at(dfd, name, lookup_flags, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		err = do_sys_name_to_handle(&path, handle, mnt_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static struct vfsmount *get_vfsmount_from_fd(int fd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct vfsmount *mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (fd == AT_FDCWD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		struct fs_struct *fs = current->fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		spin_lock(&fs->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		mnt = mntget(fs->pwd.mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		spin_unlock(&fs->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		struct fd f = fdget(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		if (!f.file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			return ERR_PTR(-EBADF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		mnt = mntget(f.file->f_path.mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		fdput(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int do_handle_to_path(int mountdirfd, struct file_handle *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			     struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	int handle_dwords;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	path->mnt = get_vfsmount_from_fd(mountdirfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (IS_ERR(path->mnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		retval = PTR_ERR(path->mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* change the handle size to multiple of sizeof(u32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	handle_dwords = handle->handle_bytes >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	path->dentry = exportfs_decode_fh(path->mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 					  (struct fid *)handle->f_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					  handle_dwords, handle->handle_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 					  vfs_dentry_acceptable, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (IS_ERR(path->dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		retval = PTR_ERR(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		goto out_mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) out_mnt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	mntput(path->mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		   struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct file_handle f_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct file_handle *handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	 * With handle we don't look at the execute bit on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * the directory. Ideally we would like CAP_DAC_SEARCH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 * But we don't have that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!capable(CAP_DAC_READ_SEARCH)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		retval = -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if ((f_handle.handle_bytes > MAX_HANDLE_SZ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	    (f_handle.handle_bytes == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (!handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	/* copy the full handle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	*handle = f_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (copy_from_user(&handle->f_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			   &ufh->f_handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			   f_handle.handle_bytes)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		goto out_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	retval = do_handle_to_path(mountdirfd, handle, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) out_handle:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	kfree(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static long do_handle_open(int mountdirfd, struct file_handle __user *ufh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			   int open_flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	long retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct path path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct file *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	retval = handle_to_path(mountdirfd, ufh, &path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	fd = get_unused_fd_flags(open_flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		return fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	file = file_open_root(path.dentry, path.mnt, "", open_flag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (IS_ERR(file)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		put_unused_fd(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		retval =  PTR_ERR(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		retval = fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		fsnotify_open(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		fd_install(fd, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	path_put(&path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * sys_open_by_handle_at: Open the file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * @mountdirfd: directory file descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * @handle: file handle to be opened
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * @flags: open flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * @mountdirfd indicate the directory file descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * of the mount point. file handle is decoded relative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * to the vfsmount pointed by the @mountdirfd. @flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * value is same as the open(2) flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		struct file_handle __user *, handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	long ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (force_o_largefile())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		flags |= O_LARGEFILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	ret = do_handle_open(mountdirfd, handle, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  * Exactly like fs/open.c:sys_open_by_handle_at(), except that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)  * doesn't set the O_LARGEFILE flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			     struct file_handle __user *, handle, int, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return do_handle_open(mountdirfd, handle, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #endif