Received: by 10.223.185.116 with SMTP id b49csp2642385wrg; Thu, 15 Feb 2018 15:14:16 -0800 (PST) X-Google-Smtp-Source: AH8x227tyvydqTU3ZnS2gNl7R+SAU7RSth7GkwKGS8DDG4V6FHuPMRaVD56c3Z2x03tdksqswsGk X-Received: by 10.101.64.204 with SMTP id u12mr3505125pgp.280.1518736456156; Thu, 15 Feb 2018 15:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518736456; cv=none; d=google.com; s=arc-20160816; b=AXc7Sg04+12WJm6mlMgQFvfh6otlvZ1InDM/vsebLdyqMmMu1bquaj9echFmRF5sst ajBt4qg7cb7Jzn+9dGEw5C4eHcyMk2J4sou4LVrXamiiWZl2Ohvam0mn5KOg/eh0xfzg Jryu0ah2DMvWaYeFiomsHvjyMjEalZ/Nzzk3VJRQkLRNwUAlmEhBXUILgQCOtjOLhdIq jfVCTcObeTfGV01DzEBMkWqz3I5CXDzdn8CTYWrfg7aYq/42WS7LAboWHcistJcP+Mgg hsHxtYEQ8VC7eECauVPW/xsybIDskFZUj7i9QeuHrEizNYmhLlHZ85VnpNgEzmCE94NM ZE0w== 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=jQVC7oTq/WPYTkzVpdjSQjbTWs4GqhwPuWR+7W4gjcQ=; b=xicUfDTww7iIF5bZKMg/0A7qTuFgrNgb1EDqiJW/2aU+RFypIxn0a1cyANK/Gieamk BgMDsfk8cP4uR3/ditTfKaAatXKwsUsuZdvEbyQL8fbMFgW1fmkGRctjNLfQ7k+Abuzo 29RLm5zow4kBOGIYi661JUSqcdR6+H/OWTLX5xtQaRG6vMpmUMMHYnEdm1wmG/qtD7/u TLeW1Y4cit/KFDmdX+L+4OaWBhoajUfIzcpVvGErQOxgBOr2I6QFkmvVlQdKXg76chRw pUIdXD5F0tcvYePLi7uOcVSkrX976qV7sm1C8r9mCMT6MLMLXfao0YiOX37C85kTyCTf 3+0g== 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 126si978325pfd.48.2018.02.15.15.13.57; Thu, 15 Feb 2018 15:14:16 -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 S1422737AbeBOPfl (ORCPT + 99 others); Thu, 15 Feb 2018 10:35:41 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:57482 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422724AbeBOPfg (ORCPT ); Thu, 15 Feb 2018 10:35:36 -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 E1B00114A; Thu, 15 Feb 2018 15:35:35 +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.14 134/195] crypto: sha512-mb - initialize pending lengths correctly Date: Thu, 15 Feb 2018 16:17:05 +0100 Message-Id: <20180215151712.491281059@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@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.14-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;