diff options
author | Wessel Dankers <wsl@fruit.je> | 2022-01-12 17:26:14 +0100 |
---|---|---|
committer | Wessel Dankers <wsl@fruit.je> | 2022-01-13 00:08:52 +0100 |
commit | 7b15324de1095f3e2e423e9c53da076d208b52d5 (patch) | |
tree | 7c4f96ea64a91e01a7e1a12631efd72feb10b76d /libbcachefs.c | |
parent | 2c0d0c4b7b2484eaadf377f4a45d6b84a0680dcb (diff) |
Fix heap corruption in bcachefs format
In bch2_format(): recompute mi after each sb modification:
its location in memory may have changed due to reallocation.
This fixes an issue where labels were not assigned (because
they were written to an undefined part of the heap instead of
the superblock).
Signed-off-by: Wessel Dankers <wsl@fruit.je>
Diffstat (limited to 'libbcachefs.c')
-rw-r--r-- | libbcachefs.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libbcachefs.c b/libbcachefs.c index 393d3685..f78ebf04 100644 --- a/libbcachefs.c +++ b/libbcachefs.c @@ -241,7 +241,7 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs, /* Disk labels*/ for (i = devs; i < devs + nr_devs; i++) { - struct bch_member *m = mi->members + (i - devs); + struct bch_member *m; int idx; if (!i->label) @@ -251,6 +251,13 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs, if (idx < 0) die("error creating disk path: %s", strerror(-idx)); + /* + * Recompute mi and m after each sb modification: its location + * in memory may have changed due to reallocation. + */ + mi = bch2_sb_get_members(sb.sb); + m = mi->members + (i - devs); + SET_BCH_MEMBER_GROUP(m, idx + 1); } |