* 'android-4.9-q' of https://android.googlesource.com/kernel/common: Linux 4.9.327 kprobes: don't call disarm_kprobe() for disabled kprobes mm/rmap: Fix anon_vma->degree ambiguity leading to double-reuse netfilter: conntrack: NF_CONNTRACK_PROCFS should no longer default to y s390/hypfs: avoid error message under KVM arm64: map FDT as RW for early_init_dt_scan() ftrace: Fix NULL pointer dereference in is_ftrace_trampoline when ftrace is dead fbdev: fb_pm2fb: Avoid potential divide by zero error HID: hidraw: fix memory leak in hidraw_release() media: pvrusb2: fix memory leak in pvr_probe Bluetooth: L2CAP: Fix build errors in some archs kbuild: Fix include path in scripts/Makefile.modpost x86/bugs: Add "unknown" reporting for MMIO Stale Data x86/cpu: Add Tiger Lake to Intel family s390/mm: do not trigger write fault when vma does not allow VM_WRITE mm: Force TLB flush for PFNMAP mappings before unlink_file_vma() mm/hugetlb: fix hugetlb not supporting softdirty tracking asm-generic: sections: refactor memory_intersects loop: Check for overflow while configuring loop btrfs: check if root is readonly while setting security xattr ixgbe: stop resetting SYSTIME in ixgbe_ptp_start_cyclecounter net: Fix a data-race around sysctl_somaxconn. net: Fix a data-race around sysctl_net_busy_read. net: Fix a data-race around sysctl_net_busy_poll. net: Fix a data-race around sysctl_tstamp_allow_data. ratelimit: Fix data-races in ___ratelimit(). netfilter: nft_payload: report ERANGE for too long offset and length bonding: 802.3ad: fix no transmission of LACPDUs rose: check NULL rose_loopback_neigh->loopback af_key: Do not call xfrm_probe_algs in parallel xfrm: fix refcount leak in __xfrm_policy_check() parisc: Fix exception handler for fldw and fstw instructions Linux 4.9.326 MIPS: tlbex: Explicitly compare _PAGE_NO_EXEC against 0 video: fbdev: i740fb: Check the argument of i740_calc_vclk() powerpc/64: Init jump labels before parse_early_param() ALSA: timer: Use deferred fasync helper ALSA: core: Add async signal helpers mips: cavium-octeon: Fix missing of_node_put() in octeon2_usb_clocks_start vfio: Clear the caps->buf to NULL after free tty: serial: Fix refcount leak bug in ucc_uart.c ext4: avoid resizing to a partial cluster size ext4: avoid remove directory when directory is corrupted drivers:md:fix a potential use-after-free bug cxl: Fix a memory leak in an error handling path gadgetfs: ep_io - wait until IRQ finishes usb: host: ohci-ppc-of: Fix refcount leak bug irqchip/tegra: Fix overflow implicit truncation warnings fec: Fix timer capture timing in `fec_ptp_enable_pps()` netfilter: nf_tables: really skip inactive sets when allocating name nios2: add force_successful_syscall_return() nios2: restarts apply only to the first sigframe we build... nios2: fix syscall restart checks nios2: traced syscall does need to check the syscall number nios2: don't leave NULLs in sys_call_table[] nios2: page fault et.al. are *not* restartable syscalls... atm: idt77252: fix use-after-free bugs caused by tst_timer xen/xenbus: fix return type in xenbus_file_read() vsock: Fix memory leak in vsock_connect() pinctrl: qcom: msm8916: Allow CAMSS GP clocks to be muxed pinctrl: nomadik: Fix refcount leak in nmk_pinctrl_dt_subnode_to_map SUNRPC: Reinitialise the backchannel request buffers before reuse NFSv4.1: RECLAIM_COMPLETE must handle EACCES can: ems_usb: fix clang's -Wunaligned-access warning btrfs: fix lost error handling when looking up extended ref on log replay ata: libata-eh: Add missing command name rds: add missing barrier to release_refill ALSA: info: Fix llseek return value when using callback net_sched: cls_route: disallow handle of 0 net/9p: Initialize the iounit field during fid creation nios2: time: Read timer in get_cycles only if initialized Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression Revert "net: usb: ax88179_178a needs FLAG_SEND_ZLP" scsi: sg: Allow waiting for commands to complete on removed device tcp: fix over estimation in sk_forced_mem_schedule() btrfs: reject log replay if there is unsupported RO compat flag net_sched: cls_route: remove from list when handle is 0 dm raid: fix address sanitizer warning in raid_status ext4: correct max_inline_xattr_value_size computing ext4: fix extent status tree race in writeback error recovery path ext4: update s_overhead_clusters in the superblock during an on-line resize ext4: fix use-after-free in ext4_xattr_set_entry ext4: make sure ext4_append() always allocates new block ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h spmi: trace: fix stack-out-of-bound access in SPMI tracing functions x86/olpc: fix 'logical not is only applied to the left hand side' scsi: zfcp: Fix missing auto port scan and thus missing target ports netfilter: nf_tables: fix null deref due to zeroed list head USB: HCD: Fix URB giveback issue in tasklet function MIPS: cpuinfo: Fix a warning for CONFIG_CPUMASK_OFFSTACK powerpc/powernv: Avoid crashing if rng is NULL powerpc/fsl-pci: Fix Class Code of PCIe Root Port PCI: Add defines for normal and subtractive PCI bridges ia64, processor: fix -Wincompatible-pointer-types in ia64_get_irr() md-raid10: fix KASAN warning fuse: limit nsec bpf: fix overflow in prog accounting drm/nouveau: fix another off-by-one in nvbios_addr parisc: Fix device names in /proc/iomem usbnet: Fix linkwatch use-after-free on disconnect vfs: Check the truncate maximum size in inode_newsize_ok() ALSA: hda/cirrus - support for iMac 12,1 model ALSA: hda/conexant: Add quirk for LENOVO 20149 Notebook model KVM: x86: Mark TSS busy during LTR emulation _after_ all fault checks KVM: SVM: Don't BUG if userspace injects an interrupt with GIF=0 add barriers to buffer_uptodate and set_buffer_uptodate ALSA: bcd2000: Fix a UAF bug on the error path of probing macintosh/adb: fix oob read in do_adb_query() function random: only call boot_init_stack_canary() once ACPI: video: Shortening quirk list by identifying Clevo by board_name only ACPI: video: Force backlight native for some TongFang devices init/main.c: extract early boot entropy from the passed cmdline init: move stack canary initialization after setup_arch init/main: properly align the multi-line comment init/main: Fix double "the" in comment include/uapi/linux/swab.h: fix userspace breakage, use __BITS_PER_LONG for swap selinux: fix inode_doinit_with_dentry() LABEL_INVALID error handling selinux: fix error initialization in inode_doinit_with_dentry() selinux: Convert isec->lock into a spinlock selinux: Clean up initialization of isec->sclass proc: Pass file mode to proc_pid_make_inode selinux: Minor cleanups ion: Make user_ion_handle_put_nolock() a void function mt7601u: add USB device ID for some versions of XiaoDu WiFi Dongle. ARM: crypto: comment out gcc warning that breaks clang builds netfilter: nf_queue: do not allow packet truncation below transport header offset net: sungem_phy: Add of_node_put() for reference returned by of_get_parent() net: ping6: Fix memleak in ipv6_renew_options(). scsi: ufs: host: Hold reference returned by of_parse_phandle() ntfs: fix use-after-free in ntfs_ucsncmp() Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put FROMLIST: binder: fix UAF of ref->proc caused by race condition Linux 4.9.325 net: usb: ax88179_178a needs FLAG_SEND_ZLP tty: use new tty_insert_flip_string_and_push_buffer() in pty_write() tty: extract tty_flip_buffer_commit() from tty_flip_buffer_push() tty: drop tty_schedule_flip() tty: the rest, stop using tty_schedule_flip() tty: drivers/tty/, stop using tty_schedule_flip() ALSA: memalloc: Align buffer allocations in page size bpf: Make sure mac_header was set before using it mm/mempolicy: fix uninit-value in mpol_rebind_policy() Revert "Revert "char/random: silence a lockdep splat with printk()"" be2net: Fix buffer overflow in be_get_module_eeprom tcp: Fix a data-race around sysctl_tcp_notsent_lowat. igmp: Fix a data-race around sysctl_igmp_max_memberships. igmp: Fix data-races around sysctl_igmp_llm_reports. i2c: cadence: Change large transfer count reset logic to be unconditional tcp: Fix a data-race around sysctl_tcp_probe_threshold. tcp/dccp: Fix a data-race around sysctl_tcp_fwmark_accept. ip: Fix a data-race around sysctl_fwmark_reflect. perf/core: Fix data race between perf_event_set_output() and perf_mmap_close() power/reset: arm-versatile: Fix refcount leak in versatile_reboot_probe xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup() misc: rtsx_usb: set return value in rsp_buf alloc err path misc: rtsx_usb: use separate command and response buffers misc: rtsx_usb: fix use of dma mapped buffer for usb bulk transfer xen/gntdev: Ignore failure to unmap INVALID_GRANT_HANDLE security,selinux,smack: kill security_task_wait hook FROMGIT: arm64: fix oops in concurrently setting insn_emulation sysctls Linux 4.9.324 can: m_can: m_can_tx_handler(): fix use after free of skb mm: invalidate hwpoison page cache page in fault path serial: 8250: fix return error code in serial8250_request_std_resource() tty: serial: samsung_tty: set dma burst_size to 1 usb: dwc3: gadget: Fix event pending check USB: serial: ftdi_sio: add Belimo device ids signal handling: don't use BUG_ON() for debugging x86: Clear .brk area at early boot ASoC: wm5110: Fix DRE control ASoC: ops: Fix off by one in range control validation NFC: nxp-nci: don't print header length mismatch on i2c error net: tipc: fix possible refcount leak in tipc_sk_create() cpufreq: pmac32-cpufreq: Fix refcount leak bug virtio_mmio: Restore guest page size on resume virtio_mmio: Add missing PM calls to freeze/restore sfc: fix kernel panic when creating VF sfc: fix use after free when disabling sriov ipv4: Fix data-races around sysctl_ip_dynaddr. icmp: Fix data-races around sysctl. cipso: Fix data-races around sysctl. ARM: 9209/1: Spectre-BHB: avoid pr_info() every time a CPU comes out of idle net: dsa: bcm_sf2: force pause link settings nilfs2: fix incorrect masking of permission flags for symlinks ARM: 9213/1: Print message about disabled Spectre workarounds only once net: sock: tracing: Fix sock_exceed_buf_limit not to dereference stale pointer xen/netback: avoid entering xenvif_rx_next_skb() with an empty rx queue ALSA: hda - Add fixup for Dell Latitidue E5430 arm64: entry: Restore tramp_map_kernel ISB Linux 4.9.323 dmaengine: ti: Add missing put_device in ti_dra7_xbar_route_allocate dmaengine: ti: Fix refcount leak in ti_dra7_xbar_route_allocate dmaengine: at_xdma: handle errors of at_xdmac_alloc_desc() correctly ida: don't use BUG_ON() for debugging i2c: cadence: Unregister the clk notifier in error path pinctrl: sunxi: a83t: Fix NAND function name for some pins xfs: remove incorrect ASSERT in xfs_rename video: of_display_timing.h: include errno.h iommu/vt-d: Fix PCI bus rescan device hot add net: rose: fix UAF bug caused by rose_t0timer_expiry usbnet: fix memory leak in error case can: gs_usb: gs_usb_open/close(): fix memory leak can: grcan: grcan_probe(): remove extra of_node_get() mm/slub: add missing TID updates on slab deactivation Linux 4.9.322 net: usb: qmi_wwan: add Telit 0x1070 composition net: usb: qmi_wwan: add Telit 0x1060 composition net: usb: qmi_wwan: add Telit LE910Cx 0x1230 composition net: usb: qmi_wwan: add Telit 0x1260 and 0x1261 compositions qmi_wwan: Added support for Telit LN940 series xen/arm: Fix race in RB-tree based P2M accounting xen/blkfront: force data bouncing when backend is untrusted xen/netfront: force data bouncing when backend is untrusted xen/netfront: fix leaking data in shared pages xen/blkfront: fix leaking data in shared pages net: Rename and export copy_skb_header ipv6/sit: fix ipip6_tunnel_get_prl return value sit: use min hwmon: (ibmaem) don't call platform_device_del() if platform_device_add() fails xen/gntdev: Avoid blocking in unmap_grant_pages() NFC: nxp-nci: Don't issue a zero length i2c_master_read() nfc: nfcmrvl: Fix irq_of_parse_and_map() return value net: bonding: fix use-after-free after 802.3ad slave unbind net: bonding: fix possible NULL deref in rlb code netfilter: nft_dynset: restore set element counter when failing to update caif_virtio: fix race between virtio_device_ready() and ndo_open() powerpc/powernv: wire up rng during setup_arch usbnet: fix memory allocation in helpers usbnet: make sure no NULL pointer is passed through net: usb: ax88179_178a: Fix packet receiving net: rose: fix UAF bugs caused by timer handler SUNRPC: Fix READ_PLUS crasher dm raid: fix KASAN warning in raid5_add_disks Linux 4.9.321 swiotlb: skip swiotlb_bounce when orig_addr is zero kexec_file: drop weak attribute from arch_kexec_apply_relocations[_add] fdt: Update CRC check for rng-seed xen: unexport __init-annotated xen_xlate_map_ballooned_pages() drm: remove drm_fb_helper_modinit powerpc/pseries: wire up rng during setup_arch() modpost: fix section mismatch check for exported init/exit sections ARM: cns3xxx: Fix refcount leak in cns3xxx_init ARM: Fix refcount leak in axxia_boot_secondary ARM: exynos: Fix refcount leak in exynos_map_pmu ARM: dts: imx6qdl: correct PU regulator ramp delay powerpc: Enable execve syscall exit tracepoint xtensa: Fix refcount leak bug in time.c xtensa: xtfpga: Fix refcount leak bug in setup iio: trigger: sysfs: fix use-after-free on remove iio: accel: mma8452: ignore the return value of reset operation iio:accel:bma180: rearrange iio trigger get and register usb: chipidea: udc: check request status before setting device address iio: adc: vf610: fix conversion mode sysfs node name igb: Make DMA faster when CPU is active on the PCIe link MIPS: Remove repetitive increase irq_err_count x86/xen: Remove undefined behavior in setup_features() bonding: ARP monitor spams NETDEV_NOTIFY_PEERS notifiers USB: serial: option: add Telit LE910Cx 0x1250 composition random: quiet urandom warning ratelimit suppression message dm era: commit metadata in postsuspend after worker stops ata: libata: add qc->flags in ata_qc_complete_template tracepoint random: schedule mix_interrupt_randomness() less often vt: drop old FONT ioctls BACKPORT: l2tp: fix race in pppol2tp_release with session object destroy BACKPORT: l2tp: don't use inet_shutdown on ppp session destroy Linux 4.9.320 tcp: drop the hash_32() part from the index calculation tcp: increase source port perturb table to 2^16 tcp: dynamically allocate the perturb table used by source ports tcp: add small random increments to the source port tcp: use different parts of the port_offset for index and offset secure_seq: use the 64 bits of the siphash for port offset calculation tcp: add some entropy in __inet_hash_connect() tcp: change source port randomizarion at connect() time fuse: fix pipe buffer lifetime for direct_io Reinstate some of "swiotlb: rework "fix info leak with DMA_FROM_DEVICE"" swiotlb: fix info leak with DMA_FROM_DEVICE xprtrdma: fix incorrect header size calculations s390/mm: use non-quiescing sske for KVM switch to keyed guest l2tp: fix race in pppol2tp_release with session object destroy l2tp: don't use inet_shutdown on ppp session destroy ext4: add reserved GDT blocks check ext4: make variable "count" signed ext4: fix bug_on ext4_mb_use_inode_pa serial: 8250: Store to lsr_save_flags after lsr read usb: gadget: lpc32xx_udc: Fix refcount leak in lpc32xx_udc_probe USB: serial: io_ti: add Agilent E5805A support USB: serial: option: add support for Cinterion MV31 with new baseline comedi: vmk80xx: fix expression for tx buffer size irqchip/gic-v3: Iterate over possible CPUs by for_each_possible_cpu() irqchip/gic/realview: Fix refcount leak in realview_gic_of_init misc: atmel-ssc: Fix IRQ check in ssc_probe pNFS: Don't keep retrying if the server replied NFS4ERR_LAYOUTUNAVAILABLE random: credit cpu and bootloader seeds by default net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred virtio-mmio: fix missing put_device() when vm_cmdline_parent registration failed scsi: lpfc: Fix port stuck in bypassed state after LIP in PT2PT topology scsi: vmw_pvscsi: Expand vcpuHint to 16 bits ASoC: wm8962: Fix suspend while playing music ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo() ASoC: cs42l56: Correct typo in minimum level for SX volume controls ASoC: cs42l52: Correct TLV for Bypass Volume ASoC: cs53l30: Correct number of volume levels on SX controls ASoC: cs42l52: Fix TLV scales for mixer controls random: account for arch randomness in bits random: mark bootloader randomness code as __init random: avoid checking crng_ready() twice in random_init() crypto: drbg - make reseeding from get_random_bytes() synchronous crypto: drbg - always try to free Jitter RNG instance crypto: drbg - move dynamic ->reseed_threshold adjustments to __drbg_seed() crypto: drbg - track whether DRBG was seeded with !rng_is_initialized() crypto: drbg - prepare for more fine-grained tracking of seeding state crypto: drbg - always seeded with SP800-90B compliant noise source crypto: drbg - add FIPS 140-2 CTRNG for noise source Revert "random: use static branch for crng_ready()" random: check for signals after page of pool writes random: wire up fops->splice_{read,write}_iter() random: convert to using fops->write_iter() random: move randomize_page() into mm where it belongs random: move initialization functions out of hot pages random: use proper return types on get_random_{int,long}_wait() random: remove extern from functions in header random: use static branch for crng_ready() random: credit architectural init the exact amount random: handle latent entropy and command line from random_init() random: use proper jiffies comparison macro random: remove ratelimiting for in-kernel unseeded randomness random: avoid initializing twice in credit race random: use symbolic constants for crng_init states siphash: use one source of truth for siphash permutations random: help compiler out with fast_mix() by using simpler arguments random: do not use input pool from hard IRQs random: order timer entropy functions below interrupt functions random: do not pretend to handle premature next security model random: do not use batches when !crng_ready() random: insist on random_get_entropy() existing in order to simplify uapi: rename ext2_swab() to swab() and share globally in swab.h xtensa: use fallback for random_get_entropy() instead of zero sparc: use fallback for random_get_entropy() instead of zero um: use fallback for random_get_entropy() instead of zero x86/tsc: Use fallback for random_get_entropy() instead of zero nios2: use fallback for random_get_entropy() instead of zero arm: use fallback for random_get_entropy() instead of zero mips: use fallback for random_get_entropy() instead of just c0 random m68k: use fallback for random_get_entropy() instead of zero timekeeping: Add raw clock fallback for random_get_entropy() powerpc: define get_cycles macro for arch-override alpha: define get_cycles macro for arch-override parisc: define get_cycles macro for arch-override s390: define get_cycles macro for arch-override ia64: define get_cycles macro for arch-override init: call time_init() before rand_initialize() random: fix sysctl documentation nits random: document crng_fast_key_erasure() destination possibility random: make random_get_entropy() return an unsigned long random: check for signals every PAGE_SIZE chunk of /dev/[u]random random: check for signal_pending() outside of need_resched() check random: do not allow user to keep crng key around on stack random: do not split fast init input in add_hwgenerator_randomness() random: mix build-time latent entropy into pool at init random: re-add removed comment about get_random_{u32,u64} reseeding random: treat bootloader trust toggle the same way as cpu trust toggle random: skip fast_init if hwrng provides large chunk of entropy random: check for signal and try earlier when generating entropy random: reseed more often immediately after booting random: make consistent usage of crng_ready() random: use SipHash as interrupt entropy accumulator random: replace custom notifier chain with standard one random: don't let 644 read-only sysctls be written to random: give sysctl_random_min_urandom_seed a more sensible value random: do crng pre-init loading in worker rather than irq random: unify cycles_t and jiffies usage and types random: cleanup UUID handling random: only wake up writers after zap if threshold was passed random: round-robin registers as ulong, not u32 random: clear fast pool, crng, and batches in cpuhp bring up random: pull add_hwgenerator_randomness() declaration into random.h hwrng: remember rng chosen by user hwrng: use rng source with best quality hwrng: core - remove unused PFX macro hwrng: core - Move hwrng miscdev minor number to include/linux/miscdevice.h hwrng: core - Rewrite the header hwrng: core - rewrite better comparison to NULL hwrng: core - do not use multiple blank lines random: check for crng_init == 0 in add_device_randomness() random: unify early init crng load accounting random: do not take pool spinlock at boot random: defer fast pool mixing to worker workqueue: make workqueue available early during boot random: rewrite header introductory comment random: group sysctl functions random: group userspace read/write functions random: group entropy collection functions random: group entropy extraction functions random: group initialization wait functions random: remove whitespace and reorder includes random: remove useless header comment random: introduce drain_entropy() helper to declutter crng_reseed() random: deobfuscate irq u32/u64 contributions random: add proper SPDX header random: remove unused tracepoints random: remove ifdef'd out interrupt bench random: tie batched entropy generation to base_crng generation random: zero buffer after reading entropy from userspace random: remove outdated INT_MAX >> 6 check in urandom_read() random: use hash function for crng_slow_load() random: absorb fast pool into input pool after fast load random: do not xor RDRAND when writing into /dev/random random: ensure early RDSEED goes through mixer on init random: inline leaves of rand_initialize() random: use RDSEED instead of RDRAND in entropy extraction random: fix locking in crng_fast_load() random: remove batched entropy locking random: remove use_input_pool parameter from crng_reseed() random: make credit_entropy_bits() always safe random: always wake up entropy writers after extraction random: use linear min-entropy accumulation crediting random: simplify entropy debiting random: use computational hash for entropy extraction random: only call crng_finalize_init() for primary_crng random: access primary_pool directly rather than through pointer random: continually use hwgenerator randomness random: simplify arithmetic function flow in account() random: access input_pool_data directly rather than through pointer random: cleanup fractional entropy shift constants random: prepend remaining pool constants with POOL_ random: de-duplicate INPUT_POOL constants random: remove unused OUTPUT_POOL constants random: rather than entropy_store abstraction, use global random: try to actively add entropy rather than passively wait for it random: remove unused extract_entropy() reserved argument random: remove incomplete last_data logic random: cleanup integer types crypto: chacha20 - Fix chacha20_block() keystream alignment (again) random: cleanup poolinfo abstraction random: fix typo in comments random: don't reset crng_init_cnt on urandom_read() random: avoid superfluous call to RDRAND in CRNG extraction random: early initialization of ChaCha constants random: initialize ChaCha20 constants with correct endianness random: use IS_ENABLED(CONFIG_NUMA) instead of ifdefs random: harmonize "crng init done" messages random: mix bootloader randomness into pool random: do not re-init if crng_reseed completes before primary init random: do not sign extend bytes for rotation when mixing random: use BLAKE2s instead of SHA1 in extraction random: remove unused irq_flags argument from add_interrupt_randomness() random: document add_hwgenerator_randomness() with other input functions crypto: blake2s - adjust include guard naming crypto: blake2s - include <linux/bug.h> instead of <asm/bug.h> MAINTAINERS: co-maintain random.c random: remove dead code left over from blocking pool random: avoid arch_get_random_seed_long() when collecting IRQ randomness random: add arch_get_random_*long_early() powerpc: Use bool in archrandom.h linux/random.h: Mark CONFIG_ARCH_RANDOM functions __must_check linux/random.h: Use false with bool linux/random.h: Remove arch_has_random, arch_has_random_seed powerpc: Remove arch_has_random, arch_has_random_seed x86: Remove arch_has_random, arch_has_random_seed random: avoid warnings for !CONFIG_NUMA builds random: split primary/secondary crng init paths random: remove some dead code of poolinfo random: fix typo in add_timer_randomness() random: Add and use pr_fmt() random: convert to ENTROPY_BITS for better code readability random: remove unnecessary unlikely() random: remove kernel.random.read_wakeup_threshold random: delete code to pull data into pools random: remove the blocking pool random: fix crash on multiple early calls to add_bootloader_randomness() random: make /dev/random be almost like /dev/urandom random: ignore GRND_RANDOM in getentropy(2) random: add GRND_INSECURE to return best-effort non-cryptographic bytes random: Add a urandom_read_nowait() for random APIs that don't warn random: Don't wake crng_init_wait when crng_init == 1 lib/crypto: sha1: re-roll loops to reduce code size lib/crypto: blake2s: move hmac construction into wireguard crypto: blake2s - generic C library implementation and selftest crypto: Deduplicate le32_to_cpu_array() and cpu_to_le32_array() Revert "hwrng: core - Freeze khwrng thread during suspend" char/random: Add a newline at the end of the file random: Use wait_event_freezable() in add_hwgenerator_randomness() fdt: add support for rng-seed random: Support freezable kthreads in add_hwgenerator_randomness() random: fix soft lockup when trying to read from an uninitialized blocking pool latent_entropy: avoid build error when plugin cflags are not set random: document get_random_int() family random: move rand_initialize() earlier random: only read from /dev/random after its pool has received 128 bits drivers/char/random.c: make primary_crng static drivers/char/random.c: remove unused stuct poolinfo::poolbits drivers/char/random.c: constify poolinfo_table random: make CPU trust a boot parameter random: Make crng state queryable random: remove preempt disabled region random: add a config option to trust the CPU's hwrng random: Return nbytes filled from hw RNG random: Fix whitespace pre random-bytes work drivers/char/random.c: remove unused dont_count_entropy random: optimize add_interrupt_randomness random: always fill buffer in get_random_bytes_wait crypto: chacha20 - Fix keystream alignment for chacha20_block() random: fix data race on crng_node_pool random: always use batched entropy for get_random_u{32,64} Revert "char/random: silence a lockdep splat with printk()" char/random: silence a lockdep splat with printk() random: add a spinlock_t to struct batched_entropy random: rate limit unseeded randomness warnings random: fix possible sleeping allocation from irq context random: set up the NUMA crng instances after the CRNG is fully initialized random: use a different mixing algorithm for add_device_randomness() random: fix warning message on ia64 and parisc random: reorder READ_ONCE() in get_random_uXX random: suppress spammy warnings about unseeded randomness random: do not ignore early device randomness random: warn when kernel uses unseeded randomness random: add get_random_{bytes,u32,u64,int,long,once}_wait family random: add wait_for_random_bytes() API random: silence compiler warnings and fix race random: invalidate batched entropy after crng init random: move random_min_urandom_seed into CONFIG_SYSCTL ifdef block random: convert get_random_int/long into get_random_u32/u64 random: fix comment for unused random_min_urandom_seed random: remove variable limit random: remove stale urandom_init_wait random: remove stale maybe_reseed_primary_crng 9p: missing chunk of "fs/9p: Don't update file type when updating file attributes" Linux 4.9.319 x86/speculation/mmio: Print SMT warning KVM: x86/speculation: Disable Fill buffer clear within guests x86/speculation/mmio: Reuse SRBDS mitigation for SBDS x86/speculation/srbds: Update SRBDS mitigation selection x86/speculation/mmio: Add sysfs reporting for Processor MMIO Stale Data x86/speculation/mmio: Enable CPU Fill buffer clearing on idle x86/bugs: Group MDS, TAA & Processor MMIO Stale Data mitigations x86/speculation/mmio: Add mitigation for Processor MMIO Stale Data x86/speculation: Add a common function for MD_CLEAR mitigation update x86/speculation/mmio: Enumerate Processor MMIO Stale Data bug Documentation: Add documentation for Processor MMIO Stale Data x86/cpu: Add another Alder Lake CPU to the Intel family x86/cpu: Add Lakefield, Alder Lake and Rocket Lake models to the to Intel CPU family x86/cpu: Add Comet Lake to the Intel CPU models header x86/CPU: Add more Icelake model numbers x86/CPU: Add Icelake model number x86/cpu: Add Cannonlake to Intel family x86/cpu: Add Jasper Lake to Intel family cpu/speculation: Add prototype for cpu_show_srbds() x86/cpu: Add Elkhart Lake to Intel family ANDROID: arch: fix backported syscall numbers Linux 4.9.318 tcp: fix tcp_mtup_probe_success vs wrong snd_cwnd PCI: qcom: Fix unbalanced PHY init on probe errors mtd: cfi_cmdset_0002: Use chip_ready() for write on S29GL064N mtd: cfi_cmdset_0002: Move and rename chip_check/chip_ready/chip_good_for_write powerpc/32: Fix overread/overwrite of thread_struct via ptrace Input: bcm5974 - set missing URB_NO_TRANSFER_DMA_MAP urb flag nfc: st21nfca: fix memory leaks in EVT_TRANSACTION handling nfc: st21nfca: fix incorrect validating logic in EVT_TRANSACTION ata: libata-transport: fix {dma|pio|xfer}_mode sysfs files cifs: return errors during session setup during reconnects ALSA: hda/conexant - Fix loopback issue with CX20632 vringh: Fix loop descriptors check in the indirect cases nodemask: Fix return values to be unsigned modpost: fix undefined behavior of is_arm_mapping_symbol() drm/radeon: fix a possible null pointer dereference Revert "net: af_key: add check for pfkey_broadcast in function pfkey_process" md: protect md_unregister_thread from reentrancy serial: msm_serial: disable interrupts in __msm_console_write() staging: rtl8712: fix uninit-value in r871xu_drv_init() clocksource/drivers/sp804: Avoid error on multiple instances misc: rtsx: set NULL intfdata when probe fails usb: dwc2: gadget: don't reset gadget's driver->bus USB: hcd-pci: Fully suspend across freeze/thaw cycle drivers: usb: host: Fix deadlock in oxu_bus_suspend() drivers: tty: serial: Fix deadlock in sa1100_set_termios() USB: host: isp116x: check return value after calling platform_get_resource() drivers: staging: rtl8192e: Fix deadlock in rtllib_beacons_stop() tty: Fix a possible resource leak in icom_probe tty: synclink_gt: Fix null-pointer-dereference in slgt_clean() lkdtm/usercopy: Expand size of "out of frame" object iio: dummy: iio_simple_dummy: check the return value of kstrdup() net: altera: Fix refcount leak in altera_tse_mdio_create net: xfrm: unexport __init-annotated xfrm4_protocol_init() SUNRPC: Fix the calculation of xdr->end in xdr_get_next_encode_buffer() net/mlx4_en: Fix wrong return value on ioctl EEPROM query failure ata: pata_octeon_cf: Fix refcount leak in octeon_cf_probe net: fix nla_strcmp to handle more then one trailing null character video: fbdev: pxa3xx-gcu: release the resources correctly in pxa3xx_gcu_probe/remove() m68knommu: fix undefined reference to `_init_sp' m68knommu: set ZERO_PAGE() to the allocated zeroed page i2c: cadence: Increase timeout per message if necessary tracing: Avoid adding tracer option before update_tracer_options tcp: tcp_rtx_synack() can be called from process context jffs2: fix memory leak in jffs2_do_fill_super modpost: fix removing numeric suffixes net: ethernet: mtk_eth_soc: out of bounds read in mtk_hwlro_get_fdir_entry() clocksource/drivers/oxnas-rps: Fix irq_of_parse_and_map() return value firmware: dmi-sysfs: Fix memory leak in dmi_sysfs_register_handle serial: st-asc: Sanitize CSIZE and correct PARENB for CS7 serial: sh-sci: Don't allow CS5-6 serial: txx9: Don't allow CS5-6 serial: digicolor-usart: Don't allow CS5-6 serial: meson: acquire port->lock in startup() rtc: mt6397: check return value after calling platform_get_resource() rpmsg: qcom_smd: Fix irq_of_parse_and_map() return value pwm: lp3943: Fix duty calculation in case period was clamped USB: storage: karma: fix rio_karma_init return usb: usbip: add missing device lock on tweak configuration cmd usb: usbip: fix a refcount leak in stub_probe() staging: greybus: codecs: fix type confusion of list iterator variable pcmcia: db1xxx_ss: restrict to MIPS_DB1XXX boards netfilter: nf_tables: disallow non-stateful expression in sets earlier MIPS: IP27: Remove incorrect `cpu_has_fpu' override RDMA/rxe: Generate a completion for unsupported/invalid opcode dt-bindings: gpio: altera: correct interrupt-cells docs/conf.py: Cope with removal of language=None in Sphinx 5.0.0 gma500: fix an incorrect NULL check on list iterator carl9170: tx: fix an incorrect use of list iterator ASoC: rt5514: Fix event generation for "DSP Voice Wake Up" control rtl818x: Prevent using not initialized queues hugetlb: fix huge_pmd_unshare address update nodemask.h: fix compilation error with GCC12 iommu/msm: Fix an incorrect NULL check on list iterator um: Fix out-of-bounds read in LDT setup um: chan_user: Fix winch_tramp() return value mac80211: upgrade passive scan to active scan on DFS channels after beacon rx irqchip: irq-xtensa-mx: fix initial IRQ affinity irqchip/armada-370-xp: Do not touch Performance Counter Overflow on A375, A38x, A39x RDMA/hfi1: Fix potential integer multiplication overflow errors md: fix an incorrect NULL check in md_reload_sb md: fix an incorrect NULL check in does_sb_need_changing drm/bridge: analogix_dp: Grab runtime PM reference for DP-AUX drm/amdgpu/cs: make commands with 0 chunks illegal behaviour. scsi: ufs: qcom: Add a readl() to make sure ref_clk gets enabled scsi: dc395x: Fix a missing check on list iterator ocfs2: dlmfs: fix error handling of user_dlm_destroy_lock dlm: fix missing lkb refcount handling dlm: fix plock invalid read ext4: verify dir block before splitting it ext4: fix bug_on in ext4_writepages ext4: fix use-after-free in ext4_rename_dir_prepare fs-writeback: writeback_sb_inodes:Recalculate 'wrote' according skipped pages iwlwifi: mvm: fix assert 1F04 upon reconfig wifi: mac80211: fix use-after-free in chanctx code iommu/amd: Increase timeout waiting for GA log enablement video: fbdev: clcdfb: Fix refcount leak in clcdfb_of_vram_setup Input: sparcspkr - fix refcount leak in bbc_beep_probe tty: fix deadlock caused by calling printk() under tty_port->lock powerpc/4xx/cpm: Fix return value of __setup() handler powerpc/idle: Fix return value of __setup() handler powerpc/8xx: export 'cpm_setbrg' for modules drivers/base/node.c: fix compaction sysfs file leak scsi: fcoe: Fix Wstringop-overflow warnings in fcoe_wwn_from_mac() mfd: ipaq-micro: Fix error check return value of platform_get_irq() soc: qcom: smsm: Fix missing of_node_put() in smsm_parse_ipc soc: qcom: smp2p: Fix missing of_node_put() in smp2p_parse_ipc rxrpc: Don't try to resend the request if we're receiving the reply rxrpc: Fix listen() setting the bar too high for the prealloc rings ASoC: wm2000: fix missing clk_disable_unprepare() on error in wm2000_anc_transition() sctp: read sk->sk_bound_dev_if once in sctp_rcv() m68k: math-emu: Fix dependencies of math emulation support Bluetooth: fix dangling sco_conn and use-after-free in sco_sock_timeout media: pvrusb2: fix array-index-out-of-bounds in pvr2_i2c_core_init media: exynos4-is: Change clk_disable to clk_disable_unprepare regulator: pfuze100: Fix refcount leak in pfuze_parse_regulators_dt ASoC: mxs-saif: Fix refcount leak in mxs_saif_probe media: uvcvideo: Fix missing check to determine if element is found in list drm/msm: return an error pointer in msm_gem_prime_get_sg_table() x86/mm: Cleanup the control_va_addr_alignment() __setup handler drm/rockchip: vop: fix possible null-ptr-deref in vop_bind() drm/msm/hdmi: check return value after calling platform_get_resource_byname() drm/msm/dsi: fix error checks and return values for DSI xmit functions x86/pm: Fix false positive kmemleak report in msr_build_context() inotify: show inotify mask flags in proc fdinfo ath9k_htc: fix potential out of bounds access with invalid rxstatus->rs_keyix spi: img-spfi: Fix pm_runtime_get_sync() error checking HID: hid-led: fix maximum brightness for Dream Cheeky NFC: NULL out the dev->rfkill to prevent UAF spi: spi-ti-qspi: Fix return value handling of wait_for_completion_timeout drm/mediatek: Fix mtk_cec_mask() x86/delay: Fix the wrong asm constraint in delay_loop() ASoC: mediatek: Fix error handling in mt8173_max98090_dev_probe drm: fix EDID struct for old ARM OABI format macintosh/via-pmu: Fix build failure when CONFIG_INPUT is disabled powerpc/xics: fix refcount leak in icp_opal_init() PCI: Avoid pci_dev_lock() AB/BA deadlock with sriov_numvfs_store() ARM: hisi: Add missing of_node_put after of_find_compatible_node ARM: dts: exynos: add atmel,24c128 fallback to Samsung EEPROM ARM: versatile: Add missing of_node_put in dcscb_init fat: add ratelimit to fat*_ent_bread() ARM: OMAP1: clock: Fix UART rate reporting algorithm fs: jfs: fix possible NULL pointer dereference in dbFree() eth: tg3: silence the GCC 12 array-bounds warning rxrpc: Return an error to sendmsg if call failed media: exynos4-is: Fix compile warning ASoC: rt5645: Fix errorenous cleanup order nvme-pci: fix a NULL pointer dereference in nvme_alloc_admin_tags openrisc: start CPU timer early in boot ipmi:ssif: Check for NULL msg when handling events and messages dma-debug: change allocation mode from GFP_NOWAIT to GFP_ATIOMIC ASoC: dapm: Don't fold register value changes into notifications ipv6: Don't send rs packets to the interface of ARPHRD_TUNNEL drm/amd/pm: fix the compile warning scsi: megaraid: Fix error check return value of register_chrdev() media: cx25821: Fix the warning when removing the module ath9k: fix QCA9561 PA bias level drm/amd/pm: fix double free in si_parse_power_table() ALSA: jack: Access input_dev under mutex ACPICA: Avoid cache flush inside virtual machines ipw2x00: Fix potential NULL dereference in libipw_xmit() b43: Fix assigning negative value to unsigned variable b43legacy: Fix assigning negative value to unsigned variable mwifiex: add mutex lock for call in mwifiex_dfs_chan_sw_work_queue drm/virtio: fix NULL pointer dereference in virtio_gpu_conn_get_modes btrfs: add "0x" prefix for unsupported optional features ptrace: Reimplement PTRACE_KILL by always sending SIGKILL ptrace/xtensa: Replace PT_SINGLESTEP with TIF_SINGLESTEP USB: new quirk for Dell Gen 2 devices BACKPORT: psi: Fix uaf issue when psi trigger is destroyed while being polled ANDROID: android-verity: Prevent double-freeing metadata Linux 4.9.317 bpf: Enlarge offset check value to INT_MAX in bpf_skb_{load,store}_bytes NFSD: Fix possible sleep during nfsd4_release_lockowner() tpm: ibmvtpm: Correct the return value in tpm_ibmvtpm_probe() dm verity: set DM_TARGET_IMMUTABLE feature flag dm stats: add cond_resched when looping over entries dm crypt: make printing of the key constant-time exec: Force single empty string when argv is empty block-map: add __GFP_ZERO flag for alloc_page in function bio_copy_kern drm/i915: Fix -Wstringop-overflow warning in call to intel_read_wm_latency() assoc_array: Fix BUG_ON during garbage collect drivers: i2c: thunderx: Allow driver to work with ACPI defined TWSI controllers net: af_key: check encryption module availability consistency Conflicts: arch/arm/include/asm/unistd.h arch/arm/kernel/calls.S arch/arm64/kernel/setup.c init/main.c drivers/char/Kconfig drivers/char/random.c drivers/of/fdt.c drivers/staging/android/ion/ion-ioctl.c drivers/usb/dwc3/gadget.c fs/fat/fatent.c include/linux/random.h kernel/cpu.c lib/Makefile security/selinux/include/objsec.h Change-Id: I1b456460585ab9080cfb9eadfd14cae311238112
3436 lines
83 KiB
C
3436 lines
83 KiB
C
/*
|
|
* NET An implementation of the SOCKET network access protocol.
|
|
*
|
|
* Version: @(#)socket.c 1.1.93 18/02/95
|
|
*
|
|
* Authors: Orest Zborowski, <obz@Kodak.COM>
|
|
* Ross Biro
|
|
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
|
*
|
|
* Fixes:
|
|
* Anonymous : NOTSOCK/BADF cleanup. Error fix in
|
|
* shutdown()
|
|
* Alan Cox : verify_area() fixes
|
|
* Alan Cox : Removed DDI
|
|
* Jonathan Kamens : SOCK_DGRAM reconnect bug
|
|
* Alan Cox : Moved a load of checks to the very
|
|
* top level.
|
|
* Alan Cox : Move address structures to/from user
|
|
* mode above the protocol layers.
|
|
* Rob Janssen : Allow 0 length sends.
|
|
* Alan Cox : Asynchronous I/O support (cribbed from the
|
|
* tty drivers).
|
|
* Niibe Yutaka : Asynchronous I/O for writes (4.4BSD style)
|
|
* Jeff Uphoff : Made max number of sockets command-line
|
|
* configurable.
|
|
* Matti Aarnio : Made the number of sockets dynamic,
|
|
* to be allocated when needed, and mr.
|
|
* Uphoff's max is used as max to be
|
|
* allowed to allocate.
|
|
* Linus : Argh. removed all the socket allocation
|
|
* altogether: it's in the inode now.
|
|
* Alan Cox : Made sock_alloc()/sock_release() public
|
|
* for NetROM and future kernel nfsd type
|
|
* stuff.
|
|
* Alan Cox : sendmsg/recvmsg basics.
|
|
* Tom Dyas : Export net symbols.
|
|
* Marcin Dalecki : Fixed problems with CONFIG_NET="n".
|
|
* Alan Cox : Added thread locking to sys_* calls
|
|
* for sockets. May have errors at the
|
|
* moment.
|
|
* Kevin Buhr : Fixed the dumb errors in the above.
|
|
* Andi Kleen : Some small cleanups, optimizations,
|
|
* and fixed a copy_from_user() bug.
|
|
* Tigran Aivazian : sys_send(args) calls sys_sendto(args, NULL, 0)
|
|
* Tigran Aivazian : Made listen(2) backlog sanity checks
|
|
* protocol-independent
|
|
*
|
|
*
|
|
* 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.
|
|
*
|
|
*
|
|
* This module is effectively the top level interface to the BSD socket
|
|
* paradigm.
|
|
*
|
|
* Based upon Swansea University Computer Society NET3.039
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/file.h>
|
|
#include <linux/net.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/thread_info.h>
|
|
#include <linux/rcupdate.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/if_bridge.h>
|
|
#include <linux/if_frad.h>
|
|
#include <linux/if_vlan.h>
|
|
#include <linux/ptp_classify.h>
|
|
#include <linux/init.h>
|
|
#include <linux/poll.h>
|
|
#include <linux/cache.h>
|
|
#include <linux/module.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/security.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/kmod.h>
|
|
#include <linux/audit.h>
|
|
#include <linux/wireless.h>
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/magic.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/xattr.h>
|
|
#include <linux/seemp_api.h>
|
|
#include <linux/seemp_instrumentation.h>
|
|
#include <linux/nospec.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
#include <asm/unistd.h>
|
|
|
|
#include <net/compat.h>
|
|
#include <net/wext.h>
|
|
#include <net/cls_cgroup.h>
|
|
|
|
#include <net/sock.h>
|
|
#include <linux/netfilter.h>
|
|
|
|
#include <linux/if_tun.h>
|
|
#include <linux/ipv6_route.h>
|
|
#include <linux/route.h>
|
|
#include <linux/sockios.h>
|
|
#include <linux/atalk.h>
|
|
#include <net/busy_poll.h>
|
|
#include <linux/errqueue.h>
|
|
|
|
#ifdef CONFIG_NET_RX_BUSY_POLL
|
|
unsigned int sysctl_net_busy_read __read_mostly;
|
|
unsigned int sysctl_net_busy_poll __read_mostly;
|
|
#endif
|
|
|
|
static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to);
|
|
static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from);
|
|
static BLOCKING_NOTIFIER_HEAD(sockev_notifier_list);
|
|
|
|
static int sock_mmap(struct file *file, struct vm_area_struct *vma);
|
|
|
|
static int sock_close(struct inode *inode, struct file *file);
|
|
static unsigned int sock_poll(struct file *file,
|
|
struct poll_table_struct *wait);
|
|
static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
|
|
#ifdef CONFIG_COMPAT
|
|
static long compat_sock_ioctl(struct file *file,
|
|
unsigned int cmd, unsigned long arg);
|
|
#endif
|
|
static int sock_fasync(int fd, struct file *filp, int on);
|
|
static ssize_t sock_sendpage(struct file *file, struct page *page,
|
|
int offset, size_t size, loff_t *ppos, int more);
|
|
static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
|
|
struct pipe_inode_info *pipe, size_t len,
|
|
unsigned int flags);
|
|
|
|
/*
|
|
* Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
|
|
* in the operation structures but are done directly via the socketcall() multiplexor.
|
|
*/
|
|
|
|
static const struct file_operations socket_file_ops = {
|
|
.owner = THIS_MODULE,
|
|
.llseek = no_llseek,
|
|
.read_iter = sock_read_iter,
|
|
.write_iter = sock_write_iter,
|
|
.poll = sock_poll,
|
|
.unlocked_ioctl = sock_ioctl,
|
|
#ifdef CONFIG_COMPAT
|
|
.compat_ioctl = compat_sock_ioctl,
|
|
#endif
|
|
.mmap = sock_mmap,
|
|
.release = sock_close,
|
|
.fasync = sock_fasync,
|
|
.sendpage = sock_sendpage,
|
|
.splice_write = generic_splice_sendpage,
|
|
.splice_read = sock_splice_read,
|
|
};
|
|
|
|
/*
|
|
* The protocol list. Each protocol is registered in here.
|
|
*/
|
|
|
|
static DEFINE_SPINLOCK(net_family_lock);
|
|
static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
|
|
|
|
/*
|
|
* Statistics counters of the socket lists
|
|
*/
|
|
|
|
static DEFINE_PER_CPU(int, sockets_in_use);
|
|
|
|
/*
|
|
* Socket Event framework helpers
|
|
*/
|
|
static void sockev_notify(unsigned long event, struct socket *sk)
|
|
{
|
|
blocking_notifier_call_chain(&sockev_notifier_list, event, sk);
|
|
}
|
|
|
|
/**
|
|
* Support routines.
|
|
* Move socket addresses back and forth across the kernel/user
|
|
* divide and look after the messy bits.
|
|
*/
|
|
|
|
/**
|
|
* move_addr_to_kernel - copy a socket address into kernel space
|
|
* @uaddr: Address in user space
|
|
* @kaddr: Address in kernel space
|
|
* @ulen: Length in user space
|
|
*
|
|
* The address is copied into kernel space. If the provided address is
|
|
* too long an error code of -EINVAL is returned. If the copy gives
|
|
* invalid addresses -EFAULT is returned. On a success 0 is returned.
|
|
*/
|
|
|
|
int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr)
|
|
{
|
|
if (ulen < 0 || ulen > sizeof(struct sockaddr_storage))
|
|
return -EINVAL;
|
|
if (ulen == 0)
|
|
return 0;
|
|
if (copy_from_user(kaddr, uaddr, ulen))
|
|
return -EFAULT;
|
|
return audit_sockaddr(ulen, kaddr);
|
|
}
|
|
|
|
/**
|
|
* move_addr_to_user - copy an address to user space
|
|
* @kaddr: kernel space address
|
|
* @klen: length of address in kernel
|
|
* @uaddr: user space address
|
|
* @ulen: pointer to user length field
|
|
*
|
|
* The value pointed to by ulen on entry is the buffer length available.
|
|
* This is overwritten with the buffer space used. -EINVAL is returned
|
|
* if an overlong buffer is specified or a negative buffer size. -EFAULT
|
|
* is returned if either the buffer or the length field are not
|
|
* accessible.
|
|
* After copying the data up to the limit the user specifies, the true
|
|
* length of the data is written over the length limit the user
|
|
* specified. Zero is returned for a success.
|
|
*/
|
|
|
|
static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
|
|
void __user *uaddr, int __user *ulen)
|
|
{
|
|
int err;
|
|
int len;
|
|
|
|
BUG_ON(klen > sizeof(struct sockaddr_storage));
|
|
err = get_user(len, ulen);
|
|
if (err)
|
|
return err;
|
|
if (len > klen)
|
|
len = klen;
|
|
if (len < 0)
|
|
return -EINVAL;
|
|
if (len) {
|
|
if (audit_sockaddr(klen, kaddr))
|
|
return -ENOMEM;
|
|
if (copy_to_user(uaddr, kaddr, len))
|
|
return -EFAULT;
|
|
}
|
|
/*
|
|
* "fromlen shall refer to the value before truncation.."
|
|
* 1003.1g
|
|
*/
|
|
return __put_user(klen, ulen);
|
|
}
|
|
|
|
static struct kmem_cache *sock_inode_cachep __read_mostly;
|
|
|
|
static struct inode *sock_alloc_inode(struct super_block *sb)
|
|
{
|
|
struct socket_alloc *ei;
|
|
struct socket_wq *wq;
|
|
|
|
ei = kmem_cache_alloc(sock_inode_cachep, GFP_KERNEL);
|
|
if (!ei)
|
|
return NULL;
|
|
wq = kmalloc(sizeof(*wq), GFP_KERNEL);
|
|
if (!wq) {
|
|
kmem_cache_free(sock_inode_cachep, ei);
|
|
return NULL;
|
|
}
|
|
init_waitqueue_head(&wq->wait);
|
|
wq->fasync_list = NULL;
|
|
wq->flags = 0;
|
|
RCU_INIT_POINTER(ei->socket.wq, wq);
|
|
|
|
ei->socket.state = SS_UNCONNECTED;
|
|
ei->socket.flags = 0;
|
|
ei->socket.ops = NULL;
|
|
ei->socket.sk = NULL;
|
|
ei->socket.file = NULL;
|
|
|
|
return &ei->vfs_inode;
|
|
}
|
|
|
|
static void sock_destroy_inode(struct inode *inode)
|
|
{
|
|
struct socket_alloc *ei;
|
|
struct socket_wq *wq;
|
|
|
|
ei = container_of(inode, struct socket_alloc, vfs_inode);
|
|
wq = rcu_dereference_protected(ei->socket.wq, 1);
|
|
kfree_rcu(wq, rcu);
|
|
kmem_cache_free(sock_inode_cachep, ei);
|
|
}
|
|
|
|
static void init_once(void *foo)
|
|
{
|
|
struct socket_alloc *ei = (struct socket_alloc *)foo;
|
|
|
|
inode_init_once(&ei->vfs_inode);
|
|
}
|
|
|
|
static int init_inodecache(void)
|
|
{
|
|
sock_inode_cachep = kmem_cache_create("sock_inode_cache",
|
|
sizeof(struct socket_alloc),
|
|
0,
|
|
(SLAB_HWCACHE_ALIGN |
|
|
SLAB_RECLAIM_ACCOUNT |
|
|
SLAB_MEM_SPREAD | SLAB_ACCOUNT),
|
|
init_once);
|
|
if (sock_inode_cachep == NULL)
|
|
return -ENOMEM;
|
|
return 0;
|
|
}
|
|
|
|
static const struct super_operations sockfs_ops = {
|
|
.alloc_inode = sock_alloc_inode,
|
|
.destroy_inode = sock_destroy_inode,
|
|
.statfs = simple_statfs,
|
|
};
|
|
|
|
/*
|
|
* sockfs_dname() is called from d_path().
|
|
*/
|
|
static char *sockfs_dname(struct dentry *dentry, char *buffer, int buflen)
|
|
{
|
|
return dynamic_dname(dentry, buffer, buflen, "socket:[%lu]",
|
|
d_inode(dentry)->i_ino);
|
|
}
|
|
|
|
static const struct dentry_operations sockfs_dentry_operations = {
|
|
.d_dname = sockfs_dname,
|
|
};
|
|
|
|
static int sockfs_xattr_get(const struct xattr_handler *handler,
|
|
struct dentry *dentry, struct inode *inode,
|
|
const char *suffix, void *value, size_t size)
|
|
{
|
|
if (value) {
|
|
if (dentry->d_name.len + 1 > size)
|
|
return -ERANGE;
|
|
memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
|
|
}
|
|
return dentry->d_name.len + 1;
|
|
}
|
|
|
|
#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
|
|
#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
|
|
#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
|
|
|
|
static const struct xattr_handler sockfs_xattr_handler = {
|
|
.name = XATTR_NAME_SOCKPROTONAME,
|
|
.get = sockfs_xattr_get,
|
|
};
|
|
|
|
static int sockfs_security_xattr_set(const struct xattr_handler *handler,
|
|
struct dentry *dentry, struct inode *inode,
|
|
const char *suffix, const void *value,
|
|
size_t size, int flags)
|
|
{
|
|
/* Handled by LSM. */
|
|
return -EAGAIN;
|
|
}
|
|
|
|
static const struct xattr_handler sockfs_security_xattr_handler = {
|
|
.prefix = XATTR_SECURITY_PREFIX,
|
|
.set = sockfs_security_xattr_set,
|
|
};
|
|
|
|
static const struct xattr_handler *sockfs_xattr_handlers[] = {
|
|
&sockfs_xattr_handler,
|
|
&sockfs_security_xattr_handler,
|
|
NULL
|
|
};
|
|
|
|
static struct dentry *sockfs_mount(struct file_system_type *fs_type,
|
|
int flags, const char *dev_name, void *data)
|
|
{
|
|
return mount_pseudo_xattr(fs_type, "socket:", &sockfs_ops,
|
|
sockfs_xattr_handlers,
|
|
&sockfs_dentry_operations, SOCKFS_MAGIC);
|
|
}
|
|
|
|
static struct vfsmount *sock_mnt __read_mostly;
|
|
|
|
static struct file_system_type sock_fs_type = {
|
|
.name = "sockfs",
|
|
.mount = sockfs_mount,
|
|
.kill_sb = kill_anon_super,
|
|
};
|
|
|
|
/*
|
|
* Obtains the first available file descriptor and sets it up for use.
|
|
*
|
|
* These functions create file structures and maps them to fd space
|
|
* of the current process. On success it returns file descriptor
|
|
* and file struct implicitly stored in sock->file.
|
|
* Note that another thread may close file descriptor before we return
|
|
* from this function. We use the fact that now we do not refer
|
|
* to socket after mapping. If one day we will need it, this
|
|
* function will increment ref. count on file by 1.
|
|
*
|
|
* In any case returned fd MAY BE not valid!
|
|
* This race condition is unavoidable
|
|
* with shared fd spaces, we cannot solve it inside kernel,
|
|
* but we take care of internal coherence yet.
|
|
*/
|
|
|
|
struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
|
|
{
|
|
struct qstr name = { .name = "" };
|
|
struct path path;
|
|
struct file *file;
|
|
|
|
if (dname) {
|
|
name.name = dname;
|
|
name.len = strlen(name.name);
|
|
} else if (sock->sk) {
|
|
name.name = sock->sk->sk_prot_creator->name;
|
|
name.len = strlen(name.name);
|
|
}
|
|
path.dentry = d_alloc_pseudo(sock_mnt->mnt_sb, &name);
|
|
if (unlikely(!path.dentry))
|
|
return ERR_PTR(-ENOMEM);
|
|
path.mnt = mntget(sock_mnt);
|
|
|
|
d_instantiate(path.dentry, SOCK_INODE(sock));
|
|
|
|
file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
|
|
&socket_file_ops);
|
|
if (IS_ERR(file)) {
|
|
/* drop dentry, keep inode */
|
|
ihold(d_inode(path.dentry));
|
|
path_put(&path);
|
|
return file;
|
|
}
|
|
|
|
sock->file = file;
|
|
file->f_flags = O_RDWR | (flags & O_NONBLOCK);
|
|
file->private_data = sock;
|
|
return file;
|
|
}
|
|
EXPORT_SYMBOL(sock_alloc_file);
|
|
|
|
static int sock_map_fd(struct socket *sock, int flags)
|
|
{
|
|
struct file *newfile;
|
|
int fd = get_unused_fd_flags(flags);
|
|
if (unlikely(fd < 0))
|
|
return fd;
|
|
|
|
newfile = sock_alloc_file(sock, flags, NULL);
|
|
if (likely(!IS_ERR(newfile))) {
|
|
fd_install(fd, newfile);
|
|
return fd;
|
|
}
|
|
|
|
put_unused_fd(fd);
|
|
return PTR_ERR(newfile);
|
|
}
|
|
|
|
struct socket *sock_from_file(struct file *file, int *err)
|
|
{
|
|
if (file->f_op == &socket_file_ops)
|
|
return file->private_data; /* set in sock_map_fd */
|
|
|
|
*err = -ENOTSOCK;
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(sock_from_file);
|
|
|
|
/**
|
|
* sockfd_lookup - Go from a file number to its socket slot
|
|
* @fd: file handle
|
|
* @err: pointer to an error code return
|
|
*
|
|
* The file handle passed in is locked and the socket it is bound
|
|
* too is returned. If an error occurs the err pointer is overwritten
|
|
* with a negative errno code and NULL is returned. The function checks
|
|
* for both invalid handles and passing a handle which is not a socket.
|
|
*
|
|
* On a success the socket object pointer is returned.
|
|
*/
|
|
|
|
struct socket *sockfd_lookup(int fd, int *err)
|
|
{
|
|
struct file *file;
|
|
struct socket *sock;
|
|
|
|
file = fget(fd);
|
|
if (!file) {
|
|
*err = -EBADF;
|
|
return NULL;
|
|
}
|
|
|
|
sock = sock_from_file(file, err);
|
|
if (!sock)
|
|
fput(file);
|
|
return sock;
|
|
}
|
|
EXPORT_SYMBOL(sockfd_lookup);
|
|
|
|
static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
|
|
{
|
|
struct fd f = fdget(fd);
|
|
struct socket *sock;
|
|
|
|
*err = -EBADF;
|
|
if (f.file) {
|
|
sock = sock_from_file(f.file, err);
|
|
if (likely(sock)) {
|
|
*fput_needed = f.flags & FDPUT_FPUT;
|
|
return sock;
|
|
}
|
|
fdput(f);
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
|
|
size_t size)
|
|
{
|
|
ssize_t len;
|
|
ssize_t used = 0;
|
|
|
|
len = security_inode_listsecurity(d_inode(dentry), buffer, size);
|
|
if (len < 0)
|
|
return len;
|
|
used += len;
|
|
if (buffer) {
|
|
if (size < used)
|
|
return -ERANGE;
|
|
buffer += len;
|
|
}
|
|
|
|
len = (XATTR_NAME_SOCKPROTONAME_LEN + 1);
|
|
used += len;
|
|
if (buffer) {
|
|
if (size < used)
|
|
return -ERANGE;
|
|
memcpy(buffer, XATTR_NAME_SOCKPROTONAME, len);
|
|
buffer += len;
|
|
}
|
|
|
|
return used;
|
|
}
|
|
|
|
static int sockfs_setattr(struct dentry *dentry, struct iattr *iattr)
|
|
{
|
|
int err = simple_setattr(dentry, iattr);
|
|
|
|
if (!err && (iattr->ia_valid & ATTR_UID)) {
|
|
struct socket *sock = SOCKET_I(d_inode(dentry));
|
|
|
|
if (sock->sk)
|
|
sock->sk->sk_uid = iattr->ia_uid;
|
|
else
|
|
err = -ENOENT;
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static const struct inode_operations sockfs_inode_ops = {
|
|
.listxattr = sockfs_listxattr,
|
|
.setattr = sockfs_setattr,
|
|
};
|
|
|
|
/**
|
|
* sock_alloc - allocate a socket
|
|
*
|
|
* Allocate a new inode and socket object. The two are bound together
|
|
* and initialised. The socket is then returned. If we are out of inodes
|
|
* NULL is returned.
|
|
*/
|
|
|
|
struct socket *sock_alloc(void)
|
|
{
|
|
struct inode *inode;
|
|
struct socket *sock;
|
|
|
|
inode = new_inode_pseudo(sock_mnt->mnt_sb);
|
|
if (!inode)
|
|
return NULL;
|
|
|
|
sock = SOCKET_I(inode);
|
|
|
|
kmemcheck_annotate_bitfield(sock, type);
|
|
inode->i_ino = get_next_ino();
|
|
inode->i_mode = S_IFSOCK | S_IRWXUGO;
|
|
inode->i_uid = current_fsuid();
|
|
inode->i_gid = current_fsgid();
|
|
inode->i_op = &sockfs_inode_ops;
|
|
|
|
this_cpu_add(sockets_in_use, 1);
|
|
return sock;
|
|
}
|
|
EXPORT_SYMBOL(sock_alloc);
|
|
|
|
/**
|
|
* sock_release - close a socket
|
|
* @sock: socket to close
|
|
*
|
|
* The socket is released from the protocol stack if it has a release
|
|
* callback, and the inode is then released if the socket is bound to
|
|
* an inode not a file.
|
|
*/
|
|
|
|
static void __sock_release(struct socket *sock, struct inode *inode)
|
|
{
|
|
if (sock->ops) {
|
|
struct module *owner = sock->ops->owner;
|
|
|
|
if (inode)
|
|
inode_lock(inode);
|
|
sock->ops->release(sock);
|
|
sock->sk = NULL;
|
|
if (inode)
|
|
inode_unlock(inode);
|
|
sock->ops = NULL;
|
|
module_put(owner);
|
|
}
|
|
|
|
if (rcu_dereference_protected(sock->wq, 1)->fasync_list)
|
|
pr_err("%s: fasync list not empty!\n", __func__);
|
|
|
|
this_cpu_sub(sockets_in_use, 1);
|
|
if (!sock->file) {
|
|
iput(SOCK_INODE(sock));
|
|
return;
|
|
}
|
|
sock->file = NULL;
|
|
}
|
|
|
|
void sock_release(struct socket *sock)
|
|
{
|
|
__sock_release(sock, NULL);
|
|
}
|
|
EXPORT_SYMBOL(sock_release);
|
|
|
|
void __sock_tx_timestamp(__u16 tsflags, __u8 *tx_flags)
|
|
{
|
|
u8 flags = *tx_flags;
|
|
|
|
if (tsflags & SOF_TIMESTAMPING_TX_HARDWARE)
|
|
flags |= SKBTX_HW_TSTAMP;
|
|
|
|
if (tsflags & SOF_TIMESTAMPING_TX_SOFTWARE)
|
|
flags |= SKBTX_SW_TSTAMP;
|
|
|
|
if (tsflags & SOF_TIMESTAMPING_TX_SCHED)
|
|
flags |= SKBTX_SCHED_TSTAMP;
|
|
|
|
*tx_flags = flags;
|
|
}
|
|
EXPORT_SYMBOL(__sock_tx_timestamp);
|
|
|
|
static inline int sock_sendmsg_nosec(struct socket *sock, struct msghdr *msg)
|
|
{
|
|
int ret = sock->ops->sendmsg(sock, msg, msg_data_left(msg));
|
|
BUG_ON(ret == -EIOCBQUEUED);
|
|
return ret;
|
|
}
|
|
|
|
int sock_sendmsg(struct socket *sock, struct msghdr *msg)
|
|
{
|
|
int err = security_socket_sendmsg(sock, msg,
|
|
msg_data_left(msg));
|
|
|
|
return err ?: sock_sendmsg_nosec(sock, msg);
|
|
}
|
|
EXPORT_SYMBOL(sock_sendmsg);
|
|
|
|
int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
|
|
struct kvec *vec, size_t num, size_t size)
|
|
{
|
|
iov_iter_kvec(&msg->msg_iter, WRITE | ITER_KVEC, vec, num, size);
|
|
return sock_sendmsg(sock, msg);
|
|
}
|
|
EXPORT_SYMBOL(kernel_sendmsg);
|
|
|
|
/*
|
|
* called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP)
|
|
*/
|
|
void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
|
|
struct sk_buff *skb)
|
|
{
|
|
int need_software_tstamp = sock_flag(sk, SOCK_RCVTSTAMP);
|
|
struct scm_timestamping tss;
|
|
int empty = 1;
|
|
struct skb_shared_hwtstamps *shhwtstamps =
|
|
skb_hwtstamps(skb);
|
|
|
|
/* Race occurred between timestamp enabling and packet
|
|
receiving. Fill in the current time for now. */
|
|
if (need_software_tstamp && skb->tstamp.tv64 == 0)
|
|
__net_timestamp(skb);
|
|
|
|
if (need_software_tstamp) {
|
|
if (!sock_flag(sk, SOCK_RCVTSTAMPNS)) {
|
|
struct timeval tv;
|
|
skb_get_timestamp(skb, &tv);
|
|
put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP,
|
|
sizeof(tv), &tv);
|
|
} else {
|
|
struct timespec ts;
|
|
skb_get_timestampns(skb, &ts);
|
|
put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPNS,
|
|
sizeof(ts), &ts);
|
|
}
|
|
}
|
|
|
|
memset(&tss, 0, sizeof(tss));
|
|
if ((sk->sk_tsflags & SOF_TIMESTAMPING_SOFTWARE) &&
|
|
ktime_to_timespec_cond(skb->tstamp, tss.ts + 0))
|
|
empty = 0;
|
|
if (shhwtstamps &&
|
|
(sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
|
|
ktime_to_timespec_cond(shhwtstamps->hwtstamp, tss.ts + 2))
|
|
empty = 0;
|
|
if (!empty)
|
|
put_cmsg(msg, SOL_SOCKET,
|
|
SCM_TIMESTAMPING, sizeof(tss), &tss);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__sock_recv_timestamp);
|
|
|
|
void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
|
|
struct sk_buff *skb)
|
|
{
|
|
int ack;
|
|
|
|
if (!sock_flag(sk, SOCK_WIFI_STATUS))
|
|
return;
|
|
if (!skb->wifi_acked_valid)
|
|
return;
|
|
|
|
ack = skb->wifi_acked;
|
|
|
|
put_cmsg(msg, SOL_SOCKET, SCM_WIFI_STATUS, sizeof(ack), &ack);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__sock_recv_wifi_status);
|
|
|
|
static inline void sock_recv_drops(struct msghdr *msg, struct sock *sk,
|
|
struct sk_buff *skb)
|
|
{
|
|
if (sock_flag(sk, SOCK_RXQ_OVFL) && skb && SOCK_SKB_CB(skb)->dropcount)
|
|
put_cmsg(msg, SOL_SOCKET, SO_RXQ_OVFL,
|
|
sizeof(__u32), &SOCK_SKB_CB(skb)->dropcount);
|
|
}
|
|
|
|
void __sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk,
|
|
struct sk_buff *skb)
|
|
{
|
|
sock_recv_timestamp(msg, sk, skb);
|
|
sock_recv_drops(msg, sk, skb);
|
|
}
|
|
EXPORT_SYMBOL_GPL(__sock_recv_ts_and_drops);
|
|
|
|
static inline int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg,
|
|
int flags)
|
|
{
|
|
return sock->ops->recvmsg(sock, msg, msg_data_left(msg), flags);
|
|
}
|
|
|
|
int sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags)
|
|
{
|
|
int err = security_socket_recvmsg(sock, msg, msg_data_left(msg), flags);
|
|
|
|
return err ?: sock_recvmsg_nosec(sock, msg, flags);
|
|
}
|
|
EXPORT_SYMBOL(sock_recvmsg);
|
|
|
|
/**
|
|
* kernel_recvmsg - Receive a message from a socket (kernel space)
|
|
* @sock: The socket to receive the message from
|
|
* @msg: Received message
|
|
* @vec: Input s/g array for message data
|
|
* @num: Size of input s/g array
|
|
* @size: Number of bytes to read
|
|
* @flags: Message flags (MSG_DONTWAIT, etc...)
|
|
*
|
|
* On return the msg structure contains the scatter/gather array passed in the
|
|
* vec argument. The array is modified so that it consists of the unfilled
|
|
* portion of the original array.
|
|
*
|
|
* The returned value is the total number of bytes received, or an error.
|
|
*/
|
|
int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
|
|
struct kvec *vec, size_t num, size_t size, int flags)
|
|
{
|
|
mm_segment_t oldfs = get_fs();
|
|
int result;
|
|
|
|
iov_iter_kvec(&msg->msg_iter, READ | ITER_KVEC, vec, num, size);
|
|
set_fs(KERNEL_DS);
|
|
result = sock_recvmsg(sock, msg, flags);
|
|
set_fs(oldfs);
|
|
return result;
|
|
}
|
|
EXPORT_SYMBOL(kernel_recvmsg);
|
|
|
|
static ssize_t sock_sendpage(struct file *file, struct page *page,
|
|
int offset, size_t size, loff_t *ppos, int more)
|
|
{
|
|
struct socket *sock;
|
|
int flags;
|
|
|
|
sock = file->private_data;
|
|
|
|
flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0;
|
|
/* more is a combination of MSG_MORE and MSG_SENDPAGE_NOTLAST */
|
|
flags |= more;
|
|
|
|
return kernel_sendpage(sock, page, offset, size, flags);
|
|
}
|
|
|
|
static ssize_t sock_splice_read(struct file *file, loff_t *ppos,
|
|
struct pipe_inode_info *pipe, size_t len,
|
|
unsigned int flags)
|
|
{
|
|
struct socket *sock = file->private_data;
|
|
|
|
if (unlikely(!sock->ops->splice_read))
|
|
return -EINVAL;
|
|
|
|
return sock->ops->splice_read(sock, ppos, pipe, len, flags);
|
|
}
|
|
|
|
static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
|
{
|
|
struct file *file = iocb->ki_filp;
|
|
struct socket *sock = file->private_data;
|
|
struct msghdr msg = {.msg_iter = *to,
|
|
.msg_iocb = iocb};
|
|
ssize_t res;
|
|
|
|
if (file->f_flags & O_NONBLOCK)
|
|
msg.msg_flags = MSG_DONTWAIT;
|
|
|
|
if (iocb->ki_pos != 0)
|
|
return -ESPIPE;
|
|
|
|
if (!iov_iter_count(to)) /* Match SYS5 behaviour */
|
|
return 0;
|
|
|
|
res = sock_recvmsg(sock, &msg, msg.msg_flags);
|
|
*to = msg.msg_iter;
|
|
return res;
|
|
}
|
|
|
|
static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
|
{
|
|
struct file *file = iocb->ki_filp;
|
|
struct socket *sock = file->private_data;
|
|
struct msghdr msg = {.msg_iter = *from,
|
|
.msg_iocb = iocb};
|
|
ssize_t res;
|
|
|
|
if (iocb->ki_pos != 0)
|
|
return -ESPIPE;
|
|
|
|
if (file->f_flags & O_NONBLOCK)
|
|
msg.msg_flags = MSG_DONTWAIT;
|
|
|
|
if (sock->type == SOCK_SEQPACKET)
|
|
msg.msg_flags |= MSG_EOR;
|
|
|
|
res = sock_sendmsg(sock, &msg);
|
|
*from = msg.msg_iter;
|
|
return res;
|
|
}
|
|
|
|
/*
|
|
* Atomic setting of ioctl hooks to avoid race
|
|
* with module unload.
|
|
*/
|
|
|
|
static DEFINE_MUTEX(br_ioctl_mutex);
|
|
static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg);
|
|
|
|
void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *))
|
|
{
|
|
mutex_lock(&br_ioctl_mutex);
|
|
br_ioctl_hook = hook;
|
|
mutex_unlock(&br_ioctl_mutex);
|
|
}
|
|
EXPORT_SYMBOL(brioctl_set);
|
|
|
|
static DEFINE_MUTEX(vlan_ioctl_mutex);
|
|
static int (*vlan_ioctl_hook) (struct net *, void __user *arg);
|
|
|
|
void vlan_ioctl_set(int (*hook) (struct net *, void __user *))
|
|
{
|
|
mutex_lock(&vlan_ioctl_mutex);
|
|
vlan_ioctl_hook = hook;
|
|
mutex_unlock(&vlan_ioctl_mutex);
|
|
}
|
|
EXPORT_SYMBOL(vlan_ioctl_set);
|
|
|
|
static DEFINE_MUTEX(dlci_ioctl_mutex);
|
|
static int (*dlci_ioctl_hook) (unsigned int, void __user *);
|
|
|
|
void dlci_ioctl_set(int (*hook) (unsigned int, void __user *))
|
|
{
|
|
mutex_lock(&dlci_ioctl_mutex);
|
|
dlci_ioctl_hook = hook;
|
|
mutex_unlock(&dlci_ioctl_mutex);
|
|
}
|
|
EXPORT_SYMBOL(dlci_ioctl_set);
|
|
|
|
static long sock_do_ioctl(struct net *net, struct socket *sock,
|
|
unsigned int cmd, unsigned long arg)
|
|
{
|
|
int err;
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
err = sock->ops->ioctl(sock, cmd, arg);
|
|
|
|
/*
|
|
* If this ioctl is unknown try to hand it down
|
|
* to the NIC driver.
|
|
*/
|
|
if (err == -ENOIOCTLCMD)
|
|
err = dev_ioctl(net, cmd, argp);
|
|
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* With an ioctl, arg may well be a user mode pointer, but we don't know
|
|
* what to do with it - that's up to the protocol still.
|
|
*/
|
|
|
|
static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg)
|
|
{
|
|
struct socket *sock;
|
|
struct sock *sk;
|
|
void __user *argp = (void __user *)arg;
|
|
int pid, err;
|
|
struct net *net;
|
|
|
|
sock = file->private_data;
|
|
sk = sock->sk;
|
|
net = sock_net(sk);
|
|
if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
|
|
err = dev_ioctl(net, cmd, argp);
|
|
} else
|
|
#ifdef CONFIG_WEXT_CORE
|
|
if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
|
|
err = dev_ioctl(net, cmd, argp);
|
|
} else
|
|
#endif
|
|
switch (cmd) {
|
|
case FIOSETOWN:
|
|
case SIOCSPGRP:
|
|
err = -EFAULT;
|
|
if (get_user(pid, (int __user *)argp))
|
|
break;
|
|
f_setown(sock->file, pid, 1);
|
|
err = 0;
|
|
break;
|
|
case FIOGETOWN:
|
|
case SIOCGPGRP:
|
|
err = put_user(f_getown(sock->file),
|
|
(int __user *)argp);
|
|
break;
|
|
case SIOCGIFBR:
|
|
case SIOCSIFBR:
|
|
case SIOCBRADDBR:
|
|
case SIOCBRDELBR:
|
|
err = -ENOPKG;
|
|
if (!br_ioctl_hook)
|
|
request_module("bridge");
|
|
|
|
mutex_lock(&br_ioctl_mutex);
|
|
if (br_ioctl_hook)
|
|
err = br_ioctl_hook(net, cmd, argp);
|
|
mutex_unlock(&br_ioctl_mutex);
|
|
break;
|
|
case SIOCGIFVLAN:
|
|
case SIOCSIFVLAN:
|
|
err = -ENOPKG;
|
|
if (!vlan_ioctl_hook)
|
|
request_module("8021q");
|
|
|
|
mutex_lock(&vlan_ioctl_mutex);
|
|
if (vlan_ioctl_hook)
|
|
err = vlan_ioctl_hook(net, argp);
|
|
mutex_unlock(&vlan_ioctl_mutex);
|
|
break;
|
|
case SIOCADDDLCI:
|
|
case SIOCDELDLCI:
|
|
err = -ENOPKG;
|
|
if (!dlci_ioctl_hook)
|
|
request_module("dlci");
|
|
|
|
mutex_lock(&dlci_ioctl_mutex);
|
|
if (dlci_ioctl_hook)
|
|
err = dlci_ioctl_hook(cmd, argp);
|
|
mutex_unlock(&dlci_ioctl_mutex);
|
|
break;
|
|
default:
|
|
err = sock_do_ioctl(net, sock, cmd, arg);
|
|
break;
|
|
}
|
|
return err;
|
|
}
|
|
|
|
int sock_create_lite(int family, int type, int protocol, struct socket **res)
|
|
{
|
|
int err;
|
|
struct socket *sock = NULL;
|
|
|
|
err = security_socket_create(family, type, protocol, 1);
|
|
if (err)
|
|
goto out;
|
|
|
|
sock = sock_alloc();
|
|
if (!sock) {
|
|
err = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
sock->type = type;
|
|
err = security_socket_post_create(sock, family, type, protocol, 1);
|
|
if (err)
|
|
goto out_release;
|
|
|
|
out:
|
|
*res = sock;
|
|
return err;
|
|
out_release:
|
|
sock_release(sock);
|
|
sock = NULL;
|
|
goto out;
|
|
}
|
|
EXPORT_SYMBOL(sock_create_lite);
|
|
|
|
/* No kernel lock held - perfect */
|
|
static unsigned int sock_poll(struct file *file, poll_table *wait)
|
|
{
|
|
unsigned int busy_flag = 0;
|
|
struct socket *sock;
|
|
|
|
/*
|
|
* We can't return errors to poll, so it's either yes or no.
|
|
*/
|
|
sock = file->private_data;
|
|
|
|
if (sk_can_busy_loop(sock->sk)) {
|
|
/* this socket can poll_ll so tell the system call */
|
|
busy_flag = POLL_BUSY_LOOP;
|
|
|
|
/* once, only if requested by syscall */
|
|
if (wait && (wait->_key & POLL_BUSY_LOOP))
|
|
sk_busy_loop(sock->sk, 1);
|
|
}
|
|
|
|
return busy_flag | sock->ops->poll(file, sock, wait);
|
|
}
|
|
|
|
static int sock_mmap(struct file *file, struct vm_area_struct *vma)
|
|
{
|
|
struct socket *sock = file->private_data;
|
|
|
|
return sock->ops->mmap(file, sock, vma);
|
|
}
|
|
|
|
static int sock_close(struct inode *inode, struct file *filp)
|
|
{
|
|
__sock_release(SOCKET_I(inode), inode);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Update the socket async list
|
|
*
|
|
* Fasync_list locking strategy.
|
|
*
|
|
* 1. fasync_list is modified only under process context socket lock
|
|
* i.e. under semaphore.
|
|
* 2. fasync_list is used under read_lock(&sk->sk_callback_lock)
|
|
* or under socket lock
|
|
*/
|
|
|
|
static int sock_fasync(int fd, struct file *filp, int on)
|
|
{
|
|
struct socket *sock = filp->private_data;
|
|
struct sock *sk = sock->sk;
|
|
struct socket_wq *wq;
|
|
|
|
if (sk == NULL)
|
|
return -EINVAL;
|
|
|
|
lock_sock(sk);
|
|
wq = rcu_dereference_protected(sock->wq, lockdep_sock_is_held(sk));
|
|
fasync_helper(fd, filp, on, &wq->fasync_list);
|
|
|
|
if (!wq->fasync_list)
|
|
sock_reset_flag(sk, SOCK_FASYNC);
|
|
else
|
|
sock_set_flag(sk, SOCK_FASYNC);
|
|
|
|
release_sock(sk);
|
|
return 0;
|
|
}
|
|
|
|
/* This function may be called only under rcu_lock */
|
|
|
|
int sock_wake_async(struct socket_wq *wq, int how, int band)
|
|
{
|
|
if (!wq || !wq->fasync_list)
|
|
return -1;
|
|
|
|
switch (how) {
|
|
case SOCK_WAKE_WAITD:
|
|
if (test_bit(SOCKWQ_ASYNC_WAITDATA, &wq->flags))
|
|
break;
|
|
goto call_kill;
|
|
case SOCK_WAKE_SPACE:
|
|
if (!test_and_clear_bit(SOCKWQ_ASYNC_NOSPACE, &wq->flags))
|
|
break;
|
|
/* fall through */
|
|
case SOCK_WAKE_IO:
|
|
call_kill:
|
|
kill_fasync(&wq->fasync_list, SIGIO, band);
|
|
break;
|
|
case SOCK_WAKE_URG:
|
|
kill_fasync(&wq->fasync_list, SIGURG, band);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(sock_wake_async);
|
|
|
|
int __sock_create(struct net *net, int family, int type, int protocol,
|
|
struct socket **res, int kern)
|
|
{
|
|
int err;
|
|
struct socket *sock;
|
|
const struct net_proto_family *pf;
|
|
|
|
/*
|
|
* Check protocol is in range
|
|
*/
|
|
if (family < 0 || family >= NPROTO)
|
|
return -EAFNOSUPPORT;
|
|
if (type < 0 || type >= SOCK_MAX)
|
|
return -EINVAL;
|
|
|
|
/* Compatibility.
|
|
|
|
This uglymoron is moved from INET layer to here to avoid
|
|
deadlock in module load.
|
|
*/
|
|
if (family == PF_INET && type == SOCK_PACKET) {
|
|
pr_info_once("%s uses obsolete (PF_INET,SOCK_PACKET)\n",
|
|
current->comm);
|
|
family = PF_PACKET;
|
|
}
|
|
|
|
err = security_socket_create(family, type, protocol, kern);
|
|
if (err)
|
|
return err;
|
|
|
|
/*
|
|
* Allocate the socket and allow the family to set things up. if
|
|
* the protocol is 0, the family is instructed to select an appropriate
|
|
* default.
|
|
*/
|
|
sock = sock_alloc();
|
|
if (!sock) {
|
|
net_warn_ratelimited("socket: no more sockets\n");
|
|
return -ENFILE; /* Not exactly a match, but its the
|
|
closest posix thing */
|
|
}
|
|
|
|
sock->type = type;
|
|
|
|
#ifdef CONFIG_MODULES
|
|
/* Attempt to load a protocol module if the find failed.
|
|
*
|
|
* 12/09/1996 Marcin: But! this makes REALLY only sense, if the user
|
|
* requested real, full-featured networking support upon configuration.
|
|
* Otherwise module support will break!
|
|
*/
|
|
if (rcu_access_pointer(net_families[family]) == NULL)
|
|
request_module("net-pf-%d", family);
|
|
#endif
|
|
|
|
rcu_read_lock();
|
|
pf = rcu_dereference(net_families[family]);
|
|
err = -EAFNOSUPPORT;
|
|
if (!pf)
|
|
goto out_release;
|
|
|
|
/*
|
|
* We will call the ->create function, that possibly is in a loadable
|
|
* module, so we have to bump that loadable module refcnt first.
|
|
*/
|
|
if (!try_module_get(pf->owner))
|
|
goto out_release;
|
|
|
|
/* Now protected by module ref count */
|
|
rcu_read_unlock();
|
|
|
|
err = pf->create(net, sock, protocol, kern);
|
|
if (err < 0)
|
|
goto out_module_put;
|
|
|
|
/*
|
|
* Now to bump the refcnt of the [loadable] module that owns this
|
|
* socket at sock_release time we decrement its refcnt.
|
|
*/
|
|
if (!try_module_get(sock->ops->owner))
|
|
goto out_module_busy;
|
|
|
|
/*
|
|
* Now that we're done with the ->create function, the [loadable]
|
|
* module can have its refcnt decremented
|
|
*/
|
|
module_put(pf->owner);
|
|
err = security_socket_post_create(sock, family, type, protocol, kern);
|
|
if (err)
|
|
goto out_sock_release;
|
|
*res = sock;
|
|
|
|
return 0;
|
|
|
|
out_module_busy:
|
|
err = -EAFNOSUPPORT;
|
|
out_module_put:
|
|
sock->ops = NULL;
|
|
module_put(pf->owner);
|
|
out_sock_release:
|
|
sock_release(sock);
|
|
return err;
|
|
|
|
out_release:
|
|
rcu_read_unlock();
|
|
goto out_sock_release;
|
|
}
|
|
EXPORT_SYMBOL(__sock_create);
|
|
|
|
int sock_create(int family, int type, int protocol, struct socket **res)
|
|
{
|
|
return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0);
|
|
}
|
|
EXPORT_SYMBOL(sock_create);
|
|
|
|
int sock_create_kern(struct net *net, int family, int type, int protocol, struct socket **res)
|
|
{
|
|
return __sock_create(net, family, type, protocol, res, 1);
|
|
}
|
|
EXPORT_SYMBOL(sock_create_kern);
|
|
|
|
SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
|
|
{
|
|
int retval;
|
|
struct socket *sock;
|
|
int flags;
|
|
|
|
/* Check the SOCK_* constants for consistency. */
|
|
BUILD_BUG_ON(SOCK_CLOEXEC != O_CLOEXEC);
|
|
BUILD_BUG_ON((SOCK_MAX | SOCK_TYPE_MASK) != SOCK_TYPE_MASK);
|
|
BUILD_BUG_ON(SOCK_CLOEXEC & SOCK_TYPE_MASK);
|
|
BUILD_BUG_ON(SOCK_NONBLOCK & SOCK_TYPE_MASK);
|
|
|
|
flags = type & ~SOCK_TYPE_MASK;
|
|
if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
|
|
return -EINVAL;
|
|
type &= SOCK_TYPE_MASK;
|
|
|
|
if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
|
|
flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
|
|
|
|
retval = sock_create(family, type, protocol, &sock);
|
|
if (retval < 0)
|
|
goto out;
|
|
|
|
if (retval == 0)
|
|
sockev_notify(SOCKEV_SOCKET, sock);
|
|
|
|
retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
|
|
if (retval < 0)
|
|
goto out_release;
|
|
|
|
out:
|
|
/* It may be already another descriptor 8) Not kernel problem. */
|
|
return retval;
|
|
|
|
out_release:
|
|
sock_release(sock);
|
|
return retval;
|
|
}
|
|
|
|
/*
|
|
* Create a pair of connected sockets.
|
|
*/
|
|
|
|
SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
|
|
int __user *, usockvec)
|
|
{
|
|
struct socket *sock1, *sock2;
|
|
int fd1, fd2, err;
|
|
struct file *newfile1, *newfile2;
|
|
int flags;
|
|
|
|
flags = type & ~SOCK_TYPE_MASK;
|
|
if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
|
|
return -EINVAL;
|
|
type &= SOCK_TYPE_MASK;
|
|
|
|
if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
|
|
flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
|
|
|
|
/*
|
|
* Obtain the first socket and check if the underlying protocol
|
|
* supports the socketpair call.
|
|
*/
|
|
|
|
err = sock_create(family, type, protocol, &sock1);
|
|
if (err < 0)
|
|
goto out;
|
|
|
|
err = sock_create(family, type, protocol, &sock2);
|
|
if (err < 0)
|
|
goto out_release_1;
|
|
|
|
err = sock1->ops->socketpair(sock1, sock2);
|
|
if (err < 0)
|
|
goto out_release_both;
|
|
|
|
fd1 = get_unused_fd_flags(flags);
|
|
if (unlikely(fd1 < 0)) {
|
|
err = fd1;
|
|
goto out_release_both;
|
|
}
|
|
|
|
fd2 = get_unused_fd_flags(flags);
|
|
if (unlikely(fd2 < 0)) {
|
|
err = fd2;
|
|
goto out_put_unused_1;
|
|
}
|
|
|
|
newfile1 = sock_alloc_file(sock1, flags, NULL);
|
|
if (IS_ERR(newfile1)) {
|
|
err = PTR_ERR(newfile1);
|
|
goto out_put_unused_both;
|
|
}
|
|
|
|
newfile2 = sock_alloc_file(sock2, flags, NULL);
|
|
if (IS_ERR(newfile2)) {
|
|
err = PTR_ERR(newfile2);
|
|
goto out_fput_1;
|
|
}
|
|
|
|
err = put_user(fd1, &usockvec[0]);
|
|
if (err)
|
|
goto out_fput_both;
|
|
|
|
err = put_user(fd2, &usockvec[1]);
|
|
if (err)
|
|
goto out_fput_both;
|
|
|
|
audit_fd_pair(fd1, fd2);
|
|
|
|
fd_install(fd1, newfile1);
|
|
fd_install(fd2, newfile2);
|
|
/* fd1 and fd2 may be already another descriptors.
|
|
* Not kernel problem.
|
|
*/
|
|
|
|
return 0;
|
|
|
|
out_fput_both:
|
|
fput(newfile2);
|
|
fput(newfile1);
|
|
put_unused_fd(fd2);
|
|
put_unused_fd(fd1);
|
|
goto out;
|
|
|
|
out_fput_1:
|
|
fput(newfile1);
|
|
put_unused_fd(fd2);
|
|
put_unused_fd(fd1);
|
|
sock_release(sock2);
|
|
goto out;
|
|
|
|
out_put_unused_both:
|
|
put_unused_fd(fd2);
|
|
out_put_unused_1:
|
|
put_unused_fd(fd1);
|
|
out_release_both:
|
|
sock_release(sock2);
|
|
out_release_1:
|
|
sock_release(sock1);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Bind a name to a socket. Nothing much to do here since it's
|
|
* the protocol's responsibility to handle the local address.
|
|
*
|
|
* We move the socket address to kernel space before we call
|
|
* the protocol layer (having also checked the address is ok).
|
|
*/
|
|
|
|
SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
|
|
{
|
|
struct socket *sock;
|
|
struct sockaddr_storage address;
|
|
int err, fput_needed;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (sock) {
|
|
err = move_addr_to_kernel(umyaddr, addrlen, &address);
|
|
if (err >= 0) {
|
|
err = security_socket_bind(sock,
|
|
(struct sockaddr *)&address,
|
|
addrlen);
|
|
if (!err)
|
|
err = sock->ops->bind(sock,
|
|
(struct sockaddr *)
|
|
&address, addrlen);
|
|
}
|
|
if (!err)
|
|
sockev_notify(SOCKEV_BIND, sock);
|
|
|
|
fput_light(sock->file, fput_needed);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Perform a listen. Basically, we allow the protocol to do anything
|
|
* necessary for a listen, and if that works, we mark the socket as
|
|
* ready for listening.
|
|
*/
|
|
|
|
SYSCALL_DEFINE2(listen, int, fd, int, backlog)
|
|
{
|
|
struct socket *sock;
|
|
int err, fput_needed;
|
|
int somaxconn;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (sock) {
|
|
somaxconn = READ_ONCE(sock_net(sock->sk)->core.sysctl_somaxconn);
|
|
if ((unsigned int)backlog > somaxconn)
|
|
backlog = somaxconn;
|
|
|
|
err = security_socket_listen(sock, backlog);
|
|
if (!err)
|
|
err = sock->ops->listen(sock, backlog);
|
|
|
|
if (!err)
|
|
sockev_notify(SOCKEV_LISTEN, sock);
|
|
|
|
fput_light(sock->file, fput_needed);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* For accept, we attempt to create a new socket, set up the link
|
|
* with the client, wake up the client, then return the new
|
|
* connected fd. We collect the address of the connector in kernel
|
|
* space and move it to user at the very end. This is unclean because
|
|
* we open the socket then return an error.
|
|
*
|
|
* 1003.1g adds the ability to recvmsg() to query connection pending
|
|
* status to recvmsg. We need to add that support in a way thats
|
|
* clean when we restucture accept also.
|
|
*/
|
|
|
|
SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
|
|
int __user *, upeer_addrlen, int, flags)
|
|
{
|
|
struct socket *sock, *newsock;
|
|
struct file *newfile;
|
|
int err, len, newfd, fput_needed;
|
|
struct sockaddr_storage address;
|
|
|
|
if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
|
|
return -EINVAL;
|
|
|
|
if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
|
|
flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
|
|
err = -ENFILE;
|
|
newsock = sock_alloc();
|
|
if (!newsock)
|
|
goto out_put;
|
|
|
|
newsock->type = sock->type;
|
|
newsock->ops = sock->ops;
|
|
|
|
/*
|
|
* We don't need try_module_get here, as the listening socket (sock)
|
|
* has the protocol module (sock->ops->owner) held.
|
|
*/
|
|
__module_get(newsock->ops->owner);
|
|
|
|
newfd = get_unused_fd_flags(flags);
|
|
if (unlikely(newfd < 0)) {
|
|
err = newfd;
|
|
sock_release(newsock);
|
|
goto out_put;
|
|
}
|
|
newfile = sock_alloc_file(newsock, flags, sock->sk->sk_prot_creator->name);
|
|
if (IS_ERR(newfile)) {
|
|
err = PTR_ERR(newfile);
|
|
put_unused_fd(newfd);
|
|
sock_release(newsock);
|
|
goto out_put;
|
|
}
|
|
|
|
err = security_socket_accept(sock, newsock);
|
|
if (err)
|
|
goto out_fd;
|
|
|
|
err = sock->ops->accept(sock, newsock, sock->file->f_flags);
|
|
if (err < 0)
|
|
goto out_fd;
|
|
|
|
if (upeer_sockaddr) {
|
|
if (newsock->ops->getname(newsock, (struct sockaddr *)&address,
|
|
&len, 2) < 0) {
|
|
err = -ECONNABORTED;
|
|
goto out_fd;
|
|
}
|
|
err = move_addr_to_user(&address,
|
|
len, upeer_sockaddr, upeer_addrlen);
|
|
if (err < 0)
|
|
goto out_fd;
|
|
}
|
|
|
|
/* File flags are not inherited via accept() unlike another OSes. */
|
|
|
|
fd_install(newfd, newfile);
|
|
err = newfd;
|
|
if (!err)
|
|
sockev_notify(SOCKEV_ACCEPT, sock);
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
out_fd:
|
|
fput(newfile);
|
|
put_unused_fd(newfd);
|
|
goto out_put;
|
|
}
|
|
|
|
SYSCALL_DEFINE3(accept, int, fd, struct sockaddr __user *, upeer_sockaddr,
|
|
int __user *, upeer_addrlen)
|
|
{
|
|
return sys_accept4(fd, upeer_sockaddr, upeer_addrlen, 0);
|
|
}
|
|
|
|
/*
|
|
* Attempt to connect to a socket with the server address. The address
|
|
* is in user space so we verify it is OK and move it to kernel space.
|
|
*
|
|
* For 1003.1g we need to add clean support for a bind to AF_UNSPEC to
|
|
* break bindings
|
|
*
|
|
* NOTE: 1003.1g draft 6.3 is broken with respect to AX.25/NetROM and
|
|
* other SEQPACKET protocols that take time to connect() as it doesn't
|
|
* include the -EINPROGRESS status for such sockets.
|
|
*/
|
|
|
|
SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
|
|
int, addrlen)
|
|
{
|
|
struct socket *sock;
|
|
struct sockaddr_storage address;
|
|
int err, fput_needed;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
err = move_addr_to_kernel(uservaddr, addrlen, &address);
|
|
if (err < 0)
|
|
goto out_put;
|
|
|
|
err =
|
|
security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
|
|
if (err)
|
|
goto out_put;
|
|
|
|
err = sock->ops->connect(sock, (struct sockaddr *)&address, addrlen,
|
|
sock->file->f_flags);
|
|
if (!err)
|
|
sockev_notify(SOCKEV_CONNECT, sock);
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Get the local address ('name') of a socket object. Move the obtained
|
|
* name to user space.
|
|
*/
|
|
|
|
SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr,
|
|
int __user *, usockaddr_len)
|
|
{
|
|
struct socket *sock;
|
|
struct sockaddr_storage address;
|
|
int len, err, fput_needed;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
|
|
err = security_socket_getsockname(sock);
|
|
if (err)
|
|
goto out_put;
|
|
|
|
err = sock->ops->getname(sock, (struct sockaddr *)&address, &len, 0);
|
|
if (err)
|
|
goto out_put;
|
|
err = move_addr_to_user(&address, len, usockaddr, usockaddr_len);
|
|
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Get the remote address ('name') of a socket object. Move the obtained
|
|
* name to user space.
|
|
*/
|
|
|
|
SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
|
|
int __user *, usockaddr_len)
|
|
{
|
|
struct socket *sock;
|
|
struct sockaddr_storage address;
|
|
int len, err, fput_needed;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (sock != NULL) {
|
|
err = security_socket_getpeername(sock);
|
|
if (err) {
|
|
fput_light(sock->file, fput_needed);
|
|
return err;
|
|
}
|
|
|
|
err =
|
|
sock->ops->getname(sock, (struct sockaddr *)&address, &len,
|
|
1);
|
|
if (!err)
|
|
err = move_addr_to_user(&address, len, usockaddr,
|
|
usockaddr_len);
|
|
fput_light(sock->file, fput_needed);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Send a datagram to a given address. We move the address into kernel
|
|
* space and check the user space data area is readable before invoking
|
|
* the protocol.
|
|
*/
|
|
|
|
SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
|
|
unsigned int, flags, struct sockaddr __user *, addr,
|
|
int, addr_len)
|
|
{
|
|
struct socket *sock;
|
|
struct sockaddr_storage address;
|
|
int err;
|
|
struct msghdr msg;
|
|
struct iovec iov;
|
|
int fput_needed;
|
|
|
|
seemp_logk_sendto(fd, buff, len, flags, addr, addr_len);
|
|
|
|
err = import_single_range(WRITE, buff, len, &iov, &msg.msg_iter);
|
|
if (unlikely(err))
|
|
return err;
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
|
|
msg.msg_name = NULL;
|
|
msg.msg_control = NULL;
|
|
msg.msg_controllen = 0;
|
|
msg.msg_namelen = 0;
|
|
if (addr) {
|
|
err = move_addr_to_kernel(addr, addr_len, &address);
|
|
if (err < 0)
|
|
goto out_put;
|
|
msg.msg_name = (struct sockaddr *)&address;
|
|
msg.msg_namelen = addr_len;
|
|
}
|
|
if (sock->file->f_flags & O_NONBLOCK)
|
|
flags |= MSG_DONTWAIT;
|
|
msg.msg_flags = flags;
|
|
err = sock_sendmsg(sock, &msg);
|
|
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Send a datagram down a socket.
|
|
*/
|
|
|
|
SYSCALL_DEFINE4(send, int, fd, void __user *, buff, size_t, len,
|
|
unsigned int, flags)
|
|
{
|
|
return sys_sendto(fd, buff, len, flags, NULL, 0);
|
|
}
|
|
|
|
/*
|
|
* Receive a frame from the socket and optionally record the address of the
|
|
* sender. We verify the buffers are writable and if needed move the
|
|
* sender address from kernel to user space.
|
|
*/
|
|
|
|
SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
|
|
unsigned int, flags, struct sockaddr __user *, addr,
|
|
int __user *, addr_len)
|
|
{
|
|
struct socket *sock;
|
|
struct iovec iov;
|
|
struct msghdr msg;
|
|
struct sockaddr_storage address;
|
|
int err, err2;
|
|
int fput_needed;
|
|
|
|
err = import_single_range(READ, ubuf, size, &iov, &msg.msg_iter);
|
|
if (unlikely(err))
|
|
return err;
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
|
|
msg.msg_control = NULL;
|
|
msg.msg_controllen = 0;
|
|
/* Save some cycles and don't copy the address if not needed */
|
|
msg.msg_name = addr ? (struct sockaddr *)&address : NULL;
|
|
/* We assume all kernel code knows the size of sockaddr_storage */
|
|
msg.msg_namelen = 0;
|
|
msg.msg_iocb = NULL;
|
|
msg.msg_flags = 0;
|
|
if (sock->file->f_flags & O_NONBLOCK)
|
|
flags |= MSG_DONTWAIT;
|
|
err = sock_recvmsg(sock, &msg, flags);
|
|
|
|
if (err >= 0 && addr != NULL) {
|
|
err2 = move_addr_to_user(&address,
|
|
msg.msg_namelen, addr, addr_len);
|
|
if (err2 < 0)
|
|
err = err2;
|
|
}
|
|
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Receive a datagram from a socket.
|
|
*/
|
|
|
|
SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,
|
|
unsigned int, flags)
|
|
{
|
|
return sys_recvfrom(fd, ubuf, size, flags, NULL, NULL);
|
|
}
|
|
|
|
/*
|
|
* Set a socket option. Because we don't know the option lengths we have
|
|
* to pass the user mode parameter for the protocols to sort out.
|
|
*/
|
|
|
|
SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname,
|
|
char __user *, optval, int, optlen)
|
|
{
|
|
int err, fput_needed;
|
|
struct socket *sock;
|
|
|
|
if (optlen < 0)
|
|
return -EINVAL;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (sock != NULL) {
|
|
err = security_socket_setsockopt(sock, level, optname);
|
|
if (err)
|
|
goto out_put;
|
|
|
|
if (level == SOL_SOCKET)
|
|
err =
|
|
sock_setsockopt(sock, level, optname, optval,
|
|
optlen);
|
|
else
|
|
err =
|
|
sock->ops->setsockopt(sock, level, optname, optval,
|
|
optlen);
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Get a socket option. Because we don't know the option lengths we have
|
|
* to pass a user mode parameter for the protocols to sort out.
|
|
*/
|
|
|
|
SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,
|
|
char __user *, optval, int __user *, optlen)
|
|
{
|
|
int err, fput_needed;
|
|
struct socket *sock;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (sock != NULL) {
|
|
err = security_socket_getsockopt(sock, level, optname);
|
|
if (err)
|
|
goto out_put;
|
|
|
|
if (level == SOL_SOCKET)
|
|
err =
|
|
sock_getsockopt(sock, level, optname, optval,
|
|
optlen);
|
|
else
|
|
err =
|
|
sock->ops->getsockopt(sock, level, optname, optval,
|
|
optlen);
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Shutdown a socket.
|
|
*/
|
|
|
|
SYSCALL_DEFINE2(shutdown, int, fd, int, how)
|
|
{
|
|
int err, fput_needed;
|
|
struct socket *sock;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (sock != NULL) {
|
|
sockev_notify(SOCKEV_SHUTDOWN, sock);
|
|
err = security_socket_shutdown(sock, how);
|
|
if (!err)
|
|
err = sock->ops->shutdown(sock, how);
|
|
fput_light(sock->file, fput_needed);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
/* A couple of helpful macros for getting the address of the 32/64 bit
|
|
* fields which are the same type (int / unsigned) on our platforms.
|
|
*/
|
|
#define COMPAT_MSG(msg, member) ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member)
|
|
#define COMPAT_NAMELEN(msg) COMPAT_MSG(msg, msg_namelen)
|
|
#define COMPAT_FLAGS(msg) COMPAT_MSG(msg, msg_flags)
|
|
|
|
struct used_address {
|
|
struct sockaddr_storage name;
|
|
unsigned int name_len;
|
|
};
|
|
|
|
static int copy_msghdr_from_user(struct msghdr *kmsg,
|
|
struct user_msghdr __user *umsg,
|
|
struct sockaddr __user **save_addr,
|
|
struct iovec **iov)
|
|
{
|
|
struct sockaddr __user *uaddr;
|
|
struct iovec __user *uiov;
|
|
size_t nr_segs;
|
|
ssize_t err;
|
|
|
|
if (!access_ok(VERIFY_READ, umsg, sizeof(*umsg)) ||
|
|
__get_user(uaddr, &umsg->msg_name) ||
|
|
__get_user(kmsg->msg_namelen, &umsg->msg_namelen) ||
|
|
__get_user(uiov, &umsg->msg_iov) ||
|
|
__get_user(nr_segs, &umsg->msg_iovlen) ||
|
|
__get_user(kmsg->msg_control, &umsg->msg_control) ||
|
|
__get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
|
|
__get_user(kmsg->msg_flags, &umsg->msg_flags))
|
|
return -EFAULT;
|
|
|
|
if (!uaddr)
|
|
kmsg->msg_namelen = 0;
|
|
|
|
if (kmsg->msg_namelen < 0)
|
|
return -EINVAL;
|
|
|
|
if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
|
|
kmsg->msg_namelen = sizeof(struct sockaddr_storage);
|
|
|
|
if (save_addr)
|
|
*save_addr = uaddr;
|
|
|
|
if (uaddr && kmsg->msg_namelen) {
|
|
if (!save_addr) {
|
|
err = move_addr_to_kernel(uaddr, kmsg->msg_namelen,
|
|
kmsg->msg_name);
|
|
if (err < 0)
|
|
return err;
|
|
}
|
|
} else {
|
|
kmsg->msg_name = NULL;
|
|
kmsg->msg_namelen = 0;
|
|
}
|
|
|
|
if (nr_segs > UIO_MAXIOV)
|
|
return -EMSGSIZE;
|
|
|
|
kmsg->msg_iocb = NULL;
|
|
|
|
return import_iovec(save_addr ? READ : WRITE, uiov, nr_segs,
|
|
UIO_FASTIOV, iov, &kmsg->msg_iter);
|
|
}
|
|
|
|
static int ___sys_sendmsg(struct socket *sock, struct user_msghdr __user *msg,
|
|
struct msghdr *msg_sys, unsigned int flags,
|
|
struct used_address *used_address,
|
|
unsigned int allowed_msghdr_flags)
|
|
{
|
|
struct compat_msghdr __user *msg_compat =
|
|
(struct compat_msghdr __user *)msg;
|
|
struct sockaddr_storage address;
|
|
struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
|
|
unsigned char ctl[sizeof(struct cmsghdr) + 20]
|
|
__attribute__ ((aligned(sizeof(__kernel_size_t))));
|
|
/* 20 is size of ipv6_pktinfo */
|
|
unsigned char *ctl_buf = ctl;
|
|
int ctl_len;
|
|
ssize_t err;
|
|
|
|
msg_sys->msg_name = &address;
|
|
|
|
if (MSG_CMSG_COMPAT & flags)
|
|
err = get_compat_msghdr(msg_sys, msg_compat, NULL, &iov);
|
|
else
|
|
err = copy_msghdr_from_user(msg_sys, msg, NULL, &iov);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
err = -ENOBUFS;
|
|
|
|
if (msg_sys->msg_controllen > INT_MAX)
|
|
goto out_freeiov;
|
|
flags |= (msg_sys->msg_flags & allowed_msghdr_flags);
|
|
ctl_len = msg_sys->msg_controllen;
|
|
if ((MSG_CMSG_COMPAT & flags) && ctl_len) {
|
|
err =
|
|
cmsghdr_from_user_compat_to_kern(msg_sys, sock->sk, ctl,
|
|
sizeof(ctl));
|
|
if (err)
|
|
goto out_freeiov;
|
|
ctl_buf = msg_sys->msg_control;
|
|
ctl_len = msg_sys->msg_controllen;
|
|
} else if (ctl_len) {
|
|
if (ctl_len > sizeof(ctl)) {
|
|
ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL);
|
|
if (ctl_buf == NULL)
|
|
goto out_freeiov;
|
|
}
|
|
err = -EFAULT;
|
|
/*
|
|
* Careful! Before this, msg_sys->msg_control contains a user pointer.
|
|
* Afterwards, it will be a kernel pointer. Thus the compiler-assisted
|
|
* checking falls down on this.
|
|
*/
|
|
if (copy_from_user(ctl_buf,
|
|
(void __user __force *)msg_sys->msg_control,
|
|
ctl_len))
|
|
goto out_freectl;
|
|
msg_sys->msg_control = ctl_buf;
|
|
}
|
|
msg_sys->msg_flags = flags;
|
|
|
|
if (sock->file->f_flags & O_NONBLOCK)
|
|
msg_sys->msg_flags |= MSG_DONTWAIT;
|
|
/*
|
|
* If this is sendmmsg() and current destination address is same as
|
|
* previously succeeded address, omit asking LSM's decision.
|
|
* used_address->name_len is initialized to UINT_MAX so that the first
|
|
* destination address never matches.
|
|
*/
|
|
if (used_address && msg_sys->msg_name &&
|
|
used_address->name_len == msg_sys->msg_namelen &&
|
|
!memcmp(&used_address->name, msg_sys->msg_name,
|
|
used_address->name_len)) {
|
|
err = sock_sendmsg_nosec(sock, msg_sys);
|
|
goto out_freectl;
|
|
}
|
|
err = sock_sendmsg(sock, msg_sys);
|
|
/*
|
|
* If this is sendmmsg() and sending to current destination address was
|
|
* successful, remember it.
|
|
*/
|
|
if (used_address && err >= 0) {
|
|
used_address->name_len = msg_sys->msg_namelen;
|
|
if (msg_sys->msg_name)
|
|
memcpy(&used_address->name, msg_sys->msg_name,
|
|
used_address->name_len);
|
|
}
|
|
|
|
out_freectl:
|
|
if (ctl_buf != ctl)
|
|
sock_kfree_s(sock->sk, ctl_buf, ctl_len);
|
|
out_freeiov:
|
|
kfree(iov);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* BSD sendmsg interface
|
|
*/
|
|
|
|
long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned flags)
|
|
{
|
|
int fput_needed, err;
|
|
struct msghdr msg_sys;
|
|
struct socket *sock;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
|
|
err = ___sys_sendmsg(sock, msg, &msg_sys, flags, NULL, 0);
|
|
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
SYSCALL_DEFINE3(sendmsg, int, fd, struct user_msghdr __user *, msg, unsigned int, flags)
|
|
{
|
|
if (flags & MSG_CMSG_COMPAT)
|
|
return -EINVAL;
|
|
return __sys_sendmsg(fd, msg, flags);
|
|
}
|
|
|
|
/*
|
|
* Linux sendmmsg interface
|
|
*/
|
|
|
|
int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
|
|
unsigned int flags)
|
|
{
|
|
int fput_needed, err, datagrams;
|
|
struct socket *sock;
|
|
struct mmsghdr __user *entry;
|
|
struct compat_mmsghdr __user *compat_entry;
|
|
struct msghdr msg_sys;
|
|
struct used_address used_address;
|
|
unsigned int oflags = flags;
|
|
|
|
if (vlen > UIO_MAXIOV)
|
|
vlen = UIO_MAXIOV;
|
|
|
|
datagrams = 0;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
return err;
|
|
|
|
used_address.name_len = UINT_MAX;
|
|
entry = mmsg;
|
|
compat_entry = (struct compat_mmsghdr __user *)mmsg;
|
|
err = 0;
|
|
flags |= MSG_BATCH;
|
|
|
|
while (datagrams < vlen) {
|
|
if (datagrams == vlen - 1)
|
|
flags = oflags;
|
|
|
|
if (MSG_CMSG_COMPAT & flags) {
|
|
err = ___sys_sendmsg(sock, (struct user_msghdr __user *)compat_entry,
|
|
&msg_sys, flags, &used_address, MSG_EOR);
|
|
if (err < 0)
|
|
break;
|
|
err = __put_user(err, &compat_entry->msg_len);
|
|
++compat_entry;
|
|
} else {
|
|
err = ___sys_sendmsg(sock,
|
|
(struct user_msghdr __user *)entry,
|
|
&msg_sys, flags, &used_address, MSG_EOR);
|
|
if (err < 0)
|
|
break;
|
|
err = put_user(err, &entry->msg_len);
|
|
++entry;
|
|
}
|
|
|
|
if (err)
|
|
break;
|
|
++datagrams;
|
|
if (msg_data_left(&msg_sys))
|
|
break;
|
|
cond_resched();
|
|
}
|
|
|
|
fput_light(sock->file, fput_needed);
|
|
|
|
/* We only return an error if no datagrams were able to be sent */
|
|
if (datagrams != 0)
|
|
return datagrams;
|
|
|
|
return err;
|
|
}
|
|
|
|
SYSCALL_DEFINE4(sendmmsg, int, fd, struct mmsghdr __user *, mmsg,
|
|
unsigned int, vlen, unsigned int, flags)
|
|
{
|
|
if (flags & MSG_CMSG_COMPAT)
|
|
return -EINVAL;
|
|
return __sys_sendmmsg(fd, mmsg, vlen, flags);
|
|
}
|
|
|
|
static int ___sys_recvmsg(struct socket *sock, struct user_msghdr __user *msg,
|
|
struct msghdr *msg_sys, unsigned int flags, int nosec)
|
|
{
|
|
struct compat_msghdr __user *msg_compat =
|
|
(struct compat_msghdr __user *)msg;
|
|
struct iovec iovstack[UIO_FASTIOV];
|
|
struct iovec *iov = iovstack;
|
|
unsigned long cmsg_ptr;
|
|
int len;
|
|
ssize_t err;
|
|
|
|
/* kernel mode address */
|
|
struct sockaddr_storage addr;
|
|
|
|
/* user mode address pointers */
|
|
struct sockaddr __user *uaddr;
|
|
int __user *uaddr_len = COMPAT_NAMELEN(msg);
|
|
|
|
msg_sys->msg_name = &addr;
|
|
|
|
if (MSG_CMSG_COMPAT & flags)
|
|
err = get_compat_msghdr(msg_sys, msg_compat, &uaddr, &iov);
|
|
else
|
|
err = copy_msghdr_from_user(msg_sys, msg, &uaddr, &iov);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
cmsg_ptr = (unsigned long)msg_sys->msg_control;
|
|
msg_sys->msg_flags = flags & (MSG_CMSG_CLOEXEC|MSG_CMSG_COMPAT);
|
|
|
|
/* We assume all kernel code knows the size of sockaddr_storage */
|
|
msg_sys->msg_namelen = 0;
|
|
|
|
if (sock->file->f_flags & O_NONBLOCK)
|
|
flags |= MSG_DONTWAIT;
|
|
err = (nosec ? sock_recvmsg_nosec : sock_recvmsg)(sock, msg_sys, flags);
|
|
if (err < 0)
|
|
goto out_freeiov;
|
|
len = err;
|
|
|
|
if (uaddr != NULL) {
|
|
err = move_addr_to_user(&addr,
|
|
msg_sys->msg_namelen, uaddr,
|
|
uaddr_len);
|
|
if (err < 0)
|
|
goto out_freeiov;
|
|
}
|
|
err = __put_user((msg_sys->msg_flags & ~MSG_CMSG_COMPAT),
|
|
COMPAT_FLAGS(msg));
|
|
if (err)
|
|
goto out_freeiov;
|
|
if (MSG_CMSG_COMPAT & flags)
|
|
err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr,
|
|
&msg_compat->msg_controllen);
|
|
else
|
|
err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr,
|
|
&msg->msg_controllen);
|
|
if (err)
|
|
goto out_freeiov;
|
|
err = len;
|
|
|
|
out_freeiov:
|
|
kfree(iov);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* BSD recvmsg interface
|
|
*/
|
|
|
|
long __sys_recvmsg(int fd, struct user_msghdr __user *msg, unsigned flags)
|
|
{
|
|
int fput_needed, err;
|
|
struct msghdr msg_sys;
|
|
struct socket *sock;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
goto out;
|
|
|
|
err = ___sys_recvmsg(sock, msg, &msg_sys, flags, 0);
|
|
|
|
fput_light(sock->file, fput_needed);
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg,
|
|
unsigned int, flags)
|
|
{
|
|
if (flags & MSG_CMSG_COMPAT)
|
|
return -EINVAL;
|
|
return __sys_recvmsg(fd, msg, flags);
|
|
}
|
|
|
|
/*
|
|
* Linux recvmmsg interface
|
|
*/
|
|
|
|
int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
|
|
unsigned int flags, struct timespec *timeout)
|
|
{
|
|
int fput_needed, err, datagrams;
|
|
struct socket *sock;
|
|
struct mmsghdr __user *entry;
|
|
struct compat_mmsghdr __user *compat_entry;
|
|
struct msghdr msg_sys;
|
|
struct timespec64 end_time;
|
|
struct timespec64 timeout64;
|
|
|
|
if (timeout &&
|
|
poll_select_set_timeout(&end_time, timeout->tv_sec,
|
|
timeout->tv_nsec))
|
|
return -EINVAL;
|
|
|
|
datagrams = 0;
|
|
|
|
sock = sockfd_lookup_light(fd, &err, &fput_needed);
|
|
if (!sock)
|
|
return err;
|
|
|
|
err = sock_error(sock->sk);
|
|
if (err) {
|
|
datagrams = err;
|
|
goto out_put;
|
|
}
|
|
|
|
entry = mmsg;
|
|
compat_entry = (struct compat_mmsghdr __user *)mmsg;
|
|
|
|
while (datagrams < vlen) {
|
|
/*
|
|
* No need to ask LSM for more than the first datagram.
|
|
*/
|
|
if (MSG_CMSG_COMPAT & flags) {
|
|
err = ___sys_recvmsg(sock, (struct user_msghdr __user *)compat_entry,
|
|
&msg_sys, flags & ~MSG_WAITFORONE,
|
|
datagrams);
|
|
if (err < 0)
|
|
break;
|
|
err = __put_user(err, &compat_entry->msg_len);
|
|
++compat_entry;
|
|
} else {
|
|
err = ___sys_recvmsg(sock,
|
|
(struct user_msghdr __user *)entry,
|
|
&msg_sys, flags & ~MSG_WAITFORONE,
|
|
datagrams);
|
|
if (err < 0)
|
|
break;
|
|
err = put_user(err, &entry->msg_len);
|
|
++entry;
|
|
}
|
|
|
|
if (err)
|
|
break;
|
|
++datagrams;
|
|
|
|
/* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */
|
|
if (flags & MSG_WAITFORONE)
|
|
flags |= MSG_DONTWAIT;
|
|
|
|
if (timeout) {
|
|
ktime_get_ts64(&timeout64);
|
|
*timeout = timespec64_to_timespec(
|
|
timespec64_sub(end_time, timeout64));
|
|
if (timeout->tv_sec < 0) {
|
|
timeout->tv_sec = timeout->tv_nsec = 0;
|
|
break;
|
|
}
|
|
|
|
/* Timeout, return less than vlen datagrams */
|
|
if (timeout->tv_nsec == 0 && timeout->tv_sec == 0)
|
|
break;
|
|
}
|
|
|
|
/* Out of band data, return right away */
|
|
if (msg_sys.msg_flags & MSG_OOB)
|
|
break;
|
|
cond_resched();
|
|
}
|
|
|
|
if (err == 0)
|
|
goto out_put;
|
|
|
|
if (datagrams == 0) {
|
|
datagrams = err;
|
|
goto out_put;
|
|
}
|
|
|
|
/*
|
|
* We may return less entries than requested (vlen) if the
|
|
* sock is non block and there aren't enough datagrams...
|
|
*/
|
|
if (err != -EAGAIN) {
|
|
/*
|
|
* ... or if recvmsg returns an error after we
|
|
* received some datagrams, where we record the
|
|
* error to return on the next call or if the
|
|
* app asks about it using getsockopt(SO_ERROR).
|
|
*/
|
|
sock->sk->sk_err = -err;
|
|
}
|
|
out_put:
|
|
fput_light(sock->file, fput_needed);
|
|
|
|
return datagrams;
|
|
}
|
|
|
|
SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg,
|
|
unsigned int, vlen, unsigned int, flags,
|
|
struct timespec __user *, timeout)
|
|
{
|
|
int datagrams;
|
|
struct timespec timeout_sys;
|
|
|
|
if (flags & MSG_CMSG_COMPAT)
|
|
return -EINVAL;
|
|
|
|
if (!timeout)
|
|
return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL);
|
|
|
|
if (copy_from_user(&timeout_sys, timeout, sizeof(timeout_sys)))
|
|
return -EFAULT;
|
|
|
|
datagrams = __sys_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys);
|
|
|
|
if (datagrams > 0 &&
|
|
copy_to_user(timeout, &timeout_sys, sizeof(timeout_sys)))
|
|
datagrams = -EFAULT;
|
|
|
|
return datagrams;
|
|
}
|
|
|
|
#ifdef __ARCH_WANT_SYS_SOCKETCALL
|
|
/* Argument list sizes for sys_socketcall */
|
|
#define AL(x) ((x) * sizeof(unsigned long))
|
|
static const unsigned char nargs[21] = {
|
|
AL(0), AL(3), AL(3), AL(3), AL(2), AL(3),
|
|
AL(3), AL(3), AL(4), AL(4), AL(4), AL(6),
|
|
AL(6), AL(2), AL(5), AL(5), AL(3), AL(3),
|
|
AL(4), AL(5), AL(4)
|
|
};
|
|
|
|
#undef AL
|
|
|
|
/*
|
|
* System call vectors.
|
|
*
|
|
* Argument checking cleaned up. Saved 20% in size.
|
|
* This function doesn't need to set the kernel lock because
|
|
* it is set by the callees.
|
|
*/
|
|
|
|
SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args)
|
|
{
|
|
unsigned long a[AUDITSC_ARGS];
|
|
unsigned long a0, a1;
|
|
int err;
|
|
unsigned int len;
|
|
|
|
if (call < 1 || call > SYS_SENDMMSG)
|
|
return -EINVAL;
|
|
call = array_index_nospec(call, SYS_SENDMMSG + 1);
|
|
|
|
len = nargs[call];
|
|
if (len > sizeof(a))
|
|
return -EINVAL;
|
|
|
|
/* copy_from_user should be SMP safe. */
|
|
if (copy_from_user(a, args, len))
|
|
return -EFAULT;
|
|
|
|
err = audit_socketcall(nargs[call] / sizeof(unsigned long), a);
|
|
if (err)
|
|
return err;
|
|
|
|
a0 = a[0];
|
|
a1 = a[1];
|
|
|
|
switch (call) {
|
|
case SYS_SOCKET:
|
|
err = sys_socket(a0, a1, a[2]);
|
|
break;
|
|
case SYS_BIND:
|
|
err = sys_bind(a0, (struct sockaddr __user *)a1, a[2]);
|
|
break;
|
|
case SYS_CONNECT:
|
|
err = sys_connect(a0, (struct sockaddr __user *)a1, a[2]);
|
|
break;
|
|
case SYS_LISTEN:
|
|
err = sys_listen(a0, a1);
|
|
break;
|
|
case SYS_ACCEPT:
|
|
err = sys_accept4(a0, (struct sockaddr __user *)a1,
|
|
(int __user *)a[2], 0);
|
|
break;
|
|
case SYS_GETSOCKNAME:
|
|
err =
|
|
sys_getsockname(a0, (struct sockaddr __user *)a1,
|
|
(int __user *)a[2]);
|
|
break;
|
|
case SYS_GETPEERNAME:
|
|
err =
|
|
sys_getpeername(a0, (struct sockaddr __user *)a1,
|
|
(int __user *)a[2]);
|
|
break;
|
|
case SYS_SOCKETPAIR:
|
|
err = sys_socketpair(a0, a1, a[2], (int __user *)a[3]);
|
|
break;
|
|
case SYS_SEND:
|
|
err = sys_send(a0, (void __user *)a1, a[2], a[3]);
|
|
break;
|
|
case SYS_SENDTO:
|
|
err = sys_sendto(a0, (void __user *)a1, a[2], a[3],
|
|
(struct sockaddr __user *)a[4], a[5]);
|
|
break;
|
|
case SYS_RECV:
|
|
err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
|
|
break;
|
|
case SYS_RECVFROM:
|
|
err = sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
|
|
(struct sockaddr __user *)a[4],
|
|
(int __user *)a[5]);
|
|
break;
|
|
case SYS_SHUTDOWN:
|
|
err = sys_shutdown(a0, a1);
|
|
break;
|
|
case SYS_SETSOCKOPT:
|
|
err = sys_setsockopt(a0, a1, a[2], (char __user *)a[3], a[4]);
|
|
break;
|
|
case SYS_GETSOCKOPT:
|
|
err =
|
|
sys_getsockopt(a0, a1, a[2], (char __user *)a[3],
|
|
(int __user *)a[4]);
|
|
break;
|
|
case SYS_SENDMSG:
|
|
err = sys_sendmsg(a0, (struct user_msghdr __user *)a1, a[2]);
|
|
break;
|
|
case SYS_SENDMMSG:
|
|
err = sys_sendmmsg(a0, (struct mmsghdr __user *)a1, a[2], a[3]);
|
|
break;
|
|
case SYS_RECVMSG:
|
|
err = sys_recvmsg(a0, (struct user_msghdr __user *)a1, a[2]);
|
|
break;
|
|
case SYS_RECVMMSG:
|
|
err = sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], a[3],
|
|
(struct timespec __user *)a[4]);
|
|
break;
|
|
case SYS_ACCEPT4:
|
|
err = sys_accept4(a0, (struct sockaddr __user *)a1,
|
|
(int __user *)a[2], a[3]);
|
|
break;
|
|
default:
|
|
err = -EINVAL;
|
|
break;
|
|
}
|
|
return err;
|
|
}
|
|
|
|
#endif /* __ARCH_WANT_SYS_SOCKETCALL */
|
|
|
|
/**
|
|
* sock_register - add a socket protocol handler
|
|
* @ops: description of protocol
|
|
*
|
|
* This function is called by a protocol handler that wants to
|
|
* advertise its address family, and have it linked into the
|
|
* socket interface. The value ops->family corresponds to the
|
|
* socket system call protocol family.
|
|
*/
|
|
int sock_register(const struct net_proto_family *ops)
|
|
{
|
|
int err;
|
|
|
|
if (ops->family >= NPROTO) {
|
|
pr_crit("protocol %d >= NPROTO(%d)\n", ops->family, NPROTO);
|
|
return -ENOBUFS;
|
|
}
|
|
|
|
spin_lock(&net_family_lock);
|
|
if (rcu_dereference_protected(net_families[ops->family],
|
|
lockdep_is_held(&net_family_lock)))
|
|
err = -EEXIST;
|
|
else {
|
|
rcu_assign_pointer(net_families[ops->family], ops);
|
|
err = 0;
|
|
}
|
|
spin_unlock(&net_family_lock);
|
|
|
|
pr_info("NET: Registered protocol family %d\n", ops->family);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(sock_register);
|
|
|
|
/**
|
|
* sock_unregister - remove a protocol handler
|
|
* @family: protocol family to remove
|
|
*
|
|
* This function is called by a protocol handler that wants to
|
|
* remove its address family, and have it unlinked from the
|
|
* new socket creation.
|
|
*
|
|
* If protocol handler is a module, then it can use module reference
|
|
* counts to protect against new references. If protocol handler is not
|
|
* a module then it needs to provide its own protection in
|
|
* the ops->create routine.
|
|
*/
|
|
void sock_unregister(int family)
|
|
{
|
|
BUG_ON(family < 0 || family >= NPROTO);
|
|
|
|
spin_lock(&net_family_lock);
|
|
RCU_INIT_POINTER(net_families[family], NULL);
|
|
spin_unlock(&net_family_lock);
|
|
|
|
synchronize_rcu();
|
|
|
|
pr_info("NET: Unregistered protocol family %d\n", family);
|
|
}
|
|
EXPORT_SYMBOL(sock_unregister);
|
|
|
|
static int __init sock_init(void)
|
|
{
|
|
int err;
|
|
/*
|
|
* Initialize the network sysctl infrastructure.
|
|
*/
|
|
err = net_sysctl_init();
|
|
if (err)
|
|
goto out;
|
|
|
|
/*
|
|
* Initialize skbuff SLAB cache
|
|
*/
|
|
skb_init();
|
|
|
|
/*
|
|
* Initialize the protocols module.
|
|
*/
|
|
|
|
init_inodecache();
|
|
|
|
err = register_filesystem(&sock_fs_type);
|
|
if (err)
|
|
goto out_fs;
|
|
sock_mnt = kern_mount(&sock_fs_type);
|
|
if (IS_ERR(sock_mnt)) {
|
|
err = PTR_ERR(sock_mnt);
|
|
goto out_mount;
|
|
}
|
|
|
|
/* The real protocol initialization is performed in later initcalls.
|
|
*/
|
|
|
|
#ifdef CONFIG_NETFILTER
|
|
err = netfilter_init();
|
|
if (err)
|
|
goto out;
|
|
#endif
|
|
|
|
ptp_classifier_init();
|
|
|
|
out:
|
|
return err;
|
|
|
|
out_mount:
|
|
unregister_filesystem(&sock_fs_type);
|
|
out_fs:
|
|
goto out;
|
|
}
|
|
|
|
core_initcall(sock_init); /* early initcall */
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
void socket_seq_show(struct seq_file *seq)
|
|
{
|
|
int cpu;
|
|
int counter = 0;
|
|
|
|
for_each_possible_cpu(cpu)
|
|
counter += per_cpu(sockets_in_use, cpu);
|
|
|
|
/* It can be negative, by the way. 8) */
|
|
if (counter < 0)
|
|
counter = 0;
|
|
|
|
seq_printf(seq, "sockets: used %d\n", counter);
|
|
}
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
static int do_siocgstamp(struct net *net, struct socket *sock,
|
|
unsigned int cmd, void __user *up)
|
|
{
|
|
mm_segment_t old_fs = get_fs();
|
|
struct timeval ktv;
|
|
int err;
|
|
|
|
set_fs(KERNEL_DS);
|
|
err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv);
|
|
set_fs(old_fs);
|
|
if (!err)
|
|
err = compat_put_timeval(&ktv, up);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int do_siocgstampns(struct net *net, struct socket *sock,
|
|
unsigned int cmd, void __user *up)
|
|
{
|
|
mm_segment_t old_fs = get_fs();
|
|
struct timespec kts;
|
|
int err;
|
|
|
|
set_fs(KERNEL_DS);
|
|
err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts);
|
|
set_fs(old_fs);
|
|
if (!err)
|
|
err = compat_put_timespec(&kts, up);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int dev_ifname32(struct net *net, struct compat_ifreq __user *uifr32)
|
|
{
|
|
struct ifreq __user *uifr;
|
|
int err;
|
|
|
|
uifr = compat_alloc_user_space(sizeof(struct ifreq));
|
|
if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
|
|
return -EFAULT;
|
|
|
|
err = dev_ioctl(net, SIOCGIFNAME, uifr);
|
|
if (err)
|
|
return err;
|
|
|
|
if (copy_in_user(uifr32, uifr, sizeof(struct compat_ifreq)))
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32)
|
|
{
|
|
struct compat_ifconf ifc32;
|
|
struct ifconf ifc;
|
|
struct ifconf __user *uifc;
|
|
struct compat_ifreq __user *ifr32;
|
|
struct ifreq __user *ifr;
|
|
unsigned int i, j;
|
|
int err;
|
|
|
|
if (copy_from_user(&ifc32, uifc32, sizeof(struct compat_ifconf)))
|
|
return -EFAULT;
|
|
|
|
memset(&ifc, 0, sizeof(ifc));
|
|
if (ifc32.ifcbuf == 0) {
|
|
ifc32.ifc_len = 0;
|
|
ifc.ifc_len = 0;
|
|
ifc.ifc_req = NULL;
|
|
uifc = compat_alloc_user_space(sizeof(struct ifconf));
|
|
} else {
|
|
size_t len = ((ifc32.ifc_len / sizeof(struct compat_ifreq)) + 1) *
|
|
sizeof(struct ifreq);
|
|
uifc = compat_alloc_user_space(sizeof(struct ifconf) + len);
|
|
ifc.ifc_len = len;
|
|
ifr = ifc.ifc_req = (void __user *)(uifc + 1);
|
|
ifr32 = compat_ptr(ifc32.ifcbuf);
|
|
for (i = 0; i < ifc32.ifc_len; i += sizeof(struct compat_ifreq)) {
|
|
if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq)))
|
|
return -EFAULT;
|
|
ifr++;
|
|
ifr32++;
|
|
}
|
|
}
|
|
if (copy_to_user(uifc, &ifc, sizeof(struct ifconf)))
|
|
return -EFAULT;
|
|
|
|
err = dev_ioctl(net, SIOCGIFCONF, uifc);
|
|
if (err)
|
|
return err;
|
|
|
|
if (copy_from_user(&ifc, uifc, sizeof(struct ifconf)))
|
|
return -EFAULT;
|
|
|
|
ifr = ifc.ifc_req;
|
|
ifr32 = compat_ptr(ifc32.ifcbuf);
|
|
for (i = 0, j = 0;
|
|
i + sizeof(struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len;
|
|
i += sizeof(struct compat_ifreq), j += sizeof(struct ifreq)) {
|
|
if (copy_in_user(ifr32, ifr, sizeof(struct compat_ifreq)))
|
|
return -EFAULT;
|
|
ifr32++;
|
|
ifr++;
|
|
}
|
|
|
|
if (ifc32.ifcbuf == 0) {
|
|
/* Translate from 64-bit structure multiple to
|
|
* a 32-bit one.
|
|
*/
|
|
i = ifc.ifc_len;
|
|
i = ((i / sizeof(struct ifreq)) * sizeof(struct compat_ifreq));
|
|
ifc32.ifc_len = i;
|
|
} else {
|
|
ifc32.ifc_len = i;
|
|
}
|
|
if (copy_to_user(uifc32, &ifc32, sizeof(struct compat_ifconf)))
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
|
|
{
|
|
struct compat_ethtool_rxnfc __user *compat_rxnfc;
|
|
bool convert_in = false, convert_out = false;
|
|
size_t buf_size = ALIGN(sizeof(struct ifreq), 8);
|
|
struct ethtool_rxnfc __user *rxnfc;
|
|
struct ifreq __user *ifr;
|
|
u32 rule_cnt = 0, actual_rule_cnt;
|
|
u32 ethcmd;
|
|
u32 data;
|
|
int ret;
|
|
|
|
if (get_user(data, &ifr32->ifr_ifru.ifru_data))
|
|
return -EFAULT;
|
|
|
|
compat_rxnfc = compat_ptr(data);
|
|
|
|
if (get_user(ethcmd, &compat_rxnfc->cmd))
|
|
return -EFAULT;
|
|
|
|
/* Most ethtool structures are defined without padding.
|
|
* Unfortunately struct ethtool_rxnfc is an exception.
|
|
*/
|
|
switch (ethcmd) {
|
|
default:
|
|
break;
|
|
case ETHTOOL_GRXCLSRLALL:
|
|
/* Buffer size is variable */
|
|
if (get_user(rule_cnt, &compat_rxnfc->rule_cnt))
|
|
return -EFAULT;
|
|
if (rule_cnt > KMALLOC_MAX_SIZE / sizeof(u32))
|
|
return -ENOMEM;
|
|
buf_size += rule_cnt * sizeof(u32);
|
|
/* fall through */
|
|
case ETHTOOL_GRXRINGS:
|
|
case ETHTOOL_GRXCLSRLCNT:
|
|
case ETHTOOL_GRXCLSRULE:
|
|
case ETHTOOL_SRXCLSRLINS:
|
|
convert_out = true;
|
|
/* fall through */
|
|
case ETHTOOL_SRXCLSRLDEL:
|
|
buf_size += sizeof(struct ethtool_rxnfc);
|
|
convert_in = true;
|
|
break;
|
|
}
|
|
|
|
ifr = compat_alloc_user_space(buf_size);
|
|
rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
|
|
|
|
if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
|
|
return -EFAULT;
|
|
|
|
if (put_user(convert_in ? rxnfc : compat_ptr(data),
|
|
&ifr->ifr_ifru.ifru_data))
|
|
return -EFAULT;
|
|
|
|
if (convert_in) {
|
|
/* We expect there to be holes between fs.m_ext and
|
|
* fs.ring_cookie and at the end of fs, but nowhere else.
|
|
*/
|
|
BUILD_BUG_ON(offsetof(struct compat_ethtool_rxnfc, fs.m_ext) +
|
|
sizeof(compat_rxnfc->fs.m_ext) !=
|
|
offsetof(struct ethtool_rxnfc, fs.m_ext) +
|
|
sizeof(rxnfc->fs.m_ext));
|
|
BUILD_BUG_ON(
|
|
offsetof(struct compat_ethtool_rxnfc, fs.location) -
|
|
offsetof(struct compat_ethtool_rxnfc, fs.ring_cookie) !=
|
|
offsetof(struct ethtool_rxnfc, fs.location) -
|
|
offsetof(struct ethtool_rxnfc, fs.ring_cookie));
|
|
|
|
if (copy_in_user(rxnfc, compat_rxnfc,
|
|
(void __user *)(&rxnfc->fs.m_ext + 1) -
|
|
(void __user *)rxnfc) ||
|
|
copy_in_user(&rxnfc->fs.ring_cookie,
|
|
&compat_rxnfc->fs.ring_cookie,
|
|
(void __user *)(&rxnfc->fs.location + 1) -
|
|
(void __user *)&rxnfc->fs.ring_cookie))
|
|
return -EFAULT;
|
|
if (ethcmd == ETHTOOL_GRXCLSRLALL) {
|
|
if (put_user(rule_cnt, &rxnfc->rule_cnt))
|
|
return -EFAULT;
|
|
} else if (copy_in_user(&rxnfc->rule_cnt,
|
|
&compat_rxnfc->rule_cnt,
|
|
sizeof(rxnfc->rule_cnt)))
|
|
return -EFAULT;
|
|
}
|
|
|
|
ret = dev_ioctl(net, SIOCETHTOOL, ifr);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (convert_out) {
|
|
if (copy_in_user(compat_rxnfc, rxnfc,
|
|
(const void __user *)(&rxnfc->fs.m_ext + 1) -
|
|
(const void __user *)rxnfc) ||
|
|
copy_in_user(&compat_rxnfc->fs.ring_cookie,
|
|
&rxnfc->fs.ring_cookie,
|
|
(const void __user *)(&rxnfc->fs.location + 1) -
|
|
(const void __user *)&rxnfc->fs.ring_cookie) ||
|
|
copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
|
|
sizeof(rxnfc->rule_cnt)))
|
|
return -EFAULT;
|
|
|
|
if (ethcmd == ETHTOOL_GRXCLSRLALL) {
|
|
/* As an optimisation, we only copy the actual
|
|
* number of rules that the underlying
|
|
* function returned. Since Mallory might
|
|
* change the rule count in user memory, we
|
|
* check that it is less than the rule count
|
|
* originally given (as the user buffer size),
|
|
* which has been range-checked.
|
|
*/
|
|
if (get_user(actual_rule_cnt, &rxnfc->rule_cnt))
|
|
return -EFAULT;
|
|
if (actual_rule_cnt < rule_cnt)
|
|
rule_cnt = actual_rule_cnt;
|
|
if (copy_in_user(&compat_rxnfc->rule_locs[0],
|
|
&rxnfc->rule_locs[0],
|
|
rule_cnt * sizeof(u32)))
|
|
return -EFAULT;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32)
|
|
{
|
|
void __user *uptr;
|
|
compat_uptr_t uptr32;
|
|
struct ifreq __user *uifr;
|
|
|
|
uifr = compat_alloc_user_space(sizeof(*uifr));
|
|
if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq)))
|
|
return -EFAULT;
|
|
|
|
if (get_user(uptr32, &uifr32->ifr_settings.ifs_ifsu))
|
|
return -EFAULT;
|
|
|
|
uptr = compat_ptr(uptr32);
|
|
|
|
if (put_user(uptr, &uifr->ifr_settings.ifs_ifsu.raw_hdlc))
|
|
return -EFAULT;
|
|
|
|
return dev_ioctl(net, SIOCWANDEV, uifr);
|
|
}
|
|
|
|
static int bond_ioctl(struct net *net, unsigned int cmd,
|
|
struct compat_ifreq __user *ifr32)
|
|
{
|
|
struct ifreq kifr;
|
|
mm_segment_t old_fs;
|
|
int err;
|
|
|
|
switch (cmd) {
|
|
case SIOCBONDENSLAVE:
|
|
case SIOCBONDRELEASE:
|
|
case SIOCBONDSETHWADDR:
|
|
case SIOCBONDCHANGEACTIVE:
|
|
if (copy_from_user(&kifr, ifr32, sizeof(struct compat_ifreq)))
|
|
return -EFAULT;
|
|
|
|
old_fs = get_fs();
|
|
set_fs(KERNEL_DS);
|
|
err = dev_ioctl(net, cmd,
|
|
(struct ifreq __user __force *) &kifr);
|
|
set_fs(old_fs);
|
|
|
|
return err;
|
|
default:
|
|
return -ENOIOCTLCMD;
|
|
}
|
|
}
|
|
|
|
/* Handle ioctls that use ifreq::ifr_data and just need struct ifreq converted */
|
|
static int compat_ifr_data_ioctl(struct net *net, unsigned int cmd,
|
|
struct compat_ifreq __user *u_ifreq32)
|
|
{
|
|
struct ifreq __user *u_ifreq64;
|
|
char tmp_buf[IFNAMSIZ];
|
|
void __user *data64;
|
|
u32 data32;
|
|
|
|
if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]),
|
|
IFNAMSIZ))
|
|
return -EFAULT;
|
|
if (get_user(data32, &u_ifreq32->ifr_ifru.ifru_data))
|
|
return -EFAULT;
|
|
data64 = compat_ptr(data32);
|
|
|
|
u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64));
|
|
|
|
if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0],
|
|
IFNAMSIZ))
|
|
return -EFAULT;
|
|
if (put_user(data64, &u_ifreq64->ifr_ifru.ifru_data))
|
|
return -EFAULT;
|
|
|
|
return dev_ioctl(net, cmd, u_ifreq64);
|
|
}
|
|
|
|
static int dev_ifsioc(struct net *net, struct socket *sock,
|
|
unsigned int cmd, struct compat_ifreq __user *uifr32)
|
|
{
|
|
struct ifreq __user *uifr;
|
|
int err;
|
|
|
|
uifr = compat_alloc_user_space(sizeof(*uifr));
|
|
if (copy_in_user(uifr, uifr32, sizeof(*uifr32)))
|
|
return -EFAULT;
|
|
|
|
err = sock_do_ioctl(net, sock, cmd, (unsigned long)uifr);
|
|
|
|
if (!err) {
|
|
switch (cmd) {
|
|
case SIOCGIFFLAGS:
|
|
case SIOCGIFMETRIC:
|
|
case SIOCGIFMTU:
|
|
case SIOCGIFMEM:
|
|
case SIOCGIFHWADDR:
|
|
case SIOCGIFINDEX:
|
|
case SIOCGIFADDR:
|
|
case SIOCGIFBRDADDR:
|
|
case SIOCGIFDSTADDR:
|
|
case SIOCGIFNETMASK:
|
|
case SIOCGIFPFLAGS:
|
|
case SIOCGIFTXQLEN:
|
|
case SIOCGMIIPHY:
|
|
case SIOCGMIIREG:
|
|
if (copy_in_user(uifr32, uifr, sizeof(*uifr32)))
|
|
err = -EFAULT;
|
|
break;
|
|
}
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
|
|
struct compat_ifreq __user *uifr32)
|
|
{
|
|
struct ifreq ifr;
|
|
struct compat_ifmap __user *uifmap32;
|
|
mm_segment_t old_fs;
|
|
int err;
|
|
|
|
uifmap32 = &uifr32->ifr_ifru.ifru_map;
|
|
err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name));
|
|
err |= get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
|
|
err |= get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
|
|
err |= get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
|
|
err |= get_user(ifr.ifr_map.irq, &uifmap32->irq);
|
|
err |= get_user(ifr.ifr_map.dma, &uifmap32->dma);
|
|
err |= get_user(ifr.ifr_map.port, &uifmap32->port);
|
|
if (err)
|
|
return -EFAULT;
|
|
|
|
old_fs = get_fs();
|
|
set_fs(KERNEL_DS);
|
|
err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
|
|
set_fs(old_fs);
|
|
|
|
if (cmd == SIOCGIFMAP && !err) {
|
|
err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name));
|
|
err |= put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start);
|
|
err |= put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end);
|
|
err |= put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr);
|
|
err |= put_user(ifr.ifr_map.irq, &uifmap32->irq);
|
|
err |= put_user(ifr.ifr_map.dma, &uifmap32->dma);
|
|
err |= put_user(ifr.ifr_map.port, &uifmap32->port);
|
|
if (err)
|
|
err = -EFAULT;
|
|
}
|
|
return err;
|
|
}
|
|
|
|
struct rtentry32 {
|
|
u32 rt_pad1;
|
|
struct sockaddr rt_dst; /* target address */
|
|
struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */
|
|
struct sockaddr rt_genmask; /* target network mask (IP) */
|
|
unsigned short rt_flags;
|
|
short rt_pad2;
|
|
u32 rt_pad3;
|
|
unsigned char rt_tos;
|
|
unsigned char rt_class;
|
|
short rt_pad4;
|
|
short rt_metric; /* +1 for binary compatibility! */
|
|
/* char * */ u32 rt_dev; /* forcing the device at add */
|
|
u32 rt_mtu; /* per route MTU/Window */
|
|
u32 rt_window; /* Window clamping */
|
|
unsigned short rt_irtt; /* Initial RTT */
|
|
};
|
|
|
|
struct in6_rtmsg32 {
|
|
struct in6_addr rtmsg_dst;
|
|
struct in6_addr rtmsg_src;
|
|
struct in6_addr rtmsg_gateway;
|
|
u32 rtmsg_type;
|
|
u16 rtmsg_dst_len;
|
|
u16 rtmsg_src_len;
|
|
u32 rtmsg_metric;
|
|
u32 rtmsg_info;
|
|
u32 rtmsg_flags;
|
|
s32 rtmsg_ifindex;
|
|
};
|
|
|
|
static int routing_ioctl(struct net *net, struct socket *sock,
|
|
unsigned int cmd, void __user *argp)
|
|
{
|
|
int ret;
|
|
void *r = NULL;
|
|
struct in6_rtmsg r6;
|
|
struct rtentry r4;
|
|
char devname[16];
|
|
u32 rtdev;
|
|
mm_segment_t old_fs = get_fs();
|
|
|
|
if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */
|
|
struct in6_rtmsg32 __user *ur6 = argp;
|
|
ret = copy_from_user(&r6.rtmsg_dst, &(ur6->rtmsg_dst),
|
|
3 * sizeof(struct in6_addr));
|
|
ret |= get_user(r6.rtmsg_type, &(ur6->rtmsg_type));
|
|
ret |= get_user(r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len));
|
|
ret |= get_user(r6.rtmsg_src_len, &(ur6->rtmsg_src_len));
|
|
ret |= get_user(r6.rtmsg_metric, &(ur6->rtmsg_metric));
|
|
ret |= get_user(r6.rtmsg_info, &(ur6->rtmsg_info));
|
|
ret |= get_user(r6.rtmsg_flags, &(ur6->rtmsg_flags));
|
|
ret |= get_user(r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex));
|
|
|
|
r = (void *) &r6;
|
|
} else { /* ipv4 */
|
|
struct rtentry32 __user *ur4 = argp;
|
|
ret = copy_from_user(&r4.rt_dst, &(ur4->rt_dst),
|
|
3 * sizeof(struct sockaddr));
|
|
ret |= get_user(r4.rt_flags, &(ur4->rt_flags));
|
|
ret |= get_user(r4.rt_metric, &(ur4->rt_metric));
|
|
ret |= get_user(r4.rt_mtu, &(ur4->rt_mtu));
|
|
ret |= get_user(r4.rt_window, &(ur4->rt_window));
|
|
ret |= get_user(r4.rt_irtt, &(ur4->rt_irtt));
|
|
ret |= get_user(rtdev, &(ur4->rt_dev));
|
|
if (rtdev) {
|
|
ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
|
|
r4.rt_dev = (char __user __force *)devname;
|
|
devname[15] = 0;
|
|
} else
|
|
r4.rt_dev = NULL;
|
|
|
|
r = (void *) &r4;
|
|
}
|
|
|
|
if (ret) {
|
|
ret = -EFAULT;
|
|
goto out;
|
|
}
|
|
|
|
set_fs(KERNEL_DS);
|
|
ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r);
|
|
set_fs(old_fs);
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
|
|
/* Since old style bridge ioctl's endup using SIOCDEVPRIVATE
|
|
* for some operations; this forces use of the newer bridge-utils that
|
|
* use compatible ioctls
|
|
*/
|
|
static int old_bridge_ioctl(compat_ulong_t __user *argp)
|
|
{
|
|
compat_ulong_t tmp;
|
|
|
|
if (get_user(tmp, argp))
|
|
return -EFAULT;
|
|
if (tmp == BRCTL_GET_VERSION)
|
|
return BRCTL_VERSION + 1;
|
|
return -EINVAL;
|
|
}
|
|
|
|
static int compat_sock_ioctl_trans(struct file *file, struct socket *sock,
|
|
unsigned int cmd, unsigned long arg)
|
|
{
|
|
void __user *argp = compat_ptr(arg);
|
|
struct sock *sk = sock->sk;
|
|
struct net *net = sock_net(sk);
|
|
|
|
if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15))
|
|
return compat_ifr_data_ioctl(net, cmd, argp);
|
|
|
|
switch (cmd) {
|
|
case SIOCSIFBR:
|
|
case SIOCGIFBR:
|
|
return old_bridge_ioctl(argp);
|
|
case SIOCGIFNAME:
|
|
return dev_ifname32(net, argp);
|
|
case SIOCGIFCONF:
|
|
return dev_ifconf(net, argp);
|
|
case SIOCETHTOOL:
|
|
return ethtool_ioctl(net, argp);
|
|
case SIOCWANDEV:
|
|
return compat_siocwandev(net, argp);
|
|
case SIOCGIFMAP:
|
|
case SIOCSIFMAP:
|
|
return compat_sioc_ifmap(net, cmd, argp);
|
|
case SIOCBONDENSLAVE:
|
|
case SIOCBONDRELEASE:
|
|
case SIOCBONDSETHWADDR:
|
|
case SIOCBONDCHANGEACTIVE:
|
|
return bond_ioctl(net, cmd, argp);
|
|
case SIOCADDRT:
|
|
case SIOCDELRT:
|
|
return routing_ioctl(net, sock, cmd, argp);
|
|
case SIOCGSTAMP:
|
|
return do_siocgstamp(net, sock, cmd, argp);
|
|
case SIOCGSTAMPNS:
|
|
return do_siocgstampns(net, sock, cmd, argp);
|
|
case SIOCBONDSLAVEINFOQUERY:
|
|
case SIOCBONDINFOQUERY:
|
|
case SIOCSHWTSTAMP:
|
|
case SIOCGHWTSTAMP:
|
|
return compat_ifr_data_ioctl(net, cmd, argp);
|
|
|
|
case FIOSETOWN:
|
|
case SIOCSPGRP:
|
|
case FIOGETOWN:
|
|
case SIOCGPGRP:
|
|
case SIOCBRADDBR:
|
|
case SIOCBRDELBR:
|
|
case SIOCGIFVLAN:
|
|
case SIOCSIFVLAN:
|
|
case SIOCADDDLCI:
|
|
case SIOCDELDLCI:
|
|
return sock_ioctl(file, cmd, arg);
|
|
|
|
case SIOCGIFFLAGS:
|
|
case SIOCSIFFLAGS:
|
|
case SIOCGIFMETRIC:
|
|
case SIOCSIFMETRIC:
|
|
case SIOCGIFMTU:
|
|
case SIOCSIFMTU:
|
|
case SIOCGIFMEM:
|
|
case SIOCSIFMEM:
|
|
case SIOCGIFHWADDR:
|
|
case SIOCSIFHWADDR:
|
|
case SIOCADDMULTI:
|
|
case SIOCDELMULTI:
|
|
case SIOCGIFINDEX:
|
|
case SIOCGIFADDR:
|
|
case SIOCSIFADDR:
|
|
case SIOCSIFHWBROADCAST:
|
|
case SIOCDIFADDR:
|
|
case SIOCGIFBRDADDR:
|
|
case SIOCSIFBRDADDR:
|
|
case SIOCGIFDSTADDR:
|
|
case SIOCSIFDSTADDR:
|
|
case SIOCGIFNETMASK:
|
|
case SIOCSIFNETMASK:
|
|
case SIOCSIFPFLAGS:
|
|
case SIOCGIFPFLAGS:
|
|
case SIOCGIFTXQLEN:
|
|
case SIOCSIFTXQLEN:
|
|
case SIOCBRADDIF:
|
|
case SIOCBRDELIF:
|
|
case SIOCSIFNAME:
|
|
case SIOCGMIIPHY:
|
|
case SIOCGMIIREG:
|
|
case SIOCSMIIREG:
|
|
return dev_ifsioc(net, sock, cmd, argp);
|
|
|
|
case SIOCSARP:
|
|
case SIOCGARP:
|
|
case SIOCDARP:
|
|
case SIOCOUTQNSD:
|
|
case SIOCATMARK:
|
|
return sock_do_ioctl(net, sock, cmd, arg);
|
|
}
|
|
|
|
return -ENOIOCTLCMD;
|
|
}
|
|
|
|
static long compat_sock_ioctl(struct file *file, unsigned int cmd,
|
|
unsigned long arg)
|
|
{
|
|
struct socket *sock = file->private_data;
|
|
int ret = -ENOIOCTLCMD;
|
|
struct sock *sk;
|
|
struct net *net;
|
|
|
|
sk = sock->sk;
|
|
net = sock_net(sk);
|
|
|
|
if (sock->ops->compat_ioctl)
|
|
ret = sock->ops->compat_ioctl(sock, cmd, arg);
|
|
|
|
if (ret == -ENOIOCTLCMD &&
|
|
(cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST))
|
|
ret = compat_wext_handle_ioctl(net, cmd, arg);
|
|
|
|
if (ret == -ENOIOCTLCMD)
|
|
ret = compat_sock_ioctl_trans(file, sock, cmd, arg);
|
|
|
|
return ret;
|
|
}
|
|
#endif
|
|
|
|
int kernel_bind(struct socket *sock, struct sockaddr *addr, int addrlen)
|
|
{
|
|
return sock->ops->bind(sock, addr, addrlen);
|
|
}
|
|
EXPORT_SYMBOL(kernel_bind);
|
|
|
|
int kernel_listen(struct socket *sock, int backlog)
|
|
{
|
|
return sock->ops->listen(sock, backlog);
|
|
}
|
|
EXPORT_SYMBOL(kernel_listen);
|
|
|
|
int kernel_accept(struct socket *sock, struct socket **newsock, int flags)
|
|
{
|
|
struct sock *sk = sock->sk;
|
|
int err;
|
|
|
|
err = sock_create_lite(sk->sk_family, sk->sk_type, sk->sk_protocol,
|
|
newsock);
|
|
if (err < 0)
|
|
goto done;
|
|
|
|
err = sock->ops->accept(sock, *newsock, flags);
|
|
if (err < 0) {
|
|
sock_release(*newsock);
|
|
*newsock = NULL;
|
|
goto done;
|
|
}
|
|
|
|
(*newsock)->ops = sock->ops;
|
|
__module_get((*newsock)->ops->owner);
|
|
|
|
done:
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(kernel_accept);
|
|
|
|
int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen,
|
|
int flags)
|
|
{
|
|
return sock->ops->connect(sock, addr, addrlen, flags);
|
|
}
|
|
EXPORT_SYMBOL(kernel_connect);
|
|
|
|
int kernel_getsockname(struct socket *sock, struct sockaddr *addr,
|
|
int *addrlen)
|
|
{
|
|
return sock->ops->getname(sock, addr, addrlen, 0);
|
|
}
|
|
EXPORT_SYMBOL(kernel_getsockname);
|
|
|
|
int kernel_getpeername(struct socket *sock, struct sockaddr *addr,
|
|
int *addrlen)
|
|
{
|
|
return sock->ops->getname(sock, addr, addrlen, 1);
|
|
}
|
|
EXPORT_SYMBOL(kernel_getpeername);
|
|
|
|
int kernel_getsockopt(struct socket *sock, int level, int optname,
|
|
char *optval, int *optlen)
|
|
{
|
|
mm_segment_t oldfs = get_fs();
|
|
char __user *uoptval;
|
|
int __user *uoptlen;
|
|
int err;
|
|
|
|
uoptval = (char __user __force *) optval;
|
|
uoptlen = (int __user __force *) optlen;
|
|
|
|
set_fs(KERNEL_DS);
|
|
if (level == SOL_SOCKET)
|
|
err = sock_getsockopt(sock, level, optname, uoptval, uoptlen);
|
|
else
|
|
err = sock->ops->getsockopt(sock, level, optname, uoptval,
|
|
uoptlen);
|
|
set_fs(oldfs);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(kernel_getsockopt);
|
|
|
|
int kernel_setsockopt(struct socket *sock, int level, int optname,
|
|
char *optval, unsigned int optlen)
|
|
{
|
|
mm_segment_t oldfs = get_fs();
|
|
char __user *uoptval;
|
|
int err;
|
|
|
|
uoptval = (char __user __force *) optval;
|
|
|
|
set_fs(KERNEL_DS);
|
|
if (level == SOL_SOCKET)
|
|
err = sock_setsockopt(sock, level, optname, uoptval, optlen);
|
|
else
|
|
err = sock->ops->setsockopt(sock, level, optname, uoptval,
|
|
optlen);
|
|
set_fs(oldfs);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(kernel_setsockopt);
|
|
|
|
int kernel_sendpage(struct socket *sock, struct page *page, int offset,
|
|
size_t size, int flags)
|
|
{
|
|
if (sock->ops->sendpage)
|
|
return sock->ops->sendpage(sock, page, offset, size, flags);
|
|
|
|
return sock_no_sendpage(sock, page, offset, size, flags);
|
|
}
|
|
EXPORT_SYMBOL(kernel_sendpage);
|
|
|
|
int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg)
|
|
{
|
|
mm_segment_t oldfs = get_fs();
|
|
int err;
|
|
|
|
set_fs(KERNEL_DS);
|
|
err = sock->ops->ioctl(sock, cmd, arg);
|
|
set_fs(oldfs);
|
|
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(kernel_sock_ioctl);
|
|
|
|
int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how)
|
|
{
|
|
return sock->ops->shutdown(sock, how);
|
|
}
|
|
EXPORT_SYMBOL(kernel_sock_shutdown);
|
|
|
|
int sockev_register_notify(struct notifier_block *nb)
|
|
{
|
|
return blocking_notifier_chain_register(&sockev_notifier_list, nb);
|
|
}
|
|
EXPORT_SYMBOL(sockev_register_notify);
|
|
|
|
int sockev_unregister_notify(struct notifier_block *nb)
|
|
{
|
|
return blocking_notifier_chain_unregister(&sockev_notifier_list, nb);
|
|
}
|
|
EXPORT_SYMBOL(sockev_unregister_notify);
|
|
|
|
/* This routine returns the IP overhead imposed by a socket i.e.
|
|
* the length of the underlying IP header, depending on whether
|
|
* this is an IPv4 or IPv6 socket and the length from IP options turned
|
|
* on at the socket. Assumes that the caller has a lock on the socket.
|
|
*/
|
|
u32 kernel_sock_ip_overhead(struct sock *sk)
|
|
{
|
|
struct inet_sock *inet;
|
|
struct ip_options_rcu *opt;
|
|
u32 overhead = 0;
|
|
bool owned_by_user;
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
struct ipv6_pinfo *np;
|
|
struct ipv6_txoptions *optv6 = NULL;
|
|
#endif /* IS_ENABLED(CONFIG_IPV6) */
|
|
|
|
if (!sk)
|
|
return overhead;
|
|
|
|
owned_by_user = sock_owned_by_user(sk);
|
|
switch (sk->sk_family) {
|
|
case AF_INET:
|
|
inet = inet_sk(sk);
|
|
overhead += sizeof(struct iphdr);
|
|
opt = rcu_dereference_protected(inet->inet_opt,
|
|
owned_by_user);
|
|
if (opt)
|
|
overhead += opt->opt.optlen;
|
|
return overhead;
|
|
#if IS_ENABLED(CONFIG_IPV6)
|
|
case AF_INET6:
|
|
np = inet6_sk(sk);
|
|
overhead += sizeof(struct ipv6hdr);
|
|
if (np)
|
|
optv6 = rcu_dereference_protected(np->opt,
|
|
owned_by_user);
|
|
if (optv6)
|
|
overhead += (optv6->opt_flen + optv6->opt_nflen);
|
|
return overhead;
|
|
#endif /* IS_ENABLED(CONFIG_IPV6) */
|
|
default: /* Returns 0 overhead if the socket is not ipv4 or ipv6 */
|
|
return overhead;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(kernel_sock_ip_overhead);
|