jbd2: Fix block tag checksum verification brokenness
Subsystems (2)
PATCH v2 1/1 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.
v2: Eliminate unnecessary variables and make it clear(er) which values are 32 bits wide.
--- fs/jbd2/commit.c | 12 ++++++------ fs/jbd2/recovery.c | 11 +++++------ 2 files changed, 11 insertions(+), 12 deletions(-)
fs/jbd2/commit.c +6 -6
@@ -343,20 +343,20 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, {struct page *page = bh->b_page;__u8 *addr; -__u32 csum; +__u32 csum32;if (!JBD2_HAS_INCOMPAT_FEATURE (j,JBD2_FEATURE_INCOMPAT_CSUM_V2 ))return ; sequence =cpu_to_be32 (sequence); addr =kmap_atomic (page); - csum =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, -sizeof (sequence)); - csum =jbd2_chksum (j, csum, addr +offset_in_page (bh->b_data), - bh->b_size); + csum32 =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, +sizeof (sequence)); + csum32 =jbd2_chksum (j, csum32, addr +offset_in_page (bh->b_data), + bh->b_size);kunmap_atomic (addr); - tag->t_checksum =cpu_to_be32 (csum); + tag->t_checksum =cpu_to_be16 (csum32); }/* * jbd2_journal_commit_transaction
fs/jbd2/recovery.c +5 -6
@@ -399,18 +399,17 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)static int jbd2_block_tag_csum_verify (journal_t *j,journal_block_tag_t *tag,void *buf,__u32 sequence) { -__u32 provided, calculated; +__u32 csum32;if (!JBD2_HAS_INCOMPAT_FEATURE (j,JBD2_FEATURE_INCOMPAT_CSUM_V2 ))return 1 ; sequence =cpu_to_be32 (sequence); - calculated =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, -sizeof (sequence)); - calculated =jbd2_chksum (j, calculated, buf, j->j_blocksize); - provided =be32_to_cpu (tag->t_checksum); + csum32 =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, +sizeof (sequence)); + csum32 =jbd2_chksum (j, csum32, buf, j->j_blocksize); -return provided ==cpu_to_be32 (calculated); +return tag->t_checksum ==cpu_to_be16 (csum32); } static int do_one_pass(journal_t *journal,
Quoted 11 lines · Darrick J. Wong
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.
v2: Eliminate unnecessary variables and make it clear(er) which values are 32 bits wide.
Reported-by Al Viro <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>
Quoted 5 lines · Darrick J. Wong
static void jbd2_block_tag_csum_set(journal_t *j,
journal_block_tag_t*tag, {+
tag->t_checksum=cpu_to_be16(csum32);
}
It wouldn't be a terrible idea to add a comment in these spots, since it is a bit non-obvious to use cpu_to_be16() on a 32-bit variable.
Cheers, Andreas
PATCH v3 1/1 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.
v2: Eliminate unnecessary variables and make it clear(er) which values are 32 bits wide.
v3: Add a comment about why we're only storing half of the crc32c.
--- fs/jbd2/commit.c | 13 +++++++------ fs/jbd2/recovery.c | 11 +++++------ 2 files changed, 12 insertions(+), 12 deletions(-)
fs/jbd2/commit.c +7 -6
@@ -343,20 +343,21 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag, {struct page *page = bh->b_page;__u8 *addr; -__u32 csum; +__u32 csum32;if (!JBD2_HAS_INCOMPAT_FEATURE (j,JBD2_FEATURE_INCOMPAT_CSUM_V2 ))return ; sequence =cpu_to_be32 (sequence); addr =kmap_atomic (page); - csum =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, -sizeof (sequence)); - csum =jbd2_chksum (j, csum, addr +offset_in_page (bh->b_data), - bh->b_size); + csum32 =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, +sizeof (sequence)); + csum32 =jbd2_chksum (j, csum32, addr +offset_in_page (bh->b_data), + bh->b_size);kunmap_atomic (addr); - tag->t_checksum =cpu_to_be32 (csum); +/* We only have space to store the lower 16 bits of the crc32c. */ + tag->t_checksum =cpu_to_be16 (csum32); }/* * jbd2_journal_commit_transaction
fs/jbd2/recovery.c +5 -6
@@ -399,18 +399,17 @@ static int jbd2_commit_block_csum_verify(journal_t *j, void *buf)static int jbd2_block_tag_csum_verify (journal_t *j,journal_block_tag_t *tag,void *buf,__u32 sequence) { -__u32 provided, calculated; +__u32 csum32;if (!JBD2_HAS_INCOMPAT_FEATURE (j,JBD2_FEATURE_INCOMPAT_CSUM_V2 ))return 1 ; sequence =cpu_to_be32 (sequence); - calculated =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, -sizeof (sequence)); - calculated =jbd2_chksum (j, calculated, buf, j->j_blocksize); - provided =be32_to_cpu (tag->t_checksum); + csum32 =jbd2_chksum (j, j->j_csum_seed, (__u8 *)&sequence, +sizeof (sequence)); + csum32 =jbd2_chksum (j, csum32, buf, j->j_blocksize); -return provided ==cpu_to_be32 (calculated); +return tag->t_checksum ==cpu_to_be16 (csum32); } static int do_one_pass(journal_t *journal,
Quoted 6 lines · Darrick J. Wong
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.
Quoted 7 lines
v2: Eliminate unnecessary variables and make it clear(er) which values are 32 bits wide.
v3: Add a comment about why we're only storing half of the crc32c.
Reported-by Al Viro <[email protected]>Signed-off-by Darrick J. Wong <[email protected]>
Thanks, applied.
- Ted