bcachefs: ec: Ensure new stripe is closed in error path
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 28 Feb 2023 03:30:54 +0000 (22:30 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:55 +0000 (17:09 -0400)
This fixes a use-after-free bug.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/ec.c

index 88f319992c371929795e173ad4c1d579767a2766..cb291b2a4dd8f124d6975c6dc71a9088b9482572 100644 (file)
@@ -1107,8 +1107,6 @@ static void ec_stripe_create(struct ec_stripe_new *s)
                        bch2_err_str(ret));
                goto err;
        }
-
-       bch2_stripe_close(c, s);
 err:
        bch2_disk_reservation_put(c, &s->res);
 
@@ -1124,6 +1122,8 @@ err:
                        }
                }
 
+       bch2_stripe_close(c, s);
+
        ec_stripe_buf_exit(&s->existing_stripe);
        ec_stripe_buf_exit(&s->new_stripe);
        closure_debug_destroy(&s->iodone);