crypto: sha512-mb - initialize pending lengths correctly

"Linux Kernel Mailing List" <[email protected]> Mon, 12 Feb 2018 17:22:09 +0000 (UTC)
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/eff84b379089cd8b4e83599639c1f5f6e34ef7bf
Commit:     eff84b379089cd8b4e83599639c1f5f6e34ef7bf
Parent:     2d55807b7f7bf62bb05a8b91247c5eb7cd19ac04
Refname:    refs/heads/master
Author:     Eric Biggers <[email protected]>
AuthorDate: Wed Jan 24 00:31:27 2018 -0800
Committer:  Herbert Xu <[email protected]>
CommitDate: Thu Feb 8 22:37:05 2018 +1100

    crypto: sha512-mb - initialize pending lengths correctly
    
    The SHA-512 multibuffer code keeps track of the number of blocks pending
    in each lane.  The minimum of these values is used to identify the next
    lane that will be completed.  Unused lanes are set to a large number
    (0xFFFFFFFF) so that they don't affect this calculation.
    
    However, it was forgotten to set the lengths to this value in the
    initial state, where all lanes are unused.  As a result it was possible
    for sha512_mb_mgr_get_comp_job_avx2() to select an unused lane, causing
    a NULL pointer dereference.  Specifically this could happen in the case
    where ->update() was passed fewer than SHA512_BLOCK_SIZE bytes of data,
    so it then called sha_complete_job() without having actually submitted
    any blocks to the multi-buffer code.  This hit a NULL pointer
    dereference if another task happened to have submitted blocks
    concurrently to the same CPU and the flush timer had not yet expired.
    
    Fix this by initializing sha512_mb_mgr->lens correctly.
    
    As usual, this bug was found by syzkaller.
    
    Fixes: 45691e2d9b18 ("crypto: sha512-mb - submit/flush routines for AVX2")
    Reported-by: syzbot <[email protected]>
    Cc: <[email protected]> # v4.8+
    Signed-off-by: Eric Biggers <[email protected]>
    Signed-off-by: Herbert Xu <[email protected]>
---
 arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c
index 36870b26067a..d08805032f01 100644
--- a/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c
+++ b/arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c
@@ -57,10 +57,12 @@ void sha512_mb_mgr_init_avx2(struct sha512_mb_mgr *state)
 {
 	unsigned int j;
 
-	state->lens[0] = 0;
-	state->lens[1] = 1;
-	state->lens[2] = 2;
-	state->lens[3] = 3;
+	/* initially all lanes are unused */
+	state->lens[0] = 0xFFFFFFFF00000000;
+	state->lens[1] = 0xFFFFFFFF00000001;
+	state->lens[2] = 0xFFFFFFFF00000002;
+	state->lens[3] = 0xFFFFFFFF00000003;
+
 	state->unused_lanes = 0xFF03020100;
 	for (j = 0; j < 4; j++)
 		state->ldata[j].job_in_lane = NULL;
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html