Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35b62551 authored by Eric Biggers's avatar Eric Biggers
Browse files

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: default avatarEric Biggers <ebiggers@google.com>
parent 5b18331d
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -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;
}

/*
+1 −1
Original line number Diff line number Diff line
@@ -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;
	}
+1 −1
Original line number Diff line number Diff line
@@ -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;
}
+1 −1
Original line number Diff line number Diff line
@@ -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);