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 04/60] crypto: s390 - fix des and des3_ede ctr concurrency issue
Date: Fri, 21 Feb 2014 13:00:31 +0000 [thread overview]
Message-ID: <1392987687-15367-5-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 ee97dc7db4cbda33e4241c2d85b42d1835bc8a35 upstream.
In s390 des and 3des ctr mode there is one preallocated page
used to speed up the en/decryption. This page is not protected
against concurrent usage and thus there is a potential of data
corruption with multiple threads.
The fix introduces locking/unlocking the ctr page and a slower
fallback solution at 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/des_s390.c | 69 +++++++++++++++++++++++++++++++--------------
1 file changed, 48 insertions(+), 21 deletions(-)
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index 5fe77d5..991fb7d 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -25,6 +25,7 @@
#define DES3_KEY_SIZE (3 * DES_KEY_SIZE)
static u8 *ctrblk;
+static DEFINE_SPINLOCK(ctrblk_lock);
struct s390_des_ctx {
u8 iv[DES_BLOCK_SIZE];
@@ -376,54 +377,80 @@ static struct crypto_alg cbc_des3_alg = {
}
};
+static unsigned int __ctrblk_init(u8 *ctrptr, unsigned int nbytes)
+{
+ unsigned int i, n;
+
+ /* align to block size, max. PAGE_SIZE */
+ n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(DES_BLOCK_SIZE - 1);
+ for (i = DES_BLOCK_SIZE; i < n; i += DES_BLOCK_SIZE) {
+ memcpy(ctrptr + i, ctrptr + i - DES_BLOCK_SIZE, DES_BLOCK_SIZE);
+ crypto_inc(ctrptr + i, DES_BLOCK_SIZE);
+ }
+ return n;
+}
+
static int ctr_desall_crypt(struct blkcipher_desc *desc, long func,
- struct s390_des_ctx *ctx, struct blkcipher_walk *walk)
+ struct s390_des_ctx *ctx,
+ struct blkcipher_walk *walk)
{
int ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE);
- unsigned int i, n, nbytes;
- u8 buf[DES_BLOCK_SIZE];
- u8 *out, *in;
+ unsigned int n, nbytes;
+ u8 buf[DES_BLOCK_SIZE], ctrbuf[DES_BLOCK_SIZE];
+ u8 *out, *in, *ctrptr = ctrbuf;
+
+ if (!walk->nbytes)
+ return ret;
- memcpy(ctrblk, walk->iv, DES_BLOCK_SIZE);
+ if (spin_trylock(&ctrblk_lock))
+ ctrptr = ctrblk;
+
+ memcpy(ctrptr, walk->iv, DES_BLOCK_SIZE);
while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
out = walk->dst.virt.addr;
in = walk->src.virt.addr;
while (nbytes >= DES_BLOCK_SIZE) {
- /* align to block size, max. PAGE_SIZE */
- n = (nbytes > PAGE_SIZE) ? PAGE_SIZE :
- nbytes & ~(DES_BLOCK_SIZE - 1);
- for (i = DES_BLOCK_SIZE; i < n; i += DES_BLOCK_SIZE) {
- memcpy(ctrblk + i, ctrblk + i - DES_BLOCK_SIZE,
- DES_BLOCK_SIZE);
- crypto_inc(ctrblk + i, DES_BLOCK_SIZE);
- }
- ret = crypt_s390_kmctr(func, ctx->key, out, in, n, ctrblk);
- if (ret < 0 || ret != n)
+ if (ctrptr == ctrblk)
+ n = __ctrblk_init(ctrptr, nbytes);
+ else
+ n = DES_BLOCK_SIZE;
+ ret = crypt_s390_kmctr(func, ctx->key, out, in,
+ n, ctrptr);
+ if (ret < 0 || ret != n) {
+ if (ctrptr == ctrblk)
+ spin_unlock(&ctrblk_lock);
return -EIO;
+ }
if (n > DES_BLOCK_SIZE)
- memcpy(ctrblk, ctrblk + n - DES_BLOCK_SIZE,
+ memcpy(ctrptr, ctrptr + n - DES_BLOCK_SIZE,
DES_BLOCK_SIZE);
- crypto_inc(ctrblk, DES_BLOCK_SIZE);
+ crypto_inc(ctrptr, DES_BLOCK_SIZE);
out += n;
in += n;
nbytes -= n;
}
ret = blkcipher_walk_done(desc, walk, nbytes);
}
-
+ if (ctrptr == ctrblk) {
+ if (nbytes)
+ memcpy(ctrbuf, ctrptr, DES_BLOCK_SIZE);
+ else
+ memcpy(walk->iv, ctrptr, DES_BLOCK_SIZE);
+ spin_unlock(&ctrblk_lock);
+ }
/* final block may be < DES_BLOCK_SIZE, copy only nbytes */
if (nbytes) {
out = walk->dst.virt.addr;
in = walk->src.virt.addr;
ret = crypt_s390_kmctr(func, ctx->key, buf, in,
- DES_BLOCK_SIZE, ctrblk);
+ DES_BLOCK_SIZE, ctrbuf);
if (ret < 0 || ret != DES_BLOCK_SIZE)
return -EIO;
memcpy(out, buf, nbytes);
- crypto_inc(ctrblk, DES_BLOCK_SIZE);
+ crypto_inc(ctrbuf, DES_BLOCK_SIZE);
ret = blkcipher_walk_done(desc, walk, 0);
+ memcpy(walk->iv, ctrbuf, DES_BLOCK_SIZE);
}
- memcpy(walk->iv, ctrblk, DES_BLOCK_SIZE);
return ret;
}
--
1.9.0
next prev parent reply other threads:[~2014-02-21 13:26 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 ` [PATCH 3.5 02/60] crypto: s390 - fix concurrency issue in aes-ctr mode Luis Henriques
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 ` Luis Henriques [this message]
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-5-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®