
Changes in 5.10.210 usb: cdns3: Fixes for sparse warnings usb: cdns3: fix uvc failure work since sg support enabled usb: cdns3: fix incorrect calculation of ep_buf_size when more than one config usb: cdns3: fix iso transfer error when mult is not zero usb: cdns3: Fix uvc fail when DMA cross 4k boundery since sg enabled PCI: mediatek: Clear interrupt status before dispatching handler units: change from 'L' to 'UL' units: add the HZ macros serial: sc16is7xx: set safe default SPI clock frequency spi: introduce SPI_MODE_X_MASK macro serial: sc16is7xx: add check for unsupported SPI modes during probe iio: adc: ad7091r: Set alert bit in config register iio: adc: ad7091r: Allow users to configure device events iio: adc: ad7091r: Enable internal vref if external vref is not supplied dmaengine: fix NULL pointer in channel unregistration function iio:adc:ad7091r: Move exports into IIO_AD7091R namespace. ext4: allow for the last group to be marked as trimmed crypto: api - Disallow identical driver names PM: hibernate: Enforce ordering during image compression/decompression hwrng: core - Fix page fault dead lock on mmap-ed hwrng crypto: s390/aes - Fix buffer overread in CTR mode rpmsg: virtio: Free driver_override when rpmsg_remove() bus: mhi: host: Drop chan lock before queuing buffers parisc/firmware: Fix F-extend for PDC addresses async: Split async_schedule_node_domain() async: Introduce async_schedule_dev_nocall() arm64: dts: qcom: sdm845: fix USB wakeup interrupt types arm64: dts: qcom: sdm845: fix USB DP/DM HS PHY interrupts lsm: new security_file_ioctl_compat() hook scripts/get_abi: fix source path leak mmc: core: Use mrq.sbc in close-ended ffu mmc: mmc_spi: remove custom DMA mapped buffers rtc: Adjust failure return code for cmos_set_alarm() nouveau/vmm: don't set addr on the fail path to avoid warning ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path rename(): fix the locking of subdirectories block: Remove special-casing of compound pages stddef: Introduce DECLARE_FLEX_ARRAY() helper smb3: Replace smb2pdu 1-element arrays with flex-arrays mm: vmalloc: introduce array allocation functions KVM: use __vcalloc for very large allocations net/smc: fix illegal rmb_desc access in SMC-D connection dump tcp: make sure init the accept_queue's spinlocks once bnxt_en: Wait for FLR to complete during probe vlan: skip nested type that is not IFLA_VLAN_QOS_MAPPING llc: make llc_ui_sendmsg() more robust against bonding changes llc: Drop support for ETH_P_TR_802_2. net/rds: Fix UBSAN: array-index-out-of-bounds in rds_cmsg_recv tracing: Ensure visibility when inserting an element into tracing_map afs: Hide silly-rename files from userspace tcp: Add memory barrier to tcp_push() netlink: fix potential sleeping issue in mqueue_flush_file ipv6: init the accept_queue's spinlocks in inet6_create net/mlx5: DR, Use the right GVMI number for drop action net/mlx5e: fix a double-free in arfs_create_groups netfilter: nf_tables: restrict anonymous set and map names to 16 bytes netfilter: nf_tables: validate NFPROTO_* family net: mvpp2: clear BM pool before initialization selftests: netdevsim: fix the udp_tunnel_nic test fjes: fix memleaks in fjes_hw_setup net: fec: fix the unhandled context fault from smmu btrfs: ref-verify: free ref cache before clearing mount opt btrfs: tree-checker: fix inline ref size in error messages btrfs: don't warn if discard range is not aligned to sector btrfs: defrag: reject unknown flags of btrfs_ioctl_defrag_range_args btrfs: don't abort filesystem when attempting to snapshot deleted subvolume rbd: don't move requests to the running list on errors exec: Fix error handling in begin_new_exec() wifi: iwlwifi: fix a memory corruption netfilter: nft_chain_filter: handle NETDEV_UNREGISTER for inet/ingress basechain netfilter: nf_tables: reject QUEUE/DROP verdict parameters gpiolib: acpi: Ignore touchpad wakeup on GPD G1619-04 drm: Don't unref the same fb many times by mistake due to deadlock handling drm/bridge: nxp-ptn3460: fix i2c_master_send() error checking drm/tidss: Fix atomic_flush check drm/bridge: nxp-ptn3460: simplify some error checking PM: sleep: Use dev_printk() when possible PM: sleep: Avoid calling put_device() under dpm_list_mtx PM: core: Remove unnecessary (void *) conversions PM: sleep: Fix possible deadlocks in core system-wide PM code fs/pipe: move check to pipe_has_watch_queue() pipe: wakeup wr_wait after setting max_usage ARM: dts: samsung: exynos4210-i9100: Unconditionally enable LDO12 arm64: dts: qcom: sc7180: Use pdc interrupts for USB instead of GIC interrupts arm64: dts: qcom: sc7180: fix USB wakeup interrupt types media: mtk-jpeg: Fix use after free bug due to error path handling in mtk_jpeg_dec_device_run mm: use __pfn_to_section() instead of open coding it mm/sparsemem: fix race in accessing memory_section->usage btrfs: remove err variable from btrfs_delete_subvolume btrfs: avoid copying BTRFS_ROOT_SUBVOL_DEAD flag to snapshot of subvolume being deleted drm: panel-simple: add missing bus flags for Tianma tm070jvhg[30/33] drm/exynos: fix accidental on-stack copy of exynos_drm_plane drm/exynos: gsc: minor fix for loop iteration in gsc_runtime_resume gpio: eic-sprd: Clear interrupt after set the interrupt type spi: bcm-qspi: fix SFDP BFPT read by usig mspi read mips: Call lose_fpu(0) before initializing fcr31 in mips_set_personality_nan tick/sched: Preserve number of idle sleeps across CPU hotplug events x86/entry/ia32: Ensure s32 is sign extended to s64 powerpc/mm: Fix null-pointer dereference in pgtable_cache_add drivers/perf: pmuv3: don't expose SW_INCR event in sysfs powerpc: Fix build error due to is_valid_bugaddr() powerpc/mm: Fix build failures due to arch_reserved_kernel_pages() x86/boot: Ignore NMIs during very early boot powerpc: pmd_move_must_withdraw() is only needed for CONFIG_TRANSPARENT_HUGEPAGE powerpc/lib: Validate size for vector operations x86/mce: Mark fatal MCE's page as poison to avoid panic in the kdump kernel perf/core: Fix narrow startup race when creating the perf nr_addr_filters sysfs file debugobjects: Stop accessing objects after releasing hash bucket lock regulator: core: Only increment use_count when enable_count changes audit: Send netlink ACK before setting connection in auditd_set ACPI: video: Add quirk for the Colorful X15 AT 23 Laptop PNP: ACPI: fix fortify warning ACPI: extlog: fix NULL pointer dereference check PM / devfreq: Synchronize devfreq_monitor_[start/stop] ACPI: APEI: set memory failure flags as MF_ACTION_REQUIRED on synchronous events FS:JFS:UBSAN:array-index-out-of-bounds in dbAdjTree UBSAN: array-index-out-of-bounds in dtSplitRoot jfs: fix slab-out-of-bounds Read in dtSearch jfs: fix array-index-out-of-bounds in dbAdjTree jfs: fix uaf in jfs_evict_inode pstore/ram: Fix crash when setting number of cpus to an odd number crypto: stm32/crc32 - fix parsing list of devices afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu() afs: fix the usage of read_seqbegin_or_lock() in afs_find_server*() rxrpc_find_service_conn_rcu: fix the usage of read_seqbegin_or_lock() jfs: fix array-index-out-of-bounds in diNewExt s390/ptrace: handle setting of fpc register correctly KVM: s390: fix setting of fpc register SUNRPC: Fix a suspicious RCU usage warning ecryptfs: Reject casefold directory inodes ext4: fix inconsistent between segment fstrim and full fstrim ext4: unify the type of flexbg_size to unsigned int ext4: remove unnecessary check from alloc_flex_gd() ext4: avoid online resizing failures due to oversized flex bg wifi: rt2x00: restart beacon queue when hardware reset selftests/bpf: satisfy compiler by having explicit return in btf test selftests/bpf: Fix pyperf180 compilation failure with clang18 scsi: lpfc: Fix possible file string name overflow when updating firmware PCI: Add no PM reset quirk for NVIDIA Spectrum devices bonding: return -ENOMEM instead of BUG in alb_upper_dev_walk scsi: arcmsr: Support new PCI device IDs 1883 and 1886 ARM: dts: imx7d: Fix coresight funnel ports ARM: dts: imx7s: Fix lcdif compatible ARM: dts: imx7s: Fix nand-controller #size-cells wifi: ath9k: Fix potential array-index-out-of-bounds read in ath9k_htc_txstatus() bpf: Add map and need_defer parameters to .map_fd_put_ptr() scsi: libfc: Don't schedule abort twice scsi: libfc: Fix up timeout error in fc_fcp_rec_error() bpf: Set uattr->batch.count as zero before batched update or deletion ARM: dts: rockchip: fix rk3036 hdmi ports node ARM: dts: imx25/27-eukrea: Fix RTC node name ARM: dts: imx: Use flash@0,0 pattern ARM: dts: imx27: Fix sram node ARM: dts: imx1: Fix sram node ionic: pass opcode to devcmd_wait block/rnbd-srv: Check for unlikely string overflow ARM: dts: imx25: Fix the iim compatible string ARM: dts: imx25/27: Pass timing0 ARM: dts: imx27-apf27dev: Fix LED name ARM: dts: imx23-sansa: Use preferred i2c-gpios properties ARM: dts: imx23/28: Fix the DMA controller node name net: dsa: mv88e6xxx: Fix mv88e6352_serdes_get_stats error path block: prevent an integer overflow in bvec_try_merge_hw_page md: Whenassemble the array, consult the superblock of the freshest device arm64: dts: qcom: msm8996: Fix 'in-ports' is a required property arm64: dts: qcom: msm8998: Fix 'out-ports' is a required property wifi: rtl8xxxu: Add additional USB IDs for RTL8192EU devices wifi: rtlwifi: rtl8723{be,ae}: using calculate_bit_shift() wifi: cfg80211: free beacon_ies when overridden from hidden BSS Bluetooth: qca: Set both WIDEBAND_SPEECH and LE_STATES quirks for QCA2066 Bluetooth: L2CAP: Fix possible multiple reject send i40e: Fix VF disable behavior to block all traffic f2fs: fix to check return value of f2fs_reserve_new_block() ALSA: hda: Refer to correct stream index at loops ASoC: doc: Fix undefined SND_SOC_DAPM_NOPM argument fast_dput(): handle underflows gracefully RDMA/IPoIB: Fix error code return in ipoib_mcast_join drm/amd/display: Fix tiled display misalignment f2fs: fix write pointers on zoned device after roll forward drm/drm_file: fix use of uninitialized variable drm/framebuffer: Fix use of uninitialized variable drm/mipi-dsi: Fix detach call without attach media: stk1160: Fixed high volume of stk1160_dbg messages media: rockchip: rga: fix swizzling for RGB formats PCI: add INTEL_HDA_ARL to pci_ids.h ALSA: hda: Intel: add HDA_ARL PCI ID support ALSA: hda: intel-dspcfg: add filters for ARL-S and ARL drm/exynos: Call drm_atomic_helper_shutdown() at shutdown/unbind time IB/ipoib: Fix mcast list locking media: ddbridge: fix an error code problem in ddb_probe drm/msm/dpu: Ratelimit framedone timeout msgs clk: hi3620: Fix memory leak in hi3620_mmc_clk_init() clk: mmp: pxa168: Fix memory leak in pxa168_clk_init() watchdog: it87_wdt: Keep WDTCTRL bit 3 unmodified for IT8784/IT8786 drm/amdgpu: Let KFD sync with VM fences drm/amdgpu: Drop 'fence' check in 'to_amdgpu_amdkfd_fence()' leds: trigger: panic: Don't register panic notifier if creating the trigger failed um: Fix naming clash between UML and scheduler um: Don't use vfprintf() for os_info() um: net: Fix return type of uml_net_start_xmit() i3c: master: cdns: Update maximum prescaler value for i2c clock xen/gntdev: Fix the abuse of underlying struct page in DMA-buf import mfd: ti_am335x_tscadc: Fix TI SoC dependencies PCI: Only override AMD USB controller if required PCI: switchtec: Fix stdev_release() crash after surprise hot remove usb: hub: Replace hardcoded quirk value with BIT() macro tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE fs/kernfs/dir: obey S_ISGID PCI/AER: Decode Requester ID when no error info found libsubcmd: Fix memory leak in uniq() virtio_net: Fix "‘%d’ directive writing between 1 and 11 bytes into a region of size 10" warnings blk-mq: fix IO hang from sbitmap wakeup race ceph: fix deadlock or deadcode of misusing dget() drm/amd/powerplay: Fix kzalloc parameter 'ATOM_Tonga_PPM_Table' in 'get_platform_power_management_table()' drm/amdgpu: Release 'adev->pm.fw' before return in 'amdgpu_device_need_post()' perf: Fix the nr_addr_filters fix wifi: cfg80211: fix RCU dereference in __cfg80211_bss_update drm: using mul_u32_u32() requires linux/math64.h scsi: isci: Fix an error code problem in isci_io_request_build() scsi: core: Introduce enum scsi_disposition scsi: core: Move scsi_host_busy() out of host lock for waking up EH handler ip6_tunnel: use dev_sw_netstats_rx_add() ip6_tunnel: make sure to pull inner header in __ip6_tnl_rcv() net-zerocopy: Refactor frag-is-remappable test. tcp: add sanity checks to rx zerocopy ixgbe: Remove non-inclusive language ixgbe: Refactor returning internal error codes ixgbe: Refactor overtemp event handling ixgbe: Fix an error handling path in ixgbe_read_iosf_sb_reg_x550() ipv6: Ensure natural alignment of const ipv6 loopback and router addresses llc: call sock_orphan() at release time netfilter: nf_log: replace BUG_ON by WARN_ON_ONCE when putting logger netfilter: nft_ct: sanitize layer 3 and 4 protocol number in custom expectations net: ipv4: fix a memleak in ip_setup_cork af_unix: fix lockdep positive in sk_diag_dump_icons() net: sysfs: Fix /sys/class/net/<iface> path HID: apple: Add support for the 2021 Magic Keyboard HID: apple: Add 2021 magic keyboard FN key mapping bonding: remove print in bond_verify_device_path uapi: stddef.h: Fix __DECLARE_FLEX_ARRAY for C++ PM: sleep: Fix error handling in dpm_prepare() dmaengine: fsl-dpaa2-qdma: Fix the size of dma pools dmaengine: ti: k3-udma: Report short packet errors dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA phy: renesas: rcar-gen3-usb2: Fix returning wrong error code dmaengine: fix is_slave_direction() return false when DMA_DEV_TO_DEV phy: ti: phy-omap-usb2: Fix NULL pointer dereference for SRP drm/msm/dp: return correct Colorimetry for DP_TEST_DYNAMIC_RANGE_CEA case net: stmmac: xgmac: fix handling of DPP safety error for DMA channels selftests: net: avoid just another constant wait tunnels: fix out of bounds access when building IPv6 PMTU error atm: idt77252: fix a memleak in open_card_ubr0 hwmon: (aspeed-pwm-tacho) mutex for tach reading hwmon: (coretemp) Fix out-of-bounds memory access hwmon: (coretemp) Fix bogus core_id to attr name mapping inet: read sk->sk_family once in inet_recv_error() rxrpc: Fix response to PING RESPONSE ACKs to a dead call tipc: Check the bearer type before calling tipc_udp_nl_bearer_add() ppp_async: limit MRU to 64K netfilter: nft_compat: reject unused compat flag netfilter: nft_compat: restrict match/target protocol to u16 netfilter: nft_ct: reject direction for ct id netfilter: nft_set_pipapo: store index in scratch maps netfilter: nft_set_pipapo: add helper to release pcpu scratch area netfilter: nft_set_pipapo: remove scratch_aligned pointer scsi: core: Move scsi_host_busy() out of host lock if it is for per-command blk-iocost: Fix an UBSAN shift-out-of-bounds warning net/af_iucv: clean up a try_then_request_module() USB: serial: qcserial: add new usb-id for Dell Wireless DW5826e USB: serial: option: add Fibocom FM101-GL variant USB: serial: cp210x: add ID for IMST iM871A-USB usb: host: xhci-plat: Add support for XHCI_SG_TRB_CACHE_SIZE_QUIRK hrtimer: Report offline hrtimer enqueue Input: i8042 - fix strange behavior of touchpad on Clevo NS70PU Input: atkbd - skip ATKBD_CMD_SETLEDS when skipping ATKBD_CMD_GETID vhost: use kzalloc() instead of kmalloc() followed by memset() clocksource: Skip watchdog check for large watchdog intervals net: stmmac: xgmac: use #define for string constants net: stmmac: xgmac: fix a typo of register name in DPP safety handling netfilter: nft_set_rbtree: skip end interval element from gc btrfs: forbid creating subvol qgroups btrfs: do not ASSERT() if the newly created subvolume already got read btrfs: forbid deleting live subvol qgroup btrfs: send: return EOPNOTSUPP on unknown flags of: unittest: Fix compile in the non-dynamic case net: openvswitch: limit the number of recursions from action sets spi: ppc4xx: Drop write-only variable ASoC: rt5645: Fix deadlock in rt5645_jack_detect_work() net: sysfs: Fix /sys/class/net/<iface> path for statistics MIPS: Add 'memory' clobber to csum_ipv6_magic() inline assembler i40e: Fix waiting for queues of all VSIs to be disabled tracing/trigger: Fix to return error if failed to alloc snapshot mm/writeback: fix possible divide-by-zero in wb_dirty_limits(), again ALSA: hda/realtek: Fix the external mic not being recognised for Acer Swift 1 SF114-32 ALSA: hda/realtek: Enable Mute LED on HP Laptop 14-fq0xxx HID: wacom: generic: Avoid reporting a serial of '0' to userspace HID: wacom: Do not register input devices until after hid_hw_start usb: ucsi_acpi: Fix command completion handling USB: hub: check for alternate port before enabling A_ALT_HNP_SUPPORT usb: f_mass_storage: forbid async queue when shutdown happen media: ir_toy: fix a memleak in irtoy_tx powerpc/kasan: Fix addr error caused by page alignment i2c: i801: Remove i801_set_block_buffer_mode i2c: i801: Fix block process call transactions modpost: trim leading spaces when processing source files list scsi: Revert "scsi: fcoe: Fix potential deadlock on &fip->ctlr_lock" lsm: fix the logic in security_inode_getsecctx() firewire: core: correct documentation of fw_csr_string() kernel API kbuild: Fix changing ELF file type for output of gen_btf for big endian nfc: nci: free rx_data_reassembly skb on NCI device cleanup net: hsr: remove WARN_ONCE() in send_hsr_supervision_frame() xen-netback: properly sync TX responses ALSA: hda/realtek: Enable headset mic on Vaio VJFE-ADL binder: signal epoll threads of self-work misc: fastrpc: Mark all sessions as invalid in cb_remove ext4: fix double-free of blocks due to wrong extents moved_len tracing: Fix wasted memory in saved_cmdlines logic staging: iio: ad5933: fix type mismatch regression iio: magnetometer: rm3100: add boundary check for the value read from RM3100_REG_TMRC iio: accel: bma400: Fix a compilation problem media: rc: bpf attach/detach requires write permission hv_netvsc: Fix race condition between netvsc_probe and netvsc_remove ring-buffer: Clean ring_buffer_poll_wait() error return serial: max310x: set default value when reading clock ready bit serial: max310x: improve crystal stable clock detection x86/Kconfig: Transmeta Crusoe is CPU family 5, not 6 x86/mm/ident_map: Use gbpages only where full GB page should be mapped. mmc: slot-gpio: Allow non-sleeping GPIO ro ALSA: hda/conexant: Add quirk for SWS JS201D nilfs2: fix data corruption in dsync block recovery for small block sizes nilfs2: fix hang in nilfs_lookup_dirty_data_buffers() crypto: ccp - Fix null pointer dereference in __sev_platform_shutdown_locked nfp: use correct macro for LengthSelect in BAR config nfp: flower: prevent re-adding mac index for bonded port wifi: mac80211: reload info pointer in ieee80211_tx_dequeue() irqchip/irq-brcmstb-l2: Add write memory barrier before exit irqchip/gic-v3-its: Fix GICv4.1 VPE affinity update s390/qeth: Fix potential loss of L3-IP@ in case of network issues ceph: prevent use-after-free in encode_cap_msg() of: property: fix typo in io-channels can: j1939: Fix UAF in j1939_sk_match_filter during setsockopt(SO_J1939_FILTER) pmdomain: core: Move the unused cleanup to a _sync initcall tracing: Inform kmemleak of saved_cmdlines allocation Revert "md/raid5: Wait for MD_SB_CHANGE_PENDING in raid5d" bus: moxtet: Add spi device table PCI: dwc: endpoint: Fix dw_pcie_ep_raise_msix_irq() alignment support mips: Fix max_mapnr being uninitialized on early stages crypto: lib/mpi - Fix unexpected pointer access in mpi_ec_init serial: Add rs485_supported to uart_port serial: 8250_exar: Fill in rs485_supported serial: 8250_exar: Set missing rs485_supported flag scripts/decode_stacktrace.sh: silence stderr messages from addr2line/nm scripts/decode_stacktrace.sh: support old bash version scripts: decode_stacktrace: demangle Rust symbols scripts/decode_stacktrace.sh: optionally use LLVM utilities netfilter: ipset: fix performance regression in swap operation netfilter: ipset: Missing gc cancellations fixed hrtimer: Ignore slack time for RT tasks in schedule_hrtimeout_range() Revert "arm64: Stash shadow stack pointer in the task struct on interrupt" net: prevent mss overflow in skb_segment() sched/membarrier: reduce the ability to hammer on sys_membarrier nilfs2: fix potential bug in end_buffer_async_write nilfs2: replace WARN_ONs for invalid DAT metadata block requests dm: limit the number of targets and parameter size area PM: runtime: add devm_pm_runtime_enable helper PM: runtime: Have devm_pm_runtime_enable() handle pm_runtime_dont_use_autosuspend() drm/msm/dsi: Enable runtime PM netfilter: nf_tables: fix pointer math issue in nft_byteorder_eval() net: bcmgenet: Fix EEE implementation PCI: dwc: Fix a 64bit bug in dw_pcie_ep_raise_msix_irq() Linux 5.10.210 Change-Id: I5e7327f58dd6abd26ac2b1e328a81c1010d1147c Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
1302 lines
30 KiB
C
1302 lines
30 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Cryptographic API for algorithms (i.e., low-level API).
|
|
*
|
|
* Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
|
|
*/
|
|
|
|
#include <crypto/algapi.h>
|
|
#include <linux/err.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/fips.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/list.h>
|
|
#include <linux/module.h>
|
|
#include <linux/rtnetlink.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
|
|
#include "internal.h"
|
|
|
|
static LIST_HEAD(crypto_template_list);
|
|
|
|
static inline void crypto_check_module_sig(struct module *mod)
|
|
{
|
|
if (fips_enabled && mod && !module_sig_ok(mod))
|
|
panic("Module %s signature verification failed in FIPS mode\n",
|
|
module_name(mod));
|
|
}
|
|
|
|
static int crypto_check_alg(struct crypto_alg *alg)
|
|
{
|
|
crypto_check_module_sig(alg->cra_module);
|
|
|
|
if (!alg->cra_name[0] || !alg->cra_driver_name[0])
|
|
return -EINVAL;
|
|
|
|
if (alg->cra_alignmask & (alg->cra_alignmask + 1))
|
|
return -EINVAL;
|
|
|
|
/* General maximums for all algs. */
|
|
if (alg->cra_alignmask > MAX_ALGAPI_ALIGNMASK)
|
|
return -EINVAL;
|
|
|
|
if (alg->cra_blocksize > MAX_ALGAPI_BLOCKSIZE)
|
|
return -EINVAL;
|
|
|
|
/* Lower maximums for specific alg types. */
|
|
if (!alg->cra_type && (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
|
|
CRYPTO_ALG_TYPE_CIPHER) {
|
|
if (alg->cra_alignmask > MAX_CIPHER_ALIGNMASK)
|
|
return -EINVAL;
|
|
|
|
if (alg->cra_blocksize > MAX_CIPHER_BLOCKSIZE)
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (alg->cra_priority < 0)
|
|
return -EINVAL;
|
|
|
|
refcount_set(&alg->cra_refcnt, 1);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void crypto_free_instance(struct crypto_instance *inst)
|
|
{
|
|
inst->alg.cra_type->free(inst);
|
|
}
|
|
|
|
static void crypto_destroy_instance(struct crypto_alg *alg)
|
|
{
|
|
struct crypto_instance *inst = (void *)alg;
|
|
struct crypto_template *tmpl = inst->tmpl;
|
|
|
|
crypto_free_instance(inst);
|
|
crypto_tmpl_put(tmpl);
|
|
}
|
|
|
|
/*
|
|
* This function adds a spawn to the list secondary_spawns which
|
|
* will be used at the end of crypto_remove_spawns to unregister
|
|
* instances, unless the spawn happens to be one that is depended
|
|
* on by the new algorithm (nalg in crypto_remove_spawns).
|
|
*
|
|
* This function is also responsible for resurrecting any algorithms
|
|
* in the dependency chain of nalg by unsetting n->dead.
|
|
*/
|
|
static struct list_head *crypto_more_spawns(struct crypto_alg *alg,
|
|
struct list_head *stack,
|
|
struct list_head *top,
|
|
struct list_head *secondary_spawns)
|
|
{
|
|
struct crypto_spawn *spawn, *n;
|
|
|
|
spawn = list_first_entry_or_null(stack, struct crypto_spawn, list);
|
|
if (!spawn)
|
|
return NULL;
|
|
|
|
n = list_prev_entry(spawn, list);
|
|
list_move(&spawn->list, secondary_spawns);
|
|
|
|
if (list_is_last(&n->list, stack))
|
|
return top;
|
|
|
|
n = list_next_entry(n, list);
|
|
if (!spawn->dead)
|
|
n->dead = false;
|
|
|
|
return &n->inst->alg.cra_users;
|
|
}
|
|
|
|
static void crypto_remove_instance(struct crypto_instance *inst,
|
|
struct list_head *list)
|
|
{
|
|
struct crypto_template *tmpl = inst->tmpl;
|
|
|
|
if (crypto_is_dead(&inst->alg))
|
|
return;
|
|
|
|
inst->alg.cra_flags |= CRYPTO_ALG_DEAD;
|
|
|
|
if (!tmpl || !crypto_tmpl_get(tmpl))
|
|
return;
|
|
|
|
list_move(&inst->alg.cra_list, list);
|
|
hlist_del(&inst->list);
|
|
inst->alg.cra_destroy = crypto_destroy_instance;
|
|
|
|
BUG_ON(!list_empty(&inst->alg.cra_users));
|
|
}
|
|
|
|
/*
|
|
* Given an algorithm alg, remove all algorithms that depend on it
|
|
* through spawns. If nalg is not null, then exempt any algorithms
|
|
* that is depended on by nalg. This is useful when nalg itself
|
|
* depends on alg.
|
|
*/
|
|
void crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list,
|
|
struct crypto_alg *nalg)
|
|
{
|
|
u32 new_type = (nalg ?: alg)->cra_flags;
|
|
struct crypto_spawn *spawn, *n;
|
|
LIST_HEAD(secondary_spawns);
|
|
struct list_head *spawns;
|
|
LIST_HEAD(stack);
|
|
LIST_HEAD(top);
|
|
|
|
spawns = &alg->cra_users;
|
|
list_for_each_entry_safe(spawn, n, spawns, list) {
|
|
if ((spawn->alg->cra_flags ^ new_type) & spawn->mask)
|
|
continue;
|
|
|
|
list_move(&spawn->list, &top);
|
|
}
|
|
|
|
/*
|
|
* Perform a depth-first walk starting from alg through
|
|
* the cra_users tree. The list stack records the path
|
|
* from alg to the current spawn.
|
|
*/
|
|
spawns = ⊤
|
|
do {
|
|
while (!list_empty(spawns)) {
|
|
struct crypto_instance *inst;
|
|
|
|
spawn = list_first_entry(spawns, struct crypto_spawn,
|
|
list);
|
|
inst = spawn->inst;
|
|
|
|
list_move(&spawn->list, &stack);
|
|
spawn->dead = !spawn->registered || &inst->alg != nalg;
|
|
|
|
if (!spawn->registered)
|
|
break;
|
|
|
|
BUG_ON(&inst->alg == alg);
|
|
|
|
if (&inst->alg == nalg)
|
|
break;
|
|
|
|
spawns = &inst->alg.cra_users;
|
|
|
|
/*
|
|
* Even if spawn->registered is true, the
|
|
* instance itself may still be unregistered.
|
|
* This is because it may have failed during
|
|
* registration. Therefore we still need to
|
|
* make the following test.
|
|
*
|
|
* We may encounter an unregistered instance here, since
|
|
* an instance's spawns are set up prior to the instance
|
|
* being registered. An unregistered instance will have
|
|
* NULL ->cra_users.next, since ->cra_users isn't
|
|
* properly initialized until registration. But an
|
|
* unregistered instance cannot have any users, so treat
|
|
* it the same as ->cra_users being empty.
|
|
*/
|
|
if (spawns->next == NULL)
|
|
break;
|
|
}
|
|
} while ((spawns = crypto_more_spawns(alg, &stack, &top,
|
|
&secondary_spawns)));
|
|
|
|
/*
|
|
* Remove all instances that are marked as dead. Also
|
|
* complete the resurrection of the others by moving them
|
|
* back to the cra_users list.
|
|
*/
|
|
list_for_each_entry_safe(spawn, n, &secondary_spawns, list) {
|
|
if (!spawn->dead)
|
|
list_move(&spawn->list, &spawn->alg->cra_users);
|
|
else if (spawn->registered)
|
|
crypto_remove_instance(spawn->inst, list);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_remove_spawns);
|
|
|
|
static struct crypto_larval *__crypto_register_alg(struct crypto_alg *alg)
|
|
{
|
|
struct crypto_alg *q;
|
|
struct crypto_larval *larval;
|
|
int ret = -EAGAIN;
|
|
|
|
if (crypto_is_dead(alg))
|
|
goto err;
|
|
|
|
INIT_LIST_HEAD(&alg->cra_users);
|
|
|
|
/* No cheating! */
|
|
alg->cra_flags &= ~CRYPTO_ALG_TESTED;
|
|
|
|
ret = -EEXIST;
|
|
|
|
list_for_each_entry(q, &crypto_alg_list, cra_list) {
|
|
if (q == alg)
|
|
goto err;
|
|
|
|
if (crypto_is_moribund(q))
|
|
continue;
|
|
|
|
if (crypto_is_larval(q)) {
|
|
if (!strcmp(alg->cra_driver_name, q->cra_driver_name))
|
|
goto err;
|
|
continue;
|
|
}
|
|
|
|
if (!strcmp(q->cra_driver_name, alg->cra_name) ||
|
|
!strcmp(q->cra_driver_name, alg->cra_driver_name) ||
|
|
!strcmp(q->cra_name, alg->cra_driver_name))
|
|
goto err;
|
|
}
|
|
|
|
larval = crypto_larval_alloc(alg->cra_name,
|
|
alg->cra_flags | CRYPTO_ALG_TESTED, 0);
|
|
if (IS_ERR(larval))
|
|
goto out;
|
|
|
|
ret = -ENOENT;
|
|
larval->adult = crypto_mod_get(alg);
|
|
if (!larval->adult)
|
|
goto free_larval;
|
|
|
|
refcount_set(&larval->alg.cra_refcnt, 1);
|
|
memcpy(larval->alg.cra_driver_name, alg->cra_driver_name,
|
|
CRYPTO_MAX_ALG_NAME);
|
|
larval->alg.cra_priority = alg->cra_priority;
|
|
|
|
list_add(&alg->cra_list, &crypto_alg_list);
|
|
list_add(&larval->alg.cra_list, &crypto_alg_list);
|
|
|
|
crypto_stats_init(alg);
|
|
|
|
out:
|
|
return larval;
|
|
|
|
free_larval:
|
|
kfree(larval);
|
|
err:
|
|
larval = ERR_PTR(ret);
|
|
goto out;
|
|
}
|
|
|
|
void crypto_alg_tested(const char *name, int err)
|
|
{
|
|
struct crypto_larval *test;
|
|
struct crypto_alg *alg;
|
|
struct crypto_alg *q;
|
|
LIST_HEAD(list);
|
|
bool best;
|
|
|
|
down_write(&crypto_alg_sem);
|
|
list_for_each_entry(q, &crypto_alg_list, cra_list) {
|
|
if (crypto_is_moribund(q) || !crypto_is_larval(q))
|
|
continue;
|
|
|
|
test = (struct crypto_larval *)q;
|
|
|
|
if (!strcmp(q->cra_driver_name, name))
|
|
goto found;
|
|
}
|
|
|
|
pr_err("alg: Unexpected test result for %s: %d\n", name, err);
|
|
goto unlock;
|
|
|
|
found:
|
|
q->cra_flags |= CRYPTO_ALG_DEAD;
|
|
alg = test->adult;
|
|
if (err || list_empty(&alg->cra_list))
|
|
goto complete;
|
|
|
|
alg->cra_flags |= CRYPTO_ALG_TESTED;
|
|
|
|
/* Only satisfy larval waiters if we are the best. */
|
|
best = true;
|
|
list_for_each_entry(q, &crypto_alg_list, cra_list) {
|
|
if (crypto_is_moribund(q) || !crypto_is_larval(q))
|
|
continue;
|
|
|
|
if (strcmp(alg->cra_name, q->cra_name))
|
|
continue;
|
|
|
|
if (q->cra_priority > alg->cra_priority) {
|
|
best = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
list_for_each_entry(q, &crypto_alg_list, cra_list) {
|
|
if (q == alg)
|
|
continue;
|
|
|
|
if (crypto_is_moribund(q))
|
|
continue;
|
|
|
|
if (crypto_is_larval(q)) {
|
|
struct crypto_larval *larval = (void *)q;
|
|
|
|
/*
|
|
* Check to see if either our generic name or
|
|
* specific name can satisfy the name requested
|
|
* by the larval entry q.
|
|
*/
|
|
if (strcmp(alg->cra_name, q->cra_name) &&
|
|
strcmp(alg->cra_driver_name, q->cra_name))
|
|
continue;
|
|
|
|
if (larval->adult)
|
|
continue;
|
|
if ((q->cra_flags ^ alg->cra_flags) & larval->mask)
|
|
continue;
|
|
|
|
if (best && crypto_mod_get(alg))
|
|
larval->adult = alg;
|
|
else
|
|
larval->adult = ERR_PTR(-EAGAIN);
|
|
|
|
continue;
|
|
}
|
|
|
|
if (strcmp(alg->cra_name, q->cra_name))
|
|
continue;
|
|
|
|
if (strcmp(alg->cra_driver_name, q->cra_driver_name) &&
|
|
q->cra_priority > alg->cra_priority)
|
|
continue;
|
|
|
|
crypto_remove_spawns(q, &list, alg);
|
|
}
|
|
|
|
complete:
|
|
complete_all(&test->completion);
|
|
|
|
unlock:
|
|
up_write(&crypto_alg_sem);
|
|
|
|
crypto_remove_final(&list);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_alg_tested);
|
|
|
|
void crypto_remove_final(struct list_head *list)
|
|
{
|
|
struct crypto_alg *alg;
|
|
struct crypto_alg *n;
|
|
|
|
list_for_each_entry_safe(alg, n, list, cra_list) {
|
|
list_del_init(&alg->cra_list);
|
|
crypto_alg_put(alg);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_remove_final);
|
|
|
|
static void crypto_wait_for_test(struct crypto_larval *larval)
|
|
{
|
|
int err;
|
|
|
|
err = crypto_probing_notify(CRYPTO_MSG_ALG_REGISTER, larval->adult);
|
|
if (err != NOTIFY_STOP) {
|
|
if (WARN_ON(err != NOTIFY_DONE))
|
|
goto out;
|
|
crypto_alg_tested(larval->alg.cra_driver_name, 0);
|
|
}
|
|
|
|
err = wait_for_completion_killable(&larval->completion);
|
|
WARN_ON(err);
|
|
if (!err)
|
|
crypto_notify(CRYPTO_MSG_ALG_LOADED, larval);
|
|
|
|
out:
|
|
crypto_larval_kill(&larval->alg);
|
|
}
|
|
|
|
int crypto_register_alg(struct crypto_alg *alg)
|
|
{
|
|
struct crypto_larval *larval;
|
|
int err;
|
|
|
|
alg->cra_flags &= ~CRYPTO_ALG_DEAD;
|
|
err = crypto_check_alg(alg);
|
|
if (err)
|
|
return err;
|
|
|
|
down_write(&crypto_alg_sem);
|
|
larval = __crypto_register_alg(alg);
|
|
up_write(&crypto_alg_sem);
|
|
|
|
if (IS_ERR(larval))
|
|
return PTR_ERR(larval);
|
|
|
|
crypto_wait_for_test(larval);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_alg);
|
|
|
|
static int crypto_remove_alg(struct crypto_alg *alg, struct list_head *list)
|
|
{
|
|
if (unlikely(list_empty(&alg->cra_list)))
|
|
return -ENOENT;
|
|
|
|
alg->cra_flags |= CRYPTO_ALG_DEAD;
|
|
|
|
list_del_init(&alg->cra_list);
|
|
crypto_remove_spawns(alg, list, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void crypto_unregister_alg(struct crypto_alg *alg)
|
|
{
|
|
int ret;
|
|
LIST_HEAD(list);
|
|
|
|
down_write(&crypto_alg_sem);
|
|
ret = crypto_remove_alg(alg, &list);
|
|
up_write(&crypto_alg_sem);
|
|
|
|
if (WARN(ret, "Algorithm %s is not registered", alg->cra_driver_name))
|
|
return;
|
|
|
|
if (WARN_ON(refcount_read(&alg->cra_refcnt) != 1))
|
|
return;
|
|
|
|
if (alg->cra_destroy)
|
|
alg->cra_destroy(alg);
|
|
|
|
crypto_remove_final(&list);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_alg);
|
|
|
|
int crypto_register_algs(struct crypto_alg *algs, int count)
|
|
{
|
|
int i, ret;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
ret = crypto_register_alg(&algs[i]);
|
|
if (ret)
|
|
goto err;
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
for (--i; i >= 0; --i)
|
|
crypto_unregister_alg(&algs[i]);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_algs);
|
|
|
|
void crypto_unregister_algs(struct crypto_alg *algs, int count)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < count; i++)
|
|
crypto_unregister_alg(&algs[i]);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_algs);
|
|
|
|
int crypto_register_template(struct crypto_template *tmpl)
|
|
{
|
|
struct crypto_template *q;
|
|
int err = -EEXIST;
|
|
|
|
down_write(&crypto_alg_sem);
|
|
|
|
crypto_check_module_sig(tmpl->module);
|
|
|
|
list_for_each_entry(q, &crypto_template_list, list) {
|
|
if (q == tmpl)
|
|
goto out;
|
|
}
|
|
|
|
list_add(&tmpl->list, &crypto_template_list);
|
|
err = 0;
|
|
out:
|
|
up_write(&crypto_alg_sem);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_template);
|
|
|
|
int crypto_register_templates(struct crypto_template *tmpls, int count)
|
|
{
|
|
int i, err;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
err = crypto_register_template(&tmpls[i]);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
return 0;
|
|
|
|
out:
|
|
for (--i; i >= 0; --i)
|
|
crypto_unregister_template(&tmpls[i]);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_templates);
|
|
|
|
void crypto_unregister_template(struct crypto_template *tmpl)
|
|
{
|
|
struct crypto_instance *inst;
|
|
struct hlist_node *n;
|
|
struct hlist_head *list;
|
|
LIST_HEAD(users);
|
|
|
|
down_write(&crypto_alg_sem);
|
|
|
|
BUG_ON(list_empty(&tmpl->list));
|
|
list_del_init(&tmpl->list);
|
|
|
|
list = &tmpl->instances;
|
|
hlist_for_each_entry(inst, list, list) {
|
|
int err = crypto_remove_alg(&inst->alg, &users);
|
|
|
|
BUG_ON(err);
|
|
}
|
|
|
|
up_write(&crypto_alg_sem);
|
|
|
|
hlist_for_each_entry_safe(inst, n, list, list) {
|
|
BUG_ON(refcount_read(&inst->alg.cra_refcnt) != 1);
|
|
crypto_free_instance(inst);
|
|
}
|
|
crypto_remove_final(&users);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_template);
|
|
|
|
void crypto_unregister_templates(struct crypto_template *tmpls, int count)
|
|
{
|
|
int i;
|
|
|
|
for (i = count - 1; i >= 0; --i)
|
|
crypto_unregister_template(&tmpls[i]);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_templates);
|
|
|
|
static struct crypto_template *__crypto_lookup_template(const char *name)
|
|
{
|
|
struct crypto_template *q, *tmpl = NULL;
|
|
|
|
down_read(&crypto_alg_sem);
|
|
list_for_each_entry(q, &crypto_template_list, list) {
|
|
if (strcmp(q->name, name))
|
|
continue;
|
|
if (unlikely(!crypto_tmpl_get(q)))
|
|
continue;
|
|
|
|
tmpl = q;
|
|
break;
|
|
}
|
|
up_read(&crypto_alg_sem);
|
|
|
|
return tmpl;
|
|
}
|
|
|
|
struct crypto_template *crypto_lookup_template(const char *name)
|
|
{
|
|
return try_then_request_module(__crypto_lookup_template(name),
|
|
"crypto-%s", name);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_lookup_template);
|
|
|
|
int crypto_register_instance(struct crypto_template *tmpl,
|
|
struct crypto_instance *inst)
|
|
{
|
|
struct crypto_larval *larval;
|
|
struct crypto_spawn *spawn;
|
|
int err;
|
|
|
|
err = crypto_check_alg(&inst->alg);
|
|
if (err)
|
|
return err;
|
|
|
|
inst->alg.cra_module = tmpl->module;
|
|
inst->alg.cra_flags |= CRYPTO_ALG_INSTANCE;
|
|
|
|
down_write(&crypto_alg_sem);
|
|
|
|
larval = ERR_PTR(-EAGAIN);
|
|
for (spawn = inst->spawns; spawn;) {
|
|
struct crypto_spawn *next;
|
|
|
|
if (spawn->dead)
|
|
goto unlock;
|
|
|
|
next = spawn->next;
|
|
spawn->inst = inst;
|
|
spawn->registered = true;
|
|
|
|
crypto_mod_put(spawn->alg);
|
|
|
|
spawn = next;
|
|
}
|
|
|
|
larval = __crypto_register_alg(&inst->alg);
|
|
if (IS_ERR(larval))
|
|
goto unlock;
|
|
|
|
hlist_add_head(&inst->list, &tmpl->instances);
|
|
inst->tmpl = tmpl;
|
|
|
|
unlock:
|
|
up_write(&crypto_alg_sem);
|
|
|
|
err = PTR_ERR(larval);
|
|
if (IS_ERR(larval))
|
|
goto err;
|
|
|
|
crypto_wait_for_test(larval);
|
|
err = 0;
|
|
|
|
err:
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_instance);
|
|
|
|
void crypto_unregister_instance(struct crypto_instance *inst)
|
|
{
|
|
LIST_HEAD(list);
|
|
|
|
down_write(&crypto_alg_sem);
|
|
|
|
crypto_remove_spawns(&inst->alg, &list, NULL);
|
|
crypto_remove_instance(inst, &list);
|
|
|
|
up_write(&crypto_alg_sem);
|
|
|
|
crypto_remove_final(&list);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_instance);
|
|
|
|
int crypto_grab_spawn(struct crypto_spawn *spawn, struct crypto_instance *inst,
|
|
const char *name, u32 type, u32 mask)
|
|
{
|
|
struct crypto_alg *alg;
|
|
int err = -EAGAIN;
|
|
|
|
if (WARN_ON_ONCE(inst == NULL))
|
|
return -EINVAL;
|
|
|
|
/* Allow the result of crypto_attr_alg_name() to be passed directly */
|
|
if (IS_ERR(name))
|
|
return PTR_ERR(name);
|
|
|
|
alg = crypto_find_alg(name, spawn->frontend, type, mask);
|
|
if (IS_ERR(alg))
|
|
return PTR_ERR(alg);
|
|
|
|
down_write(&crypto_alg_sem);
|
|
if (!crypto_is_moribund(alg)) {
|
|
list_add(&spawn->list, &alg->cra_users);
|
|
spawn->alg = alg;
|
|
spawn->mask = mask;
|
|
spawn->next = inst->spawns;
|
|
inst->spawns = spawn;
|
|
inst->alg.cra_flags |=
|
|
(alg->cra_flags & CRYPTO_ALG_INHERITED_FLAGS);
|
|
err = 0;
|
|
}
|
|
up_write(&crypto_alg_sem);
|
|
if (err)
|
|
crypto_mod_put(alg);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_grab_spawn);
|
|
|
|
void crypto_drop_spawn(struct crypto_spawn *spawn)
|
|
{
|
|
if (!spawn->alg) /* not yet initialized? */
|
|
return;
|
|
|
|
down_write(&crypto_alg_sem);
|
|
if (!spawn->dead)
|
|
list_del(&spawn->list);
|
|
up_write(&crypto_alg_sem);
|
|
|
|
if (!spawn->registered)
|
|
crypto_mod_put(spawn->alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_drop_spawn);
|
|
|
|
static struct crypto_alg *crypto_spawn_alg(struct crypto_spawn *spawn)
|
|
{
|
|
struct crypto_alg *alg = ERR_PTR(-EAGAIN);
|
|
struct crypto_alg *target;
|
|
bool shoot = false;
|
|
|
|
down_read(&crypto_alg_sem);
|
|
if (!spawn->dead) {
|
|
alg = spawn->alg;
|
|
if (!crypto_mod_get(alg)) {
|
|
target = crypto_alg_get(alg);
|
|
shoot = true;
|
|
alg = ERR_PTR(-EAGAIN);
|
|
}
|
|
}
|
|
up_read(&crypto_alg_sem);
|
|
|
|
if (shoot) {
|
|
crypto_shoot_alg(target);
|
|
crypto_alg_put(target);
|
|
}
|
|
|
|
return alg;
|
|
}
|
|
|
|
struct crypto_tfm *crypto_spawn_tfm(struct crypto_spawn *spawn, u32 type,
|
|
u32 mask)
|
|
{
|
|
struct crypto_alg *alg;
|
|
struct crypto_tfm *tfm;
|
|
|
|
alg = crypto_spawn_alg(spawn);
|
|
if (IS_ERR(alg))
|
|
return ERR_CAST(alg);
|
|
|
|
tfm = ERR_PTR(-EINVAL);
|
|
if (unlikely((alg->cra_flags ^ type) & mask))
|
|
goto out_put_alg;
|
|
|
|
tfm = __crypto_alloc_tfm(alg, type, mask);
|
|
if (IS_ERR(tfm))
|
|
goto out_put_alg;
|
|
|
|
return tfm;
|
|
|
|
out_put_alg:
|
|
crypto_mod_put(alg);
|
|
return tfm;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_spawn_tfm);
|
|
|
|
void *crypto_spawn_tfm2(struct crypto_spawn *spawn)
|
|
{
|
|
struct crypto_alg *alg;
|
|
struct crypto_tfm *tfm;
|
|
|
|
alg = crypto_spawn_alg(spawn);
|
|
if (IS_ERR(alg))
|
|
return ERR_CAST(alg);
|
|
|
|
tfm = crypto_create_tfm(alg, spawn->frontend);
|
|
if (IS_ERR(tfm))
|
|
goto out_put_alg;
|
|
|
|
return tfm;
|
|
|
|
out_put_alg:
|
|
crypto_mod_put(alg);
|
|
return tfm;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_spawn_tfm2);
|
|
|
|
int crypto_register_notifier(struct notifier_block *nb)
|
|
{
|
|
return blocking_notifier_chain_register(&crypto_chain, nb);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_register_notifier);
|
|
|
|
int crypto_unregister_notifier(struct notifier_block *nb)
|
|
{
|
|
return blocking_notifier_chain_unregister(&crypto_chain, nb);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
|
|
|
|
struct crypto_attr_type *crypto_get_attr_type(struct rtattr **tb)
|
|
{
|
|
struct rtattr *rta = tb[0];
|
|
struct crypto_attr_type *algt;
|
|
|
|
if (!rta)
|
|
return ERR_PTR(-ENOENT);
|
|
if (RTA_PAYLOAD(rta) < sizeof(*algt))
|
|
return ERR_PTR(-EINVAL);
|
|
if (rta->rta_type != CRYPTOA_TYPE)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
algt = RTA_DATA(rta);
|
|
|
|
return algt;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_get_attr_type);
|
|
|
|
/**
|
|
* crypto_check_attr_type() - check algorithm type and compute inherited mask
|
|
* @tb: the template parameters
|
|
* @type: the algorithm type the template would be instantiated as
|
|
* @mask_ret: (output) the mask that should be passed to crypto_grab_*()
|
|
* to restrict the flags of any inner algorithms
|
|
*
|
|
* Validate that the algorithm type the user requested is compatible with the
|
|
* one the template would actually be instantiated as. E.g., if the user is
|
|
* doing crypto_alloc_shash("cbc(aes)", ...), this would return an error because
|
|
* the "cbc" template creates an "skcipher" algorithm, not an "shash" algorithm.
|
|
*
|
|
* Also compute the mask to use to restrict the flags of any inner algorithms.
|
|
*
|
|
* Return: 0 on success; -errno on failure
|
|
*/
|
|
int crypto_check_attr_type(struct rtattr **tb, u32 type, u32 *mask_ret)
|
|
{
|
|
struct crypto_attr_type *algt;
|
|
|
|
algt = crypto_get_attr_type(tb);
|
|
if (IS_ERR(algt))
|
|
return PTR_ERR(algt);
|
|
|
|
if ((algt->type ^ type) & algt->mask)
|
|
return -EINVAL;
|
|
|
|
*mask_ret = crypto_algt_inherited_mask(algt);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_check_attr_type);
|
|
|
|
const char *crypto_attr_alg_name(struct rtattr *rta)
|
|
{
|
|
struct crypto_attr_alg *alga;
|
|
|
|
if (!rta)
|
|
return ERR_PTR(-ENOENT);
|
|
if (RTA_PAYLOAD(rta) < sizeof(*alga))
|
|
return ERR_PTR(-EINVAL);
|
|
if (rta->rta_type != CRYPTOA_ALG)
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
alga = RTA_DATA(rta);
|
|
alga->name[CRYPTO_MAX_ALG_NAME - 1] = 0;
|
|
|
|
return alga->name;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_attr_alg_name);
|
|
|
|
int crypto_attr_u32(struct rtattr *rta, u32 *num)
|
|
{
|
|
struct crypto_attr_u32 *nu32;
|
|
|
|
if (!rta)
|
|
return -ENOENT;
|
|
if (RTA_PAYLOAD(rta) < sizeof(*nu32))
|
|
return -EINVAL;
|
|
if (rta->rta_type != CRYPTOA_U32)
|
|
return -EINVAL;
|
|
|
|
nu32 = RTA_DATA(rta);
|
|
*num = nu32->num;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_attr_u32);
|
|
|
|
int crypto_inst_setname(struct crypto_instance *inst, const char *name,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (snprintf(inst->alg.cra_name, CRYPTO_MAX_ALG_NAME, "%s(%s)", name,
|
|
alg->cra_name) >= CRYPTO_MAX_ALG_NAME)
|
|
return -ENAMETOOLONG;
|
|
|
|
if (snprintf(inst->alg.cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s(%s)",
|
|
name, alg->cra_driver_name) >= CRYPTO_MAX_ALG_NAME)
|
|
return -ENAMETOOLONG;
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_inst_setname);
|
|
|
|
void crypto_init_queue(struct crypto_queue *queue, unsigned int max_qlen)
|
|
{
|
|
INIT_LIST_HEAD(&queue->list);
|
|
queue->backlog = &queue->list;
|
|
queue->qlen = 0;
|
|
queue->max_qlen = max_qlen;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_init_queue);
|
|
|
|
int crypto_enqueue_request(struct crypto_queue *queue,
|
|
struct crypto_async_request *request)
|
|
{
|
|
int err = -EINPROGRESS;
|
|
|
|
if (unlikely(queue->qlen >= queue->max_qlen)) {
|
|
if (!(request->flags & CRYPTO_TFM_REQ_MAY_BACKLOG)) {
|
|
err = -ENOSPC;
|
|
goto out;
|
|
}
|
|
err = -EBUSY;
|
|
if (queue->backlog == &queue->list)
|
|
queue->backlog = &request->list;
|
|
}
|
|
|
|
queue->qlen++;
|
|
list_add_tail(&request->list, &queue->list);
|
|
|
|
out:
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_enqueue_request);
|
|
|
|
void crypto_enqueue_request_head(struct crypto_queue *queue,
|
|
struct crypto_async_request *request)
|
|
{
|
|
queue->qlen++;
|
|
list_add(&request->list, &queue->list);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_enqueue_request_head);
|
|
|
|
struct crypto_async_request *crypto_dequeue_request(struct crypto_queue *queue)
|
|
{
|
|
struct list_head *request;
|
|
|
|
if (unlikely(!queue->qlen))
|
|
return NULL;
|
|
|
|
queue->qlen--;
|
|
|
|
if (queue->backlog != &queue->list)
|
|
queue->backlog = queue->backlog->next;
|
|
|
|
request = queue->list.next;
|
|
list_del(request);
|
|
|
|
return list_entry(request, struct crypto_async_request, list);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_dequeue_request);
|
|
|
|
static inline void crypto_inc_byte(u8 *a, unsigned int size)
|
|
{
|
|
u8 *b = (a + size);
|
|
u8 c;
|
|
|
|
for (; size; size--) {
|
|
c = *--b + 1;
|
|
*b = c;
|
|
if (c)
|
|
break;
|
|
}
|
|
}
|
|
|
|
void crypto_inc(u8 *a, unsigned int size)
|
|
{
|
|
__be32 *b = (__be32 *)(a + size);
|
|
u32 c;
|
|
|
|
if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ||
|
|
IS_ALIGNED((unsigned long)b, __alignof__(*b)))
|
|
for (; size >= 4; size -= 4) {
|
|
c = be32_to_cpu(*--b) + 1;
|
|
*b = cpu_to_be32(c);
|
|
if (likely(c))
|
|
return;
|
|
}
|
|
|
|
crypto_inc_byte(a, size);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_inc);
|
|
|
|
void __crypto_xor(u8 *dst, const u8 *src1, const u8 *src2, unsigned int len)
|
|
{
|
|
int relalign = 0;
|
|
|
|
if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) {
|
|
int size = sizeof(unsigned long);
|
|
int d = (((unsigned long)dst ^ (unsigned long)src1) |
|
|
((unsigned long)dst ^ (unsigned long)src2)) &
|
|
(size - 1);
|
|
|
|
relalign = d ? 1 << __ffs(d) : size;
|
|
|
|
/*
|
|
* If we care about alignment, process as many bytes as
|
|
* needed to advance dst and src to values whose alignments
|
|
* equal their relative alignment. This will allow us to
|
|
* process the remainder of the input using optimal strides.
|
|
*/
|
|
while (((unsigned long)dst & (relalign - 1)) && len > 0) {
|
|
*dst++ = *src1++ ^ *src2++;
|
|
len--;
|
|
}
|
|
}
|
|
|
|
while (IS_ENABLED(CONFIG_64BIT) && len >= 8 && !(relalign & 7)) {
|
|
*(u64 *)dst = *(u64 *)src1 ^ *(u64 *)src2;
|
|
dst += 8;
|
|
src1 += 8;
|
|
src2 += 8;
|
|
len -= 8;
|
|
}
|
|
|
|
while (len >= 4 && !(relalign & 3)) {
|
|
*(u32 *)dst = *(u32 *)src1 ^ *(u32 *)src2;
|
|
dst += 4;
|
|
src1 += 4;
|
|
src2 += 4;
|
|
len -= 4;
|
|
}
|
|
|
|
while (len >= 2 && !(relalign & 1)) {
|
|
*(u16 *)dst = *(u16 *)src1 ^ *(u16 *)src2;
|
|
dst += 2;
|
|
src1 += 2;
|
|
src2 += 2;
|
|
len -= 2;
|
|
}
|
|
|
|
while (len--)
|
|
*dst++ = *src1++ ^ *src2++;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__crypto_xor);
|
|
|
|
unsigned int crypto_alg_extsize(struct crypto_alg *alg)
|
|
{
|
|
return alg->cra_ctxsize +
|
|
(alg->cra_alignmask & ~(crypto_tfm_ctx_alignment() - 1));
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_alg_extsize);
|
|
|
|
int crypto_type_has_alg(const char *name, const struct crypto_type *frontend,
|
|
u32 type, u32 mask)
|
|
{
|
|
int ret = 0;
|
|
struct crypto_alg *alg = crypto_find_alg(name, frontend, type, mask);
|
|
|
|
if (!IS_ERR(alg)) {
|
|
crypto_mod_put(alg);
|
|
ret = 1;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_type_has_alg);
|
|
|
|
#ifdef CONFIG_CRYPTO_STATS
|
|
void crypto_stats_init(struct crypto_alg *alg)
|
|
{
|
|
memset(&alg->stats, 0, sizeof(alg->stats));
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_init);
|
|
|
|
void crypto_stats_get(struct crypto_alg *alg)
|
|
{
|
|
crypto_alg_get(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_get);
|
|
|
|
void crypto_stats_aead_encrypt(unsigned int cryptlen, struct crypto_alg *alg,
|
|
int ret)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.aead.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.aead.encrypt_cnt);
|
|
atomic64_add(cryptlen, &alg->stats.aead.encrypt_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_aead_encrypt);
|
|
|
|
void crypto_stats_aead_decrypt(unsigned int cryptlen, struct crypto_alg *alg,
|
|
int ret)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.aead.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.aead.decrypt_cnt);
|
|
atomic64_add(cryptlen, &alg->stats.aead.decrypt_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_aead_decrypt);
|
|
|
|
void crypto_stats_akcipher_encrypt(unsigned int src_len, int ret,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.akcipher.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.akcipher.encrypt_cnt);
|
|
atomic64_add(src_len, &alg->stats.akcipher.encrypt_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_encrypt);
|
|
|
|
void crypto_stats_akcipher_decrypt(unsigned int src_len, int ret,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.akcipher.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.akcipher.decrypt_cnt);
|
|
atomic64_add(src_len, &alg->stats.akcipher.decrypt_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_decrypt);
|
|
|
|
void crypto_stats_akcipher_sign(int ret, struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
|
|
atomic64_inc(&alg->stats.akcipher.err_cnt);
|
|
else
|
|
atomic64_inc(&alg->stats.akcipher.sign_cnt);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_sign);
|
|
|
|
void crypto_stats_akcipher_verify(int ret, struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
|
|
atomic64_inc(&alg->stats.akcipher.err_cnt);
|
|
else
|
|
atomic64_inc(&alg->stats.akcipher.verify_cnt);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_akcipher_verify);
|
|
|
|
void crypto_stats_compress(unsigned int slen, int ret, struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.compress.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.compress.compress_cnt);
|
|
atomic64_add(slen, &alg->stats.compress.compress_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_compress);
|
|
|
|
void crypto_stats_decompress(unsigned int slen, int ret, struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.compress.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.compress.decompress_cnt);
|
|
atomic64_add(slen, &alg->stats.compress.decompress_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_decompress);
|
|
|
|
void crypto_stats_ahash_update(unsigned int nbytes, int ret,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
|
|
atomic64_inc(&alg->stats.hash.err_cnt);
|
|
else
|
|
atomic64_add(nbytes, &alg->stats.hash.hash_tlen);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_ahash_update);
|
|
|
|
void crypto_stats_ahash_final(unsigned int nbytes, int ret,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.hash.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.hash.hash_cnt);
|
|
atomic64_add(nbytes, &alg->stats.hash.hash_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_ahash_final);
|
|
|
|
void crypto_stats_kpp_set_secret(struct crypto_alg *alg, int ret)
|
|
{
|
|
if (ret)
|
|
atomic64_inc(&alg->stats.kpp.err_cnt);
|
|
else
|
|
atomic64_inc(&alg->stats.kpp.setsecret_cnt);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_kpp_set_secret);
|
|
|
|
void crypto_stats_kpp_generate_public_key(struct crypto_alg *alg, int ret)
|
|
{
|
|
if (ret)
|
|
atomic64_inc(&alg->stats.kpp.err_cnt);
|
|
else
|
|
atomic64_inc(&alg->stats.kpp.generate_public_key_cnt);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_kpp_generate_public_key);
|
|
|
|
void crypto_stats_kpp_compute_shared_secret(struct crypto_alg *alg, int ret)
|
|
{
|
|
if (ret)
|
|
atomic64_inc(&alg->stats.kpp.err_cnt);
|
|
else
|
|
atomic64_inc(&alg->stats.kpp.compute_shared_secret_cnt);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_kpp_compute_shared_secret);
|
|
|
|
void crypto_stats_rng_seed(struct crypto_alg *alg, int ret)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY)
|
|
atomic64_inc(&alg->stats.rng.err_cnt);
|
|
else
|
|
atomic64_inc(&alg->stats.rng.seed_cnt);
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_rng_seed);
|
|
|
|
void crypto_stats_rng_generate(struct crypto_alg *alg, unsigned int dlen,
|
|
int ret)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.rng.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.rng.generate_cnt);
|
|
atomic64_add(dlen, &alg->stats.rng.generate_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_rng_generate);
|
|
|
|
void crypto_stats_skcipher_encrypt(unsigned int cryptlen, int ret,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.cipher.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.cipher.encrypt_cnt);
|
|
atomic64_add(cryptlen, &alg->stats.cipher.encrypt_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_skcipher_encrypt);
|
|
|
|
void crypto_stats_skcipher_decrypt(unsigned int cryptlen, int ret,
|
|
struct crypto_alg *alg)
|
|
{
|
|
if (ret && ret != -EINPROGRESS && ret != -EBUSY) {
|
|
atomic64_inc(&alg->stats.cipher.err_cnt);
|
|
} else {
|
|
atomic64_inc(&alg->stats.cipher.decrypt_cnt);
|
|
atomic64_add(cryptlen, &alg->stats.cipher.decrypt_tlen);
|
|
}
|
|
crypto_alg_put(alg);
|
|
}
|
|
EXPORT_SYMBOL_GPL(crypto_stats_skcipher_decrypt);
|
|
#endif
|
|
|
|
static int __init crypto_algapi_init(void)
|
|
{
|
|
crypto_init_proc();
|
|
return 0;
|
|
}
|
|
|
|
static void __exit crypto_algapi_exit(void)
|
|
{
|
|
crypto_exit_proc();
|
|
}
|
|
|
|
module_init(crypto_algapi_init);
|
|
module_exit(crypto_algapi_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Cryptographic algorithms API");
|
|
MODULE_SOFTDEP("pre: cryptomgr");
|