Received: by 10.223.185.116 with SMTP id b49csp2209592wrg; Thu, 15 Feb 2018 08:08:46 -0800 (PST) X-Google-Smtp-Source: AH8x227SyGAlmRxOpG1Z2fTI79qIOkGrs26MGCkCRZDzHkDxeVUYH9QbIlxO3/1bbDC+QSm8TYq+ X-Received: by 10.98.36.81 with SMTP id r78mr3106487pfj.196.1518710926808; Thu, 15 Feb 2018 08:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518710926; cv=none; d=google.com; s=arc-20160816; b=rVUIc4mpnkZ6rqkNOysADDXBL4hOqvg2rZ3cUOyM8DV2fn7OK7MNLU1UaAfPwp1Y/8 ZAJzMqNi4gmKfqcMbZqFeeePpg+0nj8Z7cz73K37UaxIbkf1MvEWmmWleWrwNtoBtxfA eKq/TvyuT1gllHWD4P5NTfkdgHePAHVneKlJJf297W9ij7/zyCx/d61axUut4RkEqRYx tK+zdbXYYVKKUKq0SJv91y1UZT3jLvhXn8QsslhxxrmLNGzXJthHhdcM1aJYBUcyMVHL F7of+xBDcX/2HmURBMps0RZrgb/jnaGymoA0CaviAbeT61QoZScg7Qw9pwzMDOkVBHGw PS7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wRH5E/gxeoqqVgVrb4nfKZGLq7PgCvcBBUnktftBO0Q=; b=wfYOoECwbqpAzyxRpwTvD22dY76WOo9TFtzd3rIi/apUFXHmocuFABhNRZjKNwqAEA uLE9WqZwBiM74gLBhJbjYAQvciIFWgOFBfu/GZMtQD3u4a+yUtp6FSNXubBhAFradTfQ 6LrKVL0FDFqaravP2rIA1p9HoXHchjv4TGYUbTfralNGZzhfwK/G/2N6EXw9yWsJ62RD z50106PcCDllhSPdD1liIifVU2ik3h8oa9d1/km9I63sG6MUV9QoPtUrb9YDVtXfQTHc kQ4yAe1I2aHPRXW6YKWRhyk/eWuZwBYMn5JNHZmVDzB39sN/a0GcQKgFNkncRGbWDui+ 6xXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t22si2901988pfl.51.2018.02.15.08.08.27; Thu, 15 Feb 2018 08:08:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425400AbeBOQFj (ORCPT + 99 others); Thu, 15 Feb 2018 11:05:39 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:35268 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1424612AbeBOPqK (ORCPT ); Thu, 15 Feb 2018 10:46:10 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5679511DF; Thu, 15 Feb 2018 15:46:09 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , Eric Biggers , Herbert Xu Subject: [PATCH 4.15 128/202] crypto: sha512-mb - initialize pending lengths correctly Date: Thu, 15 Feb 2018 16:17:08 +0100 Message-Id: <20180215151719.902458550@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit eff84b379089cd8b4e83599639c1f5f6e34ef7bf upstream. 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 Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- arch/x86/crypto/sha512-mb/sha512_mb_mgr_init_avx2.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- 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 sha5 { 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;