Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6270406imu; Mon, 21 Jan 2019 06:09:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN42343X14/LJCCJYDdE8nZUUQU+m9rjOBdIl3Vbfg5lRcsN2Win+MYZ3ZLsuZMV3Jpe2apN X-Received: by 2002:a62:99dd:: with SMTP id t90mr29499182pfk.179.1548079763950; Mon, 21 Jan 2019 06:09:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079763; cv=none; d=google.com; s=arc-20160816; b=OUOsdx+mQ6HcD+cwuF8ZhUdso2qtFsLJs+x9jpDpxxlM5kNyJQkbfKKAmktWVCTA87 CF/EZ96VqXaBEPmExR+agDA7oI8DGKC54QdzL1l8/F+S+IajHj+HJ1ka9C8/Z/cMeJOu 56eB+ELO5g5dmWfGo4NHYVNDwrJUS6KvMWbeZnZbkYhZt11H79q0YzVO+gcDHV2kF+Ih SouWoxv10J7epe+hhlDMUXBFJZNmCm29yY48zb6bVjFAXwKYdaFrEC+9QumFpivZ7Oeb rMG5bsjYL92FQJ9IsmaGesFO5dqixd1y7+FnIoMvwtf6C6o0HiFx3ryf5GPzVMoQxc2Y CPlg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AwFDtdpP9KgGITARQlax+YneDF8ZKzhaGdcwS61DvC0=; b=G97ud9nQxT81jkvHGLJl3CAtw01sOzWHdbwUzi16lPkb2X0dI2qS2m/8ToQ1bXNBlT oVE+JLu24+O3OmMetbo1xG+j52hAnpch1WMiaue50g+RvLTew3UvRUVAgVSNwvXOM2RH aPGMZnE3TD7bF2I6j3wS2sq1NzrfOvRnQEsqPFXBsJ6My0K2WEP4i/6avT+WBI/whGH0 SWrhUzKPQhpLKDbpe4aoF8cemgHO/J9zFVC1x8GxhdlL91JKJHGKmp4t+FhRHLZhV0wB ItmgDHrVFAnR8rYGNGdhuWLbRON0NMVrE6hTnLzSuNPDf2Km+bIXDJ21xtps4qsKUWar gxrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vYFXuhBS; 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 m32si13214574pld.86.2019.01.21.06.09.09; Mon, 21 Jan 2019 06:09:23 -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=vYFXuhBS; 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 S1732234AbfAUN7n (ORCPT + 99 others); Mon, 21 Jan 2019 08:59:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:45764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731299AbfAUN7k (ORCPT ); Mon, 21 Jan 2019 08:59:40 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7591520879; Mon, 21 Jan 2019 13:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079178; bh=fTHtBozCz//Kn43bqWyf4ntn0BA8U1bAq0Rj4guMi54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vYFXuhBSygepwV93dWy5ZSPitb6zcTaCjdMQD2+0yJEDumPPzSxNqrDJbGVJi1+L3 snENqdoXB8uLWoPQ7SAkhNmxxQwJsR+G2UvwXy0XS52v9r0Jg3fv5k3o1ciYmidBq+ wXNAi6Mz3MqCmpUpsy7t+TI7vik+7JJh3xVx/f9s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Herbert Xu Subject: [PATCH 4.19 34/99] crypto: ccree - convert to use crypto_authenc_extractkeys() Date: Mon, 21 Jan 2019 14:48:26 +0100 Message-Id: <20190121134915.194108703@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit dc95b5350a8f07d73d6bde3a79ef87289698451d upstream. Convert the ccree crypto driver to use crypto_authenc_extractkeys() so that it picks up the fix for broken validation of rtattr::rta_len. Fixes: ff27e85a85bb ("crypto: ccree - add AEAD support") Cc: # v4.17+ Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_aead.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) --- a/drivers/crypto/ccree/cc_aead.c +++ b/drivers/crypto/ccree/cc_aead.c @@ -540,13 +540,12 @@ static int cc_aead_setkey(struct crypto_ unsigned int keylen) { struct cc_aead_ctx *ctx = crypto_aead_ctx(tfm); - struct rtattr *rta = (struct rtattr *)key; struct cc_crypto_req cc_req = {}; - struct crypto_authenc_key_param *param; struct cc_hw_desc desc[MAX_AEAD_SETKEY_SEQ]; - int rc = -EINVAL; unsigned int seq_len = 0; struct device *dev = drvdata_to_dev(ctx->drvdata); + const u8 *enckey, *authkey; + int rc; dev_dbg(dev, "Setting key in context @%p for %s. key=%p keylen=%u\n", ctx, crypto_tfm_alg_name(crypto_aead_tfm(tfm)), key, keylen); @@ -554,35 +553,33 @@ static int cc_aead_setkey(struct crypto_ /* STAT_PHASE_0: Init and sanity checks */ if (ctx->auth_mode != DRV_HASH_NULL) { /* authenc() alg. */ - if (!RTA_OK(rta, keylen)) - goto badkey; - if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM) - goto badkey; - if (RTA_PAYLOAD(rta) < sizeof(*param)) - goto badkey; - param = RTA_DATA(rta); - ctx->enc_keylen = be32_to_cpu(param->enckeylen); - key += RTA_ALIGN(rta->rta_len); - keylen -= RTA_ALIGN(rta->rta_len); - if (keylen < ctx->enc_keylen) + struct crypto_authenc_keys keys; + + rc = crypto_authenc_extractkeys(&keys, key, keylen); + if (rc) goto badkey; - ctx->auth_keylen = keylen - ctx->enc_keylen; + enckey = keys.enckey; + authkey = keys.authkey; + ctx->enc_keylen = keys.enckeylen; + ctx->auth_keylen = keys.authkeylen; if (ctx->cipher_mode == DRV_CIPHER_CTR) { /* the nonce is stored in bytes at end of key */ + rc = -EINVAL; if (ctx->enc_keylen < (AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE)) goto badkey; /* Copy nonce from last 4 bytes in CTR key to * first 4 bytes in CTR IV */ - memcpy(ctx->ctr_nonce, key + ctx->auth_keylen + - ctx->enc_keylen - CTR_RFC3686_NONCE_SIZE, - CTR_RFC3686_NONCE_SIZE); + memcpy(ctx->ctr_nonce, enckey + ctx->enc_keylen - + CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE); /* Set CTR key size */ ctx->enc_keylen -= CTR_RFC3686_NONCE_SIZE; } } else { /* non-authenc - has just one key */ + enckey = key; + authkey = NULL; ctx->enc_keylen = keylen; ctx->auth_keylen = 0; } @@ -594,13 +591,14 @@ static int cc_aead_setkey(struct crypto_ /* STAT_PHASE_1: Copy key to ctx */ /* Get key material */ - memcpy(ctx->enckey, key + ctx->auth_keylen, ctx->enc_keylen); + memcpy(ctx->enckey, enckey, ctx->enc_keylen); if (ctx->enc_keylen == 24) memset(ctx->enckey + 24, 0, CC_AES_KEY_SIZE_MAX - 24); if (ctx->auth_mode == DRV_HASH_XCBC_MAC) { - memcpy(ctx->auth_state.xcbc.xcbc_keys, key, ctx->auth_keylen); + memcpy(ctx->auth_state.xcbc.xcbc_keys, authkey, + ctx->auth_keylen); } else if (ctx->auth_mode != DRV_HASH_NULL) { /* HMAC */ - rc = cc_get_plain_hmac_key(tfm, key, ctx->auth_keylen); + rc = cc_get_plain_hmac_key(tfm, authkey, ctx->auth_keylen); if (rc) goto badkey; }