mirror of
https://github.com/LineageOS/android_kernel_fxtec_sm6115.git
synced 2026-08-18 20:01:05 +00:00
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
486 lines
9.7 KiB
C
486 lines
9.7 KiB
C
/*
|
|
* algif_hash: User-space interface for hash algorithms
|
|
*
|
|
* This file provides the user-space API for hash algorithms.
|
|
*
|
|
* Copyright (c) 2010 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/hash.h>
|
|
#include <crypto/if_alg.h>
|
|
#include <linux/init.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/module.h>
|
|
#include <linux/net.h>
|
|
#include <net/sock.h>
|
|
|
|
struct hash_ctx {
|
|
struct af_alg_sgl sgl;
|
|
|
|
u8 *result;
|
|
|
|
struct crypto_wait wait;
|
|
|
|
unsigned int len;
|
|
bool more;
|
|
|
|
struct ahash_request req;
|
|
};
|
|
|
|
static int hash_alloc_result(struct sock *sk, struct hash_ctx *ctx)
|
|
{
|
|
unsigned ds;
|
|
|
|
if (ctx->result)
|
|
return 0;
|
|
|
|
ds = crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req));
|
|
|
|
ctx->result = sock_kmalloc(sk, ds, GFP_KERNEL);
|
|
if (!ctx->result)
|
|
return -ENOMEM;
|
|
|
|
memset(ctx->result, 0, ds);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void hash_free_result(struct sock *sk, struct hash_ctx *ctx)
|
|
{
|
|
unsigned ds;
|
|
|
|
if (!ctx->result)
|
|
return;
|
|
|
|
ds = crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req));
|
|
|
|
sock_kzfree_s(sk, ctx->result, ds);
|
|
ctx->result = NULL;
|
|
}
|
|
|
|
static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
|
|
size_t ignored)
|
|
{
|
|
int limit = ALG_MAX_PAGES * PAGE_SIZE;
|
|
struct sock *sk = sock->sk;
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
struct hash_ctx *ctx = ask->private;
|
|
long copied = 0;
|
|
int err;
|
|
|
|
if (limit > sk->sk_sndbuf)
|
|
limit = sk->sk_sndbuf;
|
|
|
|
lock_sock(sk);
|
|
if (!ctx->more) {
|
|
if ((msg->msg_flags & MSG_MORE))
|
|
hash_free_result(sk, ctx);
|
|
|
|
err = crypto_wait_req(crypto_ahash_init(&ctx->req), &ctx->wait);
|
|
if (err)
|
|
goto unlock;
|
|
}
|
|
|
|
ctx->more = 0;
|
|
|
|
while (msg_data_left(msg)) {
|
|
int len = msg_data_left(msg);
|
|
|
|
if (len > limit)
|
|
len = limit;
|
|
|
|
len = af_alg_make_sg(&ctx->sgl, &msg->msg_iter, len);
|
|
if (len < 0) {
|
|
err = copied ? 0 : len;
|
|
goto unlock;
|
|
}
|
|
|
|
ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len);
|
|
|
|
err = crypto_wait_req(crypto_ahash_update(&ctx->req),
|
|
&ctx->wait);
|
|
af_alg_free_sg(&ctx->sgl);
|
|
if (err)
|
|
goto unlock;
|
|
|
|
copied += len;
|
|
iov_iter_advance(&msg->msg_iter, len);
|
|
}
|
|
|
|
err = 0;
|
|
|
|
ctx->more = msg->msg_flags & MSG_MORE;
|
|
if (!ctx->more) {
|
|
err = hash_alloc_result(sk, ctx);
|
|
if (err)
|
|
goto unlock;
|
|
|
|
ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);
|
|
err = crypto_wait_req(crypto_ahash_final(&ctx->req),
|
|
&ctx->wait);
|
|
}
|
|
|
|
unlock:
|
|
release_sock(sk);
|
|
|
|
return err ?: copied;
|
|
}
|
|
|
|
static ssize_t hash_sendpage(struct socket *sock, struct page *page,
|
|
int offset, size_t size, int flags)
|
|
{
|
|
struct sock *sk = sock->sk;
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
struct hash_ctx *ctx = ask->private;
|
|
int err;
|
|
|
|
if (flags & MSG_SENDPAGE_NOTLAST)
|
|
flags |= MSG_MORE;
|
|
|
|
lock_sock(sk);
|
|
sg_init_table(ctx->sgl.sg, 1);
|
|
sg_set_page(ctx->sgl.sg, page, size, offset);
|
|
|
|
if (!(flags & MSG_MORE)) {
|
|
err = hash_alloc_result(sk, ctx);
|
|
if (err)
|
|
goto unlock;
|
|
} else if (!ctx->more)
|
|
hash_free_result(sk, ctx);
|
|
|
|
ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, ctx->result, size);
|
|
|
|
if (!(flags & MSG_MORE)) {
|
|
if (ctx->more)
|
|
err = crypto_ahash_finup(&ctx->req);
|
|
else
|
|
err = crypto_ahash_digest(&ctx->req);
|
|
} else {
|
|
if (!ctx->more) {
|
|
err = crypto_ahash_init(&ctx->req);
|
|
err = crypto_wait_req(err, &ctx->wait);
|
|
if (err)
|
|
goto unlock;
|
|
}
|
|
|
|
err = crypto_ahash_update(&ctx->req);
|
|
}
|
|
|
|
err = crypto_wait_req(err, &ctx->wait);
|
|
if (err)
|
|
goto unlock;
|
|
|
|
ctx->more = flags & MSG_MORE;
|
|
|
|
unlock:
|
|
release_sock(sk);
|
|
|
|
return err ?: size;
|
|
}
|
|
|
|
static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
|
|
int flags)
|
|
{
|
|
struct sock *sk = sock->sk;
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
struct hash_ctx *ctx = ask->private;
|
|
unsigned ds = crypto_ahash_digestsize(crypto_ahash_reqtfm(&ctx->req));
|
|
bool result;
|
|
int err;
|
|
|
|
if (len > ds)
|
|
len = ds;
|
|
else if (len < ds)
|
|
msg->msg_flags |= MSG_TRUNC;
|
|
|
|
lock_sock(sk);
|
|
result = ctx->result;
|
|
err = hash_alloc_result(sk, ctx);
|
|
if (err)
|
|
goto unlock;
|
|
|
|
ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);
|
|
|
|
if (!result && !ctx->more) {
|
|
err = crypto_wait_req(crypto_ahash_init(&ctx->req),
|
|
&ctx->wait);
|
|
if (err)
|
|
goto unlock;
|
|
}
|
|
|
|
if (!result || ctx->more) {
|
|
ctx->more = 0;
|
|
err = crypto_wait_req(crypto_ahash_final(&ctx->req),
|
|
&ctx->wait);
|
|
if (err)
|
|
goto unlock;
|
|
}
|
|
|
|
err = memcpy_to_msg(msg, ctx->result, len);
|
|
|
|
unlock:
|
|
hash_free_result(sk, ctx);
|
|
release_sock(sk);
|
|
|
|
return err ?: len;
|
|
}
|
|
|
|
static int hash_accept(struct socket *sock, struct socket *newsock, int flags,
|
|
bool kern)
|
|
{
|
|
struct sock *sk = sock->sk;
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
struct hash_ctx *ctx = ask->private;
|
|
struct ahash_request *req = &ctx->req;
|
|
char state[HASH_MAX_STATESIZE];
|
|
struct sock *sk2;
|
|
struct alg_sock *ask2;
|
|
struct hash_ctx *ctx2;
|
|
bool more;
|
|
int err;
|
|
|
|
lock_sock(sk);
|
|
more = ctx->more;
|
|
err = more ? crypto_ahash_export(req, state) : 0;
|
|
release_sock(sk);
|
|
|
|
if (err)
|
|
return err;
|
|
|
|
err = af_alg_accept(ask->parent, newsock, kern);
|
|
if (err)
|
|
return err;
|
|
|
|
sk2 = newsock->sk;
|
|
ask2 = alg_sk(sk2);
|
|
ctx2 = ask2->private;
|
|
ctx2->more = more;
|
|
|
|
if (!more)
|
|
return err;
|
|
|
|
err = crypto_ahash_import(&ctx2->req, state);
|
|
|
|
return err;
|
|
}
|
|
|
|
static struct proto_ops algif_hash_ops = {
|
|
.family = PF_ALG,
|
|
|
|
.connect = sock_no_connect,
|
|
.socketpair = sock_no_socketpair,
|
|
.getname = sock_no_getname,
|
|
.ioctl = sock_no_ioctl,
|
|
.listen = sock_no_listen,
|
|
.shutdown = sock_no_shutdown,
|
|
.getsockopt = sock_no_getsockopt,
|
|
.mmap = sock_no_mmap,
|
|
.bind = sock_no_bind,
|
|
.setsockopt = sock_no_setsockopt,
|
|
|
|
.release = af_alg_release,
|
|
.sendmsg = hash_sendmsg,
|
|
.sendpage = hash_sendpage,
|
|
.recvmsg = hash_recvmsg,
|
|
.accept = hash_accept,
|
|
};
|
|
|
|
static int hash_check_key(struct socket *sock)
|
|
{
|
|
int err = 0;
|
|
struct sock *psk;
|
|
struct alg_sock *pask;
|
|
struct crypto_ahash *tfm;
|
|
struct sock *sk = sock->sk;
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
|
|
lock_sock(sk);
|
|
if (!atomic_read(&ask->nokey_refcnt))
|
|
goto unlock_child;
|
|
|
|
psk = ask->parent;
|
|
pask = alg_sk(ask->parent);
|
|
tfm = pask->private;
|
|
|
|
err = -ENOKEY;
|
|
lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
|
|
if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
|
|
goto unlock;
|
|
|
|
atomic_dec(&pask->nokey_refcnt);
|
|
atomic_set(&ask->nokey_refcnt, 0);
|
|
|
|
err = 0;
|
|
|
|
unlock:
|
|
release_sock(psk);
|
|
unlock_child:
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int hash_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
|
|
size_t size)
|
|
{
|
|
int err;
|
|
|
|
err = hash_check_key(sock);
|
|
if (err)
|
|
return err;
|
|
|
|
return hash_sendmsg(sock, msg, size);
|
|
}
|
|
|
|
static ssize_t hash_sendpage_nokey(struct socket *sock, struct page *page,
|
|
int offset, size_t size, int flags)
|
|
{
|
|
int err;
|
|
|
|
err = hash_check_key(sock);
|
|
if (err)
|
|
return err;
|
|
|
|
return hash_sendpage(sock, page, offset, size, flags);
|
|
}
|
|
|
|
static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
|
|
size_t ignored, int flags)
|
|
{
|
|
int err;
|
|
|
|
err = hash_check_key(sock);
|
|
if (err)
|
|
return err;
|
|
|
|
return hash_recvmsg(sock, msg, ignored, flags);
|
|
}
|
|
|
|
static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
|
|
int flags, bool kern)
|
|
{
|
|
int err;
|
|
|
|
err = hash_check_key(sock);
|
|
if (err)
|
|
return err;
|
|
|
|
return hash_accept(sock, newsock, flags, kern);
|
|
}
|
|
|
|
static struct proto_ops algif_hash_ops_nokey = {
|
|
.family = PF_ALG,
|
|
|
|
.connect = sock_no_connect,
|
|
.socketpair = sock_no_socketpair,
|
|
.getname = sock_no_getname,
|
|
.ioctl = sock_no_ioctl,
|
|
.listen = sock_no_listen,
|
|
.shutdown = sock_no_shutdown,
|
|
.getsockopt = sock_no_getsockopt,
|
|
.mmap = sock_no_mmap,
|
|
.bind = sock_no_bind,
|
|
.setsockopt = sock_no_setsockopt,
|
|
|
|
.release = af_alg_release,
|
|
.sendmsg = hash_sendmsg_nokey,
|
|
.sendpage = hash_sendpage_nokey,
|
|
.recvmsg = hash_recvmsg_nokey,
|
|
.accept = hash_accept_nokey,
|
|
};
|
|
|
|
static void *hash_bind(const char *name, u32 type, u32 mask)
|
|
{
|
|
return crypto_alloc_ahash(name, type, mask);
|
|
}
|
|
|
|
static void hash_release(void *private)
|
|
{
|
|
crypto_free_ahash(private);
|
|
}
|
|
|
|
static int hash_setkey(void *private, const u8 *key, unsigned int keylen)
|
|
{
|
|
return crypto_ahash_setkey(private, key, keylen);
|
|
}
|
|
|
|
static void hash_sock_destruct(struct sock *sk)
|
|
{
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
struct hash_ctx *ctx = ask->private;
|
|
|
|
hash_free_result(sk, ctx);
|
|
sock_kfree_s(sk, ctx, ctx->len);
|
|
af_alg_release_parent(sk);
|
|
}
|
|
|
|
static int hash_accept_parent_nokey(void *private, struct sock *sk)
|
|
{
|
|
struct crypto_ahash *tfm = private;
|
|
struct alg_sock *ask = alg_sk(sk);
|
|
struct hash_ctx *ctx;
|
|
unsigned int len = sizeof(*ctx) + crypto_ahash_reqsize(tfm);
|
|
|
|
ctx = sock_kmalloc(sk, len, GFP_KERNEL);
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
|
|
memset(ctx, 0, len);
|
|
ctx->len = len;
|
|
crypto_init_wait(&ctx->wait);
|
|
|
|
ask->private = ctx;
|
|
|
|
ahash_request_set_tfm(&ctx->req, tfm);
|
|
ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
|
|
crypto_req_done, &ctx->wait);
|
|
|
|
sk->sk_destruct = hash_sock_destruct;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int hash_accept_parent(void *private, struct sock *sk)
|
|
{
|
|
struct crypto_ahash *tfm = private;
|
|
|
|
if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
|
|
return -ENOKEY;
|
|
|
|
return hash_accept_parent_nokey(private, sk);
|
|
}
|
|
|
|
static const struct af_alg_type algif_type_hash = {
|
|
.bind = hash_bind,
|
|
.release = hash_release,
|
|
.setkey = hash_setkey,
|
|
.accept = hash_accept_parent,
|
|
.accept_nokey = hash_accept_parent_nokey,
|
|
.ops = &algif_hash_ops,
|
|
.ops_nokey = &algif_hash_ops_nokey,
|
|
.name = "hash",
|
|
.owner = THIS_MODULE
|
|
};
|
|
|
|
static int __init algif_hash_init(void)
|
|
{
|
|
return af_alg_register_type(&algif_type_hash);
|
|
}
|
|
|
|
static void __exit algif_hash_exit(void)
|
|
{
|
|
int err = af_alg_unregister_type(&algif_type_hash);
|
|
BUG_ON(err);
|
|
}
|
|
|
|
module_init(algif_hash_init);
|
|
module_exit(algif_hash_exit);
|
|
MODULE_LICENSE("GPL");
|