@@ -62,6 +62,8 @@ struct convert_context {
62
62
struct skcipher_request * req ;
63
63
struct aead_request * req_aead ;
64
64
} r ;
65
+ bool aead_recheck ;
66
+ bool aead_failed ;
65
67
66
68
};
67
69
@@ -82,6 +84,8 @@ struct dm_crypt_io {
82
84
blk_status_t error ;
83
85
sector_t sector ;
84
86
87
+ struct bvec_iter saved_bi_iter ;
88
+
85
89
struct rb_node rb_node ;
86
90
} CRYPTO_MINALIGN_ATTR ;
87
91
@@ -1370,10 +1374,13 @@ static int crypt_convert_block_aead(struct crypt_config *cc,
1370
1374
if (r == - EBADMSG ) {
1371
1375
sector_t s = le64_to_cpu (* sector );
1372
1376
1373
- DMERR_LIMIT ("%pg: INTEGRITY AEAD ERROR, sector %llu" ,
1374
- ctx -> bio_in -> bi_bdev , s );
1375
- dm_audit_log_bio (DM_MSG_PREFIX , "integrity-aead" ,
1376
- ctx -> bio_in , s , 0 );
1377
+ ctx -> aead_failed = true;
1378
+ if (ctx -> aead_recheck ) {
1379
+ DMERR_LIMIT ("%pg: INTEGRITY AEAD ERROR, sector %llu" ,
1380
+ ctx -> bio_in -> bi_bdev , s );
1381
+ dm_audit_log_bio (DM_MSG_PREFIX , "integrity-aead" ,
1382
+ ctx -> bio_in , s , 0 );
1383
+ }
1377
1384
}
1378
1385
1379
1386
if (!r && cc -> iv_gen_ops && cc -> iv_gen_ops -> post )
@@ -1757,6 +1764,8 @@ static void crypt_io_init(struct dm_crypt_io *io, struct crypt_config *cc,
1757
1764
io -> base_bio = bio ;
1758
1765
io -> sector = sector ;
1759
1766
io -> error = 0 ;
1767
+ io -> ctx .aead_recheck = false;
1768
+ io -> ctx .aead_failed = false;
1760
1769
io -> ctx .r .req = NULL ;
1761
1770
io -> integrity_metadata = NULL ;
1762
1771
io -> integrity_metadata_from_pool = false;
@@ -1768,6 +1777,8 @@ static void crypt_inc_pending(struct dm_crypt_io *io)
1768
1777
atomic_inc (& io -> io_pending );
1769
1778
}
1770
1779
1780
+ static void kcryptd_queue_read (struct dm_crypt_io * io );
1781
+
1771
1782
/*
1772
1783
* One of the bios was finished. Check for completion of
1773
1784
* the whole request and correctly clean up the buffer.
@@ -1781,6 +1792,15 @@ static void crypt_dec_pending(struct dm_crypt_io *io)
1781
1792
if (!atomic_dec_and_test (& io -> io_pending ))
1782
1793
return ;
1783
1794
1795
+ if (likely (!io -> ctx .aead_recheck ) && unlikely (io -> ctx .aead_failed ) &&
1796
+ cc -> on_disk_tag_size && bio_data_dir (base_bio ) == READ ) {
1797
+ io -> ctx .aead_recheck = true;
1798
+ io -> ctx .aead_failed = false;
1799
+ io -> error = 0 ;
1800
+ kcryptd_queue_read (io );
1801
+ return ;
1802
+ }
1803
+
1784
1804
if (io -> ctx .r .req )
1785
1805
crypt_free_req (cc , io -> ctx .r .req , base_bio );
1786
1806
@@ -1816,15 +1836,19 @@ static void crypt_endio(struct bio *clone)
1816
1836
struct dm_crypt_io * io = clone -> bi_private ;
1817
1837
struct crypt_config * cc = io -> cc ;
1818
1838
unsigned int rw = bio_data_dir (clone );
1819
- blk_status_t error ;
1839
+ blk_status_t error = clone -> bi_status ;
1840
+
1841
+ if (io -> ctx .aead_recheck && !error ) {
1842
+ kcryptd_queue_crypt (io );
1843
+ return ;
1844
+ }
1820
1845
1821
1846
/*
1822
1847
* free the processed pages
1823
1848
*/
1824
- if (rw == WRITE )
1849
+ if (rw == WRITE || io -> ctx . aead_recheck )
1825
1850
crypt_free_buffer_pages (cc , clone );
1826
1851
1827
- error = clone -> bi_status ;
1828
1852
bio_put (clone );
1829
1853
1830
1854
if (rw == READ && !error ) {
@@ -1845,6 +1869,22 @@ static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
1845
1869
struct crypt_config * cc = io -> cc ;
1846
1870
struct bio * clone ;
1847
1871
1872
+ if (io -> ctx .aead_recheck ) {
1873
+ if (!(gfp & __GFP_DIRECT_RECLAIM ))
1874
+ return 1 ;
1875
+ crypt_inc_pending (io );
1876
+ clone = crypt_alloc_buffer (io , io -> base_bio -> bi_iter .bi_size );
1877
+ if (unlikely (!clone )) {
1878
+ crypt_dec_pending (io );
1879
+ return 1 ;
1880
+ }
1881
+ clone -> bi_iter .bi_sector = cc -> start + io -> sector ;
1882
+ crypt_convert_init (cc , & io -> ctx , clone , clone , io -> sector );
1883
+ io -> saved_bi_iter = clone -> bi_iter ;
1884
+ dm_submit_bio_remap (io -> base_bio , clone );
1885
+ return 0 ;
1886
+ }
1887
+
1848
1888
/*
1849
1889
* We need the original biovec array in order to decrypt the whole bio
1850
1890
* data *afterwards* -- thanks to immutable biovecs we don't need to
@@ -2113,6 +2153,14 @@ static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
2113
2153
2114
2154
static void kcryptd_crypt_read_done (struct dm_crypt_io * io )
2115
2155
{
2156
+ if (io -> ctx .aead_recheck ) {
2157
+ if (!io -> error ) {
2158
+ io -> ctx .bio_in -> bi_iter = io -> saved_bi_iter ;
2159
+ bio_copy_data (io -> base_bio , io -> ctx .bio_in );
2160
+ }
2161
+ crypt_free_buffer_pages (io -> cc , io -> ctx .bio_in );
2162
+ bio_put (io -> ctx .bio_in );
2163
+ }
2116
2164
crypt_dec_pending (io );
2117
2165
}
2118
2166
@@ -2142,11 +2190,17 @@ static void kcryptd_crypt_read_convert(struct dm_crypt_io *io)
2142
2190
2143
2191
crypt_inc_pending (io );
2144
2192
2145
- crypt_convert_init (cc , & io -> ctx , io -> base_bio , io -> base_bio ,
2146
- io -> sector );
2193
+ if (io -> ctx .aead_recheck ) {
2194
+ io -> ctx .cc_sector = io -> sector + cc -> iv_offset ;
2195
+ r = crypt_convert (cc , & io -> ctx ,
2196
+ test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags ), true);
2197
+ } else {
2198
+ crypt_convert_init (cc , & io -> ctx , io -> base_bio , io -> base_bio ,
2199
+ io -> sector );
2147
2200
2148
- r = crypt_convert (cc , & io -> ctx ,
2149
- test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags ), true);
2201
+ r = crypt_convert (cc , & io -> ctx ,
2202
+ test_bit (DM_CRYPT_NO_READ_WORKQUEUE , & cc -> flags ), true);
2203
+ }
2150
2204
/*
2151
2205
* Crypto API backlogged the request, because its queue was full
2152
2206
* and we're in softirq context, so continue from a workqueue
@@ -2188,10 +2242,13 @@ static void kcryptd_async_done(void *data, int error)
2188
2242
if (error == - EBADMSG ) {
2189
2243
sector_t s = le64_to_cpu (* org_sector_of_dmreq (cc , dmreq ));
2190
2244
2191
- DMERR_LIMIT ("%pg: INTEGRITY AEAD ERROR, sector %llu" ,
2192
- ctx -> bio_in -> bi_bdev , s );
2193
- dm_audit_log_bio (DM_MSG_PREFIX , "integrity-aead" ,
2194
- ctx -> bio_in , s , 0 );
2245
+ ctx -> aead_failed = true;
2246
+ if (ctx -> aead_recheck ) {
2247
+ DMERR_LIMIT ("%pg: INTEGRITY AEAD ERROR, sector %llu" ,
2248
+ ctx -> bio_in -> bi_bdev , s );
2249
+ dm_audit_log_bio (DM_MSG_PREFIX , "integrity-aead" ,
2250
+ ctx -> bio_in , s , 0 );
2251
+ }
2195
2252
io -> error = BLK_STS_PROTECTION ;
2196
2253
} else if (error < 0 )
2197
2254
io -> error = BLK_STS_IOERR ;
@@ -3116,7 +3173,7 @@ static int crypt_ctr_optional(struct dm_target *ti, unsigned int argc, char **ar
3116
3173
sval = strchr (opt_string + strlen ("integrity:" ), ':' ) + 1 ;
3117
3174
if (!strcasecmp (sval , "aead" )) {
3118
3175
set_bit (CRYPT_MODE_INTEGRITY_AEAD , & cc -> cipher_flags );
3119
- } else if (strcasecmp (sval , "none" )) {
3176
+ } else if (strcasecmp (sval , "none" )) {
3120
3177
ti -> error = "Unknown integrity profile" ;
3121
3178
return - EINVAL ;
3122
3179
}
0 commit comments