[PATCH 4.14 151/222] crypto: lrw - Fix out-of bounds access on counter overflow

From: Greg Kroah-Hartman
Date: Sun Nov 11 2018 - 17:56:44 EST


4.14-stable review patch. If anyone has any objections, please let me know.

------------------

From: Ondrej Mosnacek <omosnace@xxxxxxxxxx>

commit fbe1a850b3b1522e9fc22319ccbbcd2ab05328d2 upstream.

When the LRW block counter overflows, the current implementation returns
128 as the index to the precomputed multiplication table, which has 128
entries. This patch fixes it to return the correct value (127).

Fixes: 64470f1b8510 ("[CRYPTO] lrw: Liskov Rivest Wagner, a tweakable narrow block cipher mode")
Cc: <stable@xxxxxxxxxxxxxxx> # 2.6.20+
Reported-by: Eric Biggers <ebiggers@xxxxxxxxxx>
Signed-off-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx>
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
crypto/lrw.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

--- a/crypto/lrw.c
+++ b/crypto/lrw.c
@@ -139,7 +139,12 @@ static inline int get_index128(be128 *bl
return x + ffz(val);
}

- return x;
+ /*
+ * If we get here, then x == 128 and we are incrementing the counter
+ * from all ones to all zeros. This means we must return index 127, i.e.
+ * the one corresponding to key2*{ 1,...,1 }.
+ */
+ return 127;
}

static int post_crypt(struct skcipher_request *req)