From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Robbie Ko <robbieko@synology.com>,
Filipe Manana <fdmanana@suse.com>,
Sasha Levin <alexander.levin@verizon.com>
Subject: [PATCH 3.18 19/27] Btrfs: send, fix failure to rename top level inode due to name collision
Date: Thu, 19 Oct 2017 15:49:25 +0200 [thread overview]
Message-ID: <20171019134845.913674070@linuxfoundation.org> (raw)
In-Reply-To: <20171019134844.523725420@linuxfoundation.org>
3.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robbie Ko <robbieko@synology.com>
[ Upstream commit 4dd9920d991745c4a16f53a8f615f706fbe4b3f7 ]
Under certain situations, an incremental send operation can fail due to a
premature attempt to create a new top level inode (a direct child of the
subvolume/snapshot root) whose name collides with another inode that was
removed from the send snapshot.
Consider the following example scenario.
Parent snapshot:
. (ino 256, gen 8)
|---- a1/ (ino 257, gen 9)
|---- a2/ (ino 258, gen 9)
Send snapshot:
. (ino 256, gen 3)
|---- a2/ (ino 257, gen 7)
In this scenario, when receiving the incremental send stream, the btrfs
receive command fails like this (ran in verbose mode, -vv argument):
rmdir a1
mkfile o257-7-0
rename o257-7-0 -> a2
ERROR: rename o257-7-0 -> a2 failed: Is a directory
What happens when computing the incremental send stream is:
1) An operation to remove the directory with inode number 257 and
generation 9 is issued.
2) An operation to create the inode with number 257 and generation 7 is
issued. This creates the inode with an orphanized name of "o257-7-0".
3) An operation rename the new inode 257 to its final name, "a2", is
issued. This is incorrect because inode 258, which has the same name
and it's a child of the same parent (root inode 256), was not yet
processed and therefore no rmdir operation for it was yet issued.
The rename operation is issued because we fail to detect that the
name of the new inode 257 collides with inode 258, because their
parent, a subvolume/snapshot root (inode 256) has a different
generation in both snapshots.
So fix this by ignoring the generation value of a parent directory that
matches a root inode (number 256) when we are checking if the name of the
inode currently being processed collides with the name of some other
inode that was not yet processed.
We can achieve this scenario of different inodes with the same number but
different generation values either by mounting a filesystem with the inode
cache option (-o inode_cache) or by creating and sending snapshots across
different filesystems, like in the following example:
$ mkfs.btrfs -f /dev/sdb
$ mount /dev/sdb /mnt
$ mkdir /mnt/a1
$ mkdir /mnt/a2
$ btrfs subvolume snapshot -r /mnt /mnt/snap1
$ btrfs send /mnt/snap1 -f /tmp/1.snap
$ umount /mnt
$ mkfs.btrfs -f /dev/sdc
$ mount /dev/sdc /mnt
$ touch /mnt/a2
$ btrfs subvolume snapshot -r /mnt /mnt/snap2
$ btrfs receive /mnt -f /tmp/1.snap
# Take note that once the filesystem is created, its current
# generation has value 7 so the inode from the second snapshot has
# a generation value of 7. And after receiving the first snapshot
# the filesystem is at a generation value of 10, because the call to
# create the second snapshot bumps the generation to 8 (the snapshot
# creation ioctl does a transaction commit), the receive command calls
# the snapshot creation ioctl to create the first snapshot, which bumps
# the filesystem's generation to 9, and finally when the receive
# operation finishes it calls an ioctl to transition the first snapshot
# (snap1) from RW mode to RO mode, which does another transaction commit
# and bumps the filesystem's generation to 10.
$ rm -f /tmp/1.snap
$ btrfs send /mnt/snap1 -f /tmp/1.snap
$ btrfs send -p /mnt/snap1 /mnt/snap2 -f /tmp/2.snap
$ umount /mnt
$ mkfs.btrfs -f /dev/sdd
$ mount /dev/sdd /mnt
$ btrfs receive /mnt /tmp/1.snap
# Receive of snapshot snap2 used to fail.
$ btrfs receive /mnt /tmp/2.snap
Signed-off-by: Robbie Ko <robbieko@synology.com>
Reviewed-by: Filipe Manana <fdmanana@suse.com>
[Rewrote changelog to be more precise and clear]
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/btrfs/send.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -1640,6 +1640,9 @@ static int is_inode_existent(struct send
{
int ret;
+ if (ino == BTRFS_FIRST_FREE_OBJECTID)
+ return 1;
+
ret = get_cur_inode_state(sctx, ino, gen);
if (ret < 0)
goto out;
@@ -1825,7 +1828,7 @@ static int will_overwrite_ref(struct sen
* not delted and then re-created, if it was then we have no overwrite
* and we can just unlink this entry.
*/
- if (sctx->parent_root) {
+ if (sctx->parent_root && dir != BTRFS_FIRST_FREE_OBJECTID) {
ret = get_inode_info(sctx->parent_root, dir, NULL, &gen, NULL,
NULL, NULL, NULL);
if (ret < 0 && ret != -ENOENT)
next prev parent reply other threads:[~2017-10-19 13:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-19 13:49 [PATCH 3.18 00/27] 3.18.77-stable review Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 02/27] drm/dp/mst: save vcpi with payloads Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 03/27] ext4: avoid deadlock when expanding inode size Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 04/27] sctp: potential read out of bounds in sctp_ulpevent_type_enabled() Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 05/27] bpf/verifier: reject BPF_ALU64|BPF_END Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 06/27] packet: hold bind lock when rebinding to fanout hook Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 07/27] isdn/i4l: fetch the ppp_write buffer in one shot Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 08/27] vti: fix use after free in vti_tunnel_xmit/vti6_tnl_xmit Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 09/27] l2tp: Avoid schedule while atomic in exit_net Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 10/27] l2tp: fix race condition in l2tp_tunnel_delete Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 11/27] packet: in packet_do_bind, test fanout with bind_lock held Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 12/27] net: Set sk_prot_creator when cloning sockets to the right proto Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 13/27] Revert "bsg-lib: dont free job in bsg_prepare_job" Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 15/27] watchdog: kempld: fix gcc-4.3 build Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 16/27] irqchip/crossbar: Fix incorrect type of local variables Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 17/27] netfilter: nf_ct_expect: Change __nf_ct_expect_check() return value Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 18/27] iio: adc: xilinx: Fix error handling Greg Kroah-Hartman
2017-10-19 13:49 ` Greg Kroah-Hartman [this message]
2017-10-19 13:49 ` [PATCH 3.18 20/27] net/mlx4_core: Fix VF overwrite of module param which disables DMFS on new probed PFs Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 21/27] crypto: xts - Add ECB dependency Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 22/27] ocfs2/dlmglue: prepare tracking logic to avoid recursive cluster lock Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 23/27] scsi: scsi_dh_emc: return success in clariion_std_inquiry() Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 24/27] uapi: fix linux/rds.h userspace compilation errors Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 25/27] uapi: fix linux/mroute6.h " Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 26/27] target/iscsi: Fix unsolicited data seq_end_offset calculation Greg Kroah-Hartman
2017-10-19 13:49 ` [PATCH 3.18 27/27] Revert "tty: goldfish: Fix a parameter of a call to free_irq" Greg Kroah-Hartman
2017-10-20 13:04 ` [PATCH 3.18 00/27] 3.18.77-stable review Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171019134845.913674070@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=alexander.levin@verizon.com \
--cc=fdmanana@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robbieko@synology.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).