From patchwork Thu May 18 13:29:24 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: 100103 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp721728qge; Thu, 18 May 2017 06:30:35 -0700 (PDT) X-Received: by 10.99.24.65 with SMTP id 1mr4657736pgy.49.1495114235126; Thu, 18 May 2017 06:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495114235; cv=none; d=google.com; s=arc-20160816; b=P6tqXq+LE/UGDa7vt3bnByWG3N2ClgxQI6l9G6QweJNFIaPr7sfL6BcNFRZTjFHfos 2L7b7gDc5DdDAFUGDFkVBKCVXZtvJhXK14IbXN2llP/1hFA1mfCn74Ezxd6/rTWxRwdQ e25RRzKevykyNwIQgzuRMHpIQON1S9Iz8aOHl5ZqjCUpBQfkYVfRNukO7gW7i3/9eun+ 9f/F+xnR4IuzYHNq6FVBGRmI8cu0gJP7cd4j7r8fw1VaT10YVdneP2HCReuDil3pYiC8 q5kqmaoS/x9fyTTP4N1KPkA7PyF9BaNDNRPWMaZkxLk/eOXpix8SsSLRYbTDBJHIN700 Nk6Q== 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=rgof3cZWB1QugZGIiLSlk9SbeoWjnmTLeDpGKolYQ7s=; b=MC5UTrRacIcFyhDk0ZOF8FHZv1rJH4y2OUNBO0efXNTXSj8hfUiHcFqVH6d54H2XUR Pf5qdZbxq6h/rfEVqHnIH0cIKUc8aAxvL6mYsU+SJtR9ydoxUyOEx3OIWfb/vdXE9q+L iW9+UNUVyDQpLXVCMqLi+gsvJSCpFUlfwxziglKpa108WyUnIidXyqcezyNATOwhcu7p qTKN31eMbVCab/JTsuWM15T4uJhOSrRVSeiHptrQONpQzBbnoWtt5kbN3C6KyQg0EX0O rNLLKQj56VVw0ddK19VqJhmoJvh2k9d1dxubbdAS8BL+r7uPiowzFD2QgGiB3cR04GFo w6+A== 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 33si5373150plb.270.2017.05.18.06.30.34; Thu, 18 May 2017 06:30:35 -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 S934900AbdERN35 (ORCPT + 25 others); Thu, 18 May 2017 09:29:57 -0400 Received: from foss.arm.com ([217.140.101.70]:60124 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932681AbdERN3q (ORCPT ); Thu, 18 May 2017 09:29:46 -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 E751B15BE; Thu, 18 May 2017 06:29:40 -0700 (PDT) Received: from gby.emea.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 080093F3E1; Thu, 18 May 2017 06:29:38 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells Cc: Ofir Drang , 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 v2 2/4] crypto: drbg wait for crypto op not signal safe Date: Thu, 18 May 2017 16:29:24 +0300 Message-Id: <1495114167-3073-3-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495114167-3073-1-git-send-email-gilad@benyossef.com> References: <1495114167-3073-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 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.1.4 diff --git a/crypto/drbg.c b/crypto/drbg.c index fa749f4..cdb27ac 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -1767,9 +1767,8 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg, break; case -EINPROGRESS: case -EBUSY: - ret = wait_for_completion_interruptible( - &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; } From patchwork Thu May 18 13:29:25 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: 100100 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp721490qge; Thu, 18 May 2017 06:30:06 -0700 (PDT) X-Received: by 10.98.61.207 with SMTP id x76mr4496999pfj.170.1495114205824; Thu, 18 May 2017 06:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495114205; cv=none; d=google.com; s=arc-20160816; b=dRqnbm2vgrYe9P0tyhcHdJteJBsnFl9YwqoTYYWDMdF+dX4z8jJUkgIaeRYcWp0Uw6 EAUowGCQRhQcLdcr4pUNPJMXxsB9Lj+3nqr++gTIOz28izRjbXjqia0w1u5wNKx+EhPY cftHrcY5IGd9PctIU7Jknp0aH4geD9lJv4higtmSaREb39fsUuWlO1SA5VYfF5kfzk5S xnUwv4ZgXYdABrhR0BOgINCBQJ16ZxVAMcybs2ot6++r7km62vDo4ycSosoapQ+Nd+yz /kw873GkqdInezKNUA7DCxEZOk+7m/vVbYQx0v5ICRHIkW6LzZ/W2iAbMDBTGOGdK1U5 QRnA== 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=5OBDhj7pC+gLrYrwe+c1TVXAQFma5geo+aMKtWMiSQs=; b=iA+WsRi+G9eUuRxAjV6le4CbKRR2uIOdGrN47DbchPXIIHI+IHmaB7KDBiXKua8yiB zGmJvEIXu9Kg4Ie3kA1RVXrh+D7pfKyXMcQAlYkJ4vQ1CmGA1JHQFMwfZDA31weRd/LO g5Kf+yvDucpPBDl1flotHG7ASxkR1y+/7UkhLEbp60LAGM15d6dtwj6PNGN+KMn+0hCO vv0ahlUNnx+lKbIgf4Nvqo3gA4wA3VNTy1Z2SDNq3n6+VpDTA5fGCROoVHKd3QwPB/wR VdZXhXPKWdXA1w0yt2NtMxJAumIDiEMfnHgOT/54Txxi7kixrQ1wvba9NE7543C5UFCP VD+g== 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 c19si5231671pfe.59.2017.05.18.06.30.05; Thu, 18 May 2017 06:30: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 S964794AbdERN3z (ORCPT + 25 others); Thu, 18 May 2017 09:29:55 -0400 Received: from foss.arm.com ([217.140.101.70]:60136 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934080AbdERN3o (ORCPT ); Thu, 18 May 2017 09:29:44 -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 E16871650; Thu, 18 May 2017 06:29:43 -0700 (PDT) Received: from gby.emea.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EE7723F3E1; Thu, 18 May 2017 06:29:41 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells Cc: Ofir Drang , 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 v2 3/4] crypto: gcm wait for crypto op not signal safe Date: Thu, 18 May 2017 16:29:25 +0300 Message-Id: <1495114167-3073-4-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495114167-3073-1-git-send-email-gilad@benyossef.com> References: <1495114167-3073-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/gcm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.1.4 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 18 13:29:26 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: 100102 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp721578qge; Thu, 18 May 2017 06:30:16 -0700 (PDT) X-Received: by 10.98.134.72 with SMTP id x69mr4627473pfd.106.1495114216583; Thu, 18 May 2017 06:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495114216; cv=none; d=google.com; s=arc-20160816; b=XTrtXVNEUgVF1LmBwlKZ+lp2PFZEQqkaC4QqdKAozUtZNweOlZ8y+VYKxM5pKYiIQp Dww0D4lknHOxZj1tCI1HSFtvGygNTZN4IXbeUcw5gNVQHbgUIHuin2P5/+Le8uc0CCSL okcfJ5vbLeiSH6p2RMetqufXFZsKSatb6Vtgs3cdfBwd6gISkvRYZROfl4zK40JPQnEb L7g3NnTrWaeSNeP9hxeASi2d0NVD79WnTSM5MYjGzGIUbrxUxSumioc9K7cC/22EOogW cQlFiZ5ObEsV9TsqjZ49GJiCcr9Ya4O9841GQvf9SVOQLyJgprmNbUxf/oe9bjhaa3iZ +rKQ== 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=sZEgKQi7fBW82PmT/KLOcySu+WpKIGDnhRjZ0UeS8mfJxWYLi0k/76NF3g+RIZwcm7 lGSzRJpnzxRyQK2BS+6RJ48kYyWgEPMu7Z3RS7oOTOTeBc/PA3NHNYwa5iqD+3eQ2hrq CvFnCw37oEdi0SwnvpGic1md1g73pDRksVx+5aj5ydkaifvy74z778Fpm+Zlojl9zIyW BKAV7HO51oXX9/AZVu/Dq7H8Be5y19BsM9mT81/Ylx0ltBKVZkL7gOuU7FXiPys8wJG1 0wiBvwu/PonsdZVxTyBKVLcdFTQjxwbU5ptQUIgPCtdXzly15OSbU5tWdy1BTXIZYJ6H rE1A== 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 h71si5100581pfe.101.2017.05.18.06.30.16; Thu, 18 May 2017 06:30:16 -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 S964834AbdERNaE (ORCPT + 25 others); Thu, 18 May 2017 09:30:04 -0400 Received: from foss.arm.com ([217.140.101.70]:60148 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934891AbdERN35 (ORCPT ); Thu, 18 May 2017 09:29:57 -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 98CB5165C; Thu, 18 May 2017 06:29:46 -0700 (PDT) Received: from gby.emea.arm.com (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D3A463F3E1; Thu, 18 May 2017 06:29:44 -0700 (PDT) From: Gilad Ben-Yossef To: Herbert Xu , "David S. Miller" , Jonathan Corbet , David Howells Cc: Ofir Drang , linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org Subject: [PATCH v2 4/4] crypto: Documentation: fix none signal safe sample Date: Thu, 18 May 2017 16:29:26 +0300 Message-Id: <1495114167-3073-5-git-send-email-gilad@benyossef.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1495114167-3073-1-git-send-email-gilad@benyossef.com> References: <1495114167-3073-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);