* [PATCH] jbd2: Fix block tag checksum verification brokenness
@ 2013-05-08 22:00 Darrick J. Wong
2013-05-08 23:03 ` Al Viro
0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2013-05-08 22:00 UTC (permalink / raw)
To: Al Viro
Cc: Andreas Dilger, Theodore Ts'o, linux-fsdevel@vger.kernel.org,
linux-ext4
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>
---
fs/jbd2/commit.c | 14 ++++++++------
fs/jbd2/recovery.c | 14 ++++++++------
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 750c701..e514fcd 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -343,20 +343,22 @@ 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;
+ __u16 crc;
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);
+ crc = csum32 & 0xFFFF;
- tag->t_checksum = cpu_to_be32(csum);
+ tag->t_checksum = cpu_to_be16(crc);
}
/*
* jbd2_journal_commit_transaction
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 626846b..1fa766c 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -399,18 +399,20 @@ 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;
+ __u16 provided, crc;
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);
+ crc = csum32 & 0xFFFF;
+ provided = be16_to_cpu(tag->t_checksum);
- return provided == cpu_to_be32(calculated);
+ return provided == crc;
}
static int do_one_pass(journal_t *journal,
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] jbd2: Fix block tag checksum verification brokenness
2013-05-08 22:00 [PATCH] jbd2: Fix block tag checksum verification brokenness Darrick J. Wong
@ 2013-05-08 23:03 ` Al Viro
0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2013-05-08 23:03 UTC (permalink / raw)
To: Darrick J. Wong
Cc: Andreas Dilger, Theodore Ts'o, linux-fsdevel@vger.kernel.org,
linux-ext4
On Wed, May 08, 2013 at 03:00:27PM -0700, Darrick J. Wong wrote:
> + crc = csum32 & 0xFFFF;
>
> - tag->t_checksum = cpu_to_be32(csum);
> + tag->t_checksum = cpu_to_be16(crc);
Simple cpu_to_be16(csum) will do - it'll convert the argument to __u16,
which will do exactly the same thing your & 0xFFFF is doing. Matter of
taste...
> + crc = csum32 & 0xFFFF;
> + provided = be16_to_cpu(tag->t_checksum);
>
> - return provided == cpu_to_be32(calculated);
> + return provided == crc;
I'd go for tag->t_checksum == cpu_to_be16(calculated) - less cluttered that
way, IMO. Again, a matter of taste. ACK, as far as correctness is concerned.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-05-08 23:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-08 22:00 [PATCH] jbd2: Fix block tag checksum verification brokenness Darrick J. Wong
2013-05-08 23:03 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).