From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E11A7C33CB8 for ; Sun, 1 Dec 2019 21:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B619E215F1 for ; Sun, 1 Dec 2019 21:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575237262; bh=EuAafZaO9ltKvvDUJZdS4MB+SmmRnUWxVmGC4e8CdPA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=sCpIkuivKZh8RJ3fCQdOGWXd8utSzKINSm7nu+ggZBXhhKxJ3o4Id+K72VlpwgUAl wcXKFld5iYszlPsc68Mc7XQhwWyCU+Qf3MrNw7SFzQEwdmTjyH8qqcqUUSZ3khtQvw AZf+uicSsNzc+tWpGYWcPSJOhQYYCMdJxZttHMEk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727301AbfLAVyV (ORCPT ); Sun, 1 Dec 2019 16:54:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:33400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727266AbfLAVyV (ORCPT ); Sun, 1 Dec 2019 16:54:21 -0500 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (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 4C14A217AB; Sun, 1 Dec 2019 21:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575237260; bh=EuAafZaO9ltKvvDUJZdS4MB+SmmRnUWxVmGC4e8CdPA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VyOCPAmai6+wc99y0aDPYdWyYXPWmjb0dQzI1LbI3943XFE7PqFC7wtqNNhBQA8xC hgh97sgNHM16z7NSieRXprzfHp50/LakNtOZVAHS1B2yzjZmGofdMFgW0SUBm8L578 9C5NSXvmd7Am8neFVgARg1rX7BkfORt+PmTGOPs4= From: Eric Biggers To: linux-crypto@vger.kernel.org Cc: Pascal Van Leeuwen Subject: [PATCH 3/7] crypto: testmgr - don't try to decrypt uninitialized buffers Date: Sun, 1 Dec 2019 13:53:26 -0800 Message-Id: <20191201215330.171990-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191201215330.171990-1-ebiggers@kernel.org> References: <20191201215330.171990-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Currently if the comparison fuzz tests encounter an encryption error when generating an skcipher or AEAD test vector, they will still test the decryption side (passing it the uninitialized ciphertext buffer) and expect it to fail with the same error. This is sort of broken because it's not well-defined usage of the API to pass an uninitialized buffer, and furthermore in the AEAD case it's acceptable for the decryption error to be EBADMSG (meaning "inauthentic input") even if the encryption error was something else like EINVAL. Fix this for skcipher by explicitly initializing the ciphertext buffer on error, and for AEAD by skipping the decryption test on error. Reported-by: Pascal Van Leeuwen Fixes: d435e10e67be ("crypto: testmgr - fuzz skciphers against their generic implementation") Fixes: 40153b10d91c ("crypto: testmgr - fuzz AEADs against their generic implementation") Signed-off-by: Eric Biggers --- crypto/testmgr.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crypto/testmgr.c b/crypto/testmgr.c index 85d720a57bb0..a8940415512f 100644 --- a/crypto/testmgr.c +++ b/crypto/testmgr.c @@ -2102,6 +2102,7 @@ static void generate_random_aead_testvec(struct aead_request *req, * If the key or authentication tag size couldn't be set, no need to * continue to encrypt. */ + vec->crypt_error = 0; if (vec->setkey_error || vec->setauthsize_error) goto done; @@ -2245,10 +2246,12 @@ static int test_aead_vs_generic_impl(const char *driver, req, tsgls); if (err) goto out; - err = test_aead_vec_cfg(driver, DECRYPT, &vec, vec_name, cfg, - req, tsgls); - if (err) - goto out; + if (vec.crypt_error == 0) { + err = test_aead_vec_cfg(driver, DECRYPT, &vec, vec_name, + cfg, req, tsgls); + if (err) + goto out; + } cond_resched(); } err = 0; @@ -2678,6 +2681,15 @@ static void generate_random_cipher_testvec(struct skcipher_request *req, skcipher_request_set_callback(req, 0, crypto_req_done, &wait); skcipher_request_set_crypt(req, &src, &dst, vec->len, iv); vec->crypt_error = crypto_wait_req(crypto_skcipher_encrypt(req), &wait); + if (vec->crypt_error != 0) { + /* + * The only acceptable error here is for an invalid length, so + * skcipher decryption should fail with the same error too. + * We'll test for this. But to keep the API usage well-defined, + * explicitly initialize the ciphertext buffer too. + */ + memset((u8 *)vec->ctext, 0, vec->len); + } done: snprintf(name, max_namelen, "\"random: len=%u klen=%u\"", vec->len, vec->klen); -- 2.24.0