All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV
@ 2021-08-20  4:45 Hou Tao
  2021-08-30  7:52 ` Hou Tao
  2021-09-09 17:10 ` Theodore Ts'o
  0 siblings, 2 replies; 5+ messages in thread
From: Hou Tao @ 2021-08-20  4:45 UTC (permalink / raw)
  To: tytso, adilger.kernel, harshadshirwadkar; +Cc: houtao1, linux-ext4

Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the
newly-added blocks, but the limit on the max value of
ee_len field is ignored, and it can lead to BUG_ON as
shown below when running command "fallocate -l 128M file"
on a fast_commit-enabled fs:

  kernel BUG at fs/ext4/ext4_extents.h:199!
  invalid opcode: 0000 [#1] SMP PTI
  CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
  RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200
  Call Trace:
   ? ext4_fc_write_inode+0xf2/0x150
   ext4_fc_commit+0x93b/0xa00
   ? ext4_fallocate+0x1ad/0x10d0
   ext4_sync_file+0x157/0x340
   ? ext4_sync_file+0x157/0x340
   vfs_fsync_range+0x49/0x80
   do_fsync+0x3d/0x70
   __x64_sys_fsync+0x14/0x20
   do_syscall_64+0x3b/0xc0
   entry_SYSCALL_64_after_hwframe+0x44/0xae

Simply fixing it by limiting the number of blocks
in one EXT4_FC_TAG_ADD_RANGE TLV.

Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 fs/ext4/fast_commit.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index e8195229c252..782d05a3f97a 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -893,6 +893,12 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc)
 					    sizeof(lrange), (u8 *)&lrange, crc))
 				return -ENOSPC;
 		} else {
+			unsigned int max = (map.m_flags & EXT4_MAP_UNWRITTEN) ?
+				EXT_UNWRITTEN_MAX_LEN : EXT_INIT_MAX_LEN;
+
+			/* Limit the number of blocks in one extent */
+			map.m_len = min(max, map.m_len);
+
 			fc_ext.fc_ino = cpu_to_le32(inode->i_ino);
 			ex = (struct ext4_extent *)&fc_ext.fc_ex;
 			ex->ee_block = cpu_to_le32(map.m_lblk);
-- 
2.29.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV
  2021-08-20  4:45 [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV Hou Tao
@ 2021-08-30  7:52 ` Hou Tao
  2021-09-07 11:21   ` Hou Tao
  2021-09-09 17:10 ` Theodore Ts'o
  1 sibling, 1 reply; 5+ messages in thread
From: Hou Tao @ 2021-08-30  7:52 UTC (permalink / raw)
  To: tytso, adilger.kernel, harshadshirwadkar; +Cc: linux-ext4

ping ?

On 8/20/2021 12:45 PM, Hou Tao wrote:
> Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the
> newly-added blocks, but the limit on the max value of
> ee_len field is ignored, and it can lead to BUG_ON as
> shown below when running command "fallocate -l 128M file"
> on a fast_commit-enabled fs:
>
>   kernel BUG at fs/ext4/ext4_extents.h:199!
>   invalid opcode: 0000 [#1] SMP PTI
>   CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1
>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
>   RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200
>   Call Trace:
>    ? ext4_fc_write_inode+0xf2/0x150
>    ext4_fc_commit+0x93b/0xa00
>    ? ext4_fallocate+0x1ad/0x10d0
>    ext4_sync_file+0x157/0x340
>    ? ext4_sync_file+0x157/0x340
>    vfs_fsync_range+0x49/0x80
>    do_fsync+0x3d/0x70
>    __x64_sys_fsync+0x14/0x20
>    do_syscall_64+0x3b/0xc0
>    entry_SYSCALL_64_after_hwframe+0x44/0xae
>
> Simply fixing it by limiting the number of blocks
> in one EXT4_FC_TAG_ADD_RANGE TLV.
>
> Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
> Signed-off-by: Hou Tao <houtao1@huawei.com>
> ---
>  fs/ext4/fast_commit.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index e8195229c252..782d05a3f97a 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
> @@ -893,6 +893,12 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc)
>  					    sizeof(lrange), (u8 *)&lrange, crc))
>  				return -ENOSPC;
>  		} else {
> +			unsigned int max = (map.m_flags & EXT4_MAP_UNWRITTEN) ?
> +				EXT_UNWRITTEN_MAX_LEN : EXT_INIT_MAX_LEN;
> +
> +			/* Limit the number of blocks in one extent */
> +			map.m_len = min(max, map.m_len);
> +
>  			fc_ext.fc_ino = cpu_to_le32(inode->i_ino);
>  			ex = (struct ext4_extent *)&fc_ext.fc_ex;
>  			ex->ee_block = cpu_to_le32(map.m_lblk);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV
  2021-08-30  7:52 ` Hou Tao
@ 2021-09-07 11:21   ` Hou Tao
  2021-09-09 16:51     ` harshad shirwadkar
  0 siblings, 1 reply; 5+ messages in thread
From: Hou Tao @ 2021-09-07 11:21 UTC (permalink / raw)
  To: tytso, adilger.kernel, harshadshirwadkar; +Cc: linux-ext4

ping ?

On 8/30/2021 3:52 PM, Hou Tao wrote:
> ping ?
>
> On 8/20/2021 12:45 PM, Hou Tao wrote:
>> Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the
>> newly-added blocks, but the limit on the max value of
>> ee_len field is ignored, and it can lead to BUG_ON as
>> shown below when running command "fallocate -l 128M file"
>> on a fast_commit-enabled fs:
>>
>>   kernel BUG at fs/ext4/ext4_extents.h:199!
>>   invalid opcode: 0000 [#1] SMP PTI
>>   CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1
>>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
>>   RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200
>>   Call Trace:
>>    ? ext4_fc_write_inode+0xf2/0x150
>>    ext4_fc_commit+0x93b/0xa00
>>    ? ext4_fallocate+0x1ad/0x10d0
>>    ext4_sync_file+0x157/0x340
>>    ? ext4_sync_file+0x157/0x340
>>    vfs_fsync_range+0x49/0x80
>>    do_fsync+0x3d/0x70
>>    __x64_sys_fsync+0x14/0x20
>>    do_syscall_64+0x3b/0xc0
>>    entry_SYSCALL_64_after_hwframe+0x44/0xae
>>
>> Simply fixing it by limiting the number of blocks
>> in one EXT4_FC_TAG_ADD_RANGE TLV.
>>
>> Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
>> Signed-off-by: Hou Tao <houtao1@huawei.com>
>> ---
>>  fs/ext4/fast_commit.c | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
>> index e8195229c252..782d05a3f97a 100644
>> --- a/fs/ext4/fast_commit.c
>> +++ b/fs/ext4/fast_commit.c
>> @@ -893,6 +893,12 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc)
>>  					    sizeof(lrange), (u8 *)&lrange, crc))
>>  				return -ENOSPC;
>>  		} else {
>> +			unsigned int max = (map.m_flags & EXT4_MAP_UNWRITTEN) ?
>> +				EXT_UNWRITTEN_MAX_LEN : EXT_INIT_MAX_LEN;
>> +
>> +			/* Limit the number of blocks in one extent */
>> +			map.m_len = min(max, map.m_len);
>> +
>>  			fc_ext.fc_ino = cpu_to_le32(inode->i_ino);
>>  			ex = (struct ext4_extent *)&fc_ext.fc_ex;
>>  			ex->ee_block = cpu_to_le32(map.m_lblk);
> .

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV
  2021-09-07 11:21   ` Hou Tao
@ 2021-09-09 16:51     ` harshad shirwadkar
  0 siblings, 0 replies; 5+ messages in thread
From: harshad shirwadkar @ 2021-09-09 16:51 UTC (permalink / raw)
  To: Hou Tao; +Cc: Theodore Y. Ts'o, Andreas Dilger, Ext4 Developers List

Sorry Hou for getting back to you late. This looks good to me.

Reviewed-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>


On Tue, Sep 7, 2021 at 4:21 AM Hou Tao <houtao1@huawei.com> wrote:
>
> ping ?
>
> On 8/30/2021 3:52 PM, Hou Tao wrote:
> > ping ?
> >
> > On 8/20/2021 12:45 PM, Hou Tao wrote:
> >> Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the
> >> newly-added blocks, but the limit on the max value of
> >> ee_len field is ignored, and it can lead to BUG_ON as
> >> shown below when running command "fallocate -l 128M file"
> >> on a fast_commit-enabled fs:
> >>
> >>   kernel BUG at fs/ext4/ext4_extents.h:199!
> >>   invalid opcode: 0000 [#1] SMP PTI
> >>   CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1
> >>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
> >>   RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200
> >>   Call Trace:
> >>    ? ext4_fc_write_inode+0xf2/0x150
> >>    ext4_fc_commit+0x93b/0xa00
> >>    ? ext4_fallocate+0x1ad/0x10d0
> >>    ext4_sync_file+0x157/0x340
> >>    ? ext4_sync_file+0x157/0x340
> >>    vfs_fsync_range+0x49/0x80
> >>    do_fsync+0x3d/0x70
> >>    __x64_sys_fsync+0x14/0x20
> >>    do_syscall_64+0x3b/0xc0
> >>    entry_SYSCALL_64_after_hwframe+0x44/0xae
> >>
> >> Simply fixing it by limiting the number of blocks
> >> in one EXT4_FC_TAG_ADD_RANGE TLV.
> >>
> >> Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
> >> Signed-off-by: Hou Tao <houtao1@huawei.com>
> >> ---
> >>  fs/ext4/fast_commit.c | 6 ++++++
> >>  1 file changed, 6 insertions(+)
> >>
> >> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> >> index e8195229c252..782d05a3f97a 100644
> >> --- a/fs/ext4/fast_commit.c
> >> +++ b/fs/ext4/fast_commit.c
> >> @@ -893,6 +893,12 @@ static int ext4_fc_write_inode_data(struct inode *inode, u32 *crc)
> >>                                          sizeof(lrange), (u8 *)&lrange, crc))
> >>                              return -ENOSPC;
> >>              } else {
> >> +                    unsigned int max = (map.m_flags & EXT4_MAP_UNWRITTEN) ?
> >> +                            EXT_UNWRITTEN_MAX_LEN : EXT_INIT_MAX_LEN;
> >> +
> >> +                    /* Limit the number of blocks in one extent */
> >> +                    map.m_len = min(max, map.m_len);
> >> +
> >>                      fc_ext.fc_ino = cpu_to_le32(inode->i_ino);
> >>                      ex = (struct ext4_extent *)&fc_ext.fc_ex;
> >>                      ex->ee_block = cpu_to_le32(map.m_lblk);
> > .

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV
  2021-08-20  4:45 [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV Hou Tao
  2021-08-30  7:52 ` Hou Tao
@ 2021-09-09 17:10 ` Theodore Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2021-09-09 17:10 UTC (permalink / raw)
  To: adilger.kernel, Hou Tao, harshadshirwadkar; +Cc: Theodore Ts'o, linux-ext4

On Fri, 20 Aug 2021 12:45:05 +0800, Hou Tao wrote:
> Now EXT4_FC_TAG_ADD_RANGE uses ext4_extent to track the
> newly-added blocks, but the limit on the max value of
> ee_len field is ignored, and it can lead to BUG_ON as
> shown below when running command "fallocate -l 128M file"
> on a fast_commit-enabled fs:
> 
>   kernel BUG at fs/ext4/ext4_extents.h:199!
>   invalid opcode: 0000 [#1] SMP PTI
>   CPU: 3 PID: 624 Comm: fallocate Not tainted 5.14.0-rc6+ #1
>   Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
>   RIP: 0010:ext4_fc_write_inode_data+0x1f3/0x200
>   Call Trace:
>    ? ext4_fc_write_inode+0xf2/0x150
>    ext4_fc_commit+0x93b/0xa00
>    ? ext4_fallocate+0x1ad/0x10d0
>    ext4_sync_file+0x157/0x340
>    ? ext4_sync_file+0x157/0x340
>    vfs_fsync_range+0x49/0x80
>    do_fsync+0x3d/0x70
>    __x64_sys_fsync+0x14/0x20
>    do_syscall_64+0x3b/0xc0
>    entry_SYSCALL_64_after_hwframe+0x44/0xae
> 
> [...]

Applied, thanks!

[1/1] ext4: limit the number of blocks in one ADD_RANGE TLV
      commit: af8137dff33d975ac84c8a5f63e057b2d0405fc3

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-09 17:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20  4:45 [PATCH] ext4: limit the number of blocks in one ADD_RANGE TLV Hou Tao
2021-08-30  7:52 ` Hou Tao
2021-09-07 11:21   ` Hou Tao
2021-09-09 16:51     ` harshad shirwadkar
2021-09-09 17:10 ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.