Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1319507imu; Wed, 23 Jan 2019 14:53:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN7JDQTVEx4gNywvvusXDzKPjYS8DW7949EnSA5iftkluS4yIGIpsXvp+2rMrLaFrrw7uN6y X-Received: by 2002:a63:89c2:: with SMTP id v185mr3462068pgd.97.1548284026344; Wed, 23 Jan 2019 14:53:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548284026; cv=none; d=google.com; s=arc-20160816; b=A6Ve0vJ5f6WnaEFPmmUzGqj28vxELJzVqHjyWzTHELwo8JyaOpqVLm4o+N2ZV/IMFu jRScaigjv0wMGf5Xjnno26tVnN8cN1VgL7V/z487iNG1EOM9pWEOD/c92rVhMpLbYxm3 he0G+NHx4PAQGpc8m12tet++N+vBVTGTMVpjQ5Bl2Ne+BuASU7FUzmPeuL6vZou1UsjQ 8Ad1PjUREfPGB/7YsbK2UPooyE233ytjEDLk6OVQUc8Je6ghUQYPfI6Bs3raCkkqiX5j VVIuaD7DEBf7ry4gfySuppgC8uTKOo+mDX5wvZZ6izIwbSHTQDz25pO8kBXfcFiBRuX7 ZnWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=saawsumCjfdQ592fJTNRuMMwT/Y+lcU/5wvt9C1IFFQ=; b=zEq1UVG14m5Y0hcwURz8PkCdEgcjepR+TYUmkqJBjwxKaZXHEA0O/vBuuzFielYFNu JaYCmlLhyUokaUUAVdrRUZuTydRz986We/7BF0lFQhP/PKNF59LAkRDjaU2h4jt35BDM 5HZ3YToXOduczShMWqecDA6fDl2aDxHioN/NaL4jmGi8bmfPwLWmgL9pMHC7wFhfnWOm RhdYw1am8UgUWtSkrQM7ciiMGnANK4Cy//0GDWDm2Z0h3RkXPIvdrcNS/p2yz24H5bmr RnzsvSTFzqW+muEWLgtUoTCy2pfVbWci+LcIHO1nqZdzFbxkIluQdi9KGrtdWhmGwvsr cEmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ATCOtA5L; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m8si9358836plt.171.2019.01.23.14.53.31; Wed, 23 Jan 2019 14:53: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; dkim=pass header.i=@kernel.org header.s=default header.b=ATCOtA5L; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727266AbfAWWxE (ORCPT + 99 others); Wed, 23 Jan 2019 17:53:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:50202 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727087AbfAWWwg (ORCPT ); Wed, 23 Jan 2019 17:52:36 -0500 Received: from ebiggers-linuxstation.mtv.corp.google.com (unknown [104.132.1.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A42DD218A4; Wed, 23 Jan 2019 22:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548283955; bh=MklWbl0VE4tMq0gPx0uCw+/dKmbmqahLBeql2PiT+OA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ATCOtA5Lnk4UpQpYP+YUqXTDw7+dXwjgJP5gLLviW23QeYABiPNd35f2rrQGvlIE4 z7KWMXE+p1utFpy1WacgOeRRPStqO92A3NJsQ03I4L2XUUa3YKM90gWci+ioS/8O0z yFDL7CpFMt7xK73hbsnKbqH2NaP41gwley9W1y04= From: Eric Biggers To: linux-crypto@vger.kernel.org, Herbert Xu Cc: linux-kernel@vger.kernel.org, "Jason A . Donenfeld" Subject: [RFC/RFT PATCH 15/15] crypto: testmgr - check for aead_request corruption Date: Wed, 23 Jan 2019 14:49:26 -0800 Message-Id: <20190123224926.250525-16-ebiggers@kernel.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190123224926.250525-1-ebiggers@kernel.org> References: <20190123224926.250525-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Biggers Check that algorithms do not change the aead_request structure, as users may rely on submitting the request again (e.g. after copying new data into the same source buffer) without reinitializing everything. Signed-off-by: Eric Biggers --- crypto/testmgr.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index e5f06844c793..8e36fa3605d7 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -1254,6 +1254,50 @@ static int test_aead_vec_cfg(const char *driver, int enc, return -EINVAL; } + /* Check that the algorithm didn't overwrite things it shouldn't have */ + if (req->cryptlen != (enc ? vec->plen : vec->clen) || + req->assoclen != vec->alen || + req->iv != iv || + req->src != tsgls->src.sgl_ptr || + req->dst != tsgls->dst.sgl_ptr || + crypto_aead_reqtfm(req) != tfm || + req->base.complete != crypto_req_done || + req->base.flags != req_flags || + req->base.data != &wait) { + pr_err("alg: aead: %s %s corrupted request struct on test vector %u, cfg=\"%s\"\n", + driver, op, vec_num, cfg->name); + if (req->cryptlen != (enc ? vec->plen : vec->clen)) + pr_err("alg: aead: changed 'req->cryptlen'\n"); + if (req->assoclen != vec->alen) + pr_err("alg: aead: changed 'req->assoclen'\n"); + if (req->iv != iv) + pr_err("alg: aead: changed 'req->iv'\n"); + if (req->src != tsgls->src.sgl_ptr) + pr_err("alg: aead: changed 'req->src'\n"); + if (req->dst != tsgls->dst.sgl_ptr) + pr_err("alg: aead: changed 'req->dst'\n"); + if (crypto_aead_reqtfm(req) != tfm) + pr_err("alg: aead: changed 'req->base.tfm'\n"); + if (req->base.complete != crypto_req_done) + pr_err("alg: aead: changed 'req->base.complete'\n"); + if (req->base.flags != req_flags) + pr_err("alg: aead: changed 'req->base.flags'\n"); + if (req->base.data != &wait) + pr_err("alg: aead: changed 'req->base.data'\n"); + return -EINVAL; + } + if (is_test_sglist_corrupted(&tsgls->src)) { + pr_err("alg: aead: %s %s corrupted src sgl on test vector %u, cfg=\"%s\"\n", + driver, op, vec_num, cfg->name); + return -EINVAL; + } + if (tsgls->dst.sgl_ptr != tsgls->src.sgl && + is_test_sglist_corrupted(&tsgls->dst)) { + pr_err("alg: aead: %s %s corrupted dst sgl on test vector %u, cfg=\"%s\"\n", + driver, op, vec_num, cfg->name); + return -EINVAL; + } + /* Check for the correct output (ciphertext or plaintext) */ err = verify_correct_output(&tsgls->dst, enc ? vec->ctext : vec->ptext, enc ? vec->clen : vec->plen, -- 2.20.1.321.g9e740568ce-goog