ocfs2: check new file size on fallocate call
PATCH 1/1 ocfs2: check new file size on fallocate call
When changing a file size with fallocate() the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call to inode_newsize_ok() fixes this issue.
--- fs/ocfs2/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ocfs2/file.c +7 -1
@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ; -if (mode &FALLOC_FL_KEEP_SIZE ) +if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else { + ret =inode_newsize_ok (inode, offset + len); +if (ret) +return ret; + }if (mode &FALLOC_FL_PUNCH_HOLE ) cmd =OCFS2_IOC_UNRESVSP64 ;
Quoted 7 lines · Luís Henriques
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue.Signed-off-by Luís Henriques <[email protected]>
Looks good, thanks Luis.
Joseph Qi
maintainerQuoted 15 lines · Luís Henriques
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue.Signed-off-by Luís Henriques <[email protected]>--- fs/ocfs2/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/ocfs2/file.c +0
-0
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2106
Quoted 7 lines
fs/ocfs2/file.c +1
-0@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;
This means we only support keep-size and pouch_hole. And it seems pouch_hole will also imply keep-size.
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2112
Quoted 7 lines
fs/ocfs2/file.c +2
-1if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ; -if (mode &FALLOC_FL_KEEP_SIZE ) +if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else {
Seems this will be a dead branch?
Thanks,
Joseph
Quoted 7 lines
fs/ocfs2/file.c +4
-0+ ret =inode_newsize_ok (inode, offset + len); +if (ret) +return ret; + }if (mode &FALLOC_FL_PUNCH_HOLE ) cmd =OCFS2_IOC_UNRESVSP64 ;
Quoted 21 lines · Joseph Qi
Quoted 20 lines · Luís Henriques
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue.Signed-off-by Luís Henriques <[email protected]>--- fs/ocfs2/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/ocfs2/file.c +1
-0@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;
Quoted 5 lines
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2106
Quoted 2 lines
fs/ocfs2/file.c +0
-0if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;This means we only support keep-size and
pouch_hole. And it seemspouch_holewill also imply keep-size.
I think you're forgetting about mode = 0, which is also valid. And the default '0' will allow size to be changed.
Quoted 9 lines
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2112
Quoted 7 lines
fs/ocfs2/file.c +2
-1if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ; -if (mode &FALLOC_FL_KEEP_SIZE ) +if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else {Seems this will be a dead branch?
Again, you need to consider '0' as a valid mode value. If you run generic/228 without this patch you'll see that test failing because it *does* hit this branch.
Cheers,
Signature · 1 line
Luís
Quoted 11 lines
Thanks,
JosephQuoted 7 lines
fs/ocfs2/file.c +4
-0+ ret =inode_newsize_ok (inode, offset + len); +if (ret) +return ret; + }if (mode &FALLOC_FL_PUNCH_HOLE ) cmd =OCFS2_IOC_UNRESVSP64 ;
Joseph Qi
maintainerQuoted 23 lines · Luís Henriques
Quoted 21 lines · Joseph Qi
Quoted 20 lines · Luís Henriques
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue.Signed-off-by Luís Henriques <[email protected]>--- fs/ocfs2/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/ocfs2/file.c +1
-0@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;
Quoted 9 lines
Quoted 5 lines
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2106
Quoted 2 lines
fs/ocfs2/file.c +0
-0if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;This means we only support keep-size and
pouch_hole. And it seemspouch_holewill also imply keep-size.I think you're forgetting about mode = 0, which is also valid. And the default '0' will allow size to be changed.
Oops... You are right.
Quoted 15 lines
Quoted 9 lines
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2112
Quoted 7 lines
fs/ocfs2/file.c +2
-1if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ; -if (mode &FALLOC_FL_KEEP_SIZE ) +if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else {Seems this will be a dead branch?
Again, you need to consider '0' as a valid mode value. If you run generic/228 without this patch you'll see that test failing because it *does* hit this branch.
Cheers,
Quoted 6 lines · Luís Henriques
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue.Signed-off-by Luís Henriques <[email protected]>
Quoted 20 lines
--- fs/ocfs2/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/ocfs2/file.c +1
-1@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ; -if (mode &FALLOC_FL_KEEP_SIZE )
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2119
Quoted 10 lines
fs/ocfs2/file.c +6
-0+if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else { + ret =inode_newsize_ok (inode, offset + len); +if (ret) +return ret; + }if (mode &FALLOC_FL_PUNCH_HOLE ) cmd =OCFS2_IOC_UNRESVSP64 ;
_______________________________________________
Ocfs2-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Quoted 19 lines · On Mon, 29 May 2023 16:26:45 +0100 Luís Henriques via Ocfs2-devel…
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue....
fs/ocfs2/file.c +1
-0@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ;
fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2117
Quoted 10 lines
fs/ocfs2/file.c +6
-1-if (mode &FALLOC_FL_KEEP_SIZE ) +if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else { + ret =inode_newsize_ok (inode, offset + len); +if (ret) +return ret; + }
So userspace can exceed rlimit(RLIMIT_FSIZE).
Do we think this flaw is serious enough to justify backporting the fix into earlier -stable kernels?
_______________________________________________
Ocfs2-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel
Joseph Qi
maintainerQuoted 34 lines · Andrew Morton
Quoted 19 lines · On Mon, 29 May 2023 16:26:45 +0100 Luís Henriques via Ocfs2-devel…
When changing a file size with
fallocate()the new size isn't being checked. In particular, the FSIZE ulimit isn't being checked, which makes fstest generic/228 fail. Simply adding a call toinode_newsize_ok()fixes this issue....
fs/ocfs2/file.c +1
-0@@ -2100,14 +2100,20 @@ static long ocfs2_fallocate(struct file *file, int mode, loff_t offset,struct ocfs2_space_resv sr;int change_size =1 ;int cmd =OCFS2_IOC_RESVSP64 ; +int ret =0 ;if (mode & ~(FALLOC_FL_KEEP_SIZE |FALLOC_FL_PUNCH_HOLE ))return -EOPNOTSUPP ;if (!ocfs2_writes_unwritten_extents (osb))return -EOPNOTSUPP ;fs/ocfs2/file.c static long ocfs2_fallocate(struct file *file, int mode, loff_t offset, · line 2117
Quoted 10 lines
fs/ocfs2/file.c +6
-1-if (mode &FALLOC_FL_KEEP_SIZE ) +if (mode &FALLOC_FL_KEEP_SIZE ) { change_size =0 ; + }else { + ret =inode_newsize_ok (inode, offset + len); +if (ret) +return ret; + }So userspace can exceed
rlimit(RLIMIT_FSIZE).
Quoted 2 lines
Do we think this flaw is serious enough to justify backporting the fix into earlier -stable kernels?
I think it's worth ccing stable kernel as well.
Thanks,
Joseph
_______________________________________________
Ocfs2-devel mailing list
[email protected]
https://oss.oracle.com/mailman/listinfo/ocfs2-devel