From patchwork Mon May 20 12:14:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164621 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp231293ili; Mon, 20 May 2019 05:34:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxGW14AsWoGA4DOOrrK4+Wq5B1rrpnnsyglXiw4nFffobZxpd+y5IlOhoRmEYaPw8amCz4j X-Received: by 2002:a63:fd52:: with SMTP id m18mr75539701pgj.267.1558355683769; Mon, 20 May 2019 05:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355683; cv=none; d=google.com; s=arc-20160816; b=w4HXRXrLgt02MGXQavdCD8+qevzvZaa9QiCxwUC9BGuUjNpvNis9KZsZTWwvUCrZjC JnWvBkPPlv7ehkwefFpKZXPiSL55qFQRCbTFcNb7x3ZroBcygrAFm0fU+GV/8jsPIVKh Vyi98WCn9RqlP7YL42FvIjkn/jp3666pkeAiYBWXwBeyGxehpxyk0o/xBQYxhaaXfhX4 0Pw5N5f+QTfK8h8zfZGw00mswenWvv2H/+/pHX56MKT3ZXPl/u1xtARI9F3MYl8azwIg hJOhQYahcW9x0GpNOGXqJL8bdht6l2Y6Nd2U1zwUBC0zAmlLSztoSLyVH73+HGy0QW2x etCg== 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=Kk+FINYSTHqaWjysVwi6DZb6/yuGbfud4vkMehbnu9g=; b=VW7VnIcwC7ewPG4AsqtPTMmsdodEb3H8IaiPWFVP18EqXELvcqAK0IiPzKPmx6kMGb y+pHdbYwtBibSu745SWz1/JsLvKLiMtNjzp/eecdcavO9pLAK0878bphMuk+vPZscUJH yP0l9C8Ibtl0z1wwYpGCCL7VWUf4WsTdzgl5cXWGx7mpqOLMCtywRxKUpTaKJOrEa6H3 OlZC8WZtr2E4lw2hr3BDQynWV2KHY3Vppduy4wwgZdiIjUHraXJHaemQ7BG0NqBVpGtq U3GEFBto3LXkGaqHjlsjqY04+B8pq2q6VezTe3NKQBdUx4e3E1HaKNfPI7NZXdP3MhpS wNKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Vl9+RloC; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e11si12396932pgv.569.2019.05.20.05.34.41; Mon, 20 May 2019 05:34:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=Vl9+RloC; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390767AbfETMdk (ORCPT + 14 others); Mon, 20 May 2019 08:33:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:50764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390755AbfETMdg (ORCPT ); Mon, 20 May 2019 08:33:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 3BFDB20815; Mon, 20 May 2019 12:33:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355615; bh=LIPVOzobOFCqE51m4NNu5tsrh3LZ6vm87nQqkPrsDEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vl9+RloC9GDGAtljBRID2zQYyMCvm/7Nnpp9OldluLFH/tzT+BT7q2HgPFwHmCQll m8fLj+wQ75gHyeZ9ViBJizAl4MFxr0HuuKXTt+0Sukof68Pzkx9695ZMQazdqVWt2b EKX5Mc/utAgjLqBh30AjVMHD8OGGO9nfYG4rnreA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 5.1 060/128] crypto: ccree - remove special handling of chained sg Date: Mon, 20 May 2019 14:14:07 +0200 Message-Id: <20190520115253.837081510@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gilad Ben-Yossef commit c4b22bf51b815fb61a35a27fc847a88bc28ebb63 upstream. We were handling chained scattergather lists with specialized code needlessly as the regular sg APIs handle them just fine. The code handling this also had an (unused) code path with a use-before-init error, flagged by Coverity. Remove all special handling of chained sg and leave their handling to the regular sg APIs. Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_buffer_mgr.c | 98 +++++++---------------------------- 1 file changed, 22 insertions(+), 76 deletions(-) --- a/drivers/crypto/ccree/cc_buffer_mgr.c +++ b/drivers/crypto/ccree/cc_buffer_mgr.c @@ -83,24 +83,17 @@ static void cc_copy_mac(struct device *d */ static unsigned int cc_get_sgl_nents(struct device *dev, struct scatterlist *sg_list, - unsigned int nbytes, u32 *lbytes, - bool *is_chained) + unsigned int nbytes, u32 *lbytes) { unsigned int nents = 0; while (nbytes && sg_list) { - if (sg_list->length) { - nents++; - /* get the number of bytes in the last entry */ - *lbytes = nbytes; - nbytes -= (sg_list->length > nbytes) ? - nbytes : sg_list->length; - sg_list = sg_next(sg_list); - } else { - sg_list = (struct scatterlist *)sg_page(sg_list); - if (is_chained) - *is_chained = true; - } + nents++; + /* get the number of bytes in the last entry */ + *lbytes = nbytes; + nbytes -= (sg_list->length > nbytes) ? + nbytes : sg_list->length; + sg_list = sg_next(sg_list); } dev_dbg(dev, "nents %d last bytes %d\n", nents, *lbytes); return nents; @@ -142,7 +135,7 @@ void cc_copy_sg_portion(struct device *d { u32 nents, lbytes; - nents = cc_get_sgl_nents(dev, sg, end, &lbytes, NULL); + nents = cc_get_sgl_nents(dev, sg, end, &lbytes); sg_copy_buffer(sg, nents, (void *)dest, (end - to_skip + 1), to_skip, (direct == CC_SG_TO_BUF)); } @@ -314,40 +307,10 @@ static void cc_add_sg_entry(struct devic sgl_data->num_of_buffers++; } -static int cc_dma_map_sg(struct device *dev, struct scatterlist *sg, u32 nents, - enum dma_data_direction direction) -{ - u32 i, j; - struct scatterlist *l_sg = sg; - - for (i = 0; i < nents; i++) { - if (!l_sg) - break; - if (dma_map_sg(dev, l_sg, 1, direction) != 1) { - dev_err(dev, "dma_map_page() sg buffer failed\n"); - goto err; - } - l_sg = sg_next(l_sg); - } - return nents; - -err: - /* Restore mapped parts */ - for (j = 0; j < i; j++) { - if (!sg) - break; - dma_unmap_sg(dev, sg, 1, direction); - sg = sg_next(sg); - } - return 0; -} - static int cc_map_sg(struct device *dev, struct scatterlist *sg, unsigned int nbytes, int direction, u32 *nents, u32 max_sg_nents, u32 *lbytes, u32 *mapped_nents) { - bool is_chained = false; - if (sg_is_last(sg)) { /* One entry only case -set to DLLI */ if (dma_map_sg(dev, sg, 1, direction) != 1) { @@ -361,35 +324,21 @@ static int cc_map_sg(struct device *dev, *nents = 1; *mapped_nents = 1; } else { /*sg_is_last*/ - *nents = cc_get_sgl_nents(dev, sg, nbytes, lbytes, - &is_chained); + *nents = cc_get_sgl_nents(dev, sg, nbytes, lbytes); if (*nents > max_sg_nents) { *nents = 0; dev_err(dev, "Too many fragments. current %d max %d\n", *nents, max_sg_nents); return -ENOMEM; } - if (!is_chained) { - /* In case of mmu the number of mapped nents might - * be changed from the original sgl nents - */ - *mapped_nents = dma_map_sg(dev, sg, *nents, direction); - if (*mapped_nents == 0) { - *nents = 0; - dev_err(dev, "dma_map_sg() sg buffer failed\n"); - return -ENOMEM; - } - } else { - /*In this case the driver maps entry by entry so it - * must have the same nents before and after map - */ - *mapped_nents = cc_dma_map_sg(dev, sg, *nents, - direction); - if (*mapped_nents != *nents) { - *nents = *mapped_nents; - dev_err(dev, "dma_map_sg() sg buffer failed\n"); - return -ENOMEM; - } + /* In case of mmu the number of mapped nents might + * be changed from the original sgl nents + */ + *mapped_nents = dma_map_sg(dev, sg, *nents, direction); + if (*mapped_nents == 0) { + *nents = 0; + dev_err(dev, "dma_map_sg() sg buffer failed\n"); + return -ENOMEM; } } @@ -571,7 +520,6 @@ void cc_unmap_aead_request(struct device struct crypto_aead *tfm = crypto_aead_reqtfm(req); struct cc_drvdata *drvdata = dev_get_drvdata(dev); u32 dummy; - bool chained; u32 size_to_unmap = 0; if (areq_ctx->mac_buf_dma_addr) { @@ -636,15 +584,14 @@ void cc_unmap_aead_request(struct device size_to_unmap += crypto_aead_ivsize(tfm); dma_unmap_sg(dev, req->src, - cc_get_sgl_nents(dev, req->src, size_to_unmap, - &dummy, &chained), + cc_get_sgl_nents(dev, req->src, size_to_unmap, &dummy), DMA_BIDIRECTIONAL); if (req->src != req->dst) { dev_dbg(dev, "Unmapping dst sgl: req->dst=%pK\n", sg_virt(req->dst)); dma_unmap_sg(dev, req->dst, cc_get_sgl_nents(dev, req->dst, size_to_unmap, - &dummy, &chained), + &dummy), DMA_BIDIRECTIONAL); } if (drvdata->coherent && @@ -1022,7 +969,6 @@ static int cc_aead_chain_data(struct cc_ unsigned int size_for_map = req->assoclen + req->cryptlen; struct crypto_aead *tfm = crypto_aead_reqtfm(req); u32 sg_index = 0; - bool chained = false; bool is_gcm4543 = areq_ctx->is_gcm4543; u32 size_to_skip = req->assoclen; @@ -1043,7 +989,7 @@ static int cc_aead_chain_data(struct cc_ size_for_map += (direct == DRV_CRYPTO_DIRECTION_ENCRYPT) ? authsize : 0; src_mapped_nents = cc_get_sgl_nents(dev, req->src, size_for_map, - &src_last_bytes, &chained); + &src_last_bytes); sg_index = areq_ctx->src_sgl->length; //check where the data starts while (sg_index <= size_to_skip) { @@ -1083,7 +1029,7 @@ static int cc_aead_chain_data(struct cc_ } dst_mapped_nents = cc_get_sgl_nents(dev, req->dst, size_for_map, - &dst_last_bytes, &chained); + &dst_last_bytes); sg_index = areq_ctx->dst_sgl->length; offset = size_to_skip; @@ -1484,7 +1430,7 @@ int cc_map_hash_request_update(struct cc dev_dbg(dev, " less than one block: curr_buff=%pK *curr_buff_cnt=0x%X copy_to=%pK\n", curr_buff, *curr_buff_cnt, &curr_buff[*curr_buff_cnt]); areq_ctx->in_nents = - cc_get_sgl_nents(dev, src, nbytes, &dummy, NULL); + cc_get_sgl_nents(dev, src, nbytes, &dummy); sg_copy_to_buffer(src, areq_ctx->in_nents, &curr_buff[*curr_buff_cnt], nbytes); *curr_buff_cnt += nbytes; From patchwork Mon May 20 12:14:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164620 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp231258ili; Mon, 20 May 2019 05:34:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHnQEDs96VK3Kq1MzAcQqGgXdlU/ZjDAJGgxQT9CvVVarthBTehCeuhIesuJ7gkVvBuE+D X-Received: by 2002:a17:902:ab97:: with SMTP id f23mr21130079plr.237.1558355681890; Mon, 20 May 2019 05:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355681; cv=none; d=google.com; s=arc-20160816; b=hlWa13Bpa6aHBKyDbcSMYbu7UZSYQgL+esMLjhUAnkywu+5wOyXEjxoRRAtd7KC3si WGZbYzlV/bHXeWF6Rgj8+cDMa+JAfgxePbDpJTzZIOkb7UtbO+BjiFbN0dC8iEQCn6J/ 07RGv5P9WK9UprnCf/Ahf2uf1gFG5t8V6tgux39scb0dmEdygiRFEmo3Lk2MQcHXh9Uy TS7r5Pmki1unhKIwqAoSo0O1cfgMRhlJabOP5T8v1Ccg7JJjIzo+qjmluu9Xp8W/VkQ7 gg6rWG2rxaN+Ii0SqyMumnzN/AeCCDZZr5+Avyr00eFbEowsruMY6FhRmul2wEtmCabs ivgw== 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=TEOjFFbIAKtWDVj7b5kOGp66OjQtTgLzbcPkVCXl414=; b=pDzYGhp/NDF/dB3oINSaA5eBnFJoLp9qCJhET1OShVGjUpHuQ0eoWy7QU3xloSqm0M iSEf4+q2Snd+Po/emwcDxYbNw9ie3WIBYSe2oCwCkiMlOnCqIh5WGtrvWHXyACjOCvI6 n2D0BqzvS1ll0X8uHQ7ygYro2Jz5JD+ymFKIiQyCNMjqQM7L3pzv2EYewiewuC4Tf0m0 jtxre5Fh9NwYJh7cj/kq+XPb380R/5vPG8qwRUyqhhHhc75f/oXR1BcPd7yV/vOvrkv3 IPJXnzUla3qj1BqN47Kl5c8QyeF57iBV/Ymzg1WYocKimJKwyk7SnxylZEDbD4Cptc91 v8fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J4kYahhF; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e11si12396932pgv.569.2019.05.20.05.34.40; Mon, 20 May 2019 05:34:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=J4kYahhF; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390745AbfETMdj (ORCPT + 14 others); Mon, 20 May 2019 08:33:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:50794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390765AbfETMdj (ORCPT ); Mon, 20 May 2019 08:33:39 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 E0F0E216C4; Mon, 20 May 2019 12:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355618; bh=Vc76SIEwx46ODrXQqltdqyN2/mHnKSGbQiibyzx/1hQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J4kYahhFHF1r74se7oM3JY3HDY6DSQttBkRL8t5EURYdEuIY2BrNYPgNwt15ASQPH 0iKS6WM7j54EftE7IqBZbcf/Sag1rkjrx42LF7cDuStfzpImqk3sJumLzW06lBGjYK MCzB5IOIoZMvdP6LXnePY4Y/iy7Z9hyDsdTvJpR8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 5.1 061/128] crypto: ccree - fix mem leak on error path Date: Mon, 20 May 2019 14:14:08 +0200 Message-Id: <20190520115253.906358503@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gilad Ben-Yossef commit d574b707c873d6ef1a2a155f8cfcfecd821e9a2e upstream. Fix a memory leak on the error path of IV generation code. Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_ivgen.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) --- a/drivers/crypto/ccree/cc_ivgen.c +++ b/drivers/crypto/ccree/cc_ivgen.c @@ -154,9 +154,6 @@ void cc_ivgen_fini(struct cc_drvdata *dr } ivgen_ctx->pool = NULL_SRAM_ADDR; - - /* release "this" context */ - kfree(ivgen_ctx); } /*! @@ -174,10 +171,12 @@ int cc_ivgen_init(struct cc_drvdata *drv int rc; /* Allocate "this" context */ - ivgen_ctx = kzalloc(sizeof(*ivgen_ctx), GFP_KERNEL); + ivgen_ctx = devm_kzalloc(device, sizeof(*ivgen_ctx), GFP_KERNEL); if (!ivgen_ctx) return -ENOMEM; + drvdata->ivgen_handle = ivgen_ctx; + /* Allocate pool's header for initial enc. key/IV */ ivgen_ctx->pool_meta = dma_alloc_coherent(device, CC_IVPOOL_META_SIZE, &ivgen_ctx->pool_meta_dma, @@ -196,8 +195,6 @@ int cc_ivgen_init(struct cc_drvdata *drv goto out; } - drvdata->ivgen_handle = ivgen_ctx; - return cc_init_iv_sram(drvdata); out: From patchwork Mon May 20 12:14:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164622 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp231340ili; Mon, 20 May 2019 05:34:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqysTCNlAnK/6PlJ2jzfaiityO2vgp+SYNWIrk+u57Yn6Ma6v1pZeWCiyt7DdkY5D+m1EtsC X-Received: by 2002:a65:4144:: with SMTP id x4mr16741690pgp.282.1558355685532; Mon, 20 May 2019 05:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355685; cv=none; d=google.com; s=arc-20160816; b=Z96HjKzusqRea6HW96D1sJasty6+sfLxt9Mu9HOIp/IjM2tX30GIiWn0yzrJkAUWyC nOwkdgEzb0z3OIlPy0CCn8cqD56LUQKcKeE3q1gowMmOFc/Ts/7a/VMO6Mw3RT6pt806 e3rKqm6vAZDzBDaonaomFKcrNQp6TJz+stZtXwOEA+d7qUfa1UWZdKO0sfWNCO6ABfeQ 09SSnHmO3YHa2wabo84WeRYB//RNNAadkJ14kpsYsK1kMfgcJE9hjTopbz07Dl10Xo7x Z0qF0BTbyuB1ZMWH1XLqO8JGI/UCrmQh3mfaKeUG8kJlnqxGPQx6XzHyYklMbSRR7Apc JPpA== 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=4hi58WDdbOUM/9kH+6aekOTXYHooTdZi2b7xGvjqVXg=; b=bmUZDkvxEUuDQTwQbxswzuMEvfmZ5x0b0ZbiAGDeJK/KpW1U0Su0atCncVeMiVCeyq 6R+AmaxpnqjxP7gIMy29fEJjPH+/YrIUm4ozJ+E42KQ0PHu5c8EIPzNnKQE7TnMdseh7 wkymY0nTq6TGyd7DxWLMMIN/+2oDwBsGiK4+5t4nltRwpidpfc4IoCMAwgurx0Y0yieR u5Rap0kzdtnSLyM0p5sa3u5ar//j6Rqa0DpLDeWyrWdFPjfKS9XYn+6BNFWjUzilSHHV pqI5RdoQ+vsJtaJFcN1Il2wyuUXuT2tGeCbwTidI7HkvfnQdIX4j8Uz8gfx3frLToPTe LUkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ov9DsBTz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e11si12396932pgv.569.2019.05.20.05.34.43; Mon, 20 May 2019 05:34:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=ov9DsBTz; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390776AbfETMdn (ORCPT + 14 others); Mon, 20 May 2019 08:33:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:50838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390770AbfETMdm (ORCPT ); Mon, 20 May 2019 08:33:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 861D920815; Mon, 20 May 2019 12:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355621; bh=jS18uhjhZFB0J7GPa296xwoUoszjtacB5vvBJtErWs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ov9DsBTzrZelEL3Gco+S8/JellBtP/rJq3ElSGZsA2pX4r0LFWb1NgMxazQst9kig bF5vFmxl40+Via/jLFw6Qw1KfnOr0Exc3N83LAkPjxupwprbF22B9JVLge9qjGJYwR gYFdTHx7ORBvINgyt4LsOtIt60nyQWyqs2Cd8wx8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 5.1 062/128] crypto: ccree - dont map MAC key on stack Date: Mon, 20 May 2019 14:14:09 +0200 Message-Id: <20190520115253.971748129@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Gilad Ben-Yossef commit 874e163759f27e0a9988c5d1f4605e3f25564fd2 upstream. The MAC hash key might be passed to us on stack. Copy it to a slab buffer before mapping to gurantee proper DMA mapping. Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_hash.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) --- a/drivers/crypto/ccree/cc_hash.c +++ b/drivers/crypto/ccree/cc_hash.c @@ -69,6 +69,7 @@ struct cc_hash_alg { struct hash_key_req_ctx { u32 keylen; dma_addr_t key_dma_addr; + u8 *key; }; /* hash per-session context */ @@ -730,13 +731,20 @@ static int cc_hash_setkey(struct crypto_ ctx->key_params.keylen = keylen; ctx->key_params.key_dma_addr = 0; ctx->is_hmac = true; + ctx->key_params.key = NULL; if (keylen) { + ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL); + if (!ctx->key_params.key) + return -ENOMEM; + ctx->key_params.key_dma_addr = - dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); + dma_map_single(dev, (void *)ctx->key_params.key, keylen, + DMA_TO_DEVICE); if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", - key, keylen); + ctx->key_params.key, keylen); + kzfree(ctx->key_params.key); return -ENOMEM; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n", @@ -887,6 +895,9 @@ out: dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", &ctx->key_params.key_dma_addr, ctx->key_params.keylen); } + + kzfree(ctx->key_params.key); + return rc; } @@ -913,11 +924,16 @@ static int cc_xcbc_setkey(struct crypto_ ctx->key_params.keylen = keylen; + ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL); + if (!ctx->key_params.key) + return -ENOMEM; + ctx->key_params.key_dma_addr = - dma_map_single(dev, (void *)key, keylen, DMA_TO_DEVICE); + dma_map_single(dev, ctx->key_params.key, keylen, DMA_TO_DEVICE); if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) { dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n", key, keylen); + kzfree(ctx->key_params.key); return -ENOMEM; } dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n", @@ -969,6 +985,8 @@ static int cc_xcbc_setkey(struct crypto_ dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n", &ctx->key_params.key_dma_addr, ctx->key_params.keylen); + kzfree(ctx->key_params.key); + return rc; } From patchwork Mon May 20 12:14:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164623 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp231437ili; Mon, 20 May 2019 05:34:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0PSQr/JOu2v9DRTMevgeeKVsK1tje8cPxckcYlVUEaYW5yu6RTSgTrA6J7L+exCNQ+PFS X-Received: by 2002:a65:5785:: with SMTP id b5mr39224160pgr.252.1558355691319; Mon, 20 May 2019 05:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355691; cv=none; d=google.com; s=arc-20160816; b=hdTHlJ+cZ4lTstu1RzZjqJr75OrssTzVf4LuLEh20RSv3+k/NhT6caxaP2RmWMvIqu /JbAWb+nX0kb5idj10UELrJWwF4C7hqeAyBPozC2aoJnFemvIOhtjOQ5cgVdJo33vCTg mVm3JcbPXpa6PmgdSgdLeb8ZCJlC3Kc9ppOuMW6vidSBFJ79/rvBgNe9cAEb1FNzTAVE r2vF0/kcWBDYX3W7wPrI9P4nOBhzqiWFAwaF2H7jFZtgngZDmlq0P30vgxmvrS+OFxiO iJUTNEQKAvnRVmM2j/vUZDGEPzKtgRDn/BdKRAWoHECnp6bvulB0R9OzMNo99eQRTkAb Z3mQ== 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=7VDXYu1Vil/45PCSSpHKBrSUhZb+7wVJ3dTnv4Vglp8=; b=bv6UbHzhn1RX/oAQxhIqf/P7LeMc7uwSDCJz9sMeHAFYX9TjoXQezI1nY6oEv0Oq3w /DBUlu0MXKZr6HSpiml1UlglN0XFKfYcNt/Z5iHnAm8HjzbTqRuZtVE2Kd2A2f3KkmQT 8QOY4dobCymUWBVZKmQ1mWKHJY1bZdDcvkVg+H+mOSC9gGVmelnEIJnumGDEbcylaP2v Oc/Gy+KwP3UG7HUcOq/pPTmY9tG1pdoKmuq/T8shRgCjBlcNJou6+Ze6bW7Nr4logQP+ 1VG5cx9Hvlsem1WxHCSCo1D3gCPGt5rHjKW5Ez1EtIqaabZtVhr9zE8stys0msNtXC4q bIVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qb1Miz7D; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e11si12396932pgv.569.2019.05.20.05.34.49; Mon, 20 May 2019 05:34:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=qb1Miz7D; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390801AbfETMdt (ORCPT + 14 others); Mon, 20 May 2019 08:33:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:50978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390464AbfETMdt (ORCPT ); Mon, 20 May 2019 08:33:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 858F3214DA; Mon, 20 May 2019 12:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355629; bh=Uw0pF31YOHlAKBRVzNCneThPQgBmKK3R8VVsUrLP+AI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qb1Miz7DnCy45IpKju43H1zO9LCUOtBO4VY57sey63GJ0EHBEaq9pMBbkW/BLF/6p zjfvsC918oPLW3XEzq/742C/FAiawp5cv3hTfhejt940dY02z2PhKCYfgA06csK2gK W82Cn5xvEvXCRl5VfjlFc6gccl7ChYz7dd5Z6rYA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ofir Drang , Gilad Ben-Yossef , Herbert Xu Subject: [PATCH 5.1 065/128] crypto: ccree - pm resume first enable the source clk Date: Mon, 20 May 2019 14:14:12 +0200 Message-Id: <20190520115254.191615570@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ofir Drang commit 7766dd774d80463cec7b81d90c8672af91de2da1 upstream. On power management resume function first enable the device clk source to allow access to the device registers. Signed-off-by: Ofir Drang Signed-off-by: Gilad Ben-Yossef Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccree/cc_pm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/crypto/ccree/cc_pm.c +++ b/drivers/crypto/ccree/cc_pm.c @@ -42,14 +42,15 @@ int cc_pm_resume(struct device *dev) struct cc_drvdata *drvdata = dev_get_drvdata(dev); dev_dbg(dev, "unset HOST_POWER_DOWN_EN\n"); - cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE); - + /* Enables the device source clk */ rc = cc_clk_on(drvdata); if (rc) { dev_err(dev, "failed getting clock back on. We're toast.\n"); return rc; } + cc_iowrite(drvdata, CC_REG(HOST_POWER_DOWN_EN), POWER_DOWN_DISABLE); + rc = init_cc_regs(drvdata, false); if (rc) { dev_err(dev, "init_cc_regs (%x)\n", rc); From patchwork Mon May 20 12:15:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 164626 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp234964ili; Mon, 20 May 2019 05:38:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwN82kIy54YFEiY18xw2PBfPNEswj0iVDckFolopwj1mCO2IkC+9XraVs2VTW68zfACexR+ X-Received: by 2002:a63:b70f:: with SMTP id t15mr73065021pgf.351.1558355889169; Mon, 20 May 2019 05:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355889; cv=none; d=google.com; s=arc-20160816; b=Jyig8GN1/xL7ieNR6zh1TfFGGHMkdUiBUThMma9S37imRQmR3lgH2SbEblRFa5TK3U Wd9vPJ/xX6bSiAESflMVu12ENExbqWZtZ+YOuCRASzhrVqc6Y2Al9w9Mol4gjJi32TbO hHKY1EbHL5d832gzXgCoKIPff4HUvIgpXpUUDdxsQmbQPjHK+XP/c4lnutwhXeTxuNXL aB9Faf8yuiavVCOjtUYNxHIUcSfaCzrpKuD4c9dlc6Avxz1jsQFsCijJ9aH0TuAkCTnr 6ZuO6QQoX2BWLRKLXHIwRK9YujKliYelk6AMETPnlyn7ZU87NBqXfD2S4Fc0MPTVjVHF Y7Kg== 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=aLSPy0PJB38nhyugiEAD0hlO+VUpL6qZFyx1bRcfjE0=; b=xl3z3EBnGYECpfdup/kAP5Pjg6smvsSLWJREPXtbOm6N3h3wAySfWY/EI1dmZx9gVz UONFzAQoGd0qi2IpV4m6XvqvA3Ert3UZQSurS3YM1Ggfl87afhvms5JKLXH5GMUa0JRR 6HlmX4coGmPHjzCPUUJQaoehsryqr4YKDfT/ZDSjO/xu8eSPME3dNxrZMAm6tyXMEP4F fCRMoLFPsjuFCXig2OD2WBg7jzNtLEw1qh2HU9VEGU995Q4NHHFVOQqQAMZHQre2jQHx z1H3w5wDUpauNeS9qqXu6tts8yaHKOC5y1fOmrhZ+CaZuUM4joYhpzKS/QmYIpUzQA8E wLPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uJhRrHBQ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 e11si12396932pgv.569.2019.05.20.05.38.07; Mon, 20 May 2019 05:38:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=uJhRrHBQ; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391250AbfETMgS (ORCPT + 14 others); Mon, 20 May 2019 08:36:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:55306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391078AbfETMgR (ORCPT ); Mon, 20 May 2019 08:36:17 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 513C721479; Mon, 20 May 2019 12:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355775; bh=zPcvc2akhzzKrUb6urgykNTe+6gmgSw6iONcU2LWsAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uJhRrHBQyili9eWRFYyuh9S5tUnX1SWuJu///hB/1ZonBxBsv8ijx8J8ccJRFTyzv iLGVhO0oURVOxLW18S9+p39CGpXOwIqIu7L31d/98TcfM+azBuZOVNBV/IAI+gVWVO UcUArI1ZiSvpB0hx7WUow0j+99DVByZeKIb8QQ4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masahiro Yamada Subject: [PATCH 5.1 120/128] kbuild: turn auto.conf.cmd into a mandatory include file Date: Mon, 20 May 2019 14:15:07 +0200 Message-Id: <20190520115256.794907347@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115249.449077487@linuxfoundation.org> References: <20190520115249.449077487@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masahiro Yamada commit d2f8ae0e4c5c754f1b2a7b8388d19a1a977e698a upstream. syncconfig is responsible for keeping auto.conf up-to-date, so if it fails for any reason, the build must be terminated immediately. However, since commit 9390dff66a52 ("kbuild: invoke syncconfig if include/config/auto.conf.cmd is missing"), Kbuild continues running even after syncconfig fails. You can confirm this by intentionally making syncconfig error out: # diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c # index 08ba146..307b9de 100644 # --- a/scripts/kconfig/confdata.c # +++ b/scripts/kconfig/confdata.c # @@ -1023,6 +1023,9 @@ int conf_write_autoconf(int overwrite) # FILE *out, *tristate, *out_h; # int i; # # + if (overwrite) # + return 1; # + # if (!overwrite && is_present(autoconf_name)) # return 0; Then, syncconfig fails, but Make would not stop: $ make -s mrproper allyesconfig defconfig $ make scripts/kconfig/conf --syncconfig Kconfig *** Error during sync of the configuration. make[2]: *** [scripts/kconfig/Makefile;69: syncconfig] Error 1 make[1]: *** [Makefile;557: syncconfig] Error 2 make: *** [include/config/auto.conf.cmd] Deleting file 'include/config/tristate.conf' make: Failed to remake makefile 'include/config/auto.conf'. SYSTBL arch/x86/include/generated/asm/syscalls_32.h SYSHDR arch/x86/include/generated/asm/unistd_32_ia32.h SYSHDR arch/x86/include/generated/asm/unistd_64_x32.h SYSTBL arch/x86/include/generated/asm/syscalls_64.h [ continue running ... ] The reason is in the behavior of a pattern rule with multi-targets. %/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG) $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig GNU Make knows this rule is responsible for making all the three files simultaneously. As far as examined, auto.conf.cmd is the target in question when this rule is invoked. It is probably because auto.conf.cmd is included below the inclusion of auto.conf. The inclusion of auto.conf is mandatory, while that of auto.conf.cmd is optional. GNU Make does not care about the failure in the process of updating optional include files. I filed this issue (https://savannah.gnu.org/bugs/?56301) in case this behavior could be improved somehow in future releases of GNU Make. Anyway, it is quite easy to fix our Makefile. Given that auto.conf is already a mandatory include file, there is no reason to stick auto.conf.cmd optional. Make it mandatory as well. Cc: linux-stable # 5.0+ Fixes: 9390dff66a52 ("kbuild: invoke syncconfig if include/config/auto.conf.cmd is missing") Signed-off-by: Masahiro Yamada [commented out diff above to keep patch happy - gregkh] Signed-off-by: Greg Kroah-Hartman --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/Makefile +++ b/Makefile @@ -636,7 +636,7 @@ ifeq ($(may-sync-config),1) # Read in dependencies to all Kconfig* files, make sure to run syncconfig if # changes are detected. This should be included after arch/$(SRCARCH)/Makefile # because some architectures define CROSS_COMPILE there. --include include/config/auto.conf.cmd +include include/config/auto.conf.cmd $(KCONFIG_CONFIG): @echo >&2 '***'