Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3388979ybp; Sun, 6 Oct 2019 10:51:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwU3SyU2M75nDaFjCtCt/DdZKqggXtdGFlRKAN5s1F41HDR4J16XpKL/BzVvVFclkjXOlIh X-Received: by 2002:a17:906:8c8:: with SMTP id o8mr20912843eje.56.1570384282780; Sun, 06 Oct 2019 10:51:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570384282; cv=none; d=google.com; s=arc-20160816; b=Uc8gNtHZSxash21/TnblhGgDRVlU565TZGqxhBRgn9LhGxFVqqwZEFGUxCfH6o7tcM FDDpdoofKsuGVZJQv73nod3uj1O777ghjP2luizKlHh73MkOLbmkVlu0G86NZWmy0ljN 11ySy+UWJOi8Z76GOXsijTmmXDayTQU128fEnF8OP1bKUxxb2mVUSmuHwaFCH7AnINt6 oJRfXhNk2VQmIvRqm/DmOK6cxLV6G7WJjgoNGuqiK/qzRZpzeQ52W/LdAxt30WQtPENZ ChMpgfIOEE+WWBfKdQRitEWuKQa1oTfmsekMDrRraXw2rRoQKXCTKy4V57VCdHG4nbpS 1oQg== 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=jOfBuAzK+hir8BzYrkjsONBCish9O4MY6traox38x/k=; b=m8UBSc6WwoOKgkhjBI085L7TwhyPy6UiJgoE3VkkNFTNM3FQLZRzdY9+FFeGTzs1dK w7jv1ZmajhGxjjG0yR44ivfiKhRw83WK3kfqeCkFBvbVXC2Jz4XlSW3PNrHS9mmhTNRF FXZ/2DlYRtdKF7Rm3RgZJZJ+uT0nfnvyCmbhMjquPdFrJiHjK3E9ziJCO7SWv6A4d46d l0InsmzMbOnJRnkafBowV86phEm2wg9HPjeE8hUc3stw0Wo4N2ny2/iDd/SPLpvgoUC3 yJIIqkP9XqzpD6LVQkngAyRT6gSQb1MGWy1h7hrFn/S1xECkcN72JlSM9cM4h71QNpD/ /ayw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XBO4zxpZ; 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 o49si7261761edc.261.2019.10.06.10.50.59; Sun, 06 Oct 2019 10:51:22 -0700 (PDT) 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=XBO4zxpZ; 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 S1726773AbfJFRsA (ORCPT + 99 others); Sun, 6 Oct 2019 13:48:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:44416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731639AbfJFRoP (ORCPT ); Sun, 6 Oct 2019 13:44:15 -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 0D0532080F; Sun, 6 Oct 2019 17:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383854; bh=VHqFPei1l3XYQuzGwjYB6MtsKq7T/Rtc2e+h2ot99yM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XBO4zxpZEB9a2pxOB5mexcJJwR3WzM26gNJ7+MkOMADWFjorxsjruxnACtixX6VcD 4pBco0Rv3I1mZGMbycnuSZcZQTOifrOgUho1HPdMJ+QAsWleExEl1PvXsZp8efxB9e 2GX/vxpN3woPIvtmWP314WuW1k31pr5ix4hPPyus= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunfeng Ye , Herbert Xu , Sasha Levin Subject: [PATCH 5.3 119/166] crypto: hisilicon - Fix double free in sec_free_hw_sgl() Date: Sun, 6 Oct 2019 19:21:25 +0200 Message-Id: <20191006171223.331622817@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171212.850660298@linuxfoundation.org> References: <20191006171212.850660298@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Yunfeng Ye [ Upstream commit 24fbf7bad888767bed952f540ac963bc57e47e15 ] There are two problems in sec_free_hw_sgl(): First, when sgl_current->next is valid, @hw_sgl will be freed in the first loop, but it free again after the loop. Second, sgl_current and sgl_current->next_sgl is not match when dma_pool_free() is invoked, the third parameter should be the dma address of sgl_current, but sgl_current->next_sgl is the dma address of next chain, so use sgl_current->next_sgl is wrong. Fix this by deleting the last dma_pool_free() in sec_free_hw_sgl(), modifying the condition for while loop, and matching the address for dma_pool_free(). Fixes: 915e4e8413da ("crypto: hisilicon - SEC security accelerator driver") Signed-off-by: Yunfeng Ye Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/hisilicon/sec/sec_algs.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/crypto/hisilicon/sec/sec_algs.c b/drivers/crypto/hisilicon/sec/sec_algs.c index 02768af0dccdd..8c789b8671fc4 100644 --- a/drivers/crypto/hisilicon/sec/sec_algs.c +++ b/drivers/crypto/hisilicon/sec/sec_algs.c @@ -215,17 +215,18 @@ static void sec_free_hw_sgl(struct sec_hw_sgl *hw_sgl, dma_addr_t psec_sgl, struct sec_dev_info *info) { struct sec_hw_sgl *sgl_current, *sgl_next; + dma_addr_t sgl_next_dma; - if (!hw_sgl) - return; sgl_current = hw_sgl; - while (sgl_current->next) { + while (sgl_current) { sgl_next = sgl_current->next; - dma_pool_free(info->hw_sgl_pool, sgl_current, - sgl_current->next_sgl); + sgl_next_dma = sgl_current->next_sgl; + + dma_pool_free(info->hw_sgl_pool, sgl_current, psec_sgl); + sgl_current = sgl_next; + psec_sgl = sgl_next_dma; } - dma_pool_free(info->hw_sgl_pool, hw_sgl, psec_sgl); } static int sec_alg_skcipher_setkey(struct crypto_skcipher *tfm, -- 2.20.1