From: Luis Henriques <luis.henriques@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com
Cc: Harald Freudenberger <freude@linux.vnet.ibm.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Luis Henriques <luis.henriques@canonical.com>
Subject: [PATCH 3.5 02/60] crypto: s390 - fix concurrency issue in aes-ctr mode
Date: Fri, 21 Feb 2014 13:00:29 +0000 [thread overview]
Message-ID: <1392987687-15367-3-git-send-email-luis.henriques@canonical.com> (raw)
In-Reply-To: <1392987687-15367-1-git-send-email-luis.henriques@canonical.com>
3.5.7.31 -stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <freude@linux.vnet.ibm.com>
commit 0519e9ad89e5cd6e6b08398f57c6a71d9580564c upstream.
The aes-ctr mode uses one preallocated page without any concurrency
protection. When multiple threads run aes-ctr encryption or decryption
this can lead to data corruption.
The patch introduces locking for the page and a fallback solution with
slower en/decryption performance in concurrency situations.
Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Luis Henriques <luis.henriques@canonical.com>
---
arch/s390/crypto/aes_s390.c | 65 ++++++++++++++++++++++++++++++++-------------
1 file changed, 46 insertions(+), 19 deletions(-)
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index f3000a4..51fb1ef 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -25,6 +25,7 @@
#include <linux/err.h>
#include <linux/module.h>
#include <linux/init.h>
+#include <linux/spinlock.h>
#include "crypt_s390.h"
#define AES_KEYLEN_128 1
@@ -32,6 +33,7 @@
#define AES_KEYLEN_256 4
static u8 *ctrblk;
+static DEFINE_SPINLOCK(ctrblk_lock);
static char keylen_flag;
struct s390_aes_ctx {
@@ -760,43 +762,67 @@ static int ctr_aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
return aes_set_key(tfm, in_key, key_len);
}
+static unsigned int __ctrblk_init(u8 *ctrptr, unsigned int nbytes)
+{
+ unsigned int i, n;
+
+ /* only use complete blocks, max. PAGE_SIZE */
+ n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(AES_BLOCK_SIZE - 1);
+ for (i = AES_BLOCK_SIZE; i < n; i += AES_BLOCK_SIZE) {
+ memcpy(ctrptr + i, ctrptr + i - AES_BLOCK_SIZE,
+ AES_BLOCK_SIZE);
+ crypto_inc(ctrptr + i, AES_BLOCK_SIZE);
+ }
+ return n;
+}
+
static int ctr_aes_crypt(struct blkcipher_desc *desc, long func,
struct s390_aes_ctx *sctx, struct blkcipher_walk *walk)
{
int ret = blkcipher_walk_virt_block(desc, walk, AES_BLOCK_SIZE);
- unsigned int i, n, nbytes;
- u8 buf[AES_BLOCK_SIZE];
- u8 *out, *in;
+ unsigned int n, nbytes;
+ u8 buf[AES_BLOCK_SIZE], ctrbuf[AES_BLOCK_SIZE];
+ u8 *out, *in, *ctrptr = ctrbuf;
if (!walk->nbytes)
return ret;
- memcpy(ctrblk, walk->iv, AES_BLOCK_SIZE);
+ if (spin_trylock(&ctrblk_lock))
+ ctrptr = ctrblk;
+
+ memcpy(ctrptr, walk->iv, AES_BLOCK_SIZE);
while ((nbytes = walk->nbytes) >= AES_BLOCK_SIZE) {
out = walk->dst.virt.addr;
in = walk->src.virt.addr;
while (nbytes >= AES_BLOCK_SIZE) {
- /* only use complete blocks, max. PAGE_SIZE */
- n = (nbytes > PAGE_SIZE) ? PAGE_SIZE :
- nbytes & ~(AES_BLOCK_SIZE - 1);
- for (i = AES_BLOCK_SIZE; i < n; i += AES_BLOCK_SIZE) {
- memcpy(ctrblk + i, ctrblk + i - AES_BLOCK_SIZE,
- AES_BLOCK_SIZE);
- crypto_inc(ctrblk + i, AES_BLOCK_SIZE);
- }
- ret = crypt_s390_kmctr(func, sctx->key, out, in, n, ctrblk);
- if (ret < 0 || ret != n)
+ if (ctrptr == ctrblk)
+ n = __ctrblk_init(ctrptr, nbytes);
+ else
+ n = AES_BLOCK_SIZE;
+ ret = crypt_s390_kmctr(func, sctx->key, out, in,
+ n, ctrptr);
+ if (ret < 0 || ret != n) {
+ if (ctrptr == ctrblk)
+ spin_unlock(&ctrblk_lock);
return -EIO;
+ }
if (n > AES_BLOCK_SIZE)
- memcpy(ctrblk, ctrblk + n - AES_BLOCK_SIZE,
+ memcpy(ctrptr, ctrptr + n - AES_BLOCK_SIZE,
AES_BLOCK_SIZE);
- crypto_inc(ctrblk, AES_BLOCK_SIZE);
+ crypto_inc(ctrptr, AES_BLOCK_SIZE);
out += n;
in += n;
nbytes -= n;
}
ret = blkcipher_walk_done(desc, walk, nbytes);
}
+ if (ctrptr == ctrblk) {
+ if (nbytes)
+ memcpy(ctrbuf, ctrptr, AES_BLOCK_SIZE);
+ else
+ memcpy(walk->iv, ctrptr, AES_BLOCK_SIZE);
+ spin_unlock(&ctrblk_lock);
+ }
/*
* final block may be < AES_BLOCK_SIZE, copy only nbytes
*/
@@ -804,14 +830,15 @@ static int ctr_aes_crypt(struct blkcipher_desc *desc, long func,
out = walk->dst.virt.addr;
in = walk->src.virt.addr;
ret = crypt_s390_kmctr(func, sctx->key, buf, in,
- AES_BLOCK_SIZE, ctrblk);
+ AES_BLOCK_SIZE, ctrbuf);
if (ret < 0 || ret != AES_BLOCK_SIZE)
return -EIO;
memcpy(out, buf, nbytes);
- crypto_inc(ctrblk, AES_BLOCK_SIZE);
+ crypto_inc(ctrbuf, AES_BLOCK_SIZE);
ret = blkcipher_walk_done(desc, walk, 0);
+ memcpy(walk->iv, ctrbuf, AES_BLOCK_SIZE);
}
- memcpy(walk->iv, ctrblk, AES_BLOCK_SIZE);
+
return ret;
}
--
1.9.0
next prev parent reply other threads:[~2014-02-21 13:01 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-21 13:00 [3.5.y.z extended stable] Linux 3.5.7.31 stable review Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 01/60] PCI: Enable ARI if dev and upstream bridge support it; disable otherwise Luis Henriques
2014-02-21 13:00 ` Luis Henriques [this message]
2014-02-21 13:00 ` [PATCH 3.5 03/60] crypto: s390 - fix des and des3_ede cbc concurrency issue Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 04/60] crypto: s390 - fix des and des3_ede ctr " Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 05/60] ALSA: usb-audio: Add missing kconfig dependecy Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 06/60] [media] mxl111sf: Fix unintentional garbage stack read Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 07/60] [media] mxl111sf: Fix compile when CONFIG_DVB_USB_MXL111SF is unset Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 08/60] drm/mgag200: fix typo causing bw limits to be ignored on some chips Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 09/60] ALSA: hda - Improve loopback path lookups for AD1983 Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 10/60] SELinux: Fix kernel BUG on empty security contexts Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 11/60] pinctrl: do not init debugfs entries for unimplemented functionalities Luis Henriques
2014-02-25 9:24 ` Linus Walleij
2014-02-25 9:38 ` Luís Henriques
2014-02-21 13:00 ` [PATCH 3.5 12/60] x86, hweight: Fix BUG when booting with CONFIG_GCOV_PROFILE_ALL=y Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 13/60] mm/swap: fix race on swap_info reuse between swapoff and swapon Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 14/60] mm: __set_page_dirty_nobuffers() uses spin_lock_irqsave() instead of spin_lock_irq() Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 15/60] mm: __set_page_dirty uses spin_lock_irqsave instead of spin_lock_irq Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 16/60] sched,rt: fix isolated CPUs leaving root_task_group indefinitely throttled Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 17/60] sched: Unthrottle rt runqueues in __disable_runtime() Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 18/60] sched/rt: Avoid updating RT entry timeout twice within one tick period Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 19/60] rtc-cmos: Add an alarm disable quirk Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 20/60] timekeeping: Avoid possible deadlock from clock_was_set_delayed Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 21/60] timekeeping: fix 32-bit overflow in get_monotonic_boottime Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 22/60] ahci: Use PCI_VENDOR_ID_MARVELL_EXT for 0x1b4b Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 23/60] ahci: add an observed PCI ID for Marvell 88se9172 SATA controller Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 24/60] ftrace: Synchronize setting function_trace_op with ftrace_trace_function Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 25/60] ftrace: Fix synchronization location disabling and freeing ftrace_ops Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 26/60] ftrace: Have function graph only trace based on global_ops filters Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 27/60] printk: Fix scheduling-while-atomic problem in console_cpu_notify() Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 28/60] staging:iio:ad799x fix error_free_irq which was freeing an irq that may not have been requested Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 29/60] xhci: Fix resume issues on Renesas chips in Samsung laptops Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 30/60] KVM: return an error code in kvm_vm_ioctl_register_coalesced_mmio() Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 31/60] power: max17040: Fix NULL pointer dereference when there is no platform_data Luis Henriques
2014-02-21 13:00 ` [PATCH 3.5 32/60] s390/dump: Fix dump memory detection Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 33/60] ath9k_htc: Do not support PowerSave by default Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 34/60] ath9k: " Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 35/60] spi: nuc900: Set SPI_LSB_FIRST for master->mode_bits if hw->pdata->lsb is true Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 36/60] usb: ftdi_sio: add Mindstorms EV3 console adapter Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 37/60] usb-storage: restrict bcdDevice range for Super Top in Cypress ATACB Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 38/60] usb-storage: add unusual-devs entry for BlackBerry 9000 Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 39/60] usb-storage: enable multi-LUN scanning when needed Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 40/60] USB: ftdi_sio: add Tagsys RFID Reader IDs Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 41/60] mac80211: fix fragmentation code, particularly for encryption Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 42/60] time: Fix overflow when HZ is smaller than 60 Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 43/60] VME: Correct read/write alignment algorithm Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 44/60] raw: test against runtime value of max_raw_minors Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 45/60] tty: n_gsm: Fix for modems with brk in modem status control Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 46/60] staging: comedi: adv_pci1710: fix analog output readback value Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 47/60] xen-blkfront: handle backend CLOSED without CLOSING Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 48/60] Modpost: fixed USB alias generation for ranges including 0x9 and 0xA Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 49/60] iio: ak8975: Fix calculation formula for convert micro tesla to gauss unit Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 50/60] fs/file.c:fdtable: avoid triggering OOMs from alloc_fdmem Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 51/60] genirq: Add missing irq_to_desc export for CONFIG_SPARSE_IRQ=n Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 52/60] ring-buffer: Fix first commit on sub-buffer having non-zero delta Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 53/60] usb: option: blacklist ZTE MF667 net interface Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 54/60] md/raid5: Fix CPU hotplug callback registration Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 55/60] lockd: send correct lock when granting a delayed lock Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 56/60] IB/qib: Add missing serdes init sequence Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 57/60] EDAC: Correct workqueue setup path Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 58/60] dm sysfs: fix a module unload race Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 59/60] s390: fix kernel crash due to linkage stack instructions Luis Henriques
2014-02-21 13:01 ` [PATCH 3.5 60/60] block: add cond_resched() to potentially long running ioctl discard loop Luis Henriques
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392987687-15367-3-git-send-email-luis.henriques@canonical.com \
--to=luis.henriques@canonical.com \
--cc=freude@linux.vnet.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®