diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2013-05-28 07:31:59 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-05-28 07:31:59 -0400 |
commit | eee06c56784496805b198964c59fa8cd7c00bf48 (patch) | |
tree | cbdfeadc9a0ee81b83ef012f81dcae1acb0f660f | |
parent | 5d9cf9c6254ddc551fb51072f59dfae60e579736 (diff) |
jbd2: fix block tag checksum verification brokenness
Al Viro complained of a ton of bogosity with regards to the jbd2 block
tag header checksum. This one checksum is 16 bits, so cut off the
upper 16 bits and treat it as a 16-bit value and don't mess around
with be32* conversions. Fortunately metadata checksumming is still
"experimental" and not in a shipping e2fsprogs, so there should be few
users affected by this.
Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r-- | fs/jbd2/commit.c | 13 | ||||
-rw-r--r-- | fs/jbd2/recovery.c | 11 |
2 files changed, 12 insertions, 12 deletions
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 0f53946f13c1..e61d7224a729 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c | |||
@@ -343,20 +343,21 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, | |||
343 | { | 343 | { |
344 | struct page *page = bh->b_page; | 344 | struct page *page = bh->b_page; |
345 | __u8 *addr; | 345 | __u8 *addr; |
346 | __u32 csum; | 346 | __u32 csum32; |
347 | 347 | ||
348 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) | 348 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) |
349 | return; | 349 | return; |
350 | 350 | ||
351 | sequence = cpu_to_be32(sequence); | 351 | sequence = cpu_to_be32(sequence); |
352 | addr = kmap_atomic(page); | 352 | addr = kmap_atomic(page); |
353 | csum = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence, | 353 | csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence, |
354 | sizeof(sequence)); | 354 | sizeof(sequence)); |
355 | csum = jbd2_chksum(j, csum, addr + offset_in_page(bh->b_data), | 355 | csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data), |
356 | bh->b_size); | 356 | bh->b_size); |
357 | kunmap_atomic(addr); | 357 | kunmap_atomic(addr); |
358 | 358 | ||
359 | tag->t_checksum = cpu_to_be32(csum); | 359 | /* We only have space to store the lower 16 bits of the crc32c. */ |
360 | tag->t_checksum = cpu_to_be16(csum32); | ||
360 | } | 361 | } |
361 | /* | 362 | /* |
362 | * jbd2_journal_commit_transaction | 363 | * jbd2_journal_commit_transaction |
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index 626846bac32f..d4851464b57e 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c | |||
@@ -399,18 +399,17 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf) | |||
399 | static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, | 399 | static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag, |
400 | void *buf, __u32 sequence) | 400 | void *buf, __u32 sequence) |
401 | { | 401 | { |
402 | __u32 provided, calculated; | 402 | __u32 csum32; |
403 | 403 | ||
404 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) | 404 | if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2)) |
405 | return 1; | 405 | return 1; |
406 | 406 | ||
407 | sequence = cpu_to_be32(sequence); | 407 | sequence = cpu_to_be32(sequence); |
408 | calculated = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence, | 408 | csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence, |
409 | sizeof(sequence)); | 409 | sizeof(sequence)); |
410 | calculated = jbd2_chksum(j, calculated, buf, j->j_blocksize); | 410 | csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize); |
411 | provided = be32_to_cpu(tag->t_checksum); | ||
412 | 411 | ||
413 | return provided == cpu_to_be32(calculated); | 412 | return tag->t_checksum == cpu_to_be16(csum32); |
414 | } | 413 | } |
415 | 414 | ||
416 | static int do_one_pass(journal_t *journal, | 415 | static int do_one_pass(journal_t *journal, |