From 75fea5f6057df78af1655f2f79a9c66a94bc838f Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 21 Jan 2020 09:39:22 -0800 Subject: [PATCH] ANDROID: block: fix some inline crypto bugs While we're waiting for v7 of the inline crypto patchset, fix some bugs that made it into the v6 patchset, including one that caused bios with an encryption context to never be merged, and one that could cause non-contiguous pages to incorrectly added to a bio. Bug: 137270441 Change-Id: I3911fcd6c76b5c9063b86d6af6267ad990a46718 Signed-off-by: Eric Biggers Signed-off-by: Satya Tangirala --- block/bio-crypt-ctx.c | 7 +++---- block/blk-crypto-fallback.c | 2 +- block/blk-crypto-internal.h | 2 +- include/linux/bio-crypt-ctx.h | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/block/bio-crypt-ctx.c b/block/bio-crypt-ctx.c index 75982dabc7a3..d02d2bff991a 100644 --- a/block/bio-crypt-ctx.c +++ b/block/bio-crypt-ctx.c @@ -96,10 +96,9 @@ bool bio_crypt_ctx_compatible(struct bio *b_1, struct bio *b_2) struct bio_crypt_ctx *bc1 = b_1->bi_crypt_context; struct bio_crypt_ctx *bc2 = b_2->bi_crypt_context; - if (bc1 != bc2) - return false; - - return !bc1 || bc1->bc_key == bc2->bc_key; + if (!bc1) + return !bc2; + return bc2 && bc1->bc_key == bc2->bc_key; } /* diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c index 3f2a7d3be07b..d349b904d95d 100644 --- a/block/blk-crypto-fallback.c +++ b/block/blk-crypto-fallback.c @@ -568,7 +568,7 @@ int blk_crypto_fallback_submit_bio(struct bio **bio_ptr) struct bio_crypt_ctx *bc = bio->bi_crypt_context; struct bio_fallback_crypt_ctx *f_ctx; - if (WARN_ON_ONCE(!tfms_inited[bc->bc_key->crypto_mode])) { + if (!tfms_inited[bc->bc_key->crypto_mode]) { bio->bi_status = BLK_STS_IOERR; return -EIO; } diff --git a/block/blk-crypto-internal.h b/block/blk-crypto-internal.h index 43351eecc97a..40d826b743da 100644 --- a/block/blk-crypto-internal.h +++ b/block/blk-crypto-internal.h @@ -36,7 +36,7 @@ static inline bool bio_crypt_fallback_crypted(const struct bio_crypt_ctx *bc) static inline int blk_crypto_fallback_submit_bio(struct bio **bio_ptr) { - pr_warn_once("blk-crypto crypto API fallback disabled; failing request"); + pr_warn_once("crypto API fallback disabled; failing request\n"); (*bio_ptr)->bi_status = BLK_STS_NOTSUPP; return -EIO; } diff --git a/include/linux/bio-crypt-ctx.h b/include/linux/bio-crypt-ctx.h index 2e06b06fce47..652f92ff75fd 100644 --- a/include/linux/bio-crypt-ctx.h +++ b/include/linux/bio-crypt-ctx.h @@ -118,7 +118,7 @@ static inline bool bio_crypt_dun_is_contiguous(const struct bio_crypt_ctx *bc, int i = 0; unsigned int inc = bytes >> bc->bc_key->data_unit_size_bits; - while (inc && i < BLK_CRYPTO_DUN_ARRAY_SIZE) { + while (i < BLK_CRYPTO_DUN_ARRAY_SIZE) { if (bc->bc_dun[i] + inc != next_dun[i]) return false; inc = ((bc->bc_dun[i] + inc) < inc);