Files
android_kernel_fxtec_sm6115/crypto/seqiv.c
Thomas Turner 4b6d521246 Merge tag 'v4.19.325-cip128' of https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip into android13-4.19-kona
version 4.19.325-cip128

* tag 'v4.19.325-cip128' of https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip:
  CIP: Bump version suffix to -cip128 after merge from cip/linux-4.19.y-st tree
  Update localversion-st, tree is up-to-date with 5.10.248.
  NFSv4: ensure the open stateid seqid doesn't go backwards
  libceph: make calc_target() set t->paused, not just clear it
  crypto: af_alg - zero initialize memory allocated via sock_kmalloc
  jbd2: fix the inconsistency between checksum and data in memory for journal sb
  f2fs: fix to detect recoverable inode during dryrun of find_fsync_dnodes()
  NFS: add barriers when testing for NFS_FSDATA_BLOCKED
  NFS: unlink/rmdir shouldn't call d_delete() twice on ENOENT
  efi/cper: Fix cper_bits_to_str buffer handling and return value
  iommu/omap: fix device leaks on probe_device()
  crypto: seqiv - Do not use req->iv after crypto_aead_encrypt
  f2fs: fix return value of f2fs_recover_fsync_data()
  ext4: improve integrity checking in __mb_check_buddy by enhancing order-0 validation
  ext4: remove unused return value of __mb_check_buddy
  clk: renesas: r9a06g032: Fix memory leak in error path
  nbd: defer config put in recv_work
  jbd2: avoid bug_on in jbd2_journal_get_create_access() when file system corrupted
  scsi: sg: Fix occasional bogus elapsed time that exceeds timeout
  powercap: fix sscanf() error return value handling
  powercap: fix race condition in register_control_type()
  arp: do not assume dev_hard_header() does not change skb->head
  net: usb: pegasus: fix memory leak in update_eth_regs_async()
  HID: quirks: work around VID/PID conflict for appledisplay
  netdev: preserve NETIF_F_ALL_FOR_ALL across TSO updates
  net: sock: fix hardened usercopy panic in sock_recv_errqueue
  inet: ping: Fix icmp out counting
  netfilter: nf_conncount: update last_gc only when GC has been performed
  ARM: dts: imx6q-ba16: fix RTC interrupt level
  scsi: ipr: Enable/disable IRQD_NO_BALANCING during reset
  alpha: don't reference obsolete termio struct for TC* constants
  ARM: 9461/1: Disable HIGHPTE on PREEMPT_RT kernels
  ext4: fix out-of-bound read in ext4_xattr_inode_dec_ref_all()
  ext4: introduce ITAIL helper
  libceph: make free_choose_arg_map() resilient to partial allocation
  libceph: replace overzealous BUG_ON in osdmap_apply_incremental()
  wifi: avoid kernel-infoleak from struct iw_point
  drm/pl111: Fix error handling in pl111_amba_probe
  net: 3com: 3c59x: fix possible null dereference in vortex_probe1()
  atm: Fix dma_free_coherent() size
  Revert "iommu/amd: Skip enabling command/event buffers for kdump"
  pwm: stm32: Always program polarity
  bus: fsl-mc-bus: fix KASAN use-after-free in fsl_mc_bus_remove()
  scsi: iscsi_tcp: Fix UAF during logout when accessing the shost ipaddress
  scsi: iscsi: Move pool freeing
  wifi: mac80211: Discard Beacon frames to non-broadcast address
  media: samsung: exynos4-is: fix potential ABBA deadlock on init
  media: vpif_capture: fix section mismatch
  media: renesas: rcar_drif: fix device node reference leak in rcar_drif_bond_enabled
  SUNRPC: svcauth_gss: avoid NULL deref on zero length gss_token in gss_read_proxy_verf
  NFSD: Clear SECLABEL in the suppattr_exclcreat bitmap
  usb: ohci-nxp: fix device leak on probe failure
  usb: ohci-nxp: Use helper function devm_clk_get_enabled()
  f2fs: fix to avoid updating zero-sized extent in extent cache
  ext4: fix string copying in parse_apply_sb_mount_options()
  ALSA: wavefront: Fix integer overflow in sample size validation
  ALSA: wavefront: Clear substream pointers on close
  usb: gadget: udc: fix use-after-free in usb_gadget_state_work
  HID: core: Harden s32ton() against conversion to 0 bits
  ipv4: Fix uninit-value access in __ip_make_skb()
  ipv6: Fix potential uninit-value access in __ip6_make_skb()
  virtio_console: fix order of fields cols and rows
  drm/nouveau/dispnv50: Don't call drm_atomic_get_crtc_state() in prepare_fb
  net: nfc: fix deadlock between nfc_unregister_device and rfkill_fop_write
  net: usb: sr9700: fix incorrect command used to write single register
  fjes: Add missing iounmap in fjes_hw_init()
  e1000: fix OOB in e1000_tbi_should_accept()
  RDMA/core: Check for the presence of LS_NLA_TYPE_DGID correctly
  media: i2c: adv7842: Remove redundant cancel_delayed_work in probe
  media: i2c: ADV7604: Remove redundant cancel_delayed_work in probe
  media: TDA1997x: Remove redundant cancel_delayed_work in probe
  media: msp3400: Avoid possible out-of-bounds array accesses in msp3400c_thread()
  media: cec: Fix debugfs leak on bus_register() failure
  fbdev: tcx.c fix mem_map to correct smem_start offset
  fbdev: pxafb: Fix multiple clamped values in pxafb_adjust_timing
  fbdev: gbefb: fix to use physical address instead of dma address
  media: adv7842: Avoid possible out-of-bounds array accesses in adv7842_cp_log_status()
  parisc: entry: set W bit for !compat tasks in syscall_restore_rfi()
  parisc: entry.S: fix space adjustment on interruption for 64-bit userspace
  media: rc: st_rc: Fix reset control resource leak
  PCI/PM: Reinstate clearing state_saved in legacy and !PM codepaths
  iommu/exynos: fix device leak on of_xlate()
  ASoC: qcom: qdsp6: q6asm-dai: set 10 ms period and buffer alignment.
  ASoC: qcom: q6adm: the the copp device only during last instance
  ASoC: qcom: q6asm-dai: perform correct state check before closing
  selftests/ftrace: traceonoff_triggers: strip off names
  RDMA/bnxt_re: fix dma_free_coherent() pointer
  net: rose: fix invalid array index in rose_kill_by_device()
  ipv4: Fix reference count leak when using error routes with nexthop objects
  ipv6: BUG() in pskb_expand_head() as part of calipso_skbuff_setattr()
  net: bridge: Describe @tunnel_hash member in net_bridge_vlan_group struct
  net: dsa: b53: skip multicast entries for fdb_dump()
  firewire: nosy: Fix dma_free_coherent() size
  firewire: nosy: switch from 'pci_' to 'dma_' API
  genalloc.h: fix htmldocs warning
  net: usb: rtl8150: fix memory leak on usb_submit_urb() failure
  team: fix check for port enabled in team_queue_override_port_prio_changed()
  platform/x86: ibm_rtl: fix EBDA signature search pointer arithmetic
  platform/x86: msi-laptop: add missing sysfs_remove_group()
  ip6_gre: make ip6gre_header() robust
  i40e: fix scheduling in set_rx_mode
  hwmon: (w83l786ng) Convert macros to functions to avoid TOCTOU
  hwmon: (w83791d) Convert macros to functions to avoid TOCTOU
  rpmsg: glink: fix rpmsg device leak
  amba: tegra-ahb: Fix device leak on SMMU enable
  nfsd: Mark variable __maybe_unused to avoid W=1 build break
  PM: runtime: Do not clear needs_force_resume with enabled runtime PM
  tracing: Do not register unsupported perf events
  KVM: x86: Fix VM hard lockup after prolonged inactivity with periodic HV timer
  KVM: x86: Explicitly set new periodic hrtimer expiration in apic_timer_fn()
  KVM: x86: WARN if hrtimer callback for periodic APIC timer fires with period=0
  libceph: make decode_pool() more resilient against corrupted osdmaps
  parisc: Do not reprogram affinitiy on ASP chip
  ocfs2: fix kernel BUG in ocfs2_find_victim_chain
  tools/testing/nvdimm: Use per-DIMM device handle
  f2fs: invalidate dentry cache on failed whiteout creation
  scsi: target: Reset t_task_cdb pointer in error case
  NFSD: use correct reservation type in nfsd4_scsi_fence_client
  scsi: aic94xx: fix use-after-free in device removal path
  cpufreq: nforce2: fix reference count leak in nforce2
  char: applicom: fix NULL pointer dereference in ac_ioctl
  usb: renesas_usbhs: Fix a resource leak in usbhs_pipe_malloc()
  media: pvrusb2: Fix incorrect variable used in trace message
  media: dvb-usb: dtv5100: fix out-of-bounds in dtv5100_i2c_msg()
  usb: usb-storage: Maintain minimal modifications to the bcdDevice range.
  media: v4l2-mem2mem: Fix outdated documentation
  jbd2: use a weaker annotation in journal handling
  ext4: fix incorrect group number assertion in mb_check_buddy
  ext4: xattr: fix null pointer deref in ext4_raw_inode()
  ktest.pl: Fix uninitialized var in config-bisect.pl
  floppy: fix for PAGE_SIZE != 4KB
  usb: usb-storage: No additional quirks need to be added to the EL-R12 optical drive.
  usb: xhci: limit run_graceperiod for only usb 3.0 devices
  usb: typec: ucsi: Handle incorrect num_connectors capability
  via_wdt: fix critical boot hang due to unnamed resource allocation
  scsi: qla2xxx: Use reinit_completion on mbx_intr_comp
  powerpc/addnote: Fix overflow on 32-bit builds
  clk: mvebu: cp110 add CLK_IGNORE_UNUSED to pcie_x10, pcie_x11 & pcie_x4
  ipmi: Fix __scan_channels() failing to rescan channels
  ipmi: Fix the race between __scan_channels() and deliver_response()
  ALSA: usb-mixer: us16x08: validate meter packet indices
  ALSA: pcmcia: Fix resource leak in snd_pdacf_probe error path
  ALSA: vxpocket: Fix resource leak in vxpocket_probe error path
  spi: fsl-cpm: Check length parity before switching to 16 bit mode
  Input: ti_am335x_tsc - fix off-by-one error in wire_order validation
  MIPS: Fix a reference leak bug in ip22_check_gio()
  hwmon: (ibmpex) fix use-after-free in high/low store
  net/mlx5: fw_tracer, Handle escaped percent properly
  net/mlx5: fw_tracer, Validate format string parameters
  net/mlx5: fw_tracer, Add support for unrecognized string
  nfc: pn533: Fix error code in pn533_acr122_poweron_rdr()
  caif: fix integer underflow in cffrml_receive()
  ipvs: fix ipv4 null-ptr-deref in route error path
  netfilter: nf_conncount: fix leaked ct in error paths
  broadcom: b44: prevent uninitialized value usage
  net: openvswitch: fix middle attribute validation in push_nsh() action
  mlxsw: spectrum_router: Fix neighbour use-after-free
  ipvlan: Ignore PACKET_LOOPBACK in handle_mode_l2()
  netrom: Fix memory leak in nr_sendmsg()
  btrfs: scrub: always update btrfs_scrub_progress::last_physical
  hfsplus: fix volume corruption issue for generic/073
  hfsplus: Verify inode mode when loading from disk
  hfsplus: fix missing hfs_bnode_get() in __hfs_bnode_create
  hfsplus: fix volume corruption issue for generic/070
  cpufreq: s5pv210: fix refcount leak
  ACPI: property: Use ACPI functions in acpi_graph_get_next_endpoint() only
  ACPICA: Avoid walking the Namespace if start_node is NULL
  netfilter: nft_connlimit: memleak if nf_ct_netns_get() fails
  netfilter: nf_conncount: garbage collection is not skipped when jiffies wrap around
  NFS: Fix missing unlock in nfs_unlink()
  ALSA: dice: fix buffer overflow in detect_stream_formats()
  usb: phy: Initialize struct usb_phy list_head
  ocfs2: fix memory leak in ocfs2_merge_rec_left()
  efi/cper: Adjust infopfx size to accept an extra space
  efi/cper: Add a new helper function to print bitmasks
  dm log-writes: Add missing set_freezable() for freezable kthread
  dm-raid: fix possible NULL dereference with undefined raid type
  ARM: 9464/1: fix input-only operand modification in load_unaligned_zeropad()
  ALSA: uapi: Fix typo in asound.h comment
  fs/nls: Fix inconsistency between utf8_to_utf32() and utf32_to_utf8()
  NFSv4/pNFS: Clear NFS_INO_LAYOUTCOMMIT in pnfs_mark_layout_stateid_invalid
  fs/nls: Fix utf16 to utf8 conversion
  NFS: don't unhash dentry during unlink/rename
  NFS: Label the dentry with a verifier in nfs_rmdir() and nfs_unlink()
  fbdev: ssd1307fb: fix potential page leak in ssd1307fb_probe()
  pinctrl: single: Fix incorrect type for error return variable
  pinctrl: single: Fix PIN_CONFIG_BIAS_DISABLE handling
  perf tools: Fix split kallsyms DSO counting
  net/sched: sch_cake: Fix incorrect qlen reduction in cake_drop
  mtd: lpddr_cmds: fix signed shifts in lpddr_cmds
  netfilter: nft_connlimit: update the count if add was skipped
  netfilter: nf_conncount: rework API to use sk_buff directly
  netfilter: nf_conncount: reduce unnecessary GC
  netfilter: nft_connlimit: move stateful fields out of expression data
  regulator: core: Protect regulator_supply_alias_list with regulator_list_mutex
  virtio: fix virtqueue_set_affinity() docs
  ACPI: processor_core: fix map_x2apic_id for amd-pstate on am4
  backlight: lp855x: Fix lp855x.h kernel-doc warnings
  staging: fbtft: core: fix potential memory leak in fbtft_probe_common()
  usb: dwc2: fix hang during shutdown if set as peripheral
  usb: dwc2: disable platform lowlevel hw resources during shutdown
  usb: chaoskey: fix locking for O_NONBLOCK
  wifi: rtl818x: rtl8187: Fix potential buffer underflow in rtl8187_rx_cb()
  powerpc/64s/ptdump: Fix kernel_hash_pagetable dump for ISA v3.00 HPTE format
  NFSD/blocklayout: Fix minlength check in proc_layoutget
  scsi: sim710: Fix resource leak by adding missing ioport_unmap() calls
  ACPI: property: Fix fwnode refcount leak in acpi_fwnode_graph_parse_endpoint()
  ocfs2: relax BUG() to ocfs2_error() in __ocfs2_move_extent()
  nbd: defer config unlock in nbd_genl_connect
  wifi: cw1200: Fix potential memory leak in cw1200_bh_rx_helper()
  macintosh/mac_hid: fix race condition in mac_hid_toggle_emumouse
  scsi: stex: Fix reboot_notifier leak in probe error path
  perf/x86/intel: Correct large PEBS flag check
  ext4: correct the checking of quota files before moving extents
  ext4: minor defrag code improvements
  mfd: da9055: Fix missing regmap_del_irq_chip() in error path
  scsi: target: Do not write NUL characters into ASCII configfs output
  power: supply: apm_power: only unset own apm_get_power_status
  power: supply: wm831x: Check wm831x_set_bits() return value
  kmsan: introduce __no_sanitize_memory and __no_kmsan_checks
  compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer
  s390/smp: Fix fallback CPU detection
  crypto: asymmetric_keys - prevent overflow in asymmetric_key_generate_id
  inet: Avoid ehash lookup race in inet_ehash_insert()
  rculist: Add hlist_nulls_replace_rcu() and hlist_nulls_replace_init_rcu()
  irqchip/qcom-irq-combiner: Fix section mismatch
  USB: Fix descriptor count when handling invalid MBIM extended descriptor
  drm/vgem-fence: Fix potential deadlock on release
  smack: fix bug: unprivileged task can create labels
  staging: rtl8723bs: fix stack buffer overflow in OnAssocReq IE parsing
  comedi: multiq3: sanitize config options in multiq3_attach()
  comedi: c6xdigio: Fix invalid PNP driver unregistration
  platform/x86: acer-wmi: Ignore backlight event
  bfs: Reconstruct file type when loading from disk
  spi: imx: keep dma request disabled before dma transfer setup
  spi: xilinx: increase number of retries before declaring stall
  USB: serial: kobil_sct: fix TIOCMBIS and TIOCMBIC
  USB: serial: belkin_sa: fix TIOCMBIS and TIOCMBIC
  serial: add support of CPCI cards
  USB: serial: ftdi_sio: match on interface number for jtag
  USB: serial: option: move Telit 0x10c7 composition in the right place
  USB: serial: option: add Telit Cinterion FE910C04 new compositions
  USB: serial: option: add Foxconn T99W760
  ext4: add i_data_sem protection in ext4_destroy_inline_data_nolock()
  locking/spinlock/debug: Fix data-race in do_raw_write_lock
  ext4: refresh inline data size before write operations
  xfrm: flush all states in xfrm_state_fini
  xfrm: also call xfrm_state_delete_tunnel at destroy time for states that were never added
  Revert "xfrm: destroy xfrm_state synchronously on net exit path"
  xfrm: delete x->tunnel as we delete x

 Conflicts:
	drivers/rpmsg/qcom_glink_native.c
	drivers/usb/host/xhci-hub.c
	fs/f2fs/file.c
	fs/f2fs/super.c

Change-Id: I9e00c074af0214588acc89a73fcfc928d1724b7a
2026-02-06 18:23:19 +02:00

223 lines
5.3 KiB
C

/*
* seqiv: Sequence Number IV Generator
*
* This generator generates an IV based on a sequence number by xoring it
* with a salt. This algorithm is mainly useful for CTR and similar modes.
*
* Copyright (c) 2007 Herbert Xu <herbert@gondor.apana.org.au>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
*/
#include <crypto/internal/geniv.h>
#include <crypto/scatterwalk.h>
#include <crypto/skcipher.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/string.h>
static void seqiv_free(struct crypto_instance *inst);
static void seqiv_aead_encrypt_complete2(struct aead_request *req, int err)
{
struct aead_request *subreq = aead_request_ctx(req);
struct crypto_aead *geniv;
if (err == -EINPROGRESS || err == -EBUSY)
return;
if (err)
goto out;
geniv = crypto_aead_reqtfm(req);
memcpy(req->iv, subreq->iv, crypto_aead_ivsize(geniv));
out:
kzfree(subreq->iv);
}
static void seqiv_aead_encrypt_complete(struct crypto_async_request *base,
int err)
{
struct aead_request *req = base->data;
seqiv_aead_encrypt_complete2(req, err);
aead_request_complete(req, err);
}
static int seqiv_aead_encrypt(struct aead_request *req)
{
struct crypto_aead *geniv = crypto_aead_reqtfm(req);
struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
struct aead_request *subreq = aead_request_ctx(req);
crypto_completion_t compl;
bool unaligned_info;
void *data;
u8 *info;
unsigned int ivsize = 8;
int err;
if (req->cryptlen < ivsize)
return -EINVAL;
aead_request_set_tfm(subreq, ctx->child);
compl = req->base.complete;
data = req->base.data;
info = req->iv;
if (req->src != req->dst) {
SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->sknull);
skcipher_request_set_sync_tfm(nreq, ctx->sknull);
skcipher_request_set_callback(nreq, req->base.flags,
NULL, NULL);
skcipher_request_set_crypt(nreq, req->src, req->dst,
req->assoclen + req->cryptlen,
NULL);
err = crypto_skcipher_encrypt(nreq);
if (err)
return err;
}
unaligned_info = !IS_ALIGNED((unsigned long)info,
crypto_aead_alignmask(geniv) + 1);
if (unlikely(unaligned_info)) {
info = kmalloc(ivsize, req->base.flags &
CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL:
GFP_ATOMIC);
if (!info)
return -ENOMEM;
memcpy(info, req->iv, ivsize);
compl = seqiv_aead_encrypt_complete;
data = req;
}
aead_request_set_callback(subreq, req->base.flags, compl, data);
aead_request_set_crypt(subreq, req->dst, req->dst,
req->cryptlen - ivsize, info);
aead_request_set_ad(subreq, req->assoclen + ivsize);
crypto_xor(info, ctx->salt, ivsize);
scatterwalk_map_and_copy(info, req->dst, req->assoclen, ivsize, 1);
err = crypto_aead_encrypt(subreq);
if (unlikely(unaligned_info))
seqiv_aead_encrypt_complete2(req, err);
return err;
}
static int seqiv_aead_decrypt(struct aead_request *req)
{
struct crypto_aead *geniv = crypto_aead_reqtfm(req);
struct aead_geniv_ctx *ctx = crypto_aead_ctx(geniv);
struct aead_request *subreq = aead_request_ctx(req);
crypto_completion_t compl;
void *data;
unsigned int ivsize = 8;
if (req->cryptlen < ivsize + crypto_aead_authsize(geniv))
return -EINVAL;
aead_request_set_tfm(subreq, ctx->child);
compl = req->base.complete;
data = req->base.data;
aead_request_set_callback(subreq, req->base.flags, compl, data);
aead_request_set_crypt(subreq, req->src, req->dst,
req->cryptlen - ivsize, req->iv);
aead_request_set_ad(subreq, req->assoclen + ivsize);
scatterwalk_map_and_copy(req->iv, req->src, req->assoclen, ivsize, 0);
return crypto_aead_decrypt(subreq);
}
static int seqiv_aead_create(struct crypto_template *tmpl, struct rtattr **tb)
{
struct aead_instance *inst;
int err;
inst = aead_geniv_alloc(tmpl, tb, 0, 0);
if (IS_ERR(inst))
return PTR_ERR(inst);
err = -EINVAL;
if (inst->alg.ivsize != sizeof(u64))
goto free_inst;
inst->alg.encrypt = seqiv_aead_encrypt;
inst->alg.decrypt = seqiv_aead_decrypt;
inst->alg.init = aead_init_geniv;
inst->alg.exit = aead_exit_geniv;
inst->alg.base.cra_ctxsize = sizeof(struct aead_geniv_ctx);
inst->alg.base.cra_ctxsize += inst->alg.ivsize;
err = aead_register_instance(tmpl, inst);
if (err)
goto free_inst;
out:
return err;
free_inst:
aead_geniv_free(inst);
goto out;
}
static int seqiv_create(struct crypto_template *tmpl, struct rtattr **tb)
{
struct crypto_attr_type *algt;
algt = crypto_get_attr_type(tb);
if (IS_ERR(algt))
return PTR_ERR(algt);
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK)
return -EINVAL;
return seqiv_aead_create(tmpl, tb);
}
static void seqiv_free(struct crypto_instance *inst)
{
aead_geniv_free(aead_instance(inst));
}
static struct crypto_template seqiv_tmpl = {
.name = "seqiv",
.create = seqiv_create,
.free = seqiv_free,
.module = THIS_MODULE,
};
static int __init seqiv_module_init(void)
{
return crypto_register_template(&seqiv_tmpl);
}
static void __exit seqiv_module_exit(void)
{
crypto_unregister_template(&seqiv_tmpl);
}
module_init(seqiv_module_init);
module_exit(seqiv_module_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Sequence Number IV Generator");
MODULE_ALIAS_CRYPTO("seqiv");