From patchwork Thu Nov 9 09:16:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gilad Ben-Yossef X-Patchwork-Id: 118419 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp6347065qgn; Thu, 9 Nov 2017 01:18:14 -0800 (PST) X-Google-Smtp-Source: ABhQp+Q5/ykGU0ZR9HeVCnL8AYkRxEU9Fb8QeiCaBN6RZPFG/ayb106Mncl76Q7ot6MsSRh1kpi2 X-Received: by 10.98.189.23 with SMTP id a23mr3514097pff.124.1510219093928; Thu, 09 Nov 2017 01:18:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510219093; cv=none; d=google.com; s=arc-20160816; b=Dd0XoHtrJJl2Nrw0dcgmqQo4zDkbrf1g/k/zvmJT+XWVWQ4QKIeU9Vg9sNs9q81a/A +nnt3b6X/0D9MjFpYSRrr2Swa0O9/+k9okuMoRwzKIIoy7Pw5C8LlG5FBO0dRdDV02Jl 73YiBN9IgR42KgJ49ceL5Uqx7dHe0/MOLYRCLv9oGvCBWpl+sIvltpFIkRLc+zJT16F9 gFMG9+ztXx+wJSx569+V3FBOfs5MinrPhodXdH7Vg/kl4XxI0gc0YpZfnZIDaqT5luJY JDFKjvmOzSZWcThareV4xo/4xXIVnLqiyAgIcKgpdY6aW61qe82oMM8A8F054GgkhsIh 2ppQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=V1aLQJ1FHFs+zSxrFBsGaR8L9yMAfcNKHFvhK7ExjhQ=; b=DGMr9b7Otr621d2NQJlDnlz7yapPtXrakVJFByTrw7OJbgiG28CCrk4T6nHhNuNn0w 0/fwejs7P9eXjof4nTUaxh9RVflvJtqZk0rq9O5MW46L9LtE2zWW9g/c3JEO+AHaK5Ly WIJcr50525Zhg7kGSv4cDEYayuouHakdGi+07P9KaLCQae2VXZLXpQQJznn+mnRT0KYn qgotP6o5l+5oyoitYIeO5ioWJi0+PJazbbYP5HuogC6ERLzLvD5+S044PCjVfA+EFg/O wtk1cWOlH2CbaNqM/x7Y/n2jHL/1zRxhNX6HfYKxvRV5ZKBBPHlJGYtvb+qafGmie+a9 mrJA== ARC-Authentication-Results: i=1; mx.google.com; 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 j64si6251071pfe.155.2017.11.09.01.18.13; Thu, 09 Nov 2017 01:18:13 -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; 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 S1754011AbdKIJSL (ORCPT + 25 others); Thu, 9 Nov 2017 04:18:11 -0500 Received: from foss.arm.com ([217.140.101.70]:43586 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753909AbdKIJLB (ORCPT ); Thu, 9 Nov 2017 04:11:01 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4D3651435; Thu, 9 Nov 2017 01:11:01 -0800 (PST) Received: from sugar.kfn.arm.com (unknown [10.45.48.162]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 600CD3F246; Thu, 9 Nov 2017 01:10:59 -0800 (PST) From: Gilad Ben-Yossef To: Greg Kroah-Hartman Cc: Ofir Drang , stable , linux-crypto@vger.kernel.org, driverdev-devel@linuxdriverproject.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/10] staging: ccree: fix leak of import() after init() Date: Thu, 9 Nov 2017 09:16:09 +0000 Message-Id: <1510218980-3549-2-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510218980-3549-1-git-send-email-gilad@benyossef.com> References: <1510218980-3549-1-git-send-email-gilad@benyossef.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org crypto_ahash_import() may be called either after crypto_ahash_init() or without such call. Right now we always internally call init() as part of import(), thus leaking memory and mappings if the user has already called init() herself. Fix this by only calling init() internally if the state is not already initialized. Fixes: commit 454527d0d94f ("staging: ccree: fix hash import/export") Cc: stable Signed-off-by: Gilad Ben-Yossef --- drivers/staging/ccree/ssi_hash.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/drivers/staging/ccree/ssi_hash.c b/drivers/staging/ccree/ssi_hash.c index d79090e..1799d3f 100644 --- a/drivers/staging/ccree/ssi_hash.c +++ b/drivers/staging/ccree/ssi_hash.c @@ -1778,9 +1778,12 @@ static int ssi_ahash_import(struct ahash_request *req, const void *in) } in += sizeof(u32); - rc = ssi_hash_init(state, ctx); - if (rc) - goto out; + /* call init() to allocate bufs if the user hasn't */ + if (!state->digest_buff) { + rc = ssi_hash_init(state, ctx); + if (rc) + goto out; + } dma_sync_single_for_cpu(dev, state->digest_buff_dma_addr, ctx->inter_digestsize, DMA_BIDIRECTIONAL);