2022-03-17 03:22:06

by Tadeusz Struk

[permalink] [raw]
Subject: [PATCH v2] ext4: check if offset+length is within valid fallocate

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

==============================================
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 01c9e4f743ba..355384007d11 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3924,7 +3924,8 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
struct super_block *sb = inode->i_sb;
ext4_lblk_t first_block, stop_block;
struct address_space *mapping = inode->i_mapping;
- loff_t first_block_offset, last_block_offset;
+ loff_t first_block_offset, last_block_offset, max_length;
+ struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
handle_t *handle;
unsigned int credits;
int ret = 0, ret2 = 0;
@@ -3967,6 +3968,16 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
offset;
}

+ /*
+ * For punch hole the length + offset needs to be at least within
+ * one block before last
+ */
+ max_length = sbi->s_bitmap_maxbytes - inode->i_sb->s_blocksize;
+ if (offset + length >= max_length) {
+ ret = -ENOSPC;
+ goto out_mutex;
+ }
+
if (offset & (sb->s_blocksize - 1) ||
(offset + length) & (sb->s_blocksize - 1)) {
/*
--
2.35.1


2022-04-28 18:36:27

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH v2] ext4: check if offset+length is within valid fallocate

On Tue 15-03-22 14:38:57, Tadeusz Struk wrote:
> #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

Did this fix fall through the cracks? Tadeusz, can you do a proper patch
submission with your Signed-off-by etc.? Thanks!

Honza

>
> ==============================================
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 01c9e4f743ba..355384007d11 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3924,7 +3924,8 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
> struct super_block *sb = inode->i_sb;
> ext4_lblk_t first_block, stop_block;
> struct address_space *mapping = inode->i_mapping;
> - loff_t first_block_offset, last_block_offset;
> + loff_t first_block_offset, last_block_offset, max_length;
> + struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
> handle_t *handle;
> unsigned int credits;
> int ret = 0, ret2 = 0;
> @@ -3967,6 +3968,16 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
> offset;
> }
>
> + /*
> + * For punch hole the length + offset needs to be at least within
> + * one block before last
> + */
> + max_length = sbi->s_bitmap_maxbytes - inode->i_sb->s_blocksize;
> + if (offset + length >= max_length) {
> + ret = -ENOSPC;
> + goto out_mutex;
> + }
> +
> if (offset & (sb->s_blocksize - 1) ||
> (offset + length) & (sb->s_blocksize - 1)) {
> /*
> --
> 2.35.1
>
--
Jan Kara <[email protected]>
SUSE Labs, CR

2022-05-04 15:16:30

by Tadeusz Struk

[permalink] [raw]
Subject: Re: [PATCH v2] ext4: check if offset+length is within valid fallocate

On 4/28/22 07:02, Jan Kara wrote:
> On Tue 15-03-22 14:38:57, Tadeusz Struk wrote:
>> #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> Did this fix fall through the cracks? Tadeusz, can you do a proper patch
> submission with your Signed-off-by etc.? Thanks!

I'm still working on it.
--
Thanks,
Tadeusz