]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: Fix null ptr deref in bch2_write_endio()
authorKent Overstreet <kent.overstreet@linux.dev>
Mon, 31 Mar 2025 20:19:04 +0000 (16:19 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Mon, 31 Mar 2025 21:39:27 +0000 (17:39 -0400)
This was previously hard to hit since it requires racing with device
removal, but splitting up io_ref uncovered it.

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

index 07b55839768ea9e3241598c63cc84ff3c5418b91..0503ac1952cd0a0db71ab71ff45fa7ab6c945022 100644 (file)
@@ -697,12 +697,19 @@ static void bch2_write_endio(struct bio *bio)
        bch2_account_io_completion(ca, BCH_MEMBER_ERROR_write,
                                   wbio->submit_time, !bio->bi_status);
 
-       if (bio->bi_status) {
-               bch_err_inum_offset_ratelimited(ca,
-                                   op->pos.inode,
-                                   wbio->inode_offset << 9,
-                                   "data write error: %s",
-                                   bch2_blk_status_to_str(bio->bi_status));
+       if (unlikely(bio->bi_status)) {
+               if (ca)
+                       bch_err_inum_offset_ratelimited(ca,
+                                           op->pos.inode,
+                                           wbio->inode_offset << 9,
+                                           "data write error: %s",
+                                           bch2_blk_status_to_str(bio->bi_status));
+               else
+                       bch_err_inum_offset_ratelimited(c,
+                                           op->pos.inode,
+                                           wbio->inode_offset << 9,
+                                           "data write error: %s",
+                                           bch2_blk_status_to_str(bio->bi_status));
                set_bit(wbio->dev, op->failed.d);
                op->flags |= BCH_WRITE_io_error;
        }