From patchwork Thu May 11 11:53:44 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: 99624 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp689496qge; Thu, 11 May 2017 04:54:20 -0700 (PDT) X-Received: by 10.98.214.90 with SMTP id r87mr12020872pfg.204.1494503660757; Thu, 11 May 2017 04:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494503660; cv=none; d=google.com; s=arc-20160816; b=FP+AUlhD0Au6SgInDfCHr3800YvPtJiYOkTgOSDJJsYoLZircN4tcF0MuanqBU6BvY 7klI0IQIM+2SBIc2056GCvh38qF+MNHcXx4nO7jfE6ez/armbfcUDdaI0ZM+uWMYDhHl j83ILWqfXNF0+1bRl8xbzfNrcef9HR82/EGM5jrjgUZMHQeG5SUgjYGwQgqWa1VqCEjI mtCu31A0q4/sywPjwQMhIZdW2u7NV3IuorBeOmx8NRqcAzClW1FQNMG1XHybyDxh+Mz1 zwlsGwWs70txKSkAqUg6UW7uHCM7myjfU+Z+x6KwWm3kg5FAPw/TP7/rnU8EArQrTLvk SJ3g== 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=zZInZCwhHFP63jyB3lU/zESkEfNOTlt2rVJX5apZOMs=; b=v/xSbqzoAua43Ui5Rv180rTpp0JG+c/EKrTzccffDUuodGy8AJj9lkuJ74fICeXxIJ Q0Wi1PjVY0B7N4ro/PSnSufn4oue/CN6542/S+L2ce4EaNmokVbl1G6/F2DmJ3dYEpxM pxtbx34sUfuEny9EuLO3/ccla0GwxZgincP6wgl1HrpRwWDCXGRyIefRtiKkeO9H7CQv rHjacH7SsO3uoOD/7ZA14Y/12GxELi7wksiVvEQkR7kUjFcCxjAht5t7kH90UeBApVQh hm7G0BD1U/fGxj4gP30s2qnPE/i4F+u6KmQACGmyKxTKX2fybWpdNo2nyeYCFy1OCzQV 5FAw== 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 v2si1651466plk.313.2017.05.11.04.54.20; Thu, 11 May 2017 04:54:20 -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; 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 S932649AbdEKLyQ (ORCPT + 25 others); Thu, 11 May 2017 07:54:16 -0400 Received: from foss.arm.com ([217.140.101.70]:46612 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932631AbdEKLyN (ORCPT ); Thu, 11 May 2017 07:54:13 -0400 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 39D712B; Thu, 11 May 2017 04:54:08 -0700 (PDT) Received: from gby.kfn.arm.com (unknown [10.45.48.150]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 687403F4FF; Thu, 11 May 2017 04:54:05 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells Cc: Ofir Drang , Gilad Ben-Yossef , Eric Biggers , stable@vger.kernel.org, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Subject: [PATCH 3/4] crypto: gcm wait for crypto op not signal safe Date: Thu, 11 May 2017 14:53:44 +0300 Message-Id: <1494503626-15877-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1494503626-15877-1-git-send-email-gilad@benyossef.com> References: <1494503626-15877-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_gcm_setkey() was using wait_for_completion_interruptible() to wait for completion of async crypto op but if a signal occurs it may return before DMA ops of HW crypto provider finish, thus corrupting the data buffer that is kfree'ed in this case. Resolve this by using wait_for_completion() instead. Reported-by: Eric Biggers Signed-off-by: Gilad Ben-Yossef CC: stable@vger.kernel.org --- crypto/drbg.c | 4 ++-- crypto/gcm.c | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) -- 2.1.4 diff --git a/crypto/drbg.c b/crypto/drbg.c index fa9054d..cdb27ac 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1767,8 +1767,8 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg, break; case -EINPROGRESS: case -EBUSY: - ret = wait_for_completion(&drbg->ctr_completion); - if (!ret && !drbg->ctr_async_err) { + wait_for_completion(&drbg->ctr_completion); + if (!drbg->ctr_async_err) { reinit_completion(&drbg->ctr_completion); break; } diff --git a/crypto/gcm.c b/crypto/gcm.c index b7ad808..3841b5e 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c @@ -152,10 +152,8 @@ static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, err = crypto_skcipher_encrypt(&data->req); if (err == -EINPROGRESS || err == -EBUSY) { - err = wait_for_completion_interruptible( - &data->result.completion); - if (!err) - err = data->result.err; + wait_for_completion(&data->result.completion); + err = data->result.err; } if (err)