Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes, there's the need to delete a file in a filesystem, and make sure that the file is truly gone. A file that contains sensitive passwords, for example, should be throughly wiped from the disk.

Issuing a simple rm on a typical file system deletes the inode ("pointer") to the file, but it doesn't delete the file's content in the physical disk - these are left there until they are overwriten when the filesystem needs the free space.

On many file systems, the shred program enables such secure deletion. However, on a CoW filesystem such as btrfs, this approach is useless. The problem is exacerbated by the fact that the file may be present on volume snapshots.

Is there a way to securely delete a file on a btrfs filesystem? Is it sufficient to delete all pointers (on all volumes) and fill the free space with zeros?

share|improve this question
2  
Good question, I haven't thought of that issue before. One way to work around that issue would be to encrypt such files. You also may encrypt the whole disk but if an attacker gains root access to the running system, that won't help you... –  mreithub Jan 24 '13 at 1:36
    
@mreithub Indeed, encrypting such files is always a good idea in the first place, as is FDE. It cannot contemplate all use cases, though (a embedded system, for example - though it is arguable if such a system would be running btrfs anyway...). I'm actually asking this because I forgot to setup encryption before copying sensitive files, but I'd like to avoid wiping the whole partition –  goncalopp Jan 24 '13 at 13:57

3 Answers 3

Secure deletion is a tough proposition on any filesystem. Unless the filesystem is very peculiar and guarantees that there aren't other copies of the file lying around, you need to clear all the free space on the device. While you are more likely to find many bits of the file on copy-on-write filesystems, even more “static” filesystems don't have this guarantee in practice, because many files get edited, so there are bit from former versions of the file lying around.

Note that erasing with zeroes is as good as erasing with random bytes, and you don't need multiple passes. Erasing with zeroes left residual data that could be partially recovered in lab conditions with 1980's hard disk technologies; this is no longer applicable today. See Why is writing zeros (or random data) over a hard drive multiple times better than just doing it once?

You can get rid of the cleartext confidential data by encrypting everything on the disk. Set up an ecryptfs volume over that filesystem and move all your (confidential) files to it. Then overwrite all the unused space of the filesystem. You can erase most of it by filling the filesystem with cat /dev/zero >zero. There may still be some information left in incomplete blocks (blocks that contain the last chunk of a file, followed by some garbage — which could be leftovers from a confidential file). To ensure that there are no incomplete blocks, move everything on the filesystem to ecryptfs (ecryptfs's files use whole blocks, at least on typical setups where blocks are 4kB). Make sure to apply this to all volumes and to erase all snapshots containing plaintext confidential data.

There may still be some information left in the journal. I don't know how to scrub that.

On SSD, due to block reallocation, there may be data left that can't be read by normal software means but may be recovered by hacking the firmware or with physical access. There your only recourse is a full wipe of the SSD.

share|improve this answer
1  
Zeroes have the disadvantage that they can be compressed or entirely omitted (a SSD may TRIM instead of writing zeroes, as TRIM'd sectors return zeroes when you read them). That makes zeroes unsafe nowadays. Using random data forces the filesystem and disk to actually write out the data as is. –  frostschutz Feb 3 '13 at 17:37

Hmmm, btrfs seems to defeat all usual shredding methods...

  • There is a mount option called nodatacow but that doesn't seem to affect already existing files.
  • As you already have sensible files on your disk this btrfs FAQ entry won't help you either.
  • Then there's debugfs. It's only for ext filesystems but there's a patch for it that might work. You could use it to find out the affected block addresses and then overwrite them directly on /dev/sdXY. But that's very dangerous and might not work (especially if there are more snapshots of the file)
  • Write a btrfs patch that allows one to modifiy (or shred) specific snapshots or a whole file
  • The cleanest attempt (for really really sensitive data) would be to:

    • buy another disk (unless you've got enough free space for a copy of the affected partition on the first one)
    • setup full disk encryption and your file systems on it
    • copy everything from disk a to b
    • boot into system b and shred the whole disk a...

    This might not be the cheapest approach but considering today's low storage costs and the trouble you'd have with the other options it might actually be the cheapest one (in terms of labor hours).

share|improve this answer

There is shred(1) for Unix/Linux (should be in your distribution's packages). I's what the EFF recommends.

share|improve this answer
3  
If you double-check the question, you'll see that I mentioned shred, and why it's not enough for the job –  goncalopp Jan 24 '13 at 13:54
    
All I find are suggestions to use encryption of sensitive files, for the reason you mention. –  vonbrand Jan 24 '13 at 14:08
2  
"On many file systems, the shred program enables such secure deletion. However, on a CoW filesystem such as btrfs, this approach is useless.". There's two links there, too. –  goncalopp Jan 24 '13 at 14:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.