Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp6020804ybn; Sun, 29 Sep 2019 10:36:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnPTqGX+p13ncAh1SJ8w59KhOPghrsF8Hg2PfORZ3q+YA9T3FLgI1yC1nY6uEMUbY0W/Zt X-Received: by 2002:a17:906:2ec8:: with SMTP id s8mr16616536eji.275.1569778565457; Sun, 29 Sep 2019 10:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569778565; cv=none; d=google.com; s=arc-20160816; b=lvDjFWdoIlMJ22TDXaBcAnAy4YKPB/M1nLI3wQVEDWuVY2VsMAMrUW/XAaD8NZwTRU t5ji77BXtN9DRunhLJSWC4DCt32NeTxzCZMwIqEIqHkYfvCTVlFSosFGPtqZ5cfGS8Re 5E3B1uGdd1J76XaCkuPuixsS+boA/4o2aAQi1bxsAWUJ8eXv+c3Gz10pTZnw8AiQusct TD50VCJxw78nuSWkCcwlqyBI/rrHcXUYz1MKebiQL6RPhC9Bnwbza83XzNLF5ljg/Wpd F1VKO19FddU8QPXh5U70T+0vo5DPYoQceuqLVxQGaoo37m8xbC57NCHrTEngNmZObLx4 y7Aw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Dcor3Qh1mEv0AlozUj03slsJhAw7xPXFhYsZD4O+Ktc=; b=MPlgsNEYVSbN/NFmI48DCl2ZqDSOJoIkJde8dozSTGMuL3hIzyG5HB47O6oicYR06A jyT4zAsDgcS5rbppMV4teqi98+SrDDAaKnJpCJ7TVHdqC0UHs2mce24Ar58NVfKiMDIH z3PAVdb/NY5GMMVbAc9vmLGllJNmDYOHQBdan5ucc6HeqGrllMEBU0DTjaADNeyuah2P mk6X6ssHObr7wtZFwjSt1IsUhLqFJg+z2obPneI/27H34ZIbkKLR7j7COULRKf1xWghM +n/ypos1JHl2Oxlt1G46mEmDKMzL+Quyf8GsNZtpPgbDOGS6/OGstzgzk7sv5YEqrkTZ lTxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=m8WVzHEX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v25si5903324edb.286.2019.09.29.10.35.41; Sun, 29 Sep 2019 10:36:05 -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=m8WVzHEX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730560AbfI2RfV (ORCPT + 99 others); Sun, 29 Sep 2019 13:35:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:47360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729347AbfI2RfL (ORCPT ); Sun, 29 Sep 2019 13:35:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 20DE121925; Sun, 29 Sep 2019 17:35:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569778510; bh=d5x6H7X8RM/sSGV+fpNeGD/8PnIzqMfJl2docqT8a5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m8WVzHEXnPob+CYJbBLua8uhhKyY4U9OrNpnRMGKvS0sC3uEeK2PP1jtfDdjxVfqB 8y6/bG7cAV+XdD7jIjNYSwMI3TKih7eSoNFnihAmJ3nteu74agwtwa7eCX4Dt6qX/9 vEo4HqBJZDOKjc6yb3/4n/a892iKfU9v7n3AjLU0= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yunfeng Ye , Herbert Xu , Sasha Levin , linux-crypto@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 26/33] crypto: hisilicon - Fix double free in sec_free_hw_sgl() Date: Sun, 29 Sep 2019 13:34:14 -0400 Message-Id: <20190929173424.9361-26-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190929173424.9361-1-sashal@kernel.org> References: <20190929173424.9361-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 cdc4f9a171d98..db2983c51f1e6 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