Bug 93691 - Data loss/corruption occurs when attempting a btrfs clone from a non-ecryptfs folder to an ecryptfs mount
Summary: Data loss/corruption occurs when attempting a btrfs clone from a non-ecryptfs...
Status: NEW
Alias: None
Product: File System
Classification: Unclassified
Component: ecryptfs (show other bugs)
Hardware: All Linux
: P1 high
Assignee: fs_ecryptfs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-23 15:57 UTC by rocko
Modified: 2016-03-20 10:19 UTC (History)
2 users (show)

See Also:
Kernel Version: 3.19
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description rocko 2015-02-23 15:57:16 UTC
On a btrfs file system with a mounted ecryptfs folder, if you try to clone a file that is not in the ecryptfs folder into the ecryptfs folder (eg using cp --reflink=always or cp --reflink=auto), the clone operation reports success but the resulting higher file is zero bytes long and accessing its lower file results in an I/O error, ie the data in the copied file is completely lost.

This is especially an issue for any application using gnomevfs (eg nautilus), because the underlying libglib package automatically attempts a clone operation (since v2.36.4, anyway). Worse still, I've seen it completely lose the data when doing a move - it seems that does a copy (which produces the corrupted zero-byte file) then a delete operation on the original.

What seems to be happening is that the userspace application is calling the btrfs ioctl clone operation and passing the higher ecryptfs file as the target path, but by the time btrfs_ioctl_clone is called in the kernel the target file structure actually points to the lower ecryptfs file. So I suspect that ecryptfs is intervening at some point to convert the target from higher to lower. This means it works if you are cloning one file inside the ecryptfs mount to another file inside the same ecryptfs mount, but in this particular case it shouldn't do that.

There's more info at https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1305335 and in particular at https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/1305335/comments/20, where there's a test script that demonstrates the problem.
Comment 1 Tyler Hicks 2015-02-24 00:11:28 UTC
Thanks for the report rocko. I'll get this issue fixed in eCryptfs.

Note You need to log in before you can comment on or make changes to this bug.