Skip to content

Commit

Permalink
Merge tag 'ovl-update-6.13' of git://git.kernel.org/pub/scm/linux/ker…
Browse files Browse the repository at this point in the history
…nel/git/overlayfs/vfs

Pull overlayfs updates from Amir Goldstein:

 - Fix a syzbot reported NULL pointer deref with bfs lower layers

 - Fix a copy up failure of large file from lower fuse fs

 - Followup cleanup of backing_file API from Miklos

 - Introduction and use of revert/override_creds_light() helpers, that
   were suggested by Christian as a mitigation to cache line bouncing
   and false sharing of fields in overlayfs creator_cred long lived
   struct cred copy.

 - Store up to two backing file references (upper and lower) in an
   ovl_file container instead of storing a single backing file in
   file->private_data.

   This is used to avoid the practice of opening a short lived backing
   file for the duration of some file operations and to avoid the
   specialized use of FDPUT_FPUT in such occasions, that was getting in
   the way of Al's fd_file() conversions.

* tag 'ovl-update-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs:
  ovl: Filter invalid inodes with missing lookup function
  ovl: convert ovl_real_fdget() callers to ovl_real_file()
  ovl: convert ovl_real_fdget_path() callers to ovl_real_file_path()
  ovl: store upper real file in ovl_file struct
  ovl: allocate a container struct ovl_file for ovl private context
  ovl: do not open non-data lower file for fsync
  ovl: Optimize override/revert creds
  ovl: pass an explicit reference of creators creds to callers
  ovl: use wrapper ovl_revert_creds()
  fs/backing-file: Convert to revert/override_creds_light()
  cred: Add a light version of override/revert_creds()
  backing-file: clean up the API
  ovl: properly handle large files in ovl_security_fileattr
  • Loading branch information
Linus Torvalds committed Nov 23, 2024
2 parents 060fc10 + c8b359d commit e767523
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 237 deletions.
53 changes: 26 additions & 27 deletions fs/backing-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct backing_aio {
refcount_t ref;
struct kiocb *orig_iocb;
/* used for aio completion */
void (*end_write)(struct file *, loff_t, ssize_t);
void (*end_write)(struct kiocb *iocb, ssize_t);
struct work_struct work;
long res;
};
Expand Down Expand Up @@ -108,10 +108,10 @@ static void backing_aio_cleanup(struct backing_aio *aio, long res)
struct kiocb *iocb = &aio->iocb;
struct kiocb *orig_iocb = aio->orig_iocb;

orig_iocb->ki_pos = iocb->ki_pos;
if (aio->end_write)
aio->end_write(orig_iocb->ki_filp, iocb->ki_pos, res);
aio->end_write(orig_iocb, res);

orig_iocb->ki_pos = iocb->ki_pos;
backing_aio_put(aio);
}

Expand Down Expand Up @@ -176,7 +176,7 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
!(file->f_mode & FMODE_CAN_ODIRECT))
return -EINVAL;

old_cred = override_creds(ctx->cred);
old_cred = override_creds_light(ctx->cred);
if (is_sync_kiocb(iocb)) {
rwf_t rwf = iocb_to_rw_flags(flags);

Expand All @@ -197,10 +197,10 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
backing_aio_cleanup(aio, ret);
}
out:
revert_creds(old_cred);
revert_creds_light(old_cred);

if (ctx->accessed)
ctx->accessed(ctx->user_file);
ctx->accessed(iocb->ki_filp);

return ret;
}
Expand All @@ -219,7 +219,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
if (!iov_iter_count(iter))
return 0;

ret = file_remove_privs(ctx->user_file);
ret = file_remove_privs(iocb->ki_filp);
if (ret)
return ret;

Expand All @@ -233,13 +233,13 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
*/
flags &= ~IOCB_DIO_CALLER_COMP;

old_cred = override_creds(ctx->cred);
old_cred = override_creds_light(ctx->cred);
if (is_sync_kiocb(iocb)) {
rwf_t rwf = iocb_to_rw_flags(flags);

ret = vfs_iter_write(file, iter, &iocb->ki_pos, rwf);
if (ctx->end_write)
ctx->end_write(ctx->user_file, iocb->ki_pos, ret);
ctx->end_write(iocb, ret);
} else {
struct backing_aio *aio;

Expand All @@ -264,13 +264,13 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
backing_aio_cleanup(aio, ret);
}
out:
revert_creds(old_cred);
revert_creds_light(old_cred);

return ret;
}
EXPORT_SYMBOL_GPL(backing_file_write_iter);

ssize_t backing_file_splice_read(struct file *in, loff_t *ppos,
ssize_t backing_file_splice_read(struct file *in, struct kiocb *iocb,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags,
struct backing_file_ctx *ctx)
Expand All @@ -281,20 +281,20 @@ ssize_t backing_file_splice_read(struct file *in, loff_t *ppos,
if (WARN_ON_ONCE(!(in->f_mode & FMODE_BACKING)))
return -EIO;

old_cred = override_creds(ctx->cred);
ret = vfs_splice_read(in, ppos, pipe, len, flags);
revert_creds(old_cred);
old_cred = override_creds_light(ctx->cred);
ret = vfs_splice_read(in, &iocb->ki_pos, pipe, len, flags);
revert_creds_light(old_cred);

if (ctx->accessed)
ctx->accessed(ctx->user_file);
ctx->accessed(iocb->ki_filp);

return ret;
}
EXPORT_SYMBOL_GPL(backing_file_splice_read);

ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
struct file *out, loff_t *ppos, size_t len,
unsigned int flags,
struct file *out, struct kiocb *iocb,
size_t len, unsigned int flags,
struct backing_file_ctx *ctx)
{
const struct cred *old_cred;
Expand All @@ -306,18 +306,18 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
if (!out->f_op->splice_write)
return -EINVAL;

ret = file_remove_privs(ctx->user_file);
ret = file_remove_privs(iocb->ki_filp);
if (ret)
return ret;

old_cred = override_creds(ctx->cred);
old_cred = override_creds_light(ctx->cred);
file_start_write(out);
ret = out->f_op->splice_write(pipe, out, ppos, len, flags);
ret = out->f_op->splice_write(pipe, out, &iocb->ki_pos, len, flags);
file_end_write(out);
revert_creds(old_cred);
revert_creds_light(old_cred);

if (ctx->end_write)
ctx->end_write(ctx->user_file, ppos ? *ppos : 0, ret);
ctx->end_write(iocb, ret);

return ret;
}
Expand All @@ -329,21 +329,20 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
const struct cred *old_cred;
int ret;

if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)) ||
WARN_ON_ONCE(ctx->user_file != vma->vm_file))
if (WARN_ON_ONCE(!(file->f_mode & FMODE_BACKING)))
return -EIO;

if (!file->f_op->mmap)
return -ENODEV;

vma_set_file(vma, file);

old_cred = override_creds(ctx->cred);
old_cred = override_creds_light(ctx->cred);
ret = call_mmap(vma->vm_file, vma);
revert_creds(old_cred);
revert_creds_light(old_cred);

if (ctx->accessed)
ctx->accessed(ctx->user_file);
ctx->accessed(vma->vm_file);

return ret;
}
Expand Down
32 changes: 18 additions & 14 deletions fs/fuse/passthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ static void fuse_file_accessed(struct file *file)
fuse_invalidate_atime(inode);
}

static void fuse_passthrough_end_write(struct file *file, loff_t pos, ssize_t ret)
static void fuse_passthrough_end_write(struct kiocb *iocb, ssize_t ret)
{
struct inode *inode = file_inode(file);
struct inode *inode = file_inode(iocb->ki_filp);

fuse_write_update_attr(inode, pos, ret);
fuse_write_update_attr(inode, iocb->ki_pos, ret);
}

ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)
Expand All @@ -34,7 +34,6 @@ ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)
ssize_t ret;
struct backing_file_ctx ctx = {
.cred = ff->cred,
.user_file = file,
.accessed = fuse_file_accessed,
};

Expand Down Expand Up @@ -62,7 +61,6 @@ ssize_t fuse_passthrough_write_iter(struct kiocb *iocb,
ssize_t ret;
struct backing_file_ctx ctx = {
.cred = ff->cred,
.user_file = file,
.end_write = fuse_passthrough_end_write,
};

Expand All @@ -88,15 +86,20 @@ ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos,
struct file *backing_file = fuse_file_passthrough(ff);
struct backing_file_ctx ctx = {
.cred = ff->cred,
.user_file = in,
.accessed = fuse_file_accessed,
};
struct kiocb iocb;
ssize_t ret;

pr_debug("%s: backing_file=0x%p, pos=%lld, len=%zu, flags=0x%x\n", __func__,
backing_file, ppos ? *ppos : 0, len, flags);
backing_file, *ppos, len, flags);

return backing_file_splice_read(backing_file, ppos, pipe, len, flags,
&ctx);
init_sync_kiocb(&iocb, in);
iocb.ki_pos = *ppos;
ret = backing_file_splice_read(backing_file, &iocb, pipe, len, flags, &ctx);
*ppos = iocb.ki_pos;

return ret;
}

ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
Expand All @@ -109,16 +112,18 @@ ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
ssize_t ret;
struct backing_file_ctx ctx = {
.cred = ff->cred,
.user_file = out,
.end_write = fuse_passthrough_end_write,
};
struct kiocb iocb;

pr_debug("%s: backing_file=0x%p, pos=%lld, len=%zu, flags=0x%x\n", __func__,
backing_file, ppos ? *ppos : 0, len, flags);
backing_file, *ppos, len, flags);

inode_lock(inode);
ret = backing_file_splice_write(pipe, backing_file, ppos, len, flags,
&ctx);
init_sync_kiocb(&iocb, out);
iocb.ki_pos = *ppos;
ret = backing_file_splice_write(pipe, backing_file, &iocb, len, flags, &ctx);
*ppos = iocb.ki_pos;
inode_unlock(inode);

return ret;
Expand All @@ -130,7 +135,6 @@ ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma)
struct file *backing_file = fuse_file_passthrough(ff);
struct backing_file_ctx ctx = {
.cred = ff->cred,
.user_file = file,
.accessed = fuse_file_accessed,
};

Expand Down
2 changes: 1 addition & 1 deletion fs/overlayfs/copy_up.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ static int ovl_copy_up_flags(struct dentry *dentry, int flags)
dput(parent);
dput(next);
}
revert_creds(old_cred);
ovl_revert_creds(old_cred);

return err;
}
Expand Down
Loading

0 comments on commit e767523

Please sign in to comment.