btrfs: send: handle path ref underflow in header iterate_inode_ref()
authorDavid Sterba <dsterba@suse.com>
Tue, 6 Feb 2024 21:47:13 +0000 (22:47 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 4 Mar 2024 15:24:51 +0000 (16:24 +0100)
Change BUG_ON to proper error handling if building the path buffer
fails. The pointers are not printed so we don't accidentally leak kernel
addresses.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/send.c

index 3b3f38a76b005cfeef294149ff9c872d842ae3c3..5b7ec4f99aad4d942d8f27af67f38c6cddacf1eb 100644 (file)
@@ -1074,7 +1074,15 @@ static int iterate_inode_ref(struct btrfs_root *root, struct btrfs_path *path,
                                        ret = PTR_ERR(start);
                                        goto out;
                                }
-                               BUG_ON(start < p->buf);
+                               if (unlikely(start < p->buf)) {
+                                       btrfs_err(root->fs_info,
+                       "send: path ref buffer underflow for key (%llu %u %llu)",
+                                                 found_key->objectid,
+                                                 found_key->type,
+                                                 found_key->offset);
+                                       ret = -EINVAL;
+                                       goto out;
+                               }
                        }
                        p->start = start;
                } else {