]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: send: handle unexpected data in header buffer in begin_cmd()
authorDavid Sterba <dsterba@suse.com>
Tue, 6 Feb 2024 21:47:13 +0000 (22:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Sep 2024 11:17:37 +0000 (13:17 +0200)
[ Upstream commit e80e3f732cf53c64b0d811e1581470d67f6c3228 ]

Change BUG_ON to a proper error handling in the unlikely case of seeing
data when the command is started. This is supposed to be reset when the
command is finished (send_cmd, send_encoded_extent).

Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/send.c

index a5ed01d49f06979f14f6ed013b44c6b3109aa633..a9e72f42e91e0787037f8a6353721d3fc85b83ea 100644 (file)
@@ -685,7 +685,12 @@ static int begin_cmd(struct send_ctx *sctx, int cmd)
        if (WARN_ON(!sctx->send_buf))
                return -EINVAL;
 
-       BUG_ON(sctx->send_size);
+       if (unlikely(sctx->send_size != 0)) {
+               btrfs_err(sctx->send_root->fs_info,
+                         "send: command header buffer not empty cmd %d offset %llu",
+                         cmd, sctx->send_off);
+               return -EINVAL;
+       }
 
        sctx->send_size += sizeof(*hdr);
        hdr = (struct btrfs_cmd_header *)sctx->send_buf;