btrfs: reflink: Assure length != 0 in btrfs_extent_same()
PATCH 1/1 btrfs: reflink: Assure length != 0 in btrfs_extent_same()
btrfs_extent_same() cannot be called with zero length. Because when length is zero, it would be filtered by condition in btrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.
--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/reflink.c +1 -0
@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; +ASSERT (olen);spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info,
Signature · 1 line
2.25.1
Quoted 4 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. Because when length is zero, it would be filtered by condition inbtrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.
Do you have a specific future in mind? Adding the assert won't hurt so ok.
Quoted 8 lines · David Sterba
Quoted 4 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. Because when length is zero, it would be filtered by condition inbtrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.Do you have a specific future in mind? Adding the assert won't hurt so ok.
No, sorry, I just want to make it safe. is there any way to better than adding assert? Would it better to initialize ret?
Quoted 6 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. Because when length is zero, it would be filtered by condition inbtrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.Signed-off-by Sidong Yang <[email protected]>
This is not sufficient, with the assert compiled out the error would still be in place. It seem that it is sufficient to initialize ret to some non-arbitrary value i.e -EINVAL ?
Quoted 17 lines
--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/reflink.c +1
-0@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; +ASSERT (olen);spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info,
Quoted 8 lines · Nikolay Borisov
Quoted 5 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. Because when length is zero, it would be filtered by condition inbtrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.
Quoted 5 lines
Quoted 1 line
Signed-off-by Sidong Yang <[email protected]>This is not sufficient, with the assert compiled out the error would still be in place. It seem that it is sufficient to initialize ret to some non-arbitrary value i.e
-EINVAL?
I agree. It's better way to assign intial value than adding assert. If there is code that initialize ret, It seems that assert is no need for this.
Quoted 18 lines
Quoted 18 lines
--- fs/btrfs/reflink.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/reflink.c +1
-0@@ -653,6 +653,7 @@ static int btrfs_extent_same(struct inode *src, u64 loff, u64 olen,u64 i, tail_len, chunk_count;struct btrfs_root *root_dst =BTRFS_I (dst)->root; +ASSERT (olen);spin_lock (&root_dst->root_item_lock);if (root_dst->send_in_progress) { btrfs_warn_rl(root_dst->fs_info,
Quoted 11 lines · Sidong Yang
Quoted 10 lines · Nikolay Borisov
Quoted 6 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. Because when length is zero, it would be filtered by condition inbtrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.Signed-off-by Sidong Yang <[email protected]>
Quoted 7 lines
Quoted 3 lines
This is not sufficient, with the assert compiled out the error would still be in place. It seem that it is sufficient to initialize ret to some non-arbitrary value i.e
-EINVAL?I agree. It's better way to assign intial value than adding assert. If there is code that initialize ret, It seems that assert is no need for this.
Patch with assert removed, please send the one initializing the return value, thanks.
Quoted 16 lines · David Sterba
Quoted 15 lines · Sidong Yang
Quoted 13 lines · Nikolay Borisov
Quoted 6 lines · Sidong Yang
btrfs_extent_same()cannot be called with zero length. Because when length is zero, it would be filtered by condition inbtrfs_remap_file_range(). But if this function is used in other case in future, it can make ret as uninitialized.Signed-off-by Sidong Yang <[email protected]>This is not sufficient, with the assert compiled out the error would still be in place. It seem that it is sufficient to initialize ret to some non-arbitrary value i.e
-EINVAL?
Quoted 6 lines
Quoted 3 lines
I agree. It's better way to assign intial value than adding assert. If there is code that initialize ret, It seems that assert is no need for this.
Patch with assert removed, please send the one initializing the return value, thanks.
Sure, I'll write it in v2.
Thanks,
Sidong