From patchwork Wed Feb 26 04:59:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 198048 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 88181C4BA0B for ; Wed, 26 Feb 2020 05:01:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 591E224656 for ; Wed, 26 Feb 2020 05:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693261; bh=+Sp7ZvDmeV/GPvCqwJ66Fb86M6xqAEOefxwFSCjV/S8=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=vMBOACODZrh/Ih45ZirErPLnzaRfFNnYAMvGGEAg6puHnyUd/KMUrGoaW9Xav0ka0 mZ30z5vawMww8iSvDeQQgdtoDNeyz6RxjTB60V7Wk1xZRGbSOFwkZn4+1MTUb1Oy2N 7nWDfMI1of+7ZtKT5u/AQ5Y3zLs/ppVmfeX4oEyk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbgBZFBA (ORCPT ); Wed, 26 Feb 2020 00:01:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:50552 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbgBZFBA (ORCPT ); Wed, 26 Feb 2020 00:01:00 -0500 Received: from sol.hsd1.ca.comcast.net (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 E39F72067C for ; Wed, 26 Feb 2020 05:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693260; bh=+Sp7ZvDmeV/GPvCqwJ66Fb86M6xqAEOefxwFSCjV/S8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=0vqecRmHpZtPomgN3POK9y5Tw9OtdLLCHCjeF9PnrLHJMeN0SZATmKiPkQwEd+z22 3A2qY/f/OL5pzv733Hli7hBuH28n+XX5anP7t2xETYh7rtqMJiIBt/Ik9EsPcH7EFe TGVhrqnzMmCW7npOR3KqCm8EgikYmA9b3Wb0tYzk= From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 01/12] crypto: authencesn - fix weird comma-terminated line Date: Tue, 25 Feb 2020 20:59:13 -0800 Message-Id: <20200226045924.97053-2-ebiggers@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200226045924.97053-1-ebiggers@kernel.org> References: <20200226045924.97053-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Fix a weird case where a line was terminated by a comma rather than a semicolon, causing the statement to be continued on the next line. Fortunately the code still behaved as intended, though. Signed-off-by: Eric Biggers --- crypto/authencesn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: ff462ddfd95b915345c3c7c037c3bfafdc58bae7 diff --git a/crypto/authencesn.c b/crypto/authencesn.c index 589008146fce7..149b70df2a917 100644 --- a/crypto/authencesn.c +++ b/crypto/authencesn.c @@ -458,7 +458,7 @@ static int crypto_authenc_esn_create(struct crypto_template *tmpl, inst->alg.encrypt = crypto_authenc_esn_encrypt; inst->alg.decrypt = crypto_authenc_esn_decrypt; - inst->free = crypto_authenc_esn_free, + inst->free = crypto_authenc_esn_free; err = aead_register_instance(tmpl, inst); if (err) { From patchwork Wed Feb 26 04:59:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 198045 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 926AEC4BA0A for ; Wed, 26 Feb 2020 05:01:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6A87920658 for ; Wed, 26 Feb 2020 05:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693263; bh=kPpi7iiHdx8tqZ6wX8PT673fny11q9FyFnpnO8/nBfc=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=ilaupVBMmrD0vGOgLDs2/M1q1xYoSbOlNws5HIFRhj9N8TMinB1JdXmEtvLp73wCg NSiIoEPemHxFjoImWDMuLeVvDrGjTCUXDc5UKpvofyFFLqaVXzNgCEz0xBcqGhrlMv Ywzgv9e44DO91ZO/iuBx0+q9Qb/CqMeQ4Ce311PQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726474AbgBZFBC (ORCPT ); Wed, 26 Feb 2020 00:01:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:50556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgBZFBB (ORCPT ); Wed, 26 Feb 2020 00:01:01 -0500 Received: from sol.hsd1.ca.comcast.net (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 4AE0E21D7E for ; Wed, 26 Feb 2020 05:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693260; bh=kPpi7iiHdx8tqZ6wX8PT673fny11q9FyFnpnO8/nBfc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jwukY8HUQGalPXue3eVXX7g311BaYt+cBt+WgN4TfAYuzfTZOpL95GsBQ5mxK1jwc CXn14d6gtoZl9DSwU9H1oZg2hN08G66aATokJb2Ew9uH15G77nI/4EurBJGh6zBAqz WbnyUw28POWD8OsHv1VdSECkVFEznLPve4eiRXvs= From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 03/12] crypto: cryptd - simplify error handling in cryptd_create_*() Date: Tue, 25 Feb 2020 20:59:15 -0800 Message-Id: <20200226045924.97053-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200226045924.97053-1-ebiggers@kernel.org> References: <20200226045924.97053-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Simplify the error handling in the various cryptd_create_*() functions by taking advantage of crypto_grab_*() now handling an ERR_PTR() name and by taking advantage of crypto_drop_*() now accepting (as a no-op) a spawn that hasn't been grabbed yet. Signed-off-by: Eric Biggers --- crypto/cryptd.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/crypto/cryptd.c b/crypto/cryptd.c index d94c75c840a5e..283212262adbb 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c @@ -369,7 +369,6 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl, struct skcipherd_instance_ctx *ctx; struct skcipher_instance *inst; struct skcipher_alg *alg; - const char *name; u32 type; u32 mask; int err; @@ -379,10 +378,6 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl, cryptd_check_internal(tb, &type, &mask); - name = crypto_attr_alg_name(tb[1]); - if (IS_ERR(name)) - return PTR_ERR(name); - inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); if (!inst) return -ENOMEM; @@ -391,14 +386,14 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl, ctx->queue = queue; err = crypto_grab_skcipher(&ctx->spawn, skcipher_crypto_instance(inst), - name, type, mask); + crypto_attr_alg_name(tb[1]), type, mask); if (err) - goto out_free_inst; + goto err_free_inst; alg = crypto_spawn_skcipher_alg(&ctx->spawn); err = cryptd_init_instance(skcipher_crypto_instance(inst), &alg->base); if (err) - goto out_drop_skcipher; + goto err_free_inst; inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC | (alg->base.cra_flags & CRYPTO_ALG_INTERNAL); @@ -421,10 +416,8 @@ static int cryptd_create_skcipher(struct crypto_template *tmpl, err = skcipher_register_instance(tmpl, inst); if (err) { -out_drop_skcipher: - crypto_drop_skcipher(&ctx->spawn); -out_free_inst: - kfree(inst); +err_free_inst: + cryptd_skcipher_free(inst); } return err; } @@ -694,8 +687,7 @@ static int cryptd_create_hash(struct crypto_template *tmpl, struct rtattr **tb, err = ahash_register_instance(tmpl, inst); if (err) { err_free_inst: - crypto_drop_shash(&ctx->spawn); - kfree(inst); + cryptd_hash_free(inst); } return err; } @@ -833,17 +825,12 @@ static int cryptd_create_aead(struct crypto_template *tmpl, struct aead_instance_ctx *ctx; struct aead_instance *inst; struct aead_alg *alg; - const char *name; u32 type = 0; u32 mask = CRYPTO_ALG_ASYNC; int err; cryptd_check_internal(tb, &type, &mask); - name = crypto_attr_alg_name(tb[1]); - if (IS_ERR(name)) - return PTR_ERR(name); - inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); if (!inst) return -ENOMEM; @@ -852,14 +839,14 @@ static int cryptd_create_aead(struct crypto_template *tmpl, ctx->queue = queue; err = crypto_grab_aead(&ctx->aead_spawn, aead_crypto_instance(inst), - name, type, mask); + crypto_attr_alg_name(tb[1]), type, mask); if (err) - goto out_free_inst; + goto err_free_inst; alg = crypto_spawn_aead_alg(&ctx->aead_spawn); err = cryptd_init_instance(aead_crypto_instance(inst), &alg->base); if (err) - goto out_drop_aead; + goto err_free_inst; inst->alg.base.cra_flags = CRYPTO_ALG_ASYNC | (alg->base.cra_flags & CRYPTO_ALG_INTERNAL); @@ -879,10 +866,8 @@ static int cryptd_create_aead(struct crypto_template *tmpl, err = aead_register_instance(tmpl, inst); if (err) { -out_drop_aead: - crypto_drop_aead(&ctx->aead_spawn); -out_free_inst: - kfree(inst); +err_free_inst: + cryptd_aead_free(inst); } return err; } From patchwork Wed Feb 26 04:59:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 198046 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 2F269C4BA11 for ; Wed, 26 Feb 2020 05:01:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 062422067C for ; Wed, 26 Feb 2020 05:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693263; bh=PttdxIj3lqzreG0Wccf68PsarfLwS7UolPyxX7OQSjw=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=16Zab3dH7yfe5gDLwu8IVURSsbYgsF2gnZCQygppUChn17oMr3YKqfAOubCgXqgaZ EyUTMyjZrfhj2vYgWEAi3xfpCeSC+H8p0KXCoyFP+B1yw9Str3tKa0EAGVlnq72XU+ RmYuhQAkJmNTpPled3hE193SDNLpV/ks3U4E0glo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726407AbgBZFBC (ORCPT ); Wed, 26 Feb 2020 00:01:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:50558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725916AbgBZFBB (ORCPT ); Wed, 26 Feb 2020 00:01:01 -0500 Received: from sol.hsd1.ca.comcast.net (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 7CBCF222C2 for ; Wed, 26 Feb 2020 05:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693260; bh=PttdxIj3lqzreG0Wccf68PsarfLwS7UolPyxX7OQSjw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=F2gBKORdDf9eEmiGMG51XBIlc6U2IfGSVx6uv9E0PTwlZW5TH/lRpdQbORYRj3tkI zTm4XLcgH1eipH5mratPnATl3uj7DxTkj1bdIU0RpZInYG1b00KZ9PAMPnvQG45nH2 3OlTX+CuAtWoAw6jAA769fNmExfQ4KK6KBty6SMg= From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 04/12] crypto: ctr - simplify error handling in crypto_rfc3686_create() Date: Tue, 25 Feb 2020 20:59:16 -0800 Message-Id: <20200226045924.97053-5-ebiggers@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200226045924.97053-1-ebiggers@kernel.org> References: <20200226045924.97053-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Simplify the error handling in crypto_rfc3686_create() by taking advantage of crypto_grab_skcipher() now handling an ERR_PTR() name and by taking advantage of crypto_drop_skcipher() now accepting (as a no-op) a spawn that hasn't been grabbed yet. Signed-off-by: Eric Biggers --- crypto/ctr.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/crypto/ctr.c b/crypto/ctr.c index a8feab621c6c1..31ac4ae598e17 100644 --- a/crypto/ctr.c +++ b/crypto/ctr.c @@ -260,7 +260,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, struct skcipher_instance *inst; struct skcipher_alg *alg; struct crypto_skcipher_spawn *spawn; - const char *cipher_name; u32 mask; int err; @@ -272,10 +271,6 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, if ((algt->type ^ CRYPTO_ALG_TYPE_SKCIPHER) & algt->mask) return -EINVAL; - cipher_name = crypto_attr_alg_name(tb[1]); - if (IS_ERR(cipher_name)) - return PTR_ERR(cipher_name); - inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); if (!inst) return -ENOMEM; @@ -287,7 +282,7 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, spawn = skcipher_instance_ctx(inst); err = crypto_grab_skcipher(spawn, skcipher_crypto_instance(inst), - cipher_name, 0, mask); + crypto_attr_alg_name(tb[1]), 0, mask); if (err) goto err_free_inst; @@ -296,20 +291,20 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, /* We only support 16-byte blocks. */ err = -EINVAL; if (crypto_skcipher_alg_ivsize(alg) != CTR_RFC3686_BLOCK_SIZE) - goto err_drop_spawn; + goto err_free_inst; /* Not a stream cipher? */ if (alg->base.cra_blocksize != 1) - goto err_drop_spawn; + goto err_free_inst; err = -ENAMETOOLONG; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "rfc3686(%s)", alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME) - goto err_drop_spawn; + goto err_free_inst; if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "rfc3686(%s)", alg->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) - goto err_drop_spawn; + goto err_free_inst; inst->alg.base.cra_priority = alg->base.cra_priority; inst->alg.base.cra_blocksize = 1; @@ -336,17 +331,11 @@ static int crypto_rfc3686_create(struct crypto_template *tmpl, inst->free = crypto_rfc3686_free; err = skcipher_register_instance(tmpl, inst); - if (err) - goto err_drop_spawn; - -out: - return err; - -err_drop_spawn: - crypto_drop_skcipher(spawn); + if (err) { err_free_inst: - kfree(inst); - goto out; + crypto_rfc3686_free(inst); + } + return err; } static struct crypto_template crypto_ctr_tmpls[] = { From patchwork Wed Feb 26 04:59:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 198043 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 71F1BC4BA0D for ; Wed, 26 Feb 2020 05:01:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4405820658 for ; Wed, 26 Feb 2020 05:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693265; bh=JWiL5EYFqROT3KU3uMX3K7+vkn9rT8D0FcCaVmsk4ZI=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=PQRLR/+jLvm/EPurRCzc/Y6HPQpZ/MzgtYU+Mvm5UEVJ3hlPKSRqm7D79VA15oiN/ K4yN+gR2cMmXiDlPTe1DV29nOHXxUdEzEriOug4m4LnYUbdauEHYwnR34kTD+Xpbju cpUgx6ERf9uaiqSzoQTdj/Dl2lnu+bIfSAzpo7ag= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726527AbgBZFBE (ORCPT ); Wed, 26 Feb 2020 00:01:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:50560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725876AbgBZFBB (ORCPT ); Wed, 26 Feb 2020 00:01:01 -0500 Received: from sol.hsd1.ca.comcast.net (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 AAADA20658 for ; Wed, 26 Feb 2020 05:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693260; bh=JWiL5EYFqROT3KU3uMX3K7+vkn9rT8D0FcCaVmsk4ZI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PTzBpKYMHXenFEpjDokFpIV/SzkRw5TrhfIxVQ6tPIjnOpBXqhqV6UAGOcTSPn7wd NDXYoaTsObtooCOuQgoolJIXgntGJDasxKuTKj835lM/QVtnnXxRprpEv132+GfwFT dsyEE34f93uf+zTG5GHLg93XEcYupjncXsip4Rco= From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 05/12] crypto: cts - simplify error handling in crypto_cts_create() Date: Tue, 25 Feb 2020 20:59:17 -0800 Message-Id: <20200226045924.97053-6-ebiggers@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200226045924.97053-1-ebiggers@kernel.org> References: <20200226045924.97053-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Simplify the error handling in crypto_cts_create() by taking advantage of crypto_grab_skcipher() now handling an ERR_PTR() name and by taking advantage of crypto_drop_skcipher() now accepting (as a no-op) a spawn that hasn't been grabbed yet. Signed-off-by: Eric Biggers --- crypto/cts.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/crypto/cts.c b/crypto/cts.c index 48188adc8e91c..5e005c4f02215 100644 --- a/crypto/cts.c +++ b/crypto/cts.c @@ -327,7 +327,6 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb) struct skcipher_instance *inst; struct crypto_attr_type *algt; struct skcipher_alg *alg; - const char *cipher_name; u32 mask; int err; @@ -340,10 +339,6 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb) mask = crypto_requires_sync(algt->type, algt->mask); - cipher_name = crypto_attr_alg_name(tb[1]); - if (IS_ERR(cipher_name)) - return PTR_ERR(cipher_name); - inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); if (!inst) return -ENOMEM; @@ -351,7 +346,7 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb) spawn = skcipher_instance_ctx(inst); err = crypto_grab_skcipher(spawn, skcipher_crypto_instance(inst), - cipher_name, 0, mask); + crypto_attr_alg_name(tb[1]), 0, mask); if (err) goto err_free_inst; @@ -359,15 +354,15 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb) err = -EINVAL; if (crypto_skcipher_alg_ivsize(alg) != alg->base.cra_blocksize) - goto err_drop_spawn; + goto err_free_inst; if (strncmp(alg->base.cra_name, "cbc(", 4)) - goto err_drop_spawn; + goto err_free_inst; err = crypto_inst_setname(skcipher_crypto_instance(inst), "cts", &alg->base); if (err) - goto err_drop_spawn; + goto err_free_inst; inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; inst->alg.base.cra_priority = alg->base.cra_priority; @@ -391,17 +386,11 @@ static int crypto_cts_create(struct crypto_template *tmpl, struct rtattr **tb) inst->free = crypto_cts_free; err = skcipher_register_instance(tmpl, inst); - if (err) - goto err_drop_spawn; - -out: - return err; - -err_drop_spawn: - crypto_drop_skcipher(spawn); + if (err) { err_free_inst: - kfree(inst); - goto out; + crypto_cts_free(inst); + } + return err; } static struct crypto_template crypto_cts_tmpl = { From patchwork Wed Feb 26 04:59:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 198044 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 8A5E6C4BA14 for ; Wed, 26 Feb 2020 05:01:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6371020658 for ; Wed, 26 Feb 2020 05:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693264; bh=APCpCZ7hSn7B1jgf9/ybXYkfluvNjA0o648Pw0wRYsI=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=jzo8wXwaGDyTL7VhSWKIrgP5X5Q+W6AO6NyyAHpKFM2Zl1ioDh8WrzhcqD4uU92ol 2PzWxLFnfqpBL0GpHAPRflCnTIyLIr11QINDshSTiG+GNSIhDCQQrwyR41FAWiODMN 8/GKuw4TK34ehqhj/Z9Om7oztD4DJ6cdlCqTl7DE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726473AbgBZFBC (ORCPT ); Wed, 26 Feb 2020 00:01:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:50572 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726407AbgBZFBB (ORCPT ); Wed, 26 Feb 2020 00:01:01 -0500 Received: from sol.hsd1.ca.comcast.net (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 1180820726 for ; Wed, 26 Feb 2020 05:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693261; bh=APCpCZ7hSn7B1jgf9/ybXYkfluvNjA0o648Pw0wRYsI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZfH28Ljh0B6h+7y8kzGvSZM2bTxEo4Yyznwaqr3xa+z/+B1m5Fh+jKMNZA5jjZVkA 21qzufjXhpEfNDHKoKXaGkyB4R4RFrEDY/ODQmoat44RDLnxqKK7cE4CVYxof6de8u 4+4vekOLVN0wnjCenwLB6WUz9gaMhXOqh0BHB7V8= From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 07/12] crypto: gcm - simplify error handling in crypto_rfc4543_create() Date: Tue, 25 Feb 2020 20:59:19 -0800 Message-Id: <20200226045924.97053-8-ebiggers@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200226045924.97053-1-ebiggers@kernel.org> References: <20200226045924.97053-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Simplify the error handling in crypto_rfc4543_create() by taking advantage of crypto_grab_aead() now handling an ERR_PTR() name and by taking advantage of crypto_drop_aead() now accepting (as a no-op) a spawn that hasn't been grabbed yet. Conveniently, this eliminates the 'ccm_name' variable which was incorrectly named (it should have been 'gcm_name'). Also fix a weird case where a line was terminated by a comma rather than a semicolon, causing the statement to be continued on the next line. Fortunately the code still behaved as intended, though. Signed-off-by: Eric Biggers --- crypto/gcm.c | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/crypto/gcm.c b/crypto/gcm.c index 5560341e28105..0103d28c541eb 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -1060,10 +1060,8 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl, struct crypto_attr_type *algt; u32 mask; struct aead_instance *inst; - struct crypto_aead_spawn *spawn; struct aead_alg *alg; struct crypto_rfc4543_instance_ctx *ctx; - const char *ccm_name; int err; algt = crypto_get_attr_type(tb); @@ -1075,32 +1073,27 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl, mask = crypto_requires_sync(algt->type, algt->mask); - ccm_name = crypto_attr_alg_name(tb[1]); - if (IS_ERR(ccm_name)) - return PTR_ERR(ccm_name); - inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); if (!inst) return -ENOMEM; ctx = aead_instance_ctx(inst); - spawn = &ctx->aead; - err = crypto_grab_aead(spawn, aead_crypto_instance(inst), - ccm_name, 0, mask); + err = crypto_grab_aead(&ctx->aead, aead_crypto_instance(inst), + crypto_attr_alg_name(tb[1]), 0, mask); if (err) - goto out_free_inst; + goto err_free_inst; - alg = crypto_spawn_aead_alg(spawn); + alg = crypto_spawn_aead_alg(&ctx->aead); err = -EINVAL; /* Underlying IV size must be 12. */ if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE) - goto out_drop_alg; + goto err_free_inst; /* Not a stream cipher? */ if (alg->base.cra_blocksize != 1) - goto out_drop_alg; + goto err_free_inst; err = -ENAMETOOLONG; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, @@ -1109,7 +1102,7 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl, snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "rfc4543(%s)", alg->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) - goto out_drop_alg; + goto err_free_inst; inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; inst->alg.base.cra_priority = alg->base.cra_priority; @@ -1130,20 +1123,14 @@ static int crypto_rfc4543_create(struct crypto_template *tmpl, inst->alg.encrypt = crypto_rfc4543_encrypt; inst->alg.decrypt = crypto_rfc4543_decrypt; - inst->free = crypto_rfc4543_free, + inst->free = crypto_rfc4543_free; err = aead_register_instance(tmpl, inst); - if (err) - goto out_drop_alg; - -out: + if (err) { +err_free_inst: + crypto_rfc4543_free(inst); + } return err; - -out_drop_alg: - crypto_drop_aead(spawn); -out_free_inst: - kfree(inst); - goto out; } static struct crypto_template crypto_gcm_tmpls[] = { From patchwork Wed Feb 26 04:59:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 198047 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 05562C4BA0F for ; Wed, 26 Feb 2020 05:01:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D091920658 for ; Wed, 26 Feb 2020 05:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693262; bh=ukrrJdhCt2fYDZAvYR+ypFP4VNz9zKLiI3U7uHj4wqw=; h=From:To:Subject:Date:In-Reply-To:References:List-ID:From; b=ZBcoIV4KPUmAhqgj3iHXoxBL2TpWwzD6bIAFP85HeBk+5Fd5DSgIOD4/mrQtHG5wQ cP/nxAJbJrF0f29xL7adDdUrYWOgEDUZCD6ZwgKdSeFV6ac4L440SnIBx1vuvQTX24 3PlGryqaomgyIMsf8OsYEbalyfxmA8YRg4iLcQFU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbgBZFBC (ORCPT ); Wed, 26 Feb 2020 00:01:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:50582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726473AbgBZFBB (ORCPT ); Wed, 26 Feb 2020 00:01:01 -0500 Received: from sol.hsd1.ca.comcast.net (c-107-3-166-239.hsd1.ca.comcast.net [107.3.166.239]) (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 3EBE024650 for ; Wed, 26 Feb 2020 05:01:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582693261; bh=ukrrJdhCt2fYDZAvYR+ypFP4VNz9zKLiI3U7uHj4wqw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nrq7VUrn5J6cw3QrScXgJ6TdpsOZNrlQFUei41A3XyrBooM6EJ3/HIDQbAUDIsfY4 RDQ7snhcv5lMxxAfytAloke3ZncbpY5nMZuAqektfo4qJWuQ8zm28aUf/D0DkcfxMt uFF2Y11zduVwzAwpcvOFxsc2hZo/HUvxzMZTfU24= From: Eric Biggers To: linux-crypto@vger.kernel.org Subject: [PATCH 08/12] crypto: geniv - simply error handling in aead_geniv_alloc() Date: Tue, 25 Feb 2020 20:59:20 -0800 Message-Id: <20200226045924.97053-9-ebiggers@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200226045924.97053-1-ebiggers@kernel.org> References: <20200226045924.97053-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Simplify the error handling in aead_geniv_alloc() by taking advantage of crypto_grab_aead() now handling an ERR_PTR() name and by taking advantage of crypto_drop_aead() now accepting (as a no-op) a spawn that hasn't been grabbed yet. Signed-off-by: Eric Biggers --- crypto/geniv.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/crypto/geniv.c b/crypto/geniv.c index dbcc640274cda..6a90c52d49ad1 100644 --- a/crypto/geniv.c +++ b/crypto/geniv.c @@ -41,7 +41,6 @@ static void aead_geniv_free(struct aead_instance *inst) struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, struct rtattr **tb, u32 type, u32 mask) { - const char *name; struct crypto_aead_spawn *spawn; struct crypto_attr_type *algt; struct aead_instance *inst; @@ -57,10 +56,6 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) return ERR_PTR(-EINVAL); - name = crypto_attr_alg_name(tb[1]); - if (IS_ERR(name)) - return ERR_CAST(name); - inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); if (!inst) return ERR_PTR(-ENOMEM); @@ -71,7 +66,7 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, mask |= crypto_requires_sync(algt->type, algt->mask); err = crypto_grab_aead(spawn, aead_crypto_instance(inst), - name, type, mask); + crypto_attr_alg_name(tb[1]), type, mask); if (err) goto err_free_inst; @@ -82,17 +77,17 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, err = -EINVAL; if (ivsize < sizeof(u64)) - goto err_drop_alg; + goto err_free_inst; err = -ENAMETOOLONG; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", tmpl->name, alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME) - goto err_drop_alg; + goto err_free_inst; if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", tmpl->name, alg->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) - goto err_drop_alg; + goto err_free_inst; inst->alg.base.cra_flags = alg->base.cra_flags & CRYPTO_ALG_ASYNC; inst->alg.base.cra_priority = alg->base.cra_priority; @@ -111,10 +106,8 @@ struct aead_instance *aead_geniv_alloc(struct crypto_template *tmpl, out: return inst; -err_drop_alg: - crypto_drop_aead(spawn); err_free_inst: - kfree(inst); + aead_geniv_free(inst); inst = ERR_PTR(err); goto out; }