btrfs-progs: chunk-recover: handle duplicate cache entries
authorDavid Sterba <dsterba@suse.com>
Mon, 3 Oct 2016 13:49:45 +0000 (15:49 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 5 Oct 2016 10:39:01 +0000 (12:39 +0200)
Triggered by fuzzed image bko-155621-bad-block-group-offset.raw .

Signed-off-by: David Sterba <dsterba@suse.com>
chunk-recover.c

index d1e6c38..5bde5b1 100644 (file)
@@ -2250,6 +2250,13 @@ static int btrfs_recover_chunks(struct recover_control *rc)
                chunk->sub_stripes = calc_sub_nstripes(bg->flags);
 
                ret = insert_cache_extent(&rc->chunk, &chunk->cache);
+               if (ret == -EEXIST) {
+                       error("duplicate entry in cache start %llu size %llu",
+                                       (unsigned long long)chunk->cache.start,
+                                       (unsigned long long)chunk->cache.size);
+                       free(chunk);
+                       return ret;
+               }
                BUG_ON(ret);
 
                list_del_init(&bg->list);