mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 01:04:19 +08:00
982197277c
Pull nfsd update from Bruce Fields: "Included this time: - more nfsd containerization work from Stanislav Kinsbursky: we're not quite there yet, but should be by 3.9. - NFSv4.1 progress: implementation of basic backchannel security negotiation and the mandatory BACKCHANNEL_CTL operation. See http://wiki.linux-nfs.org/wiki/index.php/Server_4.0_and_4.1_issues for remaining TODO's - Fixes for some bugs that could be triggered by unusual compounds. Our xdr code wasn't designed with v4 compounds in mind, and it shows. A more thorough rewrite is still a todo. - If you've ever seen "RPC: multiple fragments per record not supported" logged while using some sort of odd userland NFS client, that should now be fixed. - Further work from Jeff Layton on our mechanism for storing information about NFSv4 clients across reboots. - Further work from Bryan Schumaker on his fault-injection mechanism (which allows us to discard selective NFSv4 state, to excercise rarely-taken recovery code paths in the client.) - The usual mix of miscellaneous bugs and cleanup. Thanks to everyone who tested or contributed this cycle." * 'for-3.8' of git://linux-nfs.org/~bfields/linux: (111 commits) nfsd4: don't leave freed stateid hashed nfsd4: free_stateid can use the current stateid nfsd4: cleanup: replace rq_resused count by rq_next_page pointer nfsd: warn on odd reply state in nfsd_vfs_read nfsd4: fix oops on unusual readlike compound nfsd4: disable zero-copy on non-final read ops svcrpc: fix some printks NFSD: Correct the size calculation in fault_inject_write NFSD: Pass correct buffer size to rpc_ntop nfsd: pass proper net to nfsd_destroy() from NFSd kthreads nfsd: simplify service shutdown nfsd: replace boolean nfsd_up flag by users counter nfsd: simplify NFSv4 state init and shutdown nfsd: introduce helpers for generic resources init and shutdown nfsd: make NFSd service structure allocated per net nfsd: make NFSd service boot time per-net nfsd: per-net NFSd up flag introduced nfsd: move per-net startup code to separated function nfsd: pass net to __write_ports() and down nfsd: pass net to nfsd_set_nrthreads() ...
266 lines
6.5 KiB
C
266 lines
6.5 KiB
C
#include <linux/syscalls.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/file.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/exportfs.h>
|
|
#include <linux/fs_struct.h>
|
|
#include <linux/fsnotify.h>
|
|
#include <linux/personality.h>
|
|
#include <asm/uaccess.h>
|
|
#include "internal.h"
|
|
#include "mount.h"
|
|
|
|
static long do_sys_name_to_handle(struct path *path,
|
|
struct file_handle __user *ufh,
|
|
int __user *mnt_id)
|
|
{
|
|
long retval;
|
|
struct file_handle f_handle;
|
|
int handle_dwords, handle_bytes;
|
|
struct file_handle *handle = NULL;
|
|
|
|
/*
|
|
* We need to make sure whether the file system
|
|
* support decoding of the file handle
|
|
*/
|
|
if (!path->dentry->d_sb->s_export_op ||
|
|
!path->dentry->d_sb->s_export_op->fh_to_dentry)
|
|
return -EOPNOTSUPP;
|
|
|
|
if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle)))
|
|
return -EFAULT;
|
|
|
|
if (f_handle.handle_bytes > MAX_HANDLE_SZ)
|
|
return -EINVAL;
|
|
|
|
handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
|
|
GFP_KERNEL);
|
|
if (!handle)
|
|
return -ENOMEM;
|
|
|
|
/* convert handle size to multiple of sizeof(u32) */
|
|
handle_dwords = f_handle.handle_bytes >> 2;
|
|
|
|
/* we ask for a non connected handle */
|
|
retval = exportfs_encode_fh(path->dentry,
|
|
(struct fid *)handle->f_handle,
|
|
&handle_dwords, 0);
|
|
handle->handle_type = retval;
|
|
/* convert handle size to bytes */
|
|
handle_bytes = handle_dwords * sizeof(u32);
|
|
handle->handle_bytes = handle_bytes;
|
|
if ((handle->handle_bytes > f_handle.handle_bytes) ||
|
|
(retval == FILEID_INVALID) || (retval == -ENOSPC)) {
|
|
/* As per old exportfs_encode_fh documentation
|
|
* we could return ENOSPC to indicate overflow
|
|
* But file system returned 255 always. So handle
|
|
* both the values
|
|
*/
|
|
/*
|
|
* set the handle size to zero so we copy only
|
|
* non variable part of the file_handle
|
|
*/
|
|
handle_bytes = 0;
|
|
retval = -EOVERFLOW;
|
|
} else
|
|
retval = 0;
|
|
/* copy the mount id */
|
|
if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
|
|
sizeof(*mnt_id)) ||
|
|
copy_to_user(ufh, handle,
|
|
sizeof(struct file_handle) + handle_bytes))
|
|
retval = -EFAULT;
|
|
kfree(handle);
|
|
return retval;
|
|
}
|
|
|
|
/**
|
|
* sys_name_to_handle_at: convert name to handle
|
|
* @dfd: directory relative to which name is interpreted if not absolute
|
|
* @name: name that should be converted to handle.
|
|
* @handle: resulting file handle
|
|
* @mnt_id: mount id of the file system containing the file
|
|
* @flag: flag value to indicate whether to follow symlink or not
|
|
*
|
|
* @handle->handle_size indicate the space available to store the
|
|
* variable part of the file handle in bytes. If there is not
|
|
* enough space, the field is updated to return the minimum
|
|
* value required.
|
|
*/
|
|
SYSCALL_DEFINE5(name_to_handle_at, int, dfd, const char __user *, name,
|
|
struct file_handle __user *, handle, int __user *, mnt_id,
|
|
int, flag)
|
|
{
|
|
struct path path;
|
|
int lookup_flags;
|
|
int err;
|
|
|
|
if ((flag & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
|
|
return -EINVAL;
|
|
|
|
lookup_flags = (flag & AT_SYMLINK_FOLLOW) ? LOOKUP_FOLLOW : 0;
|
|
if (flag & AT_EMPTY_PATH)
|
|
lookup_flags |= LOOKUP_EMPTY;
|
|
err = user_path_at(dfd, name, lookup_flags, &path);
|
|
if (!err) {
|
|
err = do_sys_name_to_handle(&path, handle, mnt_id);
|
|
path_put(&path);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static struct vfsmount *get_vfsmount_from_fd(int fd)
|
|
{
|
|
struct vfsmount *mnt;
|
|
|
|
if (fd == AT_FDCWD) {
|
|
struct fs_struct *fs = current->fs;
|
|
spin_lock(&fs->lock);
|
|
mnt = mntget(fs->pwd.mnt);
|
|
spin_unlock(&fs->lock);
|
|
} else {
|
|
struct fd f = fdget(fd);
|
|
if (!f.file)
|
|
return ERR_PTR(-EBADF);
|
|
mnt = mntget(f.file->f_path.mnt);
|
|
fdput(f);
|
|
}
|
|
return mnt;
|
|
}
|
|
|
|
static int vfs_dentry_acceptable(void *context, struct dentry *dentry)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
static int do_handle_to_path(int mountdirfd, struct file_handle *handle,
|
|
struct path *path)
|
|
{
|
|
int retval = 0;
|
|
int handle_dwords;
|
|
|
|
path->mnt = get_vfsmount_from_fd(mountdirfd);
|
|
if (IS_ERR(path->mnt)) {
|
|
retval = PTR_ERR(path->mnt);
|
|
goto out_err;
|
|
}
|
|
/* change the handle size to multiple of sizeof(u32) */
|
|
handle_dwords = handle->handle_bytes >> 2;
|
|
path->dentry = exportfs_decode_fh(path->mnt,
|
|
(struct fid *)handle->f_handle,
|
|
handle_dwords, handle->handle_type,
|
|
vfs_dentry_acceptable, NULL);
|
|
if (IS_ERR(path->dentry)) {
|
|
retval = PTR_ERR(path->dentry);
|
|
goto out_mnt;
|
|
}
|
|
return 0;
|
|
out_mnt:
|
|
mntput(path->mnt);
|
|
out_err:
|
|
return retval;
|
|
}
|
|
|
|
static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
|
|
struct path *path)
|
|
{
|
|
int retval = 0;
|
|
struct file_handle f_handle;
|
|
struct file_handle *handle = NULL;
|
|
|
|
/*
|
|
* With handle we don't look at the execute bit on the
|
|
* the directory. Ideally we would like CAP_DAC_SEARCH.
|
|
* But we don't have that
|
|
*/
|
|
if (!capable(CAP_DAC_READ_SEARCH)) {
|
|
retval = -EPERM;
|
|
goto out_err;
|
|
}
|
|
if (copy_from_user(&f_handle, ufh, sizeof(struct file_handle))) {
|
|
retval = -EFAULT;
|
|
goto out_err;
|
|
}
|
|
if ((f_handle.handle_bytes > MAX_HANDLE_SZ) ||
|
|
(f_handle.handle_bytes == 0)) {
|
|
retval = -EINVAL;
|
|
goto out_err;
|
|
}
|
|
handle = kmalloc(sizeof(struct file_handle) + f_handle.handle_bytes,
|
|
GFP_KERNEL);
|
|
if (!handle) {
|
|
retval = -ENOMEM;
|
|
goto out_err;
|
|
}
|
|
/* copy the full handle */
|
|
if (copy_from_user(handle, ufh,
|
|
sizeof(struct file_handle) +
|
|
f_handle.handle_bytes)) {
|
|
retval = -EFAULT;
|
|
goto out_handle;
|
|
}
|
|
|
|
retval = do_handle_to_path(mountdirfd, handle, path);
|
|
|
|
out_handle:
|
|
kfree(handle);
|
|
out_err:
|
|
return retval;
|
|
}
|
|
|
|
long do_handle_open(int mountdirfd,
|
|
struct file_handle __user *ufh, int open_flag)
|
|
{
|
|
long retval = 0;
|
|
struct path path;
|
|
struct file *file;
|
|
int fd;
|
|
|
|
retval = handle_to_path(mountdirfd, ufh, &path);
|
|
if (retval)
|
|
return retval;
|
|
|
|
fd = get_unused_fd_flags(open_flag);
|
|
if (fd < 0) {
|
|
path_put(&path);
|
|
return fd;
|
|
}
|
|
file = file_open_root(path.dentry, path.mnt, "", open_flag);
|
|
if (IS_ERR(file)) {
|
|
put_unused_fd(fd);
|
|
retval = PTR_ERR(file);
|
|
} else {
|
|
retval = fd;
|
|
fsnotify_open(file);
|
|
fd_install(fd, file);
|
|
}
|
|
path_put(&path);
|
|
return retval;
|
|
}
|
|
|
|
/**
|
|
* sys_open_by_handle_at: Open the file handle
|
|
* @mountdirfd: directory file descriptor
|
|
* @handle: file handle to be opened
|
|
* @flag: open flags.
|
|
*
|
|
* @mountdirfd indicate the directory file descriptor
|
|
* of the mount point. file handle is decoded relative
|
|
* to the vfsmount pointed by the @mountdirfd. @flags
|
|
* value is same as the open(2) flags.
|
|
*/
|
|
SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
|
|
struct file_handle __user *, handle,
|
|
int, flags)
|
|
{
|
|
long ret;
|
|
|
|
if (force_o_largefile())
|
|
flags |= O_LARGEFILE;
|
|
|
|
ret = do_handle_open(mountdirfd, handle, flags);
|
|
return ret;
|
|
}
|