]> www.infradead.org Git - linux.git/commitdiff
dm-verity: do forward error correction on metadata I/O errors
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 17 Feb 2025 21:36:02 +0000 (22:36 +0100)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 24 Feb 2025 11:09:41 +0000 (12:09 +0100)
Do forward error correction if metadata I/O fails.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
drivers/md/dm-verity-target.c

index e86c1431b108f86ad981c06083097a16f4c64409..fc5ae123670be7e7b2eecde38184959be734da33 100644 (file)
@@ -311,7 +311,7 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
 
        if (static_branch_unlikely(&use_bh_wq_enabled) && io->in_bh) {
                data = dm_bufio_get(v->bufio, hash_block, &buf);
-               if (data == NULL) {
+               if (IS_ERR_OR_NULL(data)) {
                        /*
                         * In tasklet and the hash was not in the bufio cache.
                         * Return early and resume execution from a work-queue
@@ -324,8 +324,24 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
                                                &buf, bio->bi_ioprio);
        }
 
-       if (IS_ERR(data))
-               return PTR_ERR(data);
+       if (IS_ERR(data)) {
+               if (skip_unverified)
+                       return 1;
+               r = PTR_ERR(data);
+               data = dm_bufio_new(v->bufio, hash_block, &buf);
+               if (IS_ERR(data))
+                       return r;
+               if (verity_fec_decode(v, io, DM_VERITY_BLOCK_TYPE_METADATA,
+                                     hash_block, data) == 0) {
+                       aux = dm_bufio_get_aux_data(buf);
+                       aux->hash_verified = 1;
+                       goto release_ok;
+               } else {
+                       dm_bufio_release(buf);
+                       dm_bufio_forget(v->bufio, hash_block);
+                       return r;
+               }
+       }
 
        aux = dm_bufio_get_aux_data(buf);
 
@@ -366,6 +382,7 @@ static int verity_verify_level(struct dm_verity *v, struct dm_verity_io *io,
                }
        }
 
+release_ok:
        data += offset;
        memcpy(want_digest, data, v->digest_size);
        r = 0;
@@ -1761,7 +1778,7 @@ static struct target_type verity_target = {
        .name           = "verity",
 /* Note: the LSMs depend on the singleton and immutable features */
        .features       = DM_TARGET_SINGLETON | DM_TARGET_IMMUTABLE,
-       .version        = {1, 10, 0},
+       .version        = {1, 11, 0},
        .module         = THIS_MODULE,
        .ctr            = verity_ctr,
        .dtr            = verity_dtr,