Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1196556ybn; Wed, 2 Oct 2019 12:16:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzncyuL/W+BrnkOAH/y9OeU5sM1YsdUrN4mRZ1cuVBW6TO7y4o+R+1olru5BJuPe4cA0BJ0 X-Received: by 2002:a50:ee10:: with SMTP id g16mr5549467eds.267.1570043796888; Wed, 02 Oct 2019 12:16:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043796; cv=none; d=google.com; s=arc-20160816; b=VkGC3iI1s5wDaEsRh1B2Iv9lfhY2sCR5LqK81vd8Vn8qY7vujiZBd/wwnvVyVqcH2S AtBV2H8InranZyes11WuCBPfD5ooa8flZ7+swc+sggYqtj93+rHCEQBZttjz6DaHloAm ccmHxKXXLu92s18wzO+hXLlxJpEVoJ7xhhWDuZBbgRsX2w9+9WN51TZPim3HB64kDoAc eIZf5NkQTGCXPUMe/x3AyzZ4uVaXb6dp1QjAcqTSQLNVkXrwVtpcgrAmCSpfhG7wssXp YBk6OvK+t7bqxNUxS+Fr+mgqaCSZGxbg2gpj4P7IntDtYB6tiKhP8ms5NOjlGMG3I5U1 f7XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=rdmmp7OZkAYsMy1+2pIc/J8HToIR+s7IfiaNBbqZJ3Q=; b=ARyztW1o5fkcufgpzMcmYk5BBAGmimduxEQhKCbWT8j9eC/T8lSYlOn4Q/SGshlFjl d8sgM58qjsLd9fPOPH9DEBUhdmd+tNKJ+GUGOnhgQifBdUBK/dCwJNysT2VXnTl7VLfP Mrl3be1bbxeQfR6S3TLczEwYtNf+OuscM8MaWcFluB9J3l8gDlPJ6rS6tm9GlHW6NJpJ OX3VSomvLJux71Frc55dG5sd3GCT75BWOzXwc0QEUTzAikSzKint3y8dhyG+ajtJ+XGN p2DWzAC+6nFL1s4WQNvDbap9nIwJN/TmrZZiLeYqXvOM7RzTCXpIk+MXkgagJmVYlne0 a21A== 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 i18si13481ejb.145.2019.10.02.12.16.12; Wed, 02 Oct 2019 12:16:36 -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 S1729621AbfJBTMz (ORCPT + 99 others); Wed, 2 Oct 2019 15:12:55 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35406 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729110AbfJBTIK (ORCPT ); Wed, 2 Oct 2019 15:08:10 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyo-000368-P0; Wed, 02 Oct 2019 20:08:06 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyo-0003cf-0J; Wed, 02 Oct 2019 20:08:06 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Julian Wiedmann" , "Harald Freudenberger" , "Heiko Carstens" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 35/87] s390/crypto: fix possible sleep during spinlock aquired In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Harald Freudenberger commit 1c2c7029c008922d4d48902cc386250502e73d51 upstream. This patch fixes a complain about possible sleep during spinlock aquired "BUG: sleeping function called from invalid context at include/crypto/algapi.h:426" for the ctr(aes) and ctr(des) s390 specific ciphers. Instead of using a spinlock this patch introduces a mutex which is save to be held in sleeping context. Please note a deadlock is not possible as mutex_trylock() is used. Signed-off-by: Harald Freudenberger Reported-by: Julian Wiedmann Signed-off-by: Heiko Carstens [bwh: Backported to 3.16: - Replace spin_unlock() on all exit paths - Adjust context] Signed-off-by: Ben Hutchings --- --- a/arch/s390/crypto/aes_s390.c +++ b/arch/s390/crypto/aes_s390.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include "crypt_s390.h" #define AES_KEYLEN_128 1 @@ -33,7 +33,7 @@ #define AES_KEYLEN_256 4 static u8 *ctrblk; -static DEFINE_SPINLOCK(ctrblk_lock); +static DEFINE_MUTEX(ctrblk_lock); static char keylen_flag; struct s390_aes_ctx { @@ -785,7 +785,7 @@ static int ctr_aes_crypt(struct blkciphe if (!walk->nbytes) return ret; - if (spin_trylock(&ctrblk_lock)) + if (mutex_trylock(&ctrblk_lock)) ctrptr = ctrblk; memcpy(ctrptr, walk->iv, AES_BLOCK_SIZE); @@ -801,7 +801,7 @@ static int ctr_aes_crypt(struct blkciphe n, ctrptr); if (ret < 0 || ret != n) { if (ctrptr == ctrblk) - spin_unlock(&ctrblk_lock); + mutex_unlock(&ctrblk_lock); return -EIO; } if (n > AES_BLOCK_SIZE) @@ -819,7 +819,7 @@ static int ctr_aes_crypt(struct blkciphe memcpy(ctrbuf, ctrptr, AES_BLOCK_SIZE); else memcpy(walk->iv, ctrptr, AES_BLOCK_SIZE); - spin_unlock(&ctrblk_lock); + mutex_unlock(&ctrblk_lock); } else { if (!nbytes) memcpy(walk->iv, ctrptr, AES_BLOCK_SIZE); --- a/arch/s390/crypto/des_s390.c +++ b/arch/s390/crypto/des_s390.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -25,7 +26,7 @@ #define DES3_KEY_SIZE (3 * DES_KEY_SIZE) static u8 *ctrblk; -static DEFINE_SPINLOCK(ctrblk_lock); +static DEFINE_MUTEX(ctrblk_lock); struct s390_des_ctx { u8 iv[DES_BLOCK_SIZE]; @@ -394,7 +395,7 @@ static int ctr_desall_crypt(struct blkci if (!walk->nbytes) return ret; - if (spin_trylock(&ctrblk_lock)) + if (mutex_trylock(&ctrblk_lock)) ctrptr = ctrblk; memcpy(ctrptr, walk->iv, DES_BLOCK_SIZE); @@ -410,7 +411,7 @@ static int ctr_desall_crypt(struct blkci n, ctrptr); if (ret < 0 || ret != n) { if (ctrptr == ctrblk) - spin_unlock(&ctrblk_lock); + mutex_unlock(&ctrblk_lock); return -EIO; } if (n > DES_BLOCK_SIZE) @@ -428,7 +429,7 @@ static int ctr_desall_crypt(struct blkci memcpy(ctrbuf, ctrptr, DES_BLOCK_SIZE); else memcpy(walk->iv, ctrptr, DES_BLOCK_SIZE); - spin_unlock(&ctrblk_lock); + mutex_unlock(&ctrblk_lock); } else { if (!nbytes) memcpy(walk->iv, ctrptr, DES_BLOCK_SIZE);