Changes in 4.9.181 ipv6: Consider sk_bound_dev_if when binding a raw socket to an address llc: fix skb leak in llc_build_and_send_ui_pkt() net: fec: fix the clk mismatch in failed_reset path net-gro: fix use-after-free read in napi_gro_frags() net: stmmac: fix reset gpio free missing usbnet: fix kernel crash after disconnect tipc: Avoid copying bytes beyond the supplied data bnxt_en: Fix aggregation buffer leak under OOM condition. ipv4/igmp: fix another memory leak in igmpv3_del_delrec() ipv4/igmp: fix build error if !CONFIG_IP_MULTICAST net: dsa: mv88e6xxx: fix handling of upper half of STATS_TYPE_PORT net: mvneta: Fix err code path of probe net: mvpp2: fix bad MVPP2_TXQ_SCHED_TOKEN_CNTR_REG queue value crypto: vmx - ghash: do nosimd fallback manually xen/pciback: Don't disable PCI_COMMAND on PCI device reset. Revert "tipc: fix modprobe tipc failed after switch order of device registration" tipc: fix modprobe tipc failed after switch order of device registration sparc64: Fix regression in non-hypervisor TLB flush xcall include/linux/bitops.h: sanitize rotate primitives xhci: update bounce buffer with correct sg num xhci: Use %zu for printing size_t type xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic() usb: xhci: avoid null pointer deref when bos field is NULL usbip: usbip_host: fix BUG: sleeping function called from invalid context usbip: usbip_host: fix stub_dev lock context imbalance regression USB: Fix slab-out-of-bounds write in usb_get_bos_descriptor USB: sisusbvga: fix oops in error path of sisusb_probe USB: Add LPM quirk for Surface Dock GigE adapter USB: rio500: refuse more than one device at a time USB: rio500: fix memory leak in close after disconnect media: usb: siano: Fix general protection fault in smsusb media: usb: siano: Fix false-positive "uninitialized variable" warning media: smsusb: better handle optional alignment scsi: zfcp: fix missing zfcp_port reference put on -EBUSY from port_remove scsi: zfcp: fix to prevent port_remove with pure auto scan LUNs (only sdevs) Btrfs: fix race updating log root item during fsync powerpc/perf: Fix MMCRA corruption by bhrb_filter ALSA: hda/realtek - Set default power save node to 0 drm/nouveau/i2c: Disable i2c bus access after ->fini() tty: serial: msm_serial: Fix XON/XOFF tty: max310x: Fix external crystal register setup memcg: make it work on sparse non-0-node systems kernel/signal.c: trace_signal_deliver when signal_group_exit docs: Fix conf.py for Sphinx 2.0 staging: vc04_services: prevent integer overflow in create_pagelist() CIFS: cifs_read_allocate_pages: don't iterate through whole page array on ENOMEM gcc-plugins: Fix build failures under Darwin host drm/vmwgfx: Don't send drm sysfs hotplug events on initial master set brcmfmac: add length checks in scheduled scan result handler brcmfmac: assure SSID length from firmware is limited brcmfmac: add subtype check for event handling in data path binder: Replace "%p" with "%pK" for stable binder: replace "%p" with "%pK" fs: prevent page refcount overflow in pipe_buf_get mm, gup: remove broken VM_BUG_ON_PAGE compound check for hugepages mm, gup: ensure real head page is ref-counted when using hugepages mm: prevent get_user_pages() from overflowing page refcount mm: make page ref count overflow check tighter and more explicit Revert "x86/build: Move _etext to actual end of .text" efi/libstub: Unify command line param parsing media: uvcvideo: Fix uvc_alloc_entity() allocation alignment ethtool: fix potential userspace buffer overflow neighbor: Call __ipv4_neigh_lookup_noref in neigh_xmit net/mlx4_en: ethtool, Remove unsupported SFP EEPROM high pages query net: rds: fix memory leak in rds_ib_flush_mr_pool pktgen: do not sleep with the thread lock held. ipv6: fix EFAULT on sendto with icmpv6 and hdrincl ipv6: use READ_ONCE() for inet->hdrincl as in ipv4 Revert "fib_rules: fix error in backport of e9919a24d302 ("fib_rules: return 0...")" Revert "fib_rules: return 0 directly if an exactly same rule exists when NLM_F_EXCL not supplied" rcu: locking and unlocking need to always be at least barriers parisc: Use implicit space register selection for loading the coherence index of I/O pdirs fuse: fallocate: fix return with locked inode x86/power: Fix 'nosmt' vs hibernation triple fault during resume MIPS: pistachio: Build uImage.gz by default Revert "MIPS: perf: ath79: Fix perfcount IRQ assignment" genwqe: Prevent an integer overflow in the ioctl drm/gma500/cdv: Check vbt config bits when detecting lvds panels drm/radeon: prefer lower reference dividers drm/i915: Fix I915_EXEC_RING_MASK TTY: serial_core, add ->install fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock fuse: Add FOPEN_STREAM to use stream_open() ipv4: Define __ipv4_neigh_lookup_noref when CONFIG_INET is disabled ethtool: check the return value of get_regs_len Linux 4.9.181 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
187 lines
4.5 KiB
C
187 lines
4.5 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/**
|
|
* GHASH routines supporting VMX instructions on the Power 8
|
|
*
|
|
* Copyright (C) 2015, 2019 International Business Machines Inc.
|
|
*
|
|
* Author: Marcelo Henrique Cerri <mhcerri@br.ibm.com>
|
|
*
|
|
* Extended by Daniel Axtens <dja@axtens.net> to replace the fallback
|
|
* mechanism. The new approach is based on arm64 code, which is:
|
|
* Copyright (C) 2014 - 2018 Linaro Ltd. <ard.biesheuvel@linaro.org>
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/err.h>
|
|
#include <linux/crypto.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/hardirq.h>
|
|
#include <asm/switch_to.h>
|
|
#include <crypto/aes.h>
|
|
#include <crypto/ghash.h>
|
|
#include <crypto/scatterwalk.h>
|
|
#include <crypto/internal/hash.h>
|
|
#include <crypto/b128ops.h>
|
|
|
|
#define IN_INTERRUPT in_interrupt()
|
|
|
|
void gcm_init_p8(u128 htable[16], const u64 Xi[2]);
|
|
void gcm_gmult_p8(u64 Xi[2], const u128 htable[16]);
|
|
void gcm_ghash_p8(u64 Xi[2], const u128 htable[16],
|
|
const u8 *in, size_t len);
|
|
|
|
struct p8_ghash_ctx {
|
|
/* key used by vector asm */
|
|
u128 htable[16];
|
|
/* key used by software fallback */
|
|
be128 key;
|
|
};
|
|
|
|
struct p8_ghash_desc_ctx {
|
|
u64 shash[2];
|
|
u8 buffer[GHASH_DIGEST_SIZE];
|
|
int bytes;
|
|
};
|
|
|
|
static int p8_ghash_init(struct shash_desc *desc)
|
|
{
|
|
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
|
|
|
|
dctx->bytes = 0;
|
|
memset(dctx->shash, 0, GHASH_DIGEST_SIZE);
|
|
return 0;
|
|
}
|
|
|
|
static int p8_ghash_setkey(struct crypto_shash *tfm, const u8 *key,
|
|
unsigned int keylen)
|
|
{
|
|
struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(tfm));
|
|
|
|
if (keylen != GHASH_BLOCK_SIZE)
|
|
return -EINVAL;
|
|
|
|
preempt_disable();
|
|
pagefault_disable();
|
|
enable_kernel_vsx();
|
|
gcm_init_p8(ctx->htable, (const u64 *) key);
|
|
disable_kernel_vsx();
|
|
pagefault_enable();
|
|
preempt_enable();
|
|
|
|
memcpy(&ctx->key, key, GHASH_BLOCK_SIZE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static inline void __ghash_block(struct p8_ghash_ctx *ctx,
|
|
struct p8_ghash_desc_ctx *dctx)
|
|
{
|
|
if (!IN_INTERRUPT) {
|
|
preempt_disable();
|
|
pagefault_disable();
|
|
enable_kernel_vsx();
|
|
gcm_ghash_p8(dctx->shash, ctx->htable,
|
|
dctx->buffer, GHASH_DIGEST_SIZE);
|
|
disable_kernel_vsx();
|
|
pagefault_enable();
|
|
preempt_enable();
|
|
} else {
|
|
crypto_xor((u8 *)dctx->shash, dctx->buffer, GHASH_BLOCK_SIZE);
|
|
gf128mul_lle((be128 *)dctx->shash, &ctx->key);
|
|
}
|
|
}
|
|
|
|
static inline void __ghash_blocks(struct p8_ghash_ctx *ctx,
|
|
struct p8_ghash_desc_ctx *dctx,
|
|
const u8 *src, unsigned int srclen)
|
|
{
|
|
if (!IN_INTERRUPT) {
|
|
preempt_disable();
|
|
pagefault_disable();
|
|
enable_kernel_vsx();
|
|
gcm_ghash_p8(dctx->shash, ctx->htable,
|
|
src, srclen);
|
|
disable_kernel_vsx();
|
|
pagefault_enable();
|
|
preempt_enable();
|
|
} else {
|
|
while (srclen >= GHASH_BLOCK_SIZE) {
|
|
crypto_xor((u8 *)dctx->shash, src, GHASH_BLOCK_SIZE);
|
|
gf128mul_lle((be128 *)dctx->shash, &ctx->key);
|
|
srclen -= GHASH_BLOCK_SIZE;
|
|
src += GHASH_BLOCK_SIZE;
|
|
}
|
|
}
|
|
}
|
|
|
|
static int p8_ghash_update(struct shash_desc *desc,
|
|
const u8 *src, unsigned int srclen)
|
|
{
|
|
unsigned int len;
|
|
struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
|
|
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
|
|
|
|
if (dctx->bytes) {
|
|
if (dctx->bytes + srclen < GHASH_DIGEST_SIZE) {
|
|
memcpy(dctx->buffer + dctx->bytes, src,
|
|
srclen);
|
|
dctx->bytes += srclen;
|
|
return 0;
|
|
}
|
|
memcpy(dctx->buffer + dctx->bytes, src,
|
|
GHASH_DIGEST_SIZE - dctx->bytes);
|
|
|
|
__ghash_block(ctx, dctx);
|
|
|
|
src += GHASH_DIGEST_SIZE - dctx->bytes;
|
|
srclen -= GHASH_DIGEST_SIZE - dctx->bytes;
|
|
dctx->bytes = 0;
|
|
}
|
|
len = srclen & ~(GHASH_DIGEST_SIZE - 1);
|
|
if (len) {
|
|
__ghash_blocks(ctx, dctx, src, len);
|
|
src += len;
|
|
srclen -= len;
|
|
}
|
|
if (srclen) {
|
|
memcpy(dctx->buffer, src, srclen);
|
|
dctx->bytes = srclen;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int p8_ghash_final(struct shash_desc *desc, u8 *out)
|
|
{
|
|
int i;
|
|
struct p8_ghash_ctx *ctx = crypto_tfm_ctx(crypto_shash_tfm(desc->tfm));
|
|
struct p8_ghash_desc_ctx *dctx = shash_desc_ctx(desc);
|
|
|
|
if (dctx->bytes) {
|
|
for (i = dctx->bytes; i < GHASH_DIGEST_SIZE; i++)
|
|
dctx->buffer[i] = 0;
|
|
__ghash_block(ctx, dctx);
|
|
dctx->bytes = 0;
|
|
}
|
|
memcpy(out, dctx->shash, GHASH_DIGEST_SIZE);
|
|
return 0;
|
|
}
|
|
|
|
struct shash_alg p8_ghash_alg = {
|
|
.digestsize = GHASH_DIGEST_SIZE,
|
|
.init = p8_ghash_init,
|
|
.update = p8_ghash_update,
|
|
.final = p8_ghash_final,
|
|
.setkey = p8_ghash_setkey,
|
|
.descsize = sizeof(struct p8_ghash_desc_ctx)
|
|
+ sizeof(struct ghash_desc_ctx),
|
|
.base = {
|
|
.cra_name = "ghash",
|
|
.cra_driver_name = "p8_ghash",
|
|
.cra_priority = 1000,
|
|
.cra_flags = CRYPTO_ALG_TYPE_SHASH,
|
|
.cra_blocksize = GHASH_BLOCK_SIZE,
|
|
.cra_ctxsize = sizeof(struct p8_ghash_ctx),
|
|
.cra_module = THIS_MODULE,
|
|
},
|
|
};
|