Commit 8adcc599 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull misc vfs updates from Al Viro:
 "No common topic, really - a handful of assorted stuff; the least
  trivial bits are Mark's dedupe patches"

* 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  fs/exofs: only use true/false for asignment of bool type variable
  fs/exofs: fix potential memory leak in mount option parsing
  Delete invalid assignment statements in do_sendfile
  iomap: remove duplicated include from iomap.c
  vfs: dedupe should return EPERM if permission is not granted
  vfs: allow dedupe of user owned read-only files
  ntfs: don't open-code ERR_CAST
  ext4: don't open-code ERR_CAST
parents 9931a07d 3642b29a
...@@ -101,6 +101,7 @@ static int parse_options(char *options, struct exofs_mountopt *opts) ...@@ -101,6 +101,7 @@ static int parse_options(char *options, struct exofs_mountopt *opts)
token = match_token(p, tokens, args); token = match_token(p, tokens, args);
switch (token) { switch (token) {
case Opt_name: case Opt_name:
kfree(opts->dev_name);
opts->dev_name = match_strdup(&args[0]); opts->dev_name = match_strdup(&args[0]);
if (unlikely(!opts->dev_name)) { if (unlikely(!opts->dev_name)) {
EXOFS_ERR("Error allocating dev_name"); EXOFS_ERR("Error allocating dev_name");
...@@ -117,7 +118,7 @@ static int parse_options(char *options, struct exofs_mountopt *opts) ...@@ -117,7 +118,7 @@ static int parse_options(char *options, struct exofs_mountopt *opts)
EXOFS_MIN_PID); EXOFS_MIN_PID);
return -EINVAL; return -EINVAL;
} }
s_pid = 1; s_pid = true;
break; break;
case Opt_to: case Opt_to:
if (match_int(&args[0], &option)) if (match_int(&args[0], &option))
...@@ -866,8 +867,10 @@ static struct dentry *exofs_mount(struct file_system_type *type, ...@@ -866,8 +867,10 @@ static struct dentry *exofs_mount(struct file_system_type *type,
int ret; int ret;
ret = parse_options(data, &opts); ret = parse_options(data, &opts);
if (ret) if (ret) {
kfree(opts.dev_name);
return ERR_PTR(ret); return ERR_PTR(ret);
}
if (!opts.dev_name) if (!opts.dev_name)
opts.dev_name = dev_name; opts.dev_name = dev_name;
......
...@@ -1216,7 +1216,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino) ...@@ -1216,7 +1216,7 @@ struct inode *ext4_orphan_get(struct super_block *sb, unsigned long ino)
bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb); bit = (ino - 1) % EXT4_INODES_PER_GROUP(sb);
bitmap_bh = ext4_read_inode_bitmap(sb, block_group); bitmap_bh = ext4_read_inode_bitmap(sb, block_group);
if (IS_ERR(bitmap_bh)) if (IS_ERR(bitmap_bh))
return (struct inode *) bitmap_bh; return ERR_CAST(bitmap_bh);
/* Having the inode bit set should be a 100% indicator that this /* Having the inode bit set should be a 100% indicator that this
* is a valid orphan (no e2fsck run on fs). Orphans also include * is a valid orphan (no e2fsck run on fs). Orphans also include
......
...@@ -1556,7 +1556,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi ...@@ -1556,7 +1556,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL); bh = ext4_find_entry(dir, &dentry->d_name, &de, NULL);
if (IS_ERR(bh)) if (IS_ERR(bh))
return (struct dentry *) bh; return ERR_CAST(bh);
inode = NULL; inode = NULL;
if (bh) { if (bh) {
__u32 ino = le32_to_cpu(de->inode); __u32 ino = le32_to_cpu(de->inode);
...@@ -1600,7 +1600,7 @@ struct dentry *ext4_get_parent(struct dentry *child) ...@@ -1600,7 +1600,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
bh = ext4_find_entry(d_inode(child), &dotdot, &de, NULL); bh = ext4_find_entry(d_inode(child), &dotdot, &de, NULL);
if (IS_ERR(bh)) if (IS_ERR(bh))
return (struct dentry *) bh; return ERR_CAST(bh);
if (!bh) if (!bh)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
ino = le32_to_cpu(de->inode); ino = le32_to_cpu(de->inode);
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <linux/task_io_accounting_ops.h> #include <linux/task_io_accounting_ops.h>
#include <linux/dax.h> #include <linux/dax.h>
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
#include <linux/swap.h>
#include "internal.h" #include "internal.h"
......
...@@ -312,7 +312,7 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent) ...@@ -312,7 +312,7 @@ static struct dentry *ntfs_get_parent(struct dentry *child_dent)
/* Get the mft record of the inode belonging to the child dentry. */ /* Get the mft record of the inode belonging to the child dentry. */
mrec = map_mft_record(ni); mrec = map_mft_record(ni);
if (IS_ERR(mrec)) if (IS_ERR(mrec))
return (struct dentry *)mrec; return ERR_CAST(mrec);
/* Find the first file name attribute in the mft record. */ /* Find the first file name attribute in the mft record. */
ctx = ntfs_attr_get_search_ctx(ni, mrec); ctx = ntfs_attr_get_search_ctx(ni, mrec);
if (unlikely(!ctx)) { if (unlikely(!ctx)) {
......
...@@ -1407,7 +1407,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, ...@@ -1407,7 +1407,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
goto fput_in; goto fput_in;
if (!(out.file->f_mode & FMODE_WRITE)) if (!(out.file->f_mode & FMODE_WRITE))
goto fput_out; goto fput_out;
retval = -EINVAL;
in_inode = file_inode(in.file); in_inode = file_inode(in.file);
out_inode = file_inode(out.file); out_inode = file_inode(out.file);
out_pos = out.file->f_pos; out_pos = out.file->f_pos;
...@@ -1977,6 +1976,20 @@ int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, ...@@ -1977,6 +1976,20 @@ int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
} }
EXPORT_SYMBOL(vfs_dedupe_file_range_compare); EXPORT_SYMBOL(vfs_dedupe_file_range_compare);
/* Check whether we are allowed to dedupe the destination file */
static bool allow_file_dedupe(struct file *file)
{
if (capable(CAP_SYS_ADMIN))
return true;
if (file->f_mode & FMODE_WRITE)
return true;
if (uid_eq(current_fsuid(), file_inode(file)->i_uid))
return true;
if (!inode_permission(file_inode(file), MAY_WRITE))
return true;
return false;
}
int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
struct file *dst_file, loff_t dst_pos, u64 len) struct file *dst_file, loff_t dst_pos, u64 len)
{ {
...@@ -1990,8 +2003,8 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, ...@@ -1990,8 +2003,8 @@ int vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
if (ret < 0) if (ret < 0)
goto out_drop_write; goto out_drop_write;
ret = -EINVAL; ret = -EPERM;
if (!(capable(CAP_SYS_ADMIN) || (dst_file->f_mode & FMODE_WRITE))) if (!allow_file_dedupe(dst_file))
goto out_drop_write; goto out_drop_write;
ret = -EXDEV; ret = -EXDEV;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment