1 jbd2: fix block tag checksum verification brokenness
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 Al Viro complained of a ton of bogosity with regards to the jbd2 block
6 tag header checksum. This one checksum is 16 bits, so cut off the
7 upper 16 bits and treat it as a 16-bit value and don't mess around
8 with be32* conversions. Fortunately metadata checksumming is still
9 "experimental" and not in a shipping e2fsprogs, so there should be few
10 users affected by this.
12 Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
13 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
15 fs/jbd2/commit.c | 13 +++++++------
16 fs/jbd2/recovery.c | 11 +++++------
17 2 files changed, 12 insertions(+), 12 deletions(-)
19 diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
20 index 0f53946..e61d722 100644
21 --- a/fs/jbd2/commit.c
22 +++ b/fs/jbd2/commit.c
23 @@ -343,20 +343,21 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
25 struct page *page = bh->b_page;
30 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
33 sequence = cpu_to_be32(sequence);
34 addr = kmap_atomic(page);
35 - csum = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
37 - csum = jbd2_chksum(j, csum, addr + offset_in_page(bh->b_data),
39 + csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
41 + csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data),
45 - tag->t_checksum = cpu_to_be32(csum);
46 + /* We only have space to store the lower 16 bits of the crc32c. */
47 + tag->t_checksum = cpu_to_be16(csum32);
50 * jbd2_journal_commit_transaction
51 diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
52 index 626846b..d4851464 100644
53 --- a/fs/jbd2/recovery.c
54 +++ b/fs/jbd2/recovery.c
55 @@ -399,18 +399,17 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)
56 static int jbd2_block_tag_csum_verify(journal_t *j, journal_block_tag_t *tag,
57 void *buf, __u32 sequence)
59 - __u32 provided, calculated;
62 if (!JBD2_HAS_INCOMPAT_FEATURE(j, JBD2_FEATURE_INCOMPAT_CSUM_V2))
65 sequence = cpu_to_be32(sequence);
66 - calculated = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
68 - calculated = jbd2_chksum(j, calculated, buf, j->j_blocksize);
69 - provided = be32_to_cpu(tag->t_checksum);
70 + csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&sequence,
72 + csum32 = jbd2_chksum(j, csum32, buf, j->j_blocksize);
74 - return provided == cpu_to_be32(calculated);
75 + return tag->t_checksum == cpu_to_be16(csum32);
78 static int do_one_pass(journal_t *journal,