]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - super1.c
Fix possible bug with bitmap space allocation with v1.0 metadata
[thirdparty/mdadm.git] / super1.c
index 887db10c5f4cc6f1e863702c71d606a1c30c21e0..7ea6958ad846475e421ef6e1762db9e141cf50ae 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -905,7 +905,7 @@ static int write_init_super1(struct supertype *st,
         * for a bitmap.
         */
        array_size = __le64_to_cpu(sb->size);
-       /* work out how much space we left of a bitmap */
+       /* work out how much space we left for a bitmap */
        bm_space = choose_bm_space(array_size);
 
        switch(st->minor_version) {
@@ -915,6 +915,8 @@ static int write_init_super1(struct supertype *st,
                sb_offset &= ~(4*2-1);
                sb->super_offset = __cpu_to_le64(sb_offset);
                sb->data_offset = __cpu_to_le64(0);
+               if (sb_offset - bm_space < array_size)
+                       bm_space = sb_offset - array_size;
                sb->data_size = __cpu_to_le64(sb_offset - bm_space);
                break;
        case 1: