Skip to content

Commit e767523

Browse files
committed
Merge tag 'ovl-update-6.13' of git://git.kernel.org/pub/scm/linux/kernel/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
2 parents 060fc10 + c8b359d commit e767523

14 files changed

+352
-237
lines changed

fs/backing-file.c

+26-27
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct backing_aio {
8080
refcount_t ref;
8181
struct kiocb *orig_iocb;
8282
/* used for aio completion */
83-
void (*end_write)(struct file *, loff_t, ssize_t);
83+
void (*end_write)(struct kiocb *iocb, ssize_t);
8484
struct work_struct work;
8585
long res;
8686
};
@@ -108,10 +108,10 @@ static void backing_aio_cleanup(struct backing_aio *aio, long res)
108108
struct kiocb *iocb = &aio->iocb;
109109
struct kiocb *orig_iocb = aio->orig_iocb;
110110

111+
orig_iocb->ki_pos = iocb->ki_pos;
111112
if (aio->end_write)
112-
aio->end_write(orig_iocb->ki_filp, iocb->ki_pos, res);
113+
aio->end_write(orig_iocb, res);
113114

114-
orig_iocb->ki_pos = iocb->ki_pos;
115115
backing_aio_put(aio);
116116
}
117117

@@ -176,7 +176,7 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
176176
!(file->f_mode & FMODE_CAN_ODIRECT))
177177
return -EINVAL;
178178

179-
old_cred = override_creds(ctx->cred);
179+
old_cred = override_creds_light(ctx->cred);
180180
if (is_sync_kiocb(iocb)) {
181181
rwf_t rwf = iocb_to_rw_flags(flags);
182182

@@ -197,10 +197,10 @@ ssize_t backing_file_read_iter(struct file *file, struct iov_iter *iter,
197197
backing_aio_cleanup(aio, ret);
198198
}
199199
out:
200-
revert_creds(old_cred);
200+
revert_creds_light(old_cred);
201201

202202
if (ctx->accessed)
203-
ctx->accessed(ctx->user_file);
203+
ctx->accessed(iocb->ki_filp);
204204

205205
return ret;
206206
}
@@ -219,7 +219,7 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
219219
if (!iov_iter_count(iter))
220220
return 0;
221221

222-
ret = file_remove_privs(ctx->user_file);
222+
ret = file_remove_privs(iocb->ki_filp);
223223
if (ret)
224224
return ret;
225225

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

236-
old_cred = override_creds(ctx->cred);
236+
old_cred = override_creds_light(ctx->cred);
237237
if (is_sync_kiocb(iocb)) {
238238
rwf_t rwf = iocb_to_rw_flags(flags);
239239

240240
ret = vfs_iter_write(file, iter, &iocb->ki_pos, rwf);
241241
if (ctx->end_write)
242-
ctx->end_write(ctx->user_file, iocb->ki_pos, ret);
242+
ctx->end_write(iocb, ret);
243243
} else {
244244
struct backing_aio *aio;
245245

@@ -264,13 +264,13 @@ ssize_t backing_file_write_iter(struct file *file, struct iov_iter *iter,
264264
backing_aio_cleanup(aio, ret);
265265
}
266266
out:
267-
revert_creds(old_cred);
267+
revert_creds_light(old_cred);
268268

269269
return ret;
270270
}
271271
EXPORT_SYMBOL_GPL(backing_file_write_iter);
272272

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

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

288288
if (ctx->accessed)
289-
ctx->accessed(ctx->user_file);
289+
ctx->accessed(iocb->ki_filp);
290290

291291
return ret;
292292
}
293293
EXPORT_SYMBOL_GPL(backing_file_splice_read);
294294

295295
ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
296-
struct file *out, loff_t *ppos, size_t len,
297-
unsigned int flags,
296+
struct file *out, struct kiocb *iocb,
297+
size_t len, unsigned int flags,
298298
struct backing_file_ctx *ctx)
299299
{
300300
const struct cred *old_cred;
@@ -306,18 +306,18 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
306306
if (!out->f_op->splice_write)
307307
return -EINVAL;
308308

309-
ret = file_remove_privs(ctx->user_file);
309+
ret = file_remove_privs(iocb->ki_filp);
310310
if (ret)
311311
return ret;
312312

313-
old_cred = override_creds(ctx->cred);
313+
old_cred = override_creds_light(ctx->cred);
314314
file_start_write(out);
315-
ret = out->f_op->splice_write(pipe, out, ppos, len, flags);
315+
ret = out->f_op->splice_write(pipe, out, &iocb->ki_pos, len, flags);
316316
file_end_write(out);
317-
revert_creds(old_cred);
317+
revert_creds_light(old_cred);
318318

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

322322
return ret;
323323
}
@@ -329,21 +329,20 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
329329
const struct cred *old_cred;
330330
int ret;
331331

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

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

339338
vma_set_file(vma, file);
340339

341-
old_cred = override_creds(ctx->cred);
340+
old_cred = override_creds_light(ctx->cred);
342341
ret = call_mmap(vma->vm_file, vma);
343-
revert_creds(old_cred);
342+
revert_creds_light(old_cred);
344343

345344
if (ctx->accessed)
346-
ctx->accessed(ctx->user_file);
345+
ctx->accessed(vma->vm_file);
347346

348347
return ret;
349348
}

fs/fuse/passthrough.c

+18-14
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ static void fuse_file_accessed(struct file *file)
1818
fuse_invalidate_atime(inode);
1919
}
2020

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

25-
fuse_write_update_attr(inode, pos, ret);
25+
fuse_write_update_attr(inode, iocb->ki_pos, ret);
2626
}
2727

2828
ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)
@@ -34,7 +34,6 @@ ssize_t fuse_passthrough_read_iter(struct kiocb *iocb, struct iov_iter *iter)
3434
ssize_t ret;
3535
struct backing_file_ctx ctx = {
3636
.cred = ff->cred,
37-
.user_file = file,
3837
.accessed = fuse_file_accessed,
3938
};
4039

@@ -62,7 +61,6 @@ ssize_t fuse_passthrough_write_iter(struct kiocb *iocb,
6261
ssize_t ret;
6362
struct backing_file_ctx ctx = {
6463
.cred = ff->cred,
65-
.user_file = file,
6664
.end_write = fuse_passthrough_end_write,
6765
};
6866

@@ -88,15 +86,20 @@ ssize_t fuse_passthrough_splice_read(struct file *in, loff_t *ppos,
8886
struct file *backing_file = fuse_file_passthrough(ff);
8987
struct backing_file_ctx ctx = {
9088
.cred = ff->cred,
91-
.user_file = in,
9289
.accessed = fuse_file_accessed,
9390
};
91+
struct kiocb iocb;
92+
ssize_t ret;
9493

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

98-
return backing_file_splice_read(backing_file, ppos, pipe, len, flags,
99-
&ctx);
97+
init_sync_kiocb(&iocb, in);
98+
iocb.ki_pos = *ppos;
99+
ret = backing_file_splice_read(backing_file, &iocb, pipe, len, flags, &ctx);
100+
*ppos = iocb.ki_pos;
101+
102+
return ret;
100103
}
101104

102105
ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
@@ -109,16 +112,18 @@ ssize_t fuse_passthrough_splice_write(struct pipe_inode_info *pipe,
109112
ssize_t ret;
110113
struct backing_file_ctx ctx = {
111114
.cred = ff->cred,
112-
.user_file = out,
113115
.end_write = fuse_passthrough_end_write,
114116
};
117+
struct kiocb iocb;
115118

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

119122
inode_lock(inode);
120-
ret = backing_file_splice_write(pipe, backing_file, ppos, len, flags,
121-
&ctx);
123+
init_sync_kiocb(&iocb, out);
124+
iocb.ki_pos = *ppos;
125+
ret = backing_file_splice_write(pipe, backing_file, &iocb, len, flags, &ctx);
126+
*ppos = iocb.ki_pos;
122127
inode_unlock(inode);
123128

124129
return ret;
@@ -130,7 +135,6 @@ ssize_t fuse_passthrough_mmap(struct file *file, struct vm_area_struct *vma)
130135
struct file *backing_file = fuse_file_passthrough(ff);
131136
struct backing_file_ctx ctx = {
132137
.cred = ff->cred,
133-
.user_file = file,
134138
.accessed = fuse_file_accessed,
135139
};
136140

fs/overlayfs/copy_up.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ static int ovl_copy_up_flags(struct dentry *dentry, int flags)
12591259
dput(parent);
12601260
dput(next);
12611261
}
1262-
revert_creds(old_cred);
1262+
ovl_revert_creds(old_cred);
12631263

12641264
return err;
12651265
}

0 commit comments

Comments
 (0)