Bug 1478039 - cache_check reports corrupt superblock on good cache_dump metadata
cache_check reports corrupt superblock on good cache_dump metadata
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: device-mapper-persistent-data (Show other bugs)
7.4
Unspecified Unspecified
unspecified Severity unspecified
: rc
: ---
Assigned To: Joe Thornber
Jakub Krysl
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-08-03 09:23 EDT by Jakub Krysl
Modified: 2018-04-10 09:18 EDT (History)
6 users (show)

See Also:
Fixed In Version: device-mapper-persistent-data-0.7.3-2.el7
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2018-04-10 09:17:29 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
dumped metadata (121.08 KB, text/plain)
2017-09-22 09:26 EDT, Jakub Krysl
no flags Details


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Product Errata RHEA-2018:0776 None None None 2018-04-10 09:18 EDT

  None (edit)
Description Jakub Krysl 2017-08-03 09:23:38 EDT
Description of problem:
When checking metadata dumped to file by cache_dump, cache_check reports corrupted superblock even though the metadata is completely fine - after restoring them back to device, cache_check reports no errors or corruptions.

[root@storageqe-21 cache]# cache_check /dev/mapper/vgtest-swapvol
examining superblock
examining mapping array
examining hint array
examining discard bitset
[root@storageqe-21 cache]# cache_dump /dev/mapper/vgtest-swapvol -o metadata
[root@storageqe-21 cache]# cache_check metadata
examining superblock
  superblock is corrupt
    bad checksum in superblock
[root@storageqe-21 cache]# cache_restore -i metadata -o /dev/mapper/vgtest-swapvol 
Restoring: [==================================================]   100%
[root@storageqe-21 cache]# cache_check /dev/mapper/vgtest-swapvol
examining superblock
examining mapping array
examining hint array
examining discard bitset


Version-Release number of selected component (if applicable):
0.7.0-0.1.rc6.el7

How reproducible:
100%

Steps to Reproduce:
1.get access to cache metadata
2.cache_dump $device -o $file
3.cache_check $file

Actual results:
examining superblock
  superblock is corrupt
    bad checksum in superblock

Expected results:
examining superblock
examining mapping array
examining hint array
examining discard bitset


Additional info:
Comment 2 Joe Thornber 2017-09-15 07:02:37 EDT
There are two metadata formats:

- The binary format that the kernel uses.
- An xml format that's generated by thin_dump and used by thin_restore.

thin_check runs on the binary metadata.  You are running it on the xml.
Comment 3 Jakub Krysl 2017-09-15 07:19:42 EDT
Joe,

this information is not stated in manpage nor in --help of thin_check / cache_check. So for user there is no way to know it and leads to confusion, as both sources simply state "metadata". So for now maybe just state "metadata in binary format" to quickly fix this.

Also what is the reasoning for it to work on file in binary format only?

Thanks
Comment 4 Joe Thornber 2017-09-15 07:40:52 EDT
The man pages for thin_dump and thin_restore both discuss the XML format.  Only these tools use the xml format.  thin_check is the equivalent of the fsck tool for filesystems; it checks the metadata that kernel is generating.

I'll update thin_check to print a helpful message if the superblock is corrupt, and it begins with "<superblock ..."
Comment 5 Joe Thornber 2017-09-15 10:24:11 EDT
This patch tries to spot accidental use of XML.

https://github.com/jthornber/thin-provisioning-tools/commit/b10d8d4440cc69e159e7db225dbbb5c21df7e5aa

New release in the next few days.
Comment 7 Jakub Krysl 2017-09-22 09:26:34 EDT
I found no change in cache_check behaviour, still reports bad checksum in superblock on cache_dumped correct metadata.
Attaching dumped metadata as a reference.

# cache_check -V
0.7.2-1.el7
# cache_check /dev/mapper/vgtest-swapvol
examining superblock
examining mapping array
examining hint array
examining discard bitset
# cache_dump /dev/mapper/vgtest-swapvol -o /tmp/metadata
# cache_check /tmp/metadata
examining superblock
  superblock is corrupt
    bad checksum in superblock
# cache_restore -i /tmp/metadata -o /dev/mapper/vgtest-swapvol
Restoring: [==================================================]   100%
# cache_check /dev/mapper/vgtest-swapvol
examining superblock
examining mapping array
examining hint array
examining discard bitset
Comment 8 Jakub Krysl 2017-09-22 09:26 EDT
Created attachment 1329584 [details]
dumped metadata
Comment 9 Joe Thornber 2017-10-04 09:07:34 EDT
It's correct to say there's a bad checksum in the superblock, you've given it XML after all.  It's not crashing as some tools were when given an XML file.

I'm not going to make any further changes.
Comment 10 Marian Csontos 2017-10-05 08:31:39 EDT
The patch in Comment 5 is modifying only thin_check. And the test suite suggests it is correct. The same change in other tools would be helpful.

See pull request https://github.com/jthornber/thin-provisioning-tools/pull/86

BTW, I also noticed other *_check tools are checking magic number and version, size, etc, but seems to me thin_check is not. Shall I open an issue or BZ?
Comment 11 Jakub Krysl 2017-10-09 10:29:04 EDT
Tested device-mapper-persistent-data-0.7.0-0.1.rc6.el7.x86_64 ('before') vs device-mapper-persistent-data-0.7.3-1.el7.x86_64 ('after').

before:
# thin_dump /dev/mapper/vgtest-swapvol -o meta
# thin_check meta
examining superblock
  superblock is corrupt
    block out of bounds (0 >= 0)

after:
# thin_dump /dev/mapper/vgtest-swapvol -o meta
# thin_check meta
Metadata device/file too small.  Is this binary metadata?


before:
# cache_dump /dev/mapper/vgtest-swapvol -o meta
# cache_check meta
examining superblock
  superblock is corrupt
    bad checksum in superblock

after:
# cache_dump /dev/mapper/vgtest-swapvol -o meta
# cache_check meta
examining superblock
  superblock is corrupt
    bad checksum in superblock

It looks like it does not get to check_for_xml() as the return is not "This looks like XML.  thin_check only checks the binary metadata format." but "Metadata device/file too small.  Is this binary metadata?" even though the file starts with '<superblock'. I checked the code and to get past the size 'return FATAL;' I tried creating 20MB random file with dd and added '<superblock' to the beginning:
# thin_check metadata
examining superblock
  superblock is corrupt
    bad checksum in superblock, wanted 105687546
This looks like XML.  thin_check only checks the binary metadata format.

This time I got to check_for_xml() and it returned True, but only for thin_check. So not even thin_check is fixed in 0.7.3-1, and I can't see any change to cache_check. Marian is your patch in 0.7.3-1?

Sorry, I can't in good conscience set this to VERIFIED as of yet.
Comment 12 Marian Csontos 2017-10-09 11:43:27 EDT
There were two issues:

1. tools could segfault with small metadata, and
2. unexpected XML input resulted in cryptic error.

Small metadata issue: a whole block is expected and if size is smaller than the minimum expected, there is no parsing and error is reported straight away.

Only if size is at least one block, the super-block is parsed. And only if parsing fails, it is checked if it is XML.

It would be possible to check XML if input is too small, but IMHO this is very unlikely to ever happen in production and both issues are fixed with reasonable message.
Comment 13 Jakub Krysl 2017-10-10 05:19:07 EDT
Fixed in device-mapper-persistent-data-0.7.3-2.el7.

# cache_check meta
examining superblock
  superblock is corrupt
    bad checksum in superblock
This looks like XML.  cache_check only checks the binary metadata format.

FYI: There is different behaviour between cache_check and thin_check:
# thin_dump /dev/mapper/vgtest-swapvol -o meta
# thin_check meta
Metadata device/file too small.  Is this binary metadata?

As this bug is about cache_check and it is fixed, setting to verified.
Comment 16 errata-xmlrpc 2018-04-10 09:17:29 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:0776

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