overlayfs: Conditionally use O_LARGEFILE in ovl_copy_up()
PATCH 1/2 overlayfs: Conditionally use O_LARGEFILE in ovl_copy_up()
Open the lower file with O_LARGEFILE in ovl_copy_up() if the lower file is
Quoted 1 line
= 4GiB in size.
---
fs/overlayfs/copy_up.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/overlayfs/copy_up.c +6 -3
@@ -76,16 +76,19 @@ static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len)struct file *new_file;loff_t old_pos =0 ;loff_t new_pos =0 ; -int error =0 ; +int error =0 , o_flag =0 ;if (len ==0 )return 0 ; - old_file =ovl_path_open (old,O_RDONLY ); +if (i_size_read (d_inode (old->dentry)) >MAX_NON_LFS ) + o_flag |=O_LARGEFILE ; + + old_file =ovl_path_open (old, o_flag |O_RDONLY );if (IS_ERR (old_file))return PTR_ERR (old_file); - new_file =ovl_path_open (new,O_WRONLY ); + new_file =ovl_path_open (new, o_flag |O_WRONLY );if (IS_ERR (new_file)) { error =PTR_ERR (new_file); goto out_fput;
PATCH 2/2 overlayfs: Fix dentry reference leak
In ovl_copy_up_locked(), newdentry is leaked if the function exits through out_cleanup as this just to out after calling ovl_cleanup() - which doesn't actually release the ref on newdentry.
The out_cleanup segment should instead exit through out2 as certainly newdentry leaks - and possibly upper does also, though this isn't caught given the catch of newdentry.
Without this fix, something like the following is seen:
BUG: Dentry ffff880023e9eb20{i=f861,n=#ffff880023e82d90} still in use (1) [unmount of tmpfs tmpfs]
BUG: Dentry ffff880023ece640{i=0,n=bigfile} still in use (1) [unmount of tmpfs tmpfs]when unmounting the upper layer after an error occurred in copyup.
An error can be induced by creating a big file in a lower layer with something like:
dd if=/dev/zero of=/lower/a/bigfile bs=65536 count=1 seek=$((0xf000))
to create a large file (4.1G). Overlay an upper layer that is too small (on tmpfs might do) and then induce a copy up by opening it writably.
---
fs/overlayfs/copy_up.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/overlayfs/copy_up.c +1 -1
@@ -270,7 +270,7 @@ out: out_cleanup:ovl_cleanup (wdir, newdentry); - goto out; + goto out2; }/*
Miklos Szeredi
maintainerRe: [PATCH 2/2] overlayfs: Fix dentry reference leak
Hi David,
Applied both patches.
Thanks,
Miklos