From patchwork Thu May 11 11:53:43 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: 99626 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp689774qge; Thu, 11 May 2017 04:55:05 -0700 (PDT) X-Received: by 10.98.141.16 with SMTP id z16mr11623317pfd.91.1494503705539; Thu, 11 May 2017 04:55:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494503705; cv=none; d=google.com; s=arc-20160816; b=GT5byWvcEds9URRsRzc3Bk4H8YaAVWN+Do58RxaQB89pcADHorKaKKEOIxQXuuzHKi DWPseE+fSPey+hyypvRfwLc+D7ZUqbOn1gEvCay13ee4+0cAC1xwywW/PguHTrSVgQxK spa0I8bOGsYGtnFzLLYOuHOQKSACyDJtk/o1Uwlfb0zXOd3sgoN6TZrXmMLFREysubOZ RsKBR6y0GSZcaZSS+o2StCfNtA7pLf9jke2I9OpykQTns6l8erbjiINjEq97Ogm/ppjL KZrOlWAygYuFEkuo1wz2OGfZg7lm27OUxO91ldEsgY644iJ1rzxNxczrhQczSF5MUKVD 1HaA== 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=aVKSmx3E7IAYachjEBB8lWApO1O1Re6MvtccUZ5m2+g=; b=Sjwf6jxurLuR1/4JCcPdfvPjrZMhtuPC5Xnc9aD+X+NNxIeeU2+rbwMP5107ZbME0G M47ja82LgZYFD2FdvLUMIkcsWqHCTMEmKanJsUNTcq6qL45VpQZgFo19GIzJGIJ9rZGq E/F04kg6ShgeC3YPVv7gMoJFbsHiJck42PexMcVfIiScivIQWt/4w1c6bYt63CVtrVsr 0rVu/dp9EjUUKoNdpPqxgCTf0CUop2Wah/lQKWoBkdAZlCZ+GfYhlNuoM6rgANCTxRhF +2diaospb6/JYubQ6l29y2KwGQ34QQOHkp8D8TWd6qqTntd75Sdg6FkbZpWV6WMXMwDg 9cSg== 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 i14si1672354plk.84.2017.05.11.04.55.05; Thu, 11 May 2017 04:55: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; 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 S1755459AbdEKLyr (ORCPT + 25 others); Thu, 11 May 2017 07:54:47 -0400 Received: from foss.arm.com ([217.140.101.70]:46600 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932586AbdEKLyE (ORCPT ); Thu, 11 May 2017 07:54:04 -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 495E52B; Thu, 11 May 2017 04:54:04 -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 7463F3F4FF; Thu, 11 May 2017 04:54:01 -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 2/4] crypto: drbg wait for crypto op not signal safe Date: Thu, 11 May 2017 14:53:43 +0300 Message-Id: <1494503626-15877-3-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 drbg_kcapi_sym_ctr() 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 output buffer. 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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.1.4 diff --git a/crypto/drbg.c b/crypto/drbg.c index fa749f4..fa9054d 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1767,8 +1767,7 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg, break; case -EINPROGRESS: case -EBUSY: - ret = wait_for_completion_interruptible( - &drbg->ctr_completion); + ret = wait_for_completion(&drbg->ctr_completion); if (!ret && !drbg->ctr_async_err) { reinit_completion(&drbg->ctr_completion); break; 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) From patchwork Thu May 11 11:53:45 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: 99625 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp689566qge; Thu, 11 May 2017 04:54:31 -0700 (PDT) X-Received: by 10.99.8.193 with SMTP id 184mr12335522pgi.189.1494503671252; Thu, 11 May 2017 04:54:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494503671; cv=none; d=google.com; s=arc-20160816; b=Zd8zTlVZMxhp6PimFiAr3If8Kl+D1rwpfR0XqfD7FobkqX11wS0E7lF3D2QnkU0emy Qef5hbrhN7cfxHUtYfvhRD7RApn/FzCuLLImAa2QA4xNpNC7/y33MxkRJ0tlVhXX7gUm +nnp1WXHcFdKdf9bISb2PUjoGSK+JMsl6qYAtK4lQGGGBclUNjwkI5enmFJhbuMOxbpD 1g2qpEJhIC6p/BdqEJoINky2XX+zz9sIPhNHtHZZ0jNokWmkuMVd4KVFtev7SpcwdhAP PFKQDArA8uBTqp2501CxTO1HRWp/jYHOdN4rYfRCMim7YZ8t24ctmk1hRF3IyQaFmPcC CCIQ== 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=H4Oa5yGQHLP2xIRjq3lq1JBMkgjUYBZWe/kerarE91s=; b=e7BcCPgtJkjN7jk0jhirrxaRE8IHrhyp3SvoTRu8xj3pcqmsm4Pw87/+ExhnGNxfib 7W7hoRjBPNRCF7/uXqwcRgc5lm5wWbKt2/tHUcXgB00MHwLO6u3JT7crvkZ5E40DnKbR p8EjOwBBMMmoh28mKrJ9whbfmMIPi9bx7rXD5YO0YmsMoNaZ/4WOZrGBW9KnERDMa6V3 tpj6QbFYRVECSHNrxJrQqD4q+15CiIDJlBvBd/4x434B3gscuZ+EAfcqZsYfsy9d0WdI KLUNY71rpUw7ImkHnsLk0I9x2t3OrgNQkR0IpEUfrXkfmx2T4tnIjkEXSZ0OGXyaBO2q tKHQ== 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 v2si1663678pgv.316.2017.05.11.04.54.30; Thu, 11 May 2017 04:54:31 -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 S932668AbdEKLyT (ORCPT + 25 others); Thu, 11 May 2017 07:54:19 -0400 Received: from foss.arm.com ([217.140.101.70]:46630 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932631AbdEKLyR (ORCPT ); Thu, 11 May 2017 07:54:17 -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 060721516; Thu, 11 May 2017 04:54:12 -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 60B593F4FF; Thu, 11 May 2017 04:54:09 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells Cc: Ofir Drang , Gilad Ben-Yossef , Eric Biggers , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Subject: [PATCH 4/4] crypto: Documentation: fix none signal safe sample Date: Thu, 11 May 2017 14:53:45 +0300 Message-Id: <1494503626-15877-5-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 The sample code was showing use of wait_for_completion_interruptible() for waiting for an async. crypto op to finish. However, if a signal arrived it would free the buffers used even while crypto HW might still DMA from/into the buffers. Resolve this by using wait_for_completion() instead. Reported-by: Eric Biggers Signed-off-by: Gilad Ben-Yossef --- Documentation/crypto/api-samples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.1.4 diff --git a/Documentation/crypto/api-samples.rst b/Documentation/crypto/api-samples.rst index d021fd9..944f08b 100644 --- a/Documentation/crypto/api-samples.rst +++ b/Documentation/crypto/api-samples.rst @@ -48,7 +48,7 @@ Code Example For Symmetric Key Cipher Operation break; case -EINPROGRESS: case -EBUSY: - rc = wait_for_completion_interruptible( + rc = wait_for_completion( &sk->result.completion); if (!rc && !sk->result.err) { reinit_completion(&sk->result.completion);