fs: btrfs: fix out of bounds write
PATCH v2 1/1 fs: btrfs: fix out of bounds write
Fix btrfs_read/read_and_truncate_page write out of bounds of destination buffer. Old behavior break bootstd malloc'd buffers of exact file size. Previously this OOB write have not been noticed because distroboot usually read files into huge static memory areas.
---
Changes in v2:
- fix error path handling
- add Fixes tag
- use min3
fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +6 -2
@@ -640,7 +640,11 @@ static int read_and_truncate_page(struct btrfs_path *path, extent_type =btrfs_file_extent_type (leaf, fi);if (extent_type ==BTRFS_FILE_EXTENT_INLINE ) { ret =btrfs_read_extent_inline (path, fi, buf); -memcpy (dest, buf + page_off,min (page_len, ret)); +if (ret <0 ) { +free (buf); +return ret; + } +memcpy (dest, buf + page_off,min3 (page_len, ret, len));free (buf);return len; }
@@ -652,7 +656,7 @@ static int read_and_truncate_page(struct btrfs_path *path,free (buf);return ret; } -memcpy (dest, buf + page_off, page_len); +memcpy (dest, buf + page_off,min (page_len, len));free (buf);return len; }
Signature · 1 line
2.34.1
Quoted 7 lines · Alex Shumsky
Fix btrfs_read/read_and_truncate_page write out of bounds of destination buffer. Old behavior break bootstd malloc'd buffers of exact file size. Previously this OOB write have not been noticed because distroboot usually read files into huge static memory areas.
Signed-off-by Alex Shumsky <[email protected]>Fixes e342718 ("fs: btrfs: Implement btrfs_file_read()")
Thanks,
Qu
Quoted 36 lines
---
Changes in v2:
- fix error path handling
- add Fixes tag
- use min3fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)fs/btrfs/inode.c +6
-2@@ -640,7 +640,11 @@ static int read_and_truncate_page(struct btrfs_path *path, extent_type =btrfs_file_extent_type (leaf, fi);if (extent_type ==BTRFS_FILE_EXTENT_INLINE ) { ret =btrfs_read_extent_inline (path, fi, buf); -memcpy (dest, buf + page_off,min (page_len, ret)); +if (ret <0 ) { +free (buf); +return ret; + } +memcpy (dest, buf + page_off,min3 (page_len, ret, len));free (buf);return len; }@@ -652,7 +656,7 @@ static int read_and_truncate_page(struct btrfs_path *path,free (buf);return ret; } -memcpy (dest, buf + page_off, page_len); +memcpy (dest, buf + page_off,min (page_len, len));free (buf);return len; }
Hi all,
Is there something on my side needed to push this forward?
Quoted 49 lines · Alex Shumsky
Fix btrfs_read/read_and_truncate_page write out of bounds of destination buffer. Old behavior break bootstd malloc'd buffers of exact file size. Previously this OOB write have not been noticed because distroboot usually read files into huge static memory areas.
Signed-off-by Alex Shumsky <[email protected]>Fixes e342718 ("fs: btrfs: Implement btrfs_file_read()")---
Changes in v2:
- fix error path handling
- add Fixes tag
- use min3fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)fs/btrfs/inode.c +5
-1@@ -640,7 +640,11 @@ static int read_and_truncate_page(struct btrfs_path *path, extent_type =btrfs_file_extent_type (leaf, fi);if (extent_type ==BTRFS_FILE_EXTENT_INLINE ) { ret =btrfs_read_extent_inline (path, fi, buf); -memcpy (dest, buf + page_off,min (page_len, ret)); +if (ret <0 ) { +free (buf); +return ret; + } +memcpy (dest, buf + page_off,min3 (page_len, ret, len));free (buf);return len;}fs/btrfs/inode.c +1
-1@@ -652,7 +656,7 @@ static int read_and_truncate_page(struct btrfs_path *path,free (buf);return ret; } -memcpy (dest, buf + page_off, page_len); +memcpy (dest, buf + page_off,min (page_len, len));free (buf);return len;}
--
2.34.1
Quoted 3 lines · Alex ThreeD
Hi all,
Is there something on my side needed to push this forward?
I will pick it up for -next in a while, thanks.
Quoted 52 lines · Alex Shumsky
Quoted 50 lines
Fix btrfs_read/read_and_truncate_page write out of bounds of destination buffer. Old behavior break bootstd malloc'd buffers of exact file size. Previously this OOB write have not been noticed because distroboot usually read files into huge static memory areas.
Signed-off-by Alex Shumsky <[email protected]>Fixes e342718 ("fs: btrfs: Implement btrfs_file_read()")---
Changes in v2:
- fix error path handling
- add Fixes tag
- use min3fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)fs/btrfs/inode.c +5
-1@@ -640,7 +640,11 @@ static int read_and_truncate_page(struct btrfs_path *path, extent_type =btrfs_file_extent_type (leaf, fi);if (extent_type ==BTRFS_FILE_EXTENT_INLINE ) { ret =btrfs_read_extent_inline (path, fi, buf); -memcpy (dest, buf + page_off,min (page_len, ret)); +if (ret <0 ) { +free (buf); +return ret; + } +memcpy (dest, buf + page_off,min3 (page_len, ret, len));free (buf);return len;}fs/btrfs/inode.c +1
-1@@ -652,7 +656,7 @@ static int read_and_truncate_page(struct btrfs_path *path,free (buf);return ret; } -memcpy (dest, buf + page_off, page_len); +memcpy (dest, buf + page_off,min (page_len, len));free (buf);return len;}
--
2.34.1
Signature · 1 line
Tom
Quoted 6 lines · Alex Shumsky
Fix btrfs_read/read_and_truncate_page write out of bounds of destination buffer. Old behavior break bootstd malloc'd buffers of exact file size. Previously this OOB write have not been noticed because distroboot usually read files into huge static memory areas.
Applied to u-boot/next, thanks!
Signature · 1 line
Tom