file corruption on ext3 filesystem.
Hello.
I'm experiencing file corruption problem.
Can somebody reproduce below result?
My environment:
VMware Workstation 6.5.3 with 2CPUs / 512MB RAM. ext3 filesystem ( /dev/sda1 ) mounted on / .
2.6.33-rc3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.33-rc3-ext3 )
2.6.32.3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.32.3-ext3 )
2.6.31.11 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.31.11-ext3 ) 2.6.30.10
So far, I haven't succeeded to reproduce this problem for 2.6.29 and earlier. Maybe this problem exists in only 2.6.30 and later.
Steps to reproduce:
Compile below program using "gcc -Wall -O3 -o a.out".
----------
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
FILE *fp = fopen("/testfile", "a");
char buffer[4096];
memset(buffer, argc > 1 ? argv[1][0] : 0x20, sizeof(buffer));
buffer[sizeof(buffer) - 1] = '\n';
fwrite(buffer, 1, sizeof(buffer), fp);
fflush(fp);
sleep(5);
fprintf(stderr, "Let power fail after a few seconds.\n");
while (1) {
sleep(1);
fwrite(buffer, 1, sizeof(buffer), fp);
}
return 0;
}----------
Reboot the system by executing /sbin/reboot .
Run ./a.out and let the power fail (i.e. unplug the electric cable or do equivalent) after more than 5 seconds (i.e. longer than kjournald's commit interval). Probably 2 or 3 seconds after
"Let power fail after a few seconds.\n" was printed is the best.
Restart the system (and fsck will be executed).
Run "cat /testfile". It should contain only lines of 4095 spaces + '\n' (or the byte specified via argv[]). But it contains different data.
This problem does not show up if the data written by ./a.out and the data in previously deleted files are identical. Therefore, you may want to try with different patterns like "./a.out 1" "./a.out 2" "./a.out 3" ...
Regards.
Quoted 7 lines · Tetsuo Handa
VMware Workstation 6.5.3 with 2CPUs / 512MB RAM. ext3 filesystem (
/dev/sda1) mounted on / .Run ./a.out and let the power fail (i.e. unplug the electric cable or do equivalent) after more than 5 seconds (i.e. longer than kjournald's commit interval). Probably 2 or 3 seconds after
"Let power fail after a few seconds.\n" was printed is the best.
It could be a kernel problem, but it could also be caused by VMware.
The combination of journalling, barriers, committing data safely to disk and VMs is complicated and does not always provide filesystem integrity on power failure, depending on many factors.
However, if you see corruption only with 2.6.30 and later, but not with 2.6.29, that does suggest a kernel problem.
-- Jamie
Quoted 9 lines · Tetsuo Handa
Hello.
I'm experiencing file corruption problem.
Can somebody reproduce below result?My environment:
VMware Workstation 6.5.3 with 2CPUs / 512MB RAM. ext3 filesystem (/dev/sda1) mounted on / .
Quoted 7 lines
2.6.33-rc3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.33-rc3-ext3 )
2.6.32.3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.32.3-ext3 )
2.6.31.11 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.31.11-ext3 ) 2.6.30.10So far, I haven't succeeded to reproduce this problem for 2.6.29 and earlier. Maybe this problem exists in only 2.6.30 and later.
Isn't that when the default mount options changed from data=ordered to data=writeback?
Quoted 34 lines
Steps to reproduce:
Compile below program using "gcc -Wall -O3 -o a.out".
----------
#include <stdio.h>
#include <string.h>
#include <unistd.h>int
main(int argc, char *argv[]){ FILE *fp = fopen("/testfile", "a"); char buffer[4096]; memset(buffer, argc > 1 ? argv[1][0] : 0x20, sizeof(buffer)); buffer[sizeof(buffer) - 1] = '\n'; fwrite(buffer, 1, sizeof(buffer), fp); fflush(fp); sleep(5); fprintf(stderr, "Let power fail after a few seconds.\n"); while (1) { sleep(1); fwrite(buffer, 1, sizeof(buffer), fp); } return 0; }----------
Reboot the system by executing
/sbin/reboot.Run ./a.out and let the power fail (i.e. unplug the electric cable or do equivalent) after more than 5 seconds (i.e. longer than kjournald's commit interval). Probably 2 or 3 seconds after
"Let power fail after a few seconds.\n" was printed is the best.
Quoted 4 lines
Restart the system (and fsck will be executed).
Run "cat /testfile". It should contain only lines of 4095 spaces + '\n' (or the byte specified via argv[]). But it contains different data.
You didn't fsync() it, so there is no reason for the kernel to have ever written it to disk. Therefore the result after powerfail is completely undefined - you data may be there, it may not...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Hello.
Quoted 13 lines · Dave Chinner
Quoted 12 lines · Tetsuo Handa
I'm experiencing file corruption problem.
Can somebody reproduce below result?My environment:
VMware Workstation 6.5.3 with 2CPUs / 512MB RAM. ext3 filesystem (/dev/sda1) mounted on / .2.6.33-rc3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.33-rc3-ext3 )
2.6.32.3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.32.3-ext3 )
2.6.31.11 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.31.11-ext3 ) 2.6.30.10
Quoted 5 lines
Quoted 2 lines
So far, I haven't succeeded to reproduce this problem for 2.6.29 and earlier. Maybe this problem exists in only 2.6.30 and later.
Isn't that when the default mount options changed from data=ordered to data=writeback?
Ah, indeed. 2.6.31 mounts data=writeback whereas 2.6.29 mounts data=ordered.
In my Ubuntu 9.10 environment, it is using data=writeback mode, and therefore I got garbage data taken from other deleted files.
Quoted 3 lines
You didn't
fsync()it, so there is no reason for the kernel to have ever written it to disk. Therefore the result after powerfail is completely undefined - you data may be there, it may not...
I didn't call fsync(). Thus, I don't mind if the data I wrote is not written to disk.
However, I feel something is very wrong because the file got data which I didn't write. The file gets data from deleted files. Imagine that unprivileged user can get the content of /etc/shadow if power failure occurred when the user was running ./a.out .
The file should not get data from deleted files, but I can read the data from deleted files by "cat /testfile". I feel something is very wrong.
Regards.
Quoted 24 lines · Tetsuo Handa
Quoted 13 lines · Dave Chinner
Quoted 12 lines · Tetsuo Handa
I'm experiencing file corruption problem.
Can somebody reproduce below result?My environment:
VMware Workstation 6.5.3 with 2CPUs / 512MB RAM. ext3 filesystem (/dev/sda1) mounted on / .2.6.33-rc3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.33-rc3-ext3 )
2.6.32.3 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.32.3-ext3 )
2.6.31.11 ( http://I-love.SAKURA.ne.jp/tmp/config-2.6.31.11-ext3 ) 2.6.30.10Quoted 5 lines
Quoted 2 lines
So far, I haven't succeeded to reproduce this problem for 2.6.29 and earlier. Maybe this problem exists in only 2.6.30 and later.
Isn't that when the default mount options changed from data=ordered to data=writeback?
Ah, indeed. 2.6.31 mounts data=writeback whereas 2.6.29 mounts data=ordered.
In my Ubuntu 9.10 environment, it is using data=writeback mode, and therefore I got garbage data taken from other deleted files.
Quoted 6 lines
Quoted 3 lines
You didn't
fsync()it, so there is no reason for the kernel to have ever written it to disk. Therefore the result after powerfail is completely undefined - you data may be there, it may not...I didn't call
fsync(). Thus, I don't mind if the data I wrote is not written to disk.
Ok, I was making sure you weren't misunderstanding what the fflush() is supposed to guarantee - many people do, but you're not one of them :)
Quoted 4 lines
However, I feel something is very wrong because the file got data which I didn't write. The file gets data from deleted files. Imagine that unprivileged user can get the content of
/etc/shadowif power failure occurred when the user was running ./a.out .
Ah, so it was stale data you were seeing.
Quoted 2 lines
The file should not get data from deleted files, but I can read the data from deleted files by "cat /testfile". I feel something is very wrong.
I agree that it is very wrong, but it's a known problem with writeback mode in ext3:
http://thread.gmane.org/gmane.linux.kernel/818044/focus=819977
More info as to how this change came about and the proposed but not yet realised fixes:
http://lwn.net/Articles/328363/
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 9 lines · Dave Chinner
I agree that it is very wrong, but it's a known problem with writeback mode in ext3:
http://thread.gmane.org/gmane.linux.kernel/818044/focus=819977
More info as to how this change came about and the proposed but not yet realised fixes:
Thank you for the pointer.
Indeed, most Linux boxes are used by single user.
But implicitly importing other deleted file's data is still annoying even if the box is used by only one user.
When I was trying to identify the steps to reproduce, I got ./a.out replaced by the deleted .bash_history due to power failure. I executed ./a.out as root without knowing that the file contains deleted .bash_history , and many commands listed in deleted .bash_history are executed as root.
I thought my box was cracked and trojaned. :-(
Quoted 18 lines · Tetsuo Handa
Quoted 10 lines · Dave Chinner
I agree that it is very wrong, but it's a known problem with writeback mode in ext3:
http://thread.gmane.org/gmane.linux.kernel/818044/focus=819977
More info as to how this change came about and the proposed but not yet realised fixes:
Thank you for the pointer.
Indeed, most Linux boxes are used by single user.
But implicitly importing other deleted file's data is still annoying even if the box is used by only one user.
Quoted 6 lines
When I was trying to identify the steps to reproduce, I got ./a.out replaced by the deleted .bash_history due to power failure. I executed ./a.out as root without knowing that the file contains deleted .bash_history , and many commands listed in deleted .bash_history are executed as root.
I thought my box was cracked and trojaned. :-(
Fedora and some other distributions changed the default back to data ordered mode in order to avoid exactly this kind of mess. Even if you are on a single user system, this behavior is certainly unexpected for most users :-)
Ric
Hi!
Quoted 14 lines
Quoted 8 lines
Quoted 2 lines
Thank you for the pointer.
Indeed, most Linux boxes are used by single user.
But implicitly importing other deleted file's data is still annoying even if the box is used by only one user.Quoted 5 lines
When I was trying to identify the steps to reproduce, I got ./a.out replaced by the deleted .bash_history due to power failure. I executed ./a.out as root without knowing that the file contains deleted .bash_history , and many commands listed in deleted .bash_history are executed as root.
I thought my box was cracked and trojaned. :-(
Quoted 4 lines
Fedora and some other distributions changed the default back to data ordered mode in order to avoid exactly this kind of mess. Even if you are on a single user system, this behavior is certainly unexpected for most users :-)
Also there's config option to get back the old behaviour.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html