diff mbox

[1/3] btrfs: Error handle for get_ref_objectid_v0() in relocate_block_group()

Message ID f6eb7359bee352cc27f91d26bcffa6c6f8b1a5fe.1438768766.git.zhaolei@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Zhaolei Aug. 5, 2015, 10 a.m. UTC
We need error checking code for get_ref_objectid_v0() in
relocate_block_group(), to avoid unpredictable result, especially
for accessing uninitialized value(when function failed) after
this line.

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
---
 fs/btrfs/relocation.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

David Sterba Aug. 5, 2015, 5:02 p.m. UTC | #1
On Wed, Aug 05, 2015 at 06:00:02PM +0800, Zhao Lei wrote:
> We need error checking code for get_ref_objectid_v0() in
> relocate_block_group(), to avoid unpredictable result, especially
> for accessing uninitialized value(when function failed) after
> this line.
> 
> Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>

Reviewed-by: David Sterba <dsterba@suse.com>

Are there even filesystems with v0 refs?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Zhaolei Aug. 6, 2015, 2:11 a.m. UTC | #2
Hi, David Sterba

> -----Original Message-----
> From: David Sterba [mailto:dsterba@suse.com]
> Sent: Thursday, August 06, 2015 1:03 AM
> To: Zhao Lei
> Cc: linux-btrfs@vger.kernel.org
> Subject: Re: [PATCH 1/3] btrfs: Error handle for get_ref_objectid_v0() in
> relocate_block_group()
> 
> On Wed, Aug 05, 2015 at 06:00:02PM +0800, Zhao Lei wrote:
> > We need error checking code for get_ref_objectid_v0() in
> > relocate_block_group(), to avoid unpredictable result, especially for
> > accessing uninitialized value(when function failed) after this line.
> >
> > Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
> 
> Reviewed-by: David Sterba <dsterba@suse.com>
> 
Thanks for review!

> Are there even filesystems with v0 refs?
Rarely, I think.
(Just a accidental found in debuging another problem)
But for current code, we need hold correct code until
we remove v0 refs support.

Thanks
Zhaolei


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 52fe55a..1659c94 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3976,6 +3976,10 @@  restart:
 			       sizeof(struct btrfs_extent_item_v0));
 			ret = get_ref_objectid_v0(rc, path, &key, &ref_owner,
 						  &path_change);
+			if (ret < 0) {
+				err = ret;
+				break;
+			}
 			if (ref_owner < BTRFS_FIRST_FREE_OBJECTID)
 				flags = BTRFS_EXTENT_FLAG_TREE_BLOCK;
 			else