Commit 70f48282 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'fuse-fixes-4.20-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse

Pull fuse fixes from Miklos Szeredi:
 "There's one patch fixing a minor but long lived bug, the others are
  fixing regressions introduced in this cycle"

* tag 'fuse-fixes-4.20-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse:
  fuse: continue to send FUSE_RELEASEDIR when FUSE_OPEN returns ENOSYS
  fuse: Fix memory leak in fuse_dev_free()
  fuse: fix revalidation of attributes for permission check
  fuse: fix fsync on directory
  fuse: Add bad inode check in fuse_destroy_inode()
parents b5884002 2e64ff15
...@@ -1119,8 +1119,10 @@ static int fuse_permission(struct inode *inode, int mask) ...@@ -1119,8 +1119,10 @@ static int fuse_permission(struct inode *inode, int mask)
if (fc->default_permissions || if (fc->default_permissions ||
((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) { ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
u32 perm_mask = STATX_MODE | STATX_UID | STATX_GID;
if (time_before64(fi->i_time, get_jiffies_64())) { if (perm_mask & READ_ONCE(fi->inval_mask) ||
time_before64(fi->i_time, get_jiffies_64())) {
refreshed = true; refreshed = true;
err = fuse_perm_getattr(inode, mask); err = fuse_perm_getattr(inode, mask);
...@@ -1241,7 +1243,7 @@ static int fuse_dir_open(struct inode *inode, struct file *file) ...@@ -1241,7 +1243,7 @@ static int fuse_dir_open(struct inode *inode, struct file *file)
static int fuse_dir_release(struct inode *inode, struct file *file) static int fuse_dir_release(struct inode *inode, struct file *file)
{ {
fuse_release_common(file, FUSE_RELEASEDIR); fuse_release_common(file, true);
return 0; return 0;
} }
...@@ -1249,7 +1251,25 @@ static int fuse_dir_release(struct inode *inode, struct file *file) ...@@ -1249,7 +1251,25 @@ static int fuse_dir_release(struct inode *inode, struct file *file)
static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end, static int fuse_dir_fsync(struct file *file, loff_t start, loff_t end,
int datasync) int datasync)
{ {
return fuse_fsync_common(file, start, end, datasync, 1); struct inode *inode = file->f_mapping->host;
struct fuse_conn *fc = get_fuse_conn(inode);
int err;
if (is_bad_inode(inode))
return -EIO;
if (fc->no_fsyncdir)
return 0;
inode_lock(inode);
err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNCDIR);
if (err == -ENOSYS) {
fc->no_fsyncdir = 1;
err = 0;
}
inode_unlock(inode);
return err;
} }
static long fuse_dir_ioctl(struct file *file, unsigned int cmd, static long fuse_dir_ioctl(struct file *file, unsigned int cmd,
......
...@@ -89,12 +89,12 @@ static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -89,12 +89,12 @@ static void fuse_release_end(struct fuse_conn *fc, struct fuse_req *req)
iput(req->misc.release.inode); iput(req->misc.release.inode);
} }
static void fuse_file_put(struct fuse_file *ff, bool sync) static void fuse_file_put(struct fuse_file *ff, bool sync, bool isdir)
{ {
if (refcount_dec_and_test(&ff->count)) { if (refcount_dec_and_test(&ff->count)) {
struct fuse_req *req = ff->reserved_req; struct fuse_req *req = ff->reserved_req;
if (ff->fc->no_open) { if (ff->fc->no_open && !isdir) {
/* /*
* Drop the release request when client does not * Drop the release request when client does not
* implement 'open' * implement 'open'
...@@ -247,10 +247,11 @@ static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode) ...@@ -247,10 +247,11 @@ static void fuse_prepare_release(struct fuse_file *ff, int flags, int opcode)
req->in.args[0].value = inarg; req->in.args[0].value = inarg;
} }
void fuse_release_common(struct file *file, int opcode) void fuse_release_common(struct file *file, bool isdir)
{ {
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
struct fuse_req *req = ff->reserved_req; struct fuse_req *req = ff->reserved_req;
int opcode = isdir ? FUSE_RELEASEDIR : FUSE_RELEASE;
fuse_prepare_release(ff, file->f_flags, opcode); fuse_prepare_release(ff, file->f_flags, opcode);
...@@ -272,7 +273,7 @@ void fuse_release_common(struct file *file, int opcode) ...@@ -272,7 +273,7 @@ void fuse_release_common(struct file *file, int opcode)
* synchronous RELEASE is allowed (and desirable) in this case * synchronous RELEASE is allowed (and desirable) in this case
* because the server can be trusted not to screw up. * because the server can be trusted not to screw up.
*/ */
fuse_file_put(ff, ff->fc->destroy_req != NULL); fuse_file_put(ff, ff->fc->destroy_req != NULL, isdir);
} }
static int fuse_open(struct inode *inode, struct file *file) static int fuse_open(struct inode *inode, struct file *file)
...@@ -288,7 +289,7 @@ static int fuse_release(struct inode *inode, struct file *file) ...@@ -288,7 +289,7 @@ static int fuse_release(struct inode *inode, struct file *file)
if (fc->writeback_cache) if (fc->writeback_cache)
write_inode_now(inode, 1); write_inode_now(inode, 1);
fuse_release_common(file, FUSE_RELEASE); fuse_release_common(file, false);
/* return value is ignored by VFS */ /* return value is ignored by VFS */
return 0; return 0;
...@@ -302,7 +303,7 @@ void fuse_sync_release(struct fuse_file *ff, int flags) ...@@ -302,7 +303,7 @@ void fuse_sync_release(struct fuse_file *ff, int flags)
* iput(NULL) is a no-op and since the refcount is 1 and everything's * iput(NULL) is a no-op and since the refcount is 1 and everything's
* synchronous, we are fine with not doing igrab() here" * synchronous, we are fine with not doing igrab() here"
*/ */
fuse_file_put(ff, true); fuse_file_put(ff, true, false);
} }
EXPORT_SYMBOL_GPL(fuse_sync_release); EXPORT_SYMBOL_GPL(fuse_sync_release);
...@@ -441,13 +442,30 @@ static int fuse_flush(struct file *file, fl_owner_t id) ...@@ -441,13 +442,30 @@ static int fuse_flush(struct file *file, fl_owner_t id)
} }
int fuse_fsync_common(struct file *file, loff_t start, loff_t end, int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
int datasync, int isdir) int datasync, int opcode)
{ {
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
FUSE_ARGS(args); FUSE_ARGS(args);
struct fuse_fsync_in inarg; struct fuse_fsync_in inarg;
memset(&inarg, 0, sizeof(inarg));
inarg.fh = ff->fh;
inarg.fsync_flags = datasync ? 1 : 0;
args.in.h.opcode = opcode;
args.in.h.nodeid = get_node_id(inode);
args.in.numargs = 1;
args.in.args[0].size = sizeof(inarg);
args.in.args[0].value = &inarg;
return fuse_simple_request(fc, &args);
}
static int fuse_fsync(struct file *file, loff_t start, loff_t end,
int datasync)
{
struct inode *inode = file->f_mapping->host;
struct fuse_conn *fc = get_fuse_conn(inode);
int err; int err;
if (is_bad_inode(inode)) if (is_bad_inode(inode))
...@@ -479,34 +497,18 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end, ...@@ -479,34 +497,18 @@ int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
if (err) if (err)
goto out; goto out;
if ((!isdir && fc->no_fsync) || (isdir && fc->no_fsyncdir)) if (fc->no_fsync)
goto out; goto out;
memset(&inarg, 0, sizeof(inarg)); err = fuse_fsync_common(file, start, end, datasync, FUSE_FSYNC);
inarg.fh = ff->fh;
inarg.fsync_flags = datasync ? 1 : 0;
args.in.h.opcode = isdir ? FUSE_FSYNCDIR : FUSE_FSYNC;
args.in.h.nodeid = get_node_id(inode);
args.in.numargs = 1;
args.in.args[0].size = sizeof(inarg);
args.in.args[0].value = &inarg;
err = fuse_simple_request(fc, &args);
if (err == -ENOSYS) { if (err == -ENOSYS) {
if (isdir)
fc->no_fsyncdir = 1;
else
fc->no_fsync = 1; fc->no_fsync = 1;
err = 0; err = 0;
} }
out: out:
inode_unlock(inode); inode_unlock(inode);
return err;
}
static int fuse_fsync(struct file *file, loff_t start, loff_t end, return err;
int datasync)
{
return fuse_fsync_common(file, start, end, datasync, 0);
} }
void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos, void fuse_read_fill(struct fuse_req *req, struct file *file, loff_t pos,
...@@ -807,7 +809,7 @@ static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -807,7 +809,7 @@ static void fuse_readpages_end(struct fuse_conn *fc, struct fuse_req *req)
put_page(page); put_page(page);
} }
if (req->ff) if (req->ff)
fuse_file_put(req->ff, false); fuse_file_put(req->ff, false, false);
} }
static void fuse_send_readpages(struct fuse_req *req, struct file *file) static void fuse_send_readpages(struct fuse_req *req, struct file *file)
...@@ -1460,7 +1462,7 @@ static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req) ...@@ -1460,7 +1462,7 @@ static void fuse_writepage_free(struct fuse_conn *fc, struct fuse_req *req)
__free_page(req->pages[i]); __free_page(req->pages[i]);
if (req->ff) if (req->ff)
fuse_file_put(req->ff, false); fuse_file_put(req->ff, false, false);
} }
static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req) static void fuse_writepage_finish(struct fuse_conn *fc, struct fuse_req *req)
...@@ -1619,7 +1621,7 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc) ...@@ -1619,7 +1621,7 @@ int fuse_write_inode(struct inode *inode, struct writeback_control *wbc)
ff = __fuse_write_file_get(fc, fi); ff = __fuse_write_file_get(fc, fi);
err = fuse_flush_times(inode, ff); err = fuse_flush_times(inode, ff);
if (ff) if (ff)
fuse_file_put(ff, 0); fuse_file_put(ff, false, false);
return err; return err;
} }
...@@ -1940,7 +1942,7 @@ static int fuse_writepages(struct address_space *mapping, ...@@ -1940,7 +1942,7 @@ static int fuse_writepages(struct address_space *mapping,
err = 0; err = 0;
} }
if (data.ff) if (data.ff)
fuse_file_put(data.ff, false); fuse_file_put(data.ff, false, false);
kfree(data.orig_pages); kfree(data.orig_pages);
out: out:
......
...@@ -822,13 +822,13 @@ void fuse_sync_release(struct fuse_file *ff, int flags); ...@@ -822,13 +822,13 @@ void fuse_sync_release(struct fuse_file *ff, int flags);
/** /**
* Send RELEASE or RELEASEDIR request * Send RELEASE or RELEASEDIR request
*/ */
void fuse_release_common(struct file *file, int opcode); void fuse_release_common(struct file *file, bool isdir);
/** /**
* Send FSYNC or FSYNCDIR request * Send FSYNC or FSYNCDIR request
*/ */
int fuse_fsync_common(struct file *file, loff_t start, loff_t end, int fuse_fsync_common(struct file *file, loff_t start, loff_t end,
int datasync, int isdir); int datasync, int opcode);
/** /**
* Notify poll wakeup * Notify poll wakeup
......
...@@ -115,7 +115,7 @@ static void fuse_i_callback(struct rcu_head *head) ...@@ -115,7 +115,7 @@ static void fuse_i_callback(struct rcu_head *head)
static void fuse_destroy_inode(struct inode *inode) static void fuse_destroy_inode(struct inode *inode)
{ {
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
if (S_ISREG(inode->i_mode)) { if (S_ISREG(inode->i_mode) && !is_bad_inode(inode)) {
WARN_ON(!list_empty(&fi->write_files)); WARN_ON(!list_empty(&fi->write_files));
WARN_ON(!list_empty(&fi->queued_writes)); WARN_ON(!list_empty(&fi->queued_writes));
} }
...@@ -1068,6 +1068,7 @@ void fuse_dev_free(struct fuse_dev *fud) ...@@ -1068,6 +1068,7 @@ void fuse_dev_free(struct fuse_dev *fud)
fuse_conn_put(fc); fuse_conn_put(fc);
} }
kfree(fud->pq.processing);
kfree(fud); kfree(fud);
} }
EXPORT_SYMBOL_GPL(fuse_dev_free); EXPORT_SYMBOL_GPL(fuse_dev_free);
......
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