Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1466076pxv; Fri, 16 Jul 2021 09:56:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlHCySDhmNV+7QzMFrwIbpKVeNuyVdL1EpmvM9f3mM41qFEHdfX+0ntYmawlKgM7HV/N80 X-Received: by 2002:a05:6402:2154:: with SMTP id bq20mr16022882edb.111.1626454616077; Fri, 16 Jul 2021 09:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626454616; cv=none; d=google.com; s=arc-20160816; b=ZWC6rh7YxKjb3K8fok0SHcCpPKDn/epAlLTCwE/sEgQ37edzUcwnCU6qlKk65KYjhl xKxMawL1VJd6bYY6ZOEXcFvt0F1KDJOoFMd5xm+zLgqaSWs71cWqKWv73JuwjEiMNNYb 4aKvDPbSp8lg2WafDi/X3ANhiN5B4PqSi1N3lLCUjRdQJJnH98Zgi8X18ZADK00cMLxp 6w5cz5N9UcpNhdLFMIbGqV0eqE9FtuKX5fP98bW/Lz+X6cicI5esFBS/9f0uc+W3XMpF lFSFgPBTLWXfMooQiorbB1ccCbpnBvQcchrgq4gh12NILLeHGevztoKCfrl1SLY09tIw /BUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oLyeCsdvEJ8yLb2XU1kQ+O/JXFDmzaltL9E1arbVgKU=; b=xjZq9XLIHA8uI3y/uLotGWqCULFtrfp4bN6vEdhjiEgUU8RxNRT0uig9gSoFkK6kFM 6ZsDT8mG6Ojs4oNwWetKuVtLBNcjqkSymlfJWOxtwNqbQplgr455VdK+l6toKFn2Y+Aj jptGSHKynCNu7I4HO3P8y/7LyH7oSXV2o1iSOMkI0uX7Ej9ZEN4Kxe23r4U+ARODUOo8 xqtiYwNGwXX5Y/1Pio/LqZozq0bSHsI1Tg5yAXxLBwoi0LtoK8bkicgycrAAws5acfjL i3BmX0M3vYPNqdgKsJukEZN0dUo7zjlX2sjRxC8J7ERhfU8kfFp+lsvsuMTYXCeHjLyF APmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Bp3/KC62"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e12si11312728ejh.74.2021.07.16.09.56.17; Fri, 16 Jul 2021 09:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Bp3/KC62"; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbhGPQ5S (ORCPT + 99 others); Fri, 16 Jul 2021 12:57:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:49690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229751AbhGPQ5S (ORCPT ); Fri, 16 Jul 2021 12:57:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E375F613E8; Fri, 16 Jul 2021 16:54:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626454463; bh=kmbZq07zaBwPa71lnfLpbNt1AN+xqqvsizWn06LAvD8=; h=From:To:Cc:Subject:Date:From; b=Bp3/KC6298T+EQcaJzKw38IpT5aiisoVAeZ5hN0m0/ZoHmZ0oMZ+vxQHRItHGcsmO DoIb/zhuMprYNS1y3mYN7xhd/D0n2f1BOazdfsVWkIOH3T04VFpfJeIZR4YMnVyK2l mCMK6Vvto0oo9Bq3l+Is9Y/E+QqNFOPEEacFuOx3XgE28S7Pd1La4VxbHU063jBTns +/LZEZDVychiF77gGMbQYIg9p6yHZuwwozuRYL4Ti1goVMM7ChH30Ni6F+bfbtVupu ijfgPcGQ2uC2CuUXXC3gMF2et09XBCVwX0KvTfRTrijUKjgTsKbIZh0BkdCzioJe9a tYyJJ+30mwzQw== From: Ard Biesheuvel To: linux-crypto@vger.kernel.org Cc: herbert@gondor.apana.org.au, Ard Biesheuvel , Dave Hansen , syzbot Subject: [PATCH] crypto: x86/aes-ni - add missing error checks in XTS code Date: Fri, 16 Jul 2021 18:54:03 +0200 Message-Id: <20210716165403.6115-1-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The updated XTS code fails to check the return code of skcipher_walk_virt, which may lead to skcipher_walk_abort() or skcipher_walk_done() being called while the walk argument is in an inconsistent state. So check the return value after each such call, and bail on errors. Fixes: 2481104fe98d ("crypto: x86/aes-ni-xts - rewrite and drop indirections via glue helper") Reported-by: Dave Hansen Reported-by: syzbot Signed-off-by: Ard Biesheuvel --- arch/x86/crypto/aesni-intel_glue.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c index 2144e54a6c89..388643ca2177 100644 --- a/arch/x86/crypto/aesni-intel_glue.c +++ b/arch/x86/crypto/aesni-intel_glue.c @@ -849,6 +849,8 @@ static int xts_crypt(struct skcipher_request *req, bool encrypt) return -EINVAL; err = skcipher_walk_virt(&walk, req, false); + if (err) + return err; if (unlikely(tail > 0 && walk.nbytes < walk.total)) { int blocks = DIV_ROUND_UP(req->cryptlen, AES_BLOCK_SIZE) - 2; @@ -862,7 +864,10 @@ static int xts_crypt(struct skcipher_request *req, bool encrypt) skcipher_request_set_crypt(&subreq, req->src, req->dst, blocks * AES_BLOCK_SIZE, req->iv); req = &subreq; + err = skcipher_walk_virt(&walk, req, false); + if (err) + return err; } else { tail = 0; } -- 2.30.2