---- 在 星期四, 2021-04-08 19:20:42 Chengguang Xu <cgxu519@xxxxxxxxxxxx> 撰写 ---- > In overlayfs copy-up, if open flag has O_TRUNC then upper > file will truncate to zero size, in this case we should check > VM_DENYWRITE mappings to keep compatibility with other filesystems. > > Signed-off-by: Chengguang Xu <cgxu519@xxxxxxxxxxxx> > --- > fs/overlayfs/copy_up.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c > index 0fed532efa68..c56c81494b0c 100644 > --- a/fs/overlayfs/copy_up.c > +++ b/fs/overlayfs/copy_up.c > @@ -901,8 +901,11 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry, > } > > /* maybe truncate regular file. this has no effect on dirs */ > - if (flags & O_TRUNC) > + if (flags & O_TRUNC) { > + if (atomic_read(&d_inode(ovl_dentry_real(dentry))->i_writecount) < 0) > + return -ETXTBSY; > ctx.stat.size = 0; > + } Maybe we should check this for open(with writable flag) not only for truncate case, right? Thanks, Chengguang > > if (S_ISLNK(ctx.stat.mode)) { > ctx.link = vfs_get_link(ctx.lowerpath.dentry, &done); > -- > 2.27.0 > > >