add patch prevent-online-resize-with-backup-superblock
[ext4-patch-queue.git] / use-the-shash-api-correctly-for-crc32c
blobf0c621111559822ca53252a44fd2c0dbf4fe37fc
1 ext4: use the shash api correctly for crc32c
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 Since we're using the crypto shash API, let's use the full API to set
6 the seed and get the final checksum instead assuming the private data
7 structure layout in crc32c.ko to which we're not privy.
9 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/ext4.h       | 8 ++++++--
13  include/linux/jbd2.h | 8 ++++++--
14  2 files changed, 12 insertions(+), 4 deletions(-)
16 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
17 index 84255c0..a1e734d 100644
18 --- a/fs/ext4/ext4.h
19 +++ b/fs/ext4/ext4.h
20 @@ -1742,18 +1742,22 @@ static inline u32 ext4_chksum(struct ext4_sb_info *sbi, u32 crc,
21                 struct shash_desc shash;
22                 char ctx[4];
23         } desc;
24 +       __le32 out_crc;
25         int err;
27         BUG_ON(crypto_shash_descsize(sbi->s_chksum_driver)!=sizeof(desc.ctx));
29         desc.shash.tfm = sbi->s_chksum_driver;
30         desc.shash.flags = 0;
31 -       *(u32 *)desc.ctx = crc;
32 +       out_crc = cpu_to_le32(crc);
33 +       crypto_shash_setkey(desc.shash.tfm, (u8 *)&out_crc, sizeof(out_crc));
34 +       crypto_shash_init(&desc.shash);
36         err = crypto_shash_update(&desc.shash, address, length);
37         BUG_ON(err);
39 -       return *(u32 *)desc.ctx;
40 +       crypto_shash_final(&desc.shash, (u8 *)&out_crc);
41 +       return le32_to_cpu(~out_crc);
42  }
44  #ifdef __KERNEL__
45 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
46 index 704b9a5..ae365ca 100644
47 --- a/include/linux/jbd2.h
48 +++ b/include/linux/jbd2.h
49 @@ -1374,6 +1374,7 @@ static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
50                 struct shash_desc shash;
51                 char ctx[JBD_MAX_CHECKSUM_SIZE];
52         } desc;
53 +       __le32 out_crc;
54         int err;
56         BUG_ON(crypto_shash_descsize(journal->j_chksum_driver) >
57 @@ -1381,12 +1382,15 @@ static inline u32 jbd2_chksum(journal_t *journal, u32 crc,
59         desc.shash.tfm = journal->j_chksum_driver;
60         desc.shash.flags = 0;
61 -       *(u32 *)desc.ctx = crc;
62 +       out_crc = cpu_to_le32(crc);
63 +       crypto_shash_setkey(desc.shash.tfm, (u8 *)&out_crc, sizeof(out_crc));
64 +       crypto_shash_init(&desc.shash);
66         err = crypto_shash_update(&desc.shash, address, length);
67         BUG_ON(err);
69 -       return *(u32 *)desc.ctx;
70 +       crypto_shash_final(&desc.shash, (u8 *)&out_crc);
71 +       return le32_to_cpu(~out_crc);
72  }
74  /* Return most recent uncommitted transaction */