przemoc / metastore

Store and restore metadata from a filesystem.
http://software.przemoc.net/#metastore
GNU General Public License v2.0
169 stars 31 forks source link

Reading metadata file with xattrs leads to corruption in memory on 64-bit platforms #45

Closed asmpro closed 6 years ago

asmpro commented 6 years ago

Hi.

After trying to apply xattrs using metastore -a -v -f /somedir/metafile /sourcedir, I get the following errors:

./test/test1/vzd_test:  adding xattr system.posix_acl_default
        lsetxattr failed: Bad address

strace reports this:

lsetxattr("./test/test1/vzd_test", "system.posix_acl_default", 0x148, 52, XATTR_CREATE) = -1 EFAULT (Bad address)
lsetxattr("./test/test1/vzd_test", "system.posix_acl_default", 0x148, 52, XATTR_REPLACE) = -1 EFAULT (Bad address)

If you wonder what second lsetxattr() with XATTR_REPLACE is doing after the first one, I must admit I patched original metastore.c by adding second lsetxattr in case of error in the first call, but it doesn,t help.

File system is ext4, mounted with both acl and user_xattr:

/dev/sda1 on /mnt/disk type ext4 (rw,user_xattr,acl)

Apply is being done on the same filesystem as save.

I am using the latest git clone.

Regards, Uros

przemoc commented 6 years ago

Thanks for reporting the issue, @asmpro.

(I slightly reformatted your first comment for better readability and along the way included information that you provided in second comment, so everything is in one place, and I could delete second comment as no longer needed.)

I'll be out of town starting tomorrow, so I apologize if I won't deal with the problem as swiftly as I should.

From your strace dump at least one argument provided to lsetxattr() seems wrong and that's why you got EFAULT.

int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags);

3rd value should be the address of value data, but 0x148 doesn't seem to be it.

Could you provide 2 dumps?

It should help a bit.

asmpro commented 6 years ago

Interesting first command produces segmentation fault:

# metastore -d -f test/metadata
-rwxrwxrwx      nobody  nobody  2017-11-21 09:25:31.000000000 +0100     ./test/test1/Thumbs.db
                                ./test/test1/Thumbs.db  system.posix_acl_access=0x0200000001000700ffffffff020007006300000004000700ffffffff080007006300000010000700ffffffff20000700ffffffff
                                ./test/test1/Thumbs.db  user.DOSATTRIB=0x307832360000030003000000110000002600000000000000000000000000000000000000000000006682b14e74f0d0010000000000000000
                                ./test/test1/Thumbs.db  user.SAMBA_PAI=0x020480050000000001630000000000630000000000630000000001630000000002ffffffff
                                ./test/test1/Thumbs.db  security.NTACL=0x040004000000020004000200010026165c589ffc5aef3a5befbc0f32bbb13ef92e5c05ce14daf4bc3f2ced0d86050000000000000000000000000000000000000000000000000000000000000000706f7369785f61636c0094e8b14e74f0d001acbd9ba3edac8b1bca75692e81296e71295a3ad4fe8afda49b7afdaa12b5d8a2000000000000000000000000000000000000000000000000000000000000000001000480b4000000c400000000000000d4000000010200000000001601000000630000000102000000000016020000006300000002004c000300000000001800ff011f000102000000000016010000006300000000001800ff011f000102000000000016020000006300000000001400ff011f00010100000000000100000000
-rwxrwxrwx      nobody  nobody  2015-08-26 10:25:40.000000000 +0200     ./test/test1/010626_010629.pdf
                                ./test/test1/010626_010629.pdf  system.posix_acl_access=0x0200000001000700ffffffff020007006300000004000700ffffffff080007006300000010000700ffffffff20000700ffffffff
                                ./test/test1/010626_010629.pdf  user.DOSATTRIB=0x30783230000003000300000011000000200000000000000000000000000000000000000000000000c18a96d6d8dfd0010000000000000000
                                ./test/test1/010626_010629.pdf  user.SAMBA_PAI=0x020480050000000001630000000000630000000000630000000001630000000002ffffffff
                                ./test/test1/010626_010629.pdf  security.NTACL=0x040004000000020004000200010026165c589ffc5aef3a5befbc0f32bbb13ef92e5c05ce14daf4bc3f2ced0d86050000000000000000000000000000000000000000000000000000000000000000706f7369785f61636c006cf096d6d8dfd001acbd9ba3edac8b1bca75692e81296e71295a3ad4fe8afda49b7afdaa12b5d8a2000000000000000000000000000000000000000000000000000000000000000001000480b4000000c400000000000000d4000000010200000000001601000000630000000102000000000016020000006300000002004c000300000000001800ff011f000102000000000016010000006300000000001800ff011f000102000000000016020000006300000000001400ff011f00010100000000000100000000
drwxrwxrwx      nobody  nobody  2017-11-23 16:17:20.000000000 +0100     ./test/test1/vzdrzevanje/
Segmentation fault

Same thing in gdb, produces the following:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004016e2 in mentries_dump (mhash=0x606010) at ./src/metaentry.c:668
668                                             if ((unsigned)(ch - 32) > 126 - 32) {
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.209.el6_9.2.x86_64 libbsd-0.6.0-1.el6.x86_64
(gdb) bt
#0  0x00000000004016e2 in mentries_dump (mhash=0x606010) at ./src/metaentry.c:668
#1  0x00000000004034e7 in main (argc=4, argv=0x7fffffffe648) at ./src/metastore.c:554

Result of the second:

# metastore -d test/test1-orig/vzd_test/
drwxrwxrwx      nobody  nobody  2017-08-31 15:19:20.000000000 +0200     ./test/test1-orig/vzd_test/
                                ./test/test1-orig/vzd_test/     system.posix_acl_default=0x0200000001000700ffffffff020007006300000004000700ffffffff080007006300000010000700ffffffff20000700ffffffff
                                ./test/test1-orig/vzd_test/     user.DOSATTRIB=0x3078313000000300030000001100000010000000000000000000000000000000000000000000000090c09cc15b22d3010000000000000000
                                ./test/test1-orig/vzd_test/     user.SAMBA_PAI=0x020480050005000001630000000000630000000000630000000001630000000002ffffffff0001630000000000630000000b00630000000b01630000000302ffffffff
                                ./test/test1-orig/vzd_test/     system.posix_acl_access=0x0200000001000700ffffffff020007006300000004000700ffffffff080007006300000010000700ffffffff20000700ffffffff
                                ./test/test1-orig/vzd_test/     security.NTACL=0x0400040000000200040002000100975c58781050e32143f79906a1c82fb22ae24f983630cc00f52544363ce050f60000000000000000000000000000000000000000000000000000000000000000706f7369785f61636c009c7d9fc15b22d30188a46169800b709c2608f666b748b2b1116f874f132ac58eebb02c717fd08c41000000000000000000000000000000000000000000000000000000000000000001000480b4000000c400000000000000d40000000102000000000016010000006300000001020000000000160200000063000000020074000500000000001800ff011f0001020000000000160100000063000000000b1400ff011f0001010000000000030000000000001800ff011f0001020000000000160200000063000000000b1400ff011f0001010000000000030100000000031400ff011f00010100000000000100000000

Regards, Uros

przemoc commented 6 years ago

Thanks for update. (Had to reformat your comment - next time use tildes (~~~) instead of backticks (`) if you want to have properly displayed dump.)

The segfault is possibly manifestation of the same problem that you've seen during applying (EFAULT) - metadata seems to be corrupted, not sure yet if in file or during/after reading.

przemoc commented 6 years ago

I found corruption happening during reading metadata file.

My recent commit 5b060d5b7f0d76ee5c8626d34747cf605dd81e13 should fix the problem. Unless there are more problems to be unveiled...

If you attempted applying previously stored metadata with extended attributes entries, there is possibility that your metadata on disk is corrupted now too (mostly xattrs). As long as you didn't store it again and overwritten original metadata file, you can use it to apply metadata and things should get back to better state.

I am deeply sorry that such a serious bug was present in metastore for so long.

asmpro commented 6 years ago

Thanks for the info about the formatting. Your patch seems to have fixed the issue. Generated metadata is of course the same (save command), but now apply command works as expected. Thank you for quick fix of the problem :)

Regards, Uros

przemoc commented 6 years ago

Thanks for confirming that the issue is solved. Closing.

przemoc commented 6 years ago

For the sake of completeness, let me link to the archive of the mail that has been sent to metastore-announce ML subscribers today:

https://www.freelists.org/post/metastore-announce/Serious-xattrrelated-bug-in-metastore-v110