* 4.9/tmp-8dd0f52: Linux 4.9.72 sparc32: Export vac_cache_size to fix build error bpf: fix incorrect sign extension in check_alu_op() bpf: reject out-of-bounds stack pointer calculation bpf: fix branch pruning logic bpf: adjust insn_aux_data when patching insns Revert "Bluetooth: btusb: driver to enable the usb-wakeup feature" platform/x86: asus-wireless: send an EV_SYN/SYN_REPORT between state changes MIPS: math-emu: Fix final emulation phase for certain instructions thermal/drivers/hisi: Fix multiple alarm interrupts firing thermal/drivers/hisi: Simplify the temperature/step computation thermal/drivers/hisi: Fix kernel panic on alarm interrupt thermal/drivers/hisi: Fix missing interrupt enablement thermal: hisilicon: Handle return value of clk_prepare_enable cpuidle: fix broadcast control when broadcast can not be entered rtc: set the alarm to the next expiring timer tcp: fix under-evaluated ssthresh in TCP Vegas clk: sunxi-ng: sun6i: Rename HDMI DDC clock to avoid name collision staging: greybus: light: Release memory obtained by kasprintf net: ipv6: send NS for DAD when link operationally up fm10k: ensure we process SM mbx when processing VF mbx vfio/pci: Virtualize Maximum Payload Size scsi: lpfc: PLOGI failures during NPIV testing scsi: lpfc: Fix secure firmware updates fm10k: fix mis-ordered parameters in declaration for .ndo_set_vf_bw ASoC: img-parallel-out: Add pm_runtime_get/put to set_fmt callback tracing: Exclude 'generic fields' from histograms PCI/AER: Report non-fatal errors only to the affected endpoint IB/rxe: check for allocation failure on elem ixgbe: fix use of uninitialized padding igb: check memory allocation failure PM / OPP: Move error message to debug level PCI: Create SR-IOV virtfn/physfn links before attaching driver scsi: mpt3sas: Fix IO error occurs on pulling out a drive from RAID1 volume created on two SATA drive scsi: cxgb4i: fix Tx skb leak PCI: Avoid bus reset if bridge itself is broken net: phy: at803x: Change error to EINVAL for invalid MAC kvm, mm: account kvm related kmem slabs to kmemcg rtc: pl031: make interrupt optional crypto: crypto4xx - increase context and scatter ring buffer elements backlight: pwm_bl: Fix overflow condition bnxt_en: Fix NULL pointer dereference in reopen failure path cpuidle: powernv: Pass correct drv->cpumask for registration ARM: dma-mapping: disallow dma_get_sgtable() for non-kernel managed memory Btrfs: fix an integer overflow check netfilter: nfnetlink_queue: fix secctx memory leak xhci: plat: Register shutdown for xhci_plat net: moxa: fix TX overrun memory leak isdn: kcapi: avoid uninitialized data virtio_balloon: prevent uninitialized variable use virtio-balloon: use actual number of stats for stats queue buffers KVM: pci-assign: do not map smm memory slot pages in vt-d page tables net: ipconfig: fix ic_close_devs() use-after-free cpufreq: Fix creation of symbolic links to policy directories ARM: dts: am335x-evmsk: adjust mmc2 param to allow suspend netfilter: nf_nat_snmp: Fix panic when snmp_trap_helper fails to register netfilter: nfnl_cthelper: fix a race when walk the nf_ct_helper_hash table irda: vlsi_ir: fix check for DMA mapping errors RDMA/iser: Fix possible mr leak on device removal event i40e: Do not enable NAPI on q_vectors that have no rings IB/rxe: increment msn only when completing a request IB/rxe: double free on error net: Do not allow negative values for busy_read and busy_poll sysctl interfaces nbd: set queue timeout properly infiniband: Fix alignment of mmap cookies to support VIPT caching IB/core: Protect against self-requeue of a cq work item i40iw: Receive netdev events post INET_NOTIFIER state bna: avoid writing uninitialized data into hw registers s390/qeth: no ETH header for outbound AF_IUCV s390/qeth: size calculation outbound buffers r8152: prevent the driver from transmitting packets with carrier off ASoC: STI: Fix reader substream pointer set HID: xinmo: fix for out of range for THT 2P arcade controller. hwmon: (asus_atk0110) fix uninitialized data access ARM: dts: ti: fix PCI bus dtc warnings KVM: VMX: Fix enable VPID conditions KVM: x86: correct async page present tracepoint kvm: vmx: Flush TLB when the APIC-access address changes scsi: lpfc: Fix PT2PT PRLI reject pinctrl: st: add irq_request/release_resources callbacks inet: frag: release spinlock before calling icmp_send() tipc: fix nametbl deadlock at tipc_nametbl_unsubscribe r8152: fix the rx early size of RTL8153 iommu/exynos: Workaround FLPD cache flush issues for SYSMMU v5 netfilter: nfnl_cthelper: Fix memory leak netfilter: nfnl_cthelper: fix runtime expectation policy updates usb: gadget: udc: remove pointer dereference after free usb: gadget: f_uvc: Sanity check wMaxPacketSize for SuperSpeed hwmon: (max31790) Set correct PWM value net: qmi_wwan: Add USB IDs for MDM6600 modem on Motorola Droid 4 sctp: out_qlen should be updated when pruning unsent queue bna: integer overflow bug in debugfs sch_dsmark: fix invalid skb_cow() usage vsock: cancel packets when failing to connect vhost-vsock: add pkt cancel capability vsock: track pkt owner vsock crypto: deadlock between crypto_alg_sem/rtnl_mutex/genl_mutex r8152: fix the list rx_done may be used without initialization cpuidle: Validate cpu_dev in cpuidle_add_sysfs() nvme-loop: handle cpu unplug when re-establishing the controller arm: kprobes: Align stack to 8-bytes in test code arm: kprobes: Fix the return address of multiple kretprobes HID: corsair: Add driver Scimitar Pro RGB gaming mouse 1b1c:1b3e support to hid-corsair HID: corsair: support for K65-K70 Rapidfire and Scimitar Pro RGB kvm: fix usage of uninit spinlock in avic_vm_destroy() ALSA: hda - add support for docking station for HP 840 G3 ALSA: hda - add support for docking station for HP 820 G2 arm64: Initialise high_memory global variable earlier cxl: Check if vphb exists before iterating over AFU devices Linux 4.9.71 ath9k: fix tx99 potential info leak icmp: don't fail on fragment reassembly time exceeded IB/ipoib: Grab rtnl lock on heavy flush when calling ndo_open/stop RDMA/cma: Avoid triggering undefined behavior macvlan: Only deliver one copy of the frame to the macvlan interface udf: Avoid overflow when session starts at large offset scsi: bfa: integer overflow in debugfs scsi: sd: change allow_restart to bool in sysfs interface scsi: sd: change manage_start_stop to bool in sysfs interface rtl8188eu: Fix a possible sleep-in-atomic bug in rtw_disassoc_cmd rtl8188eu: Fix a possible sleep-in-atomic bug in rtw_createbss_cmd vt6655: Fix a possible sleep-in-atomic bug in vt6655_suspend IB/core: Fix calculation of maximum RoCE MTU scsi: scsi_devinfo: Add REPORTLUN2 to EMC SYMMETRIX blacklist entry raid5: Set R5_Expanded on parity devices as well as data. pinctrl: adi2: Fix Kconfig build problem usb: musb: da8xx: fix babble condition handling tty fix oops when rmmod 8250 soc: mediatek: pwrap: fix compiler errors powerpc/perf/hv-24x7: Fix incorrect comparison in memord scsi: hpsa: destroy sas transport properties before scsi_host scsi: hpsa: cleanup sas_phy structures in sysfs when unloading PCI: Detach driver before procfs & sysfs teardown on device remove RDMA/cxgb4: Declare stag as __be32 xfs: fix incorrect extent state in xfs_bmap_add_extent_unwritten_real xfs: fix log block underflow during recovery cycle verification l2tp: cleanup l2tp_tunnel_delete calls nvme: use kref_get_unless_zero in nvme_find_get_ns platform/x86: hp_accel: Add quirk for HP ProBook 440 G4 btrfs: tests: Fix a memory leak in error handling path in 'run_test()' arm64: prevent regressions in compressed kernel image size when upgrading to binutils 2.27 Ib/hfi1: Return actual operational VLs in port info query bcache: fix wrong cache_misses statistics bcache: explicitly destroy mutex while exiting GFS2: Take inode off order_write list when setting jdata flag scsi: scsi_debug: write_same: fix error report thermal/drivers/step_wise: Fix temperature regulation misbehavior ASoC: rsnd: rsnd_ssi_run_mods() needs to care ssi_parent_mod ppp: Destroy the mutex when cleanup clk: tegra: Fix cclk_lp divisor register clk: hi6220: mark clock cs_atb_syspll as critical clk: imx6: refine hdmi_isfr's parent to make HDMI work on i.MX6 SoCs w/o VPU clk: mediatek: add the option for determining PLL source clock mm: Handle 0 flags in _calc_vm_trans() macro crypto: tcrypt - fix buffer lengths in test_aead_speed() arm-ccn: perf: Prevent module unload while PMU is in use xfs: truncate pagecache before writeback in xfs_setattr_size() iommu/amd: Limit the IOVA page range to the specified addresses badblocks: fix wrong return value in badblocks_set if badblocks are disabled target/file: Do not return error for UNMAP if length is zero target:fix condition return in core_pr_dump_initiator_port() iscsi-target: fix memory leak in lio_target_tiqn_addtpg() target/iscsi: Fix a race condition in iscsit_add_reject_from_cmd() platform/x86: intel_punit_ipc: Fix resource ioremap warning powerpc/ipic: Fix status get and status clear powerpc/opal: Fix EBUSY bug in acquiring tokens netfilter: ipvs: Fix inappropriate output of procfs iommu/mediatek: Fix driver name PCI: Do not allocate more buses than available in parent powerpc/powernv/cpufreq: Fix the frequency read by /proc/cpuinfo PCI/PME: Handle invalid data when reading Root Status dmaengine: ti-dma-crossbar: Correct am335x/am43xx mux value type ASoC: Intel: Skylake: Fix uuid_module memory leak in failure case rtc: pcf8563: fix output clock rate video: fbdev: au1200fb: Return an error code if a memory allocation fails video: fbdev: au1200fb: Release some resources if a memory allocation fails video: udlfb: Fix read EDID timeout fbdev: controlfb: Add missing modes to fix out of bounds access sfc: don't warn on successful change of MAC HID: cp2112: fix broken gpio_direction_input callback Revert "x86/acpi: Set persistent cpuid <-> nodeid mapping when booting" target: fix race during implicit transition work flushes target: fix ALUA transition timeout handling target: Use system workqueue for ALUA transitions btrfs: add missing memset while reading compressed inline extents NFSv4.1 respect server's max size in CREATE_SESSION efi/esrt: Cleanup bad memory map log messages perf symbols: Fix symbols__fixup_end heuristic for corner cases tty: fix data race in tty_ldisc_ref_wait() tty: don't panic on OOM in tty_set_ldisc() rxrpc: Ignore BUSY packets on old calls net: mpls: Fix nexthop alive tracking on down events net/mlx4_core: Avoid delays during VF driver device shutdown nvmet-rdma: Fix a possible uninitialized variable dereference nvmet: confirm sq percpu has scheduled and switched to atomic nvme-loop: fix a possible use-after-free when destroying the admin queue afs: Fix abort on signal while waiting for call completion afs: Fix afs_kill_pages() afs: Fix page leak in afs_write_begin() afs: Populate and use client modification time afs: Better abort and net error handling afs: Invalid op ID should abort with RXGEN_OPCODE afs: Fix the maths in afs_fs_store_data() afs: Prevent callback expiry timer overflow afs: Migrate vlocation fields to 64-bit afs: Flush outstanding writes when an fd is closed afs: Deal with an empty callback array afs: Adjust mode bits processing afs: Populate group ID from vnode status afs: Fix missing put_page() drm/radeon: reinstate oland workaround for sclk mmc: mediatek: Fixed bug where clock frequency could be set wrong sched/deadline: Use deadline instead of period when calculating overflow sched/deadline: Throttle a constrained deadline task activated after the deadline sched/deadline: Make sure the replenishment timer fires in the next period sched/deadline: Add missing update_rq_clock() in dl_task_timer() iwlwifi: mvm: cleanup pending frames in DQA mode Drivers: hv: util: move waiting for release to hv_utils_transport itself drm/radeon/si: add dpm quirk for Oland fjes: Fix wrong netdevice feature flags scsi: hpsa: do not timeout reset operations scsi: hpsa: limit outstanding rescans scsi: hpsa: update check for logical volume status ASoC: rcar: clear DE bit only in PDMACHCR when it stops openrisc: fix issue handling 8 byte get_user calls intel_th: pci: Add Gemini Lake support drm: amd: remove broken include path qed: Fix interrupt flags on Rx LL2 qed: Fix mapping leak on LL2 rx flow qed: Align CIDs according to DORQ requirement mlxsw: reg: Fix SPVMLR max record count mlxsw: reg: Fix SPVM max record count net: Resend IGMP memberships upon peer notification. irqchip/mvebu-odmi: Select GENERIC_MSI_IRQ_DOMAIN dmaengine: Fix array index out of bounds warning in __get_unmap_pool() net: wimax/i2400m: fix NULL-deref at probe writeback: fix memory leak in wb_queue_work() blk-mq: Fix tagset reinit in the presence of cpu hot-unplug ASoC: rsnd: fix sound route path when using SRC6/SRC9 netfilter: bridge: honor frag_max_size when refragmenting drm/omap: fix dmabuf mmap for dma_alloc'ed buffers Input: i8042 - add TUXEDO BU1406 (N24_25BU) to the nomux list NFSD: fix nfsd_reset_versions for NFSv4. NFSD: fix nfsd_minorversion(.., NFSD_AVAIL) drm/amdgpu: fix parser init error path to avoid crash in parser fini iommu/io-pgtable-arm-v7s: Check for leaf entry before dereferencing it net/mlx5: Don't save PCI state when PCI error is detected net/mlx5: Fix create autogroup prev initializer rxrpc: Wake up the transmitter if Rx window size increases on the peer net: bcmgenet: Power up the internal PHY before probing the MII net: bcmgenet: synchronize irq0 status between the isr and task net: bcmgenet: power down internal phy if open or resume fails net: bcmgenet: reserved phy revisions must be checked first net: bcmgenet: correct MIB access of UniMAC RUNT counters net: bcmgenet: correct the RBUF_OVFL_CNT and RBUF_ERR_CNT MIB values bnxt_en: Ignore 0 value in autoneg supported speed from firmware. net: initialize msg.msg_flags in recvfrom userfaultfd: selftest: vm: allow to build in vm/ directory userfaultfd: shmem: __do_fault requires VM_FAULT_NOPAGE md-cluster: free md_cluster_info if node leave cluster usb: xhci-mtk: check hcc_params after adding primary hcd KVM: nVMX: do not warn when MSR bitmap address is not backed usb: phy: isp1301: Add OF device ID table mac80211: Fix addition of mesh configuration element ext4: fix crash when a directory's i_size is too small ext4: fix fdatasync(2) after fallocate(2) operation dmaengine: dmatest: move callback wait queue to thread context eeprom: at24: change nvmem stride to 1 sched/rt: Do not pull from current CPU if only one CPU to pull nfs: don't wait on commit in nfs_commit_inode() if there were no commit requests xhci: Don't add a virt_dev to the devs array before it's fully allocated Bluetooth: btusb: driver to enable the usb-wakeup feature usb: xhci: fix TDS for MTK xHCI1.1 ceph: drop negative child dentries before try pruning inode's alias usbip: fix stub_send_ret_submit() vulnerability to null transfer_buffer usbip: fix stub_rx: harden CMD_SUBMIT path to handle malicious input usb: add helper to extract bits 12:11 of wMaxPacketSize usbip: fix stub_rx: get_pipe() to validate endpoint number USB: core: prevent malicious bNumInterfaces overflow USB: uas and storage: Add US_FL_BROKEN_FUA for another JMicron JMS567 ID tracing: Allocate mask_str buffer dynamically autofs: fix careless error in recent commit crypto: salsa20 - fix blkcipher_walk API usage crypto: hmac - require that the underlying hash algorithm is unkeyed crypto: rsa - fix buffer overread when stripping leading zeroes mfd: fsl-imx25: Clean up irq settings during removal Linux 4.9.70 RDMA/cxgb4: Annotate r2 and stag as __be32 md: free unused memory after bitmap resize audit: ensure that 'audit=1' actually enables audit for PID 1 ipvlan: fix ipv6 outbound device kbuild: do not call cc-option before KBUILD_CFLAGS initialization powerpc/64: Fix checksum folding in csum_tcpudp_nofold and ip_fast_csum_nofold KVM: arm/arm64: vgic-its: Preserve the revious read from the pending table fix kcm_clone() usb: gadget: ffs: Forbid usb_ep_alloc_request from sleeping s390: always save and restore all registers on context switch ipmi: Stop timers before cleaning up the module Fix handling of verdicts after NF_QUEUE tipc: call tipc_rcv() only if bearer is up in tipc_udp_recv() s390/qeth: fix thinko in IPv4 multicast address tracking s390/qeth: fix GSO throughput regression s390/qeth: build max size GSO skbs on L2 devices tcp/dccp: block bh before arming time_wait timer stmmac: reset last TSO segment size after device open net: remove hlist_nulls_add_tail_rcu() usbnet: fix alignment for frames with no ethernet header net/packet: fix a race in packet_bind() and packet_notifier() packet: fix crash in fanout_demux_rollover() sit: update frag_off info rds: Fix NULL pointer dereference in __rds_rdma_map tipc: fix memory leak in tipc_accept_from_sock() s390/qeth: fix early exit from error path net: qmi_wwan: add Quectel BG96 2c7c:0296 ANDROID: dma-buf/sw_sync: Rename active_list to link FROMLIST: android: binder: Fix null ptr dereference in debug msg FROMLIST: android: binder: Move buffer out of area shared with user space FROMLIST: android: binder: Add allocator selftest FROMLIST: android: binder: Refactor prev and next buffer into a helper function Linux 4.9.69 afs: Connect up the CB.ProbeUuid IB/mlx5: Assign send CQ and recv CQ of UMR QP IB/mlx4: Increase maximal message size under UD QP xfrm: Copy policy family in clone_policy jump_label: Invoke jump_label_test() via early_initcall() atm: horizon: Fix irq release error clk: uniphier: fix DAPLL2 clock rate of Pro5 bpf: fix lockdep splat sctp: use the right sk after waking up from wait_buf sleep sctp: do not free asoc when it is already dead in sctp_sendmsg zsmalloc: calling zs_map_object() from irq is a bug sparc64/mm: set fields in deferred pages block: wake up all tasks blocked in get_request() dt-bindings: usb: fix reg-property port-number range xfs: fix forgotten rcu read unlock when skipping inode reclaim sunrpc: Fix rpc_task_begin trace point NFS: Fix a typo in nfs_rename() dynamic-debug-howto: fix optional/omitted ending line number to be LARGE instead of 0 lib/genalloc.c: make the avail variable an atomic_long_t drivers/rapidio/devices/rio_mport_cdev.c: fix resource leak in error handling path in 'rio_dma_transfer()' route: update fnhe_expires for redirect when the fnhe exists route: also update fnhe_genid when updating a route cache gre6: use log_ecn_error module parameter in ip6_tnl_rcv() mac80211_hwsim: Fix memory leak in hwsim_new_radio_nl() x86/mpx/selftests: Fix up weird arrays coccinelle: fix parallel build with CHECK=scripts/coccicheck kbuild: pkg: use --transform option to prefix paths in tar EDAC, i5000, i5400: Fix definition of NRECMEMB register EDAC, i5000, i5400: Fix use of MTR_DRAM_WIDTH macro powerpc/powernv/ioda2: Gracefully fail if too many TCE levels requested drm/amd/amdgpu: fix console deadlock if late init failed axonram: Fix gendisk handling netfilter: don't track fragmented packets zram: set physical queue limits to avoid array out of bounds accesses blk-mq: initialize mq kobjects in blk_mq_init_allocated_queue() i2c: riic: fix restart condition crypto: s5p-sss - Fix completing crypto request in IRQ handler ipv6: reorder icmpv6_init() and ip6_mr_init() ibmvnic: Allocate number of rx/tx buffers agreed on by firmware ibmvnic: Fix overflowing firmware/hardware TX queue rds: tcp: Sequence teardown of listen and acceptor sockets to avoid races bnx2x: do not rollback VF MAC/VLAN filters we did not configure bnx2x: fix detection of VLAN filtering feature for VF bnx2x: fix possible overrun of VFPF multicast addresses array bnx2x: prevent crash when accessing PTP with interface down spi_ks8995: regs_size incorrect for some devices spi_ks8995: fix "BUG: key accdaa28 not in .data!" KVM: arm/arm64: VGIC: Fix command handling while ITS being disabled arm64: KVM: Survive unknown traps from guests arm: KVM: Survive unknown traps from guests KVM: nVMX: reset nested_run_pending if the vCPU is going to be reset irqchip/crossbar: Fix incorrect type of register size scsi: lpfc: Fix crash during Hardware error recovery on SLI3 adapters scsi: qla2xxx: Fix ql_dump_buffer workqueue: trigger WARN if queue_delayed_work() is called with NULL @wq libata: drop WARN from protocol error in ata_sff_qc_issue() kvm: nVMX: VMCLEAR should not cause the vCPU to shut down usb: gadget: udc: net2280: Fix tmp reusage in net2280 driver usb: gadget: pxa27x: Test for a valid argument pointer usb: dwc3: gadget: Fix system suspend/resume on TI platforms USB: gadgetfs: Fix a potential memory leak in 'dev_config()' usb: gadget: configs: plug memory leak HID: chicony: Add support for another ASUS Zen AiO keyboard gpio: altera: Use handle_level_irq when configured as a level_high ASoC: rcar: avoid SSI_MODEx settings for SSI8 ARM: OMAP2+: Release device node after it is no longer needed. ARM: OMAP2+: Fix device node reference counts powerpc/64: Fix checksum folding in csum_add() module: set __jump_table alignment to 8 lirc: fix dead lock between open and wakeup_filter powerpc: Fix compiling a BE kernel with a powerpc64le toolchain selftest/powerpc: Fix false failures for skipped tests powerpc/64: Invalidate process table caching after setting process table x86/hpet: Prevent might sleep splat on resume sched/fair: Make select_idle_cpu() more aggressive x86/platform/uv/BAU: Fix HUB errors by remove initial write to sw-ack register x86/selftests: Add clobbers for int80 on x86_64 ARM: OMAP2+: gpmc-onenand: propagate error on initialization failure vti6: Don't report path MTU below IPV6_MIN_MTU. ARM: 8657/1: uaccess: consistently check object sizes Revert "spi: SPI_FSL_DSPI should depend on HAS_DMA" Revert "drm/armada: Fix compile fail" mm: drop unused pmdp_huge_get_and_clear_notify() thp: fix MADV_DONTNEED vs. numa balancing race thp: reduce indentation level in change_huge_pmd() ARM: avoid faulting on qemu ARM: BUG if jumping to usermode address in kernel mode usb: f_fs: Force Reserved1=1 in OS_DESC_EXT_COMPAT crypto: talitos - fix ctr-aes-talitos crypto: talitos - fix use of sg_link_tbl_len crypto: talitos - fix AEAD for sha224 on non sha224 capable chips crypto: talitos - fix setkey to check key weakness crypto: talitos - fix memory corruption on SEC2 crypto: talitos - fix AEAD test failures bus: arm-ccn: fix module unloading Error: Removing state 147 which has instances left. bus: arm-ccn: Fix use of smp_processor_id() in preemptible context bus: arm-ccn: Check memory allocation failure bus: arm-cci: Fix use of smp_processor_id() in preemptible context arm64: fpsimd: Prevent registers leaking from dead tasks KVM: arm/arm64: vgic-its: Check result of allocation before use KVM: arm/arm64: vgic-irqfd: Fix MSI entry allocation KVM: arm/arm64: Fix broken GICH_ELRSR big endian conversion KVM: VMX: remove I/O port 0x80 bypass on Intel hosts arm: KVM: Fix VTTBR_BADDR_MASK BUG_ON off-by-one arm64: KVM: fix VTTBR_BADDR_MASK BUG_ON off-by-one media: dvb: i2c transfers over usb cannot be done from stack drm/exynos: gem: Drop NONCONTIG flag for buffers allocated without IOMMU kdb: Fix handling of kallsyms_symbol_next() return value brcmfmac: change driver unbind order of the sdio function devices powerpc/64s: Initialize ISAv3 MMU registers before setting partition table KVM: s390: Fix skey emulation permission check s390: fix compat system call table smp/hotplug: Move step CPUHP_AP_SMPCFD_DYING to the correct place iommu/vt-d: Fix scatterlist offset handling ALSA: usb-audio: Add check return value for usb_string() ALSA: usb-audio: Fix out-of-bound error ALSA: seq: Remove spurious WARN_ON() at timer check ALSA: pcm: prevent UAF in snd_pcm_info btrfs: fix missing error return in btrfs_drop_snapshot KVM: x86: fix APIC page invalidation x86/PCI: Make broadcom_postcore_init() check acpi_disabled X.509: fix comparisons of ->pkey_algo X.509: reject invalid BIT STRING for subjectPublicKey KEYS: add missing permission check for request_key() destination ASN.1: check for error from ASN1_OP_END__ACT actions ASN.1: fix out-of-bounds read when parsing indefinite length item efi/esrt: Use memunmap() instead of kfree() to free the remapping efi: Move some sysfs files to be read-only by root scsi: libsas: align sata_device's rps_resp on a cacheline scsi: use dma_get_cache_alignment() as minimum DMA alignment scsi: dma-mapping: always provide dma_get_cache_alignment isa: Prevent NULL dereference in isa_bus driver callbacks hv: kvp: Avoid reading past allocated blocks from KVP file virtio: release virtio index when fail to device_register can: usb_8dev: cancel urb on -EPIPE and -EPROTO can: esd_usb2: cancel urb on -EPIPE and -EPROTO can: ems_usb: cancel urb on -EPIPE and -EPROTO can: kvaser_usb: cancel urb on -EPIPE and -EPROTO can: kvaser_usb: ratelimit errors if incomplete messages are received can: kvaser_usb: Fix comparison bug in kvaser_usb_read_bulk_callback() can: kvaser_usb: free buf in error paths can: ti_hecc: Fix napi poll return value for repoll usb: gadget: udc: renesas_usb3: fix number of the pipes ANDROID: Revert "arm64: move ELF_ET_DYN_BASE to 4GB / 4MB" ANDROID: Revert "arm: move ELF_ET_DYN_BASE to 4MB" Linux 4.9.68 xen-netfront: avoid crashing on resume after a failure in talk_to_netback() usb: host: fix incorrect updating of offset USB: usbfs: Filter flags passed in from user space USB: devio: Prevent integer overflow in proc_do_submiturb() USB: Increase usbfs transfer limit USB: core: Add type-specific length check of BOS descriptors usb: xhci: fix panic in xhci_free_virt_devices_depth_first usb: hub: Cycle HUB power when initialization fails dma-buf: Update kerneldoc for sync_file_create dma-buf/sync_file: hold reference to fence when creating sync_file dma-buf/sw_sync: force signal all unsignaled fences on dying timeline dma-fence: Introduce drm_fence_set_error() helper dma-fence: Wrap querying the fence->status dma-fence: Clear fence->status during dma_fence_init() dma-buf/sw_sync: clean up list before signaling the fence dma-buf/sw_sync: move timeline_fence_ops around dma-buf/sw-sync: Use an rbtree to sort fences in the timeline dma-buf/sw-sync: Fix locking around sync_timeline lists dma-buf/sw-sync: sync_pt is private and of fixed size dma-buf/sw-sync: Reduce irqsave/irqrestore from known context dma-buf/sw-sync: Prevent user overflow on timeline advance dma-buf/sw-sync: Fix the is-signaled test to handle u32 wraparound dma-buf/dma-fence: Extract __dma_fence_is_later() net: fec: fix multicast filtering hardware setup xen-netback: vif counters from int/long to u64 cec: initiator should be the same as the destination for, poll xen-netfront: Improve error handling during initialization mm: avoid returning VM_FAULT_RETRY from ->page_mkwrite handlers vfio/spapr: Fix missing mutex unlock when creating a window be2net: fix initial MAC setting net: thunderx: avoid dereferencing xcv when NULL net: phy: micrel: KSZ8795 do not set SUPPORTED_[Asym_]Pause gtp: fix cross netns recv on gtp socket gtp: clear DF bit on GTP packet tx nvmet: cancel fatal error and flush async work before free controller i2c: i2c-cadence: Initialize configuration before probing devices tcp: correct memory barrier usage in tcp_check_space() dmaengine: pl330: fix double lock tipc: fix cleanup at module unload tipc: fix nametbl_lock soft lockup at module exit RDMA/qedr: Fix RDMA CM loopback RDMA/qedr: Return success when not changing QP state mac80211: don't try to sleep in rate_control_rate_init() drm/amdgpu: fix unload driver issue for virtual display x86/fpu: Set the xcomp_bv when we fake up a XSAVES area net: sctp: fix array overrun read on sctp_timer_tbl drm/exynos/decon5433: set STANDALONE_UPDATE_F on output enablement drm/amdgpu: fix bug set incorrect value to vce register qla2xxx: Fix wrong IOCB type assumption powerpc/mm: Fix memory hotplug BUG() on radix perf/x86/intel: Account interrupts for PEBS errors NFSv4: Fix client recovery when server reboots multiple times mac80211: prevent skb/txq mismatch KVM: arm/arm64: Fix occasional warning from the timer work function drm/exynos/decon5433: set STANDALONE_UPDATE_F also if planes are disabled drm/exynos/decon5433: update shadow registers iff there are active windows nfs: Don't take a reference on fl->fl_file for LOCK operation ravb: Remove Rx overflow log messages mac80211: calculate min channel width correctly mm: fix remote numa hits statistics net: qrtr: Mark 'buf' as little endian libfs: Modify mount_pseudo_xattr to be clear it is not a userspace mount net/appletalk: Fix kernel memory disclosure be2net: fix unicast list filling be2net: fix accesses to unicast list vti6: fix device register to report IFLA_INFO_KIND ARM: OMAP1: DMA: Correct the number of logical channels ARM: OMAP2+: Fix WL1283 Bluetooth Baud Rate net: systemport: Pad packet before inserting TSB net: systemport: Utilize skb_put_padto() libcxgb: fix error check for ip6_route_output() usb: gadget: f_fs: Fix ExtCompat descriptor validation dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status dmaengine: stm32-dma: Set correct args number for DMA request from DT l2tp: take remote address into account in l2tp_ip and l2tp_ip6 socket lookups net/mlx4_en: Fix type mismatch for 32-bit systems dax: Avoid page invalidation races and unnecessary radix tree traversals iio: adc: ti-ads1015: add 10% to conversion wait time tools include: Do not use poison with C++ kprobes/x86: Disable preemption in ftrace-based jprobes perf test attr: Fix ignored test case result usbip: tools: Install all headers needed for libusbip development sysrq : fix Show Regs call trace on ARM EDAC, sb_edac: Fix missing break in switch x86/entry: Use SYSCALL_DEFINE() macros for sys_modify_ldt() serial: 8250: Preserve DLD[7:4] for PORT_XR17V35X usb: phy: tahvo: fix error handling in tahvo_usb_probe() mmc: sdhci-msm: fix issue with power irq spi: spi-axi: fix potential use-after-free after deregistration spi: sh-msiof: Fix DMA transfer size check staging: rtl8188eu: avoid a null dereference on pmlmepriv serial: 8250_fintek: Fix rs485 disablement on invalid ioctl() m68k: fix ColdFire node shift size calculation staging: greybus: loopback: Fix iteration count on async path selftests/x86/ldt_get: Add a few additional tests for limits s390/pci: do not require AIS facility ima: fix hash algorithm initialization USB: serial: option: add Quectel BG96 id s390/runtime instrumentation: simplify task exit handling serial: 8250_pci: Add Amazon PCI serial device ID usb: quirks: Add no-lpm quirk for KY-688 USB 3.1 Type-C Hub uas: Always apply US_FL_NO_ATA_1X quirk to Seagate devices mm, oom_reaper: gather each vma to prevent leaking TLB entry Revert "crypto: caam - get rid of tasklet" drm/fsl-dcu: enable IRQ before drm_atomic_helper_resume() drm/fsl-dcu: avoid disabling pixel clock twice on suspend bcache: recover data from backing when data is clean bcache: only permit to recovery read error when cache device is clean Linux 4.9.67 drm/i915: Prevent zero length "index" write drm/i915: Don't try indexed reads to alternate slave addresses NFS: revalidate "." etc correctly on "open". Revert "x86/entry/64: Add missing irqflags tracing to native_load_gs_index()" drm/amd/pp: fix typecast error in powerplay. drm/ttm: once more fix ttm_buffer_object_transfer drm/hisilicon: Ensure LDI regs are properly configured. drm/panel: simple: Add missing panel_simple_unprepare() calls drm/radeon: fix atombios on big endian drm/amdgpu: Potential uninitialized variable in amdgpu_vm_update_directories() drm/amdgpu: potential uninitialized variable in amdgpu_vce_ring_parse_cs() Revert "drm/radeon: dont switch vt on suspend" nvme-pci: add quirk for delay before CHK RDY for WDC SN200 hwmon: (jc42) optionally try to disable the SMBUS timeout bcache: Fix building error on MIPS i2c: i801: Fix Failed to allocate irq -2147483648 error eeprom: at24: check at24_read/write arguments eeprom: at24: correctly set the size for at24mac402 eeprom: at24: fix reading from 24MAC402/24MAC602 mmc: core: prepend 0x to OCR entry in sysfs mmc: core: Do not leave the block driver in a suspended state KVM: lapic: Fixup LDR on load in x2apic KVM: lapic: Split out x2apic ldr calculation KVM: x86: inject exceptions produced by x86_decode_insn KVM: x86: Exit to user-mode on #UD intercept when emulator requires KVM: x86: pvclock: Handle first-time write to pvclock-page contains random junk ARM: OMAP2+: Fix WL1283 Bluetooth Baud Rate mfd: twl4030-power: Fix pmic for boards that need vmmc1 on reboot nfsd: fix panic in posix_unblock_lock called from nfs4_laundromat nfsd: Fix another OPEN stateid race nfsd: Fix stateid races between OPEN and CLOSE btrfs: clear space cache inode generation always mm/madvise.c: fix madvise() infinite loop under special circumstances mm, hugetlbfs: introduce ->split() to vm_operations_struct mm/cma: fix alloc_contig_range ret code/potential leak mm, thp: Do not make page table dirty unconditionally in touch_p[mu]d() ARM: dts: omap3: logicpd-torpedo-37xx-devkit: Fix MMC1 cd-gpio ARM: dts: LogicPD Torpedo: Fix camera pin mux Linux 4.9.66 xen: xenbus driver must not accept invalid transaction ids nvmet: fix KATO offset in Set Features cec: update log_addr[] before finishing configuration cec: CEC_MSG_GIVE_FEATURES should abort for CEC version < 2 cec: when canceling a message, don't overwrite old status info s390/kbuild: enable modversions for symbols exported from asm ASoC: wm_adsp: Don't overrun firmware file buffer when reading region data btrfs: return the actual error value from from btrfs_uuid_tree_iterate crypto: marvell - Copy IVDIG before launching partial DMA ahash requests ASoC: rsnd: don't double free kctrl netfilter: nf_tables: fix oob access netfilter: nft_queue: use raw_smp_processor_id() spi: SPI_FSL_DSPI should depend on HAS_DMA staging: iio: cdc: fix improper return value iio: light: fix improper return value adm80211: add checks for dma mapping errors mac80211: Suppress NEW_PEER_CANDIDATE event if no room mac80211: Remove invalid flag operations in mesh TSF synchronization drm/mediatek: don't use drm_put_dev clk: qcom: ipq4019: Add all the frequencies for apss cpu drm: Apply range restriction after color adjustment when allocation gpio: mockup: dynamically allocate memory for chip name ALSA: hda - Apply ALC269_FIXUP_NO_SHUTUP on HDA_FIXUP_ACT_PROBE ath10k: set CTS protection VDEV param only if VDEV is up bnxt_en: Set default completion ring for async events. pinctrl: sirf: atlas7: Add missing 'of_node_put()' ath10k: fix potential memory leak in ath10k_wmi_tlv_op_pull_fw_stats() ath10k: ignore configuring the incorrect board_id ath10k: fix incorrect txpower set by P2P_DEVICE interface mwifiex: sdio: fix use after free issue for save_adapter adm80211: return an error if adm8211_alloc_rings() fails rt2800: set minimum MPDU and PSDU lengths to sane values drm/armada: Fix compile fail net: 3com: typhoon: typhoon_init_one: fix incorrect return values net: 3com: typhoon: typhoon_init_one: make return values more specific net: Allow IP_MULTICAST_IF to set index to L3 slave fscrypt: use ENOTDIR when setting encryption policy on nondirectory fscrypt: use ENOKEY when file cannot be created w/o key dmaengine: zx: set DMA_CYCLIC cap_mask bit clk: sunxi-ng: fix PLL_CPUX adjusting on A33 clk: sunxi-ng: A31: Fix spdif clock register drm/sun4i: Fix a return value in case of error PCI: Apply _HPX settings only to relevant devices RDS: RDMA: fix the ib_map_mr_sg_zbva() argument RDS: RDMA: return appropriate error on rdma map failures RDS: make message size limit compliant with spec e1000e: Avoid receiver overrun interrupt bursts e1000e: Separate signaling for link check/link up e1000e: Fix return value test e1000e: Fix error path in link detection Revert "drm/i915: Do not rely on wm preservation for ILK watermarks" PM / OPP: Add missing of_node_put(np) net/9p: Switch to wait_event_killable() fscrypt: lock mutex before checking for bounce page pool sched/rt: Simplify the IPI based RT balancing logic media: v4l2-ctrl: Fix flags field on Control events cx231xx-cards: fix NULL-deref on missing association descriptor media: rc: check for integer overflow media: Don't do DMA on stack for firmware upload in the AS102 driver powerpc/signal: Properly handle return value from uprobe_deny_signal() parisc: Fix validity check of pointer size argument in new CAS implementation ixgbe: Fix skb list corruption on Power systems fm10k: Use smp_rmb rather than read_barrier_depends i40evf: Use smp_rmb rather than read_barrier_depends ixgbevf: Use smp_rmb rather than read_barrier_depends igbvf: Use smp_rmb rather than read_barrier_depends igb: Use smp_rmb rather than read_barrier_depends i40e: Use smp_rmb rather than read_barrier_depends NFC: fix device-allocation error return IB/srp: Avoid that a cable pull can trigger a kernel crash IB/srpt: Do not accept invalid initiator port names libnvdimm, namespace: make 'resource' attribute only readable by root libnvdimm, namespace: fix label initialization to use valid seq numbers libnvdimm, pfn: make 'resource' attribute only readable by root clk: ti: dra7-atl-clock: fix child-node lookups SUNRPC: Fix tracepoint storage issues with svc_recv and svc_rqst_status KVM: SVM: obey guest PAT KVM: nVMX: set IDTR and GDTR limits when loading L1 host state lockd: double unregister of inetaddr notifiers irqchip/gic-v3: Fix ppi-partitions lookup block: Fix a race between blk_cleanup_queue() and timeout handling p54: don't unregister leds when they are not initialized mtd: nand: mtk: fix infinite ECC decode IRQ issue mtd: nand: Fix writing mtdoops to nand flash. mtd: nand: omap2: Fix subpage write target: Fix QUEUE_FULL + SCSI task attribute handling iscsi-target: Fix non-immediate TMR reference leak fs/9p: Compare qid.path in v9fs_test_inode fix a page leak in vhost_scsi_iov_to_sgl() error recovery ALSA: hda/realtek - Fix ALC700 family no sound issue ALSA: hda: Fix too short HDMI/DP chmap reporting ALSA: timer: Remove kernel warning at compat ioctl error paths ALSA: usb-audio: Add sanity checks in v2 clock parsers ALSA: usb-audio: Fix potential out-of-bound access at parsing SU ALSA: usb-audio: Add sanity checks to FE parser ALSA: pcm: update tstamp only if audio_tstamp changed ext4: fix interaction between i_size, fallocate, and delalloc after a crash ata: fixes kernel crash while tracing ata_eh_link_autopsy event rtlwifi: fix uninitialized rtlhal->last_suspend_sec time rtlwifi: rtl8192ee: Fix memory leak when loading firmware nfsd: deal with revoked delegations appropriately NFS: Avoid RCU usage in tracepoints nfs: Fix ugly referral attributes NFS: Fix typo in nomigration mount option isofs: fix timestamps beyond 2027 bcache: check ca->alloc_thread initialized before wake up it libceph: don't WARN() if user tries to add invalid key eCryptfs: use after free in ecryptfs_release_messaging() nilfs2: fix race condition that causes file system corruption autofs: don't fail mount for transient error rt2x00usb: mark device removed when get ENOENT usb error MIPS: BCM47XX: Fix LED inversion for WRT54GSv1 MIPS: Fix an n32 core file generation regset support regression MIPS: dts: remove bogus bcm96358nb4ser.dtb from dtb-y entry MIPS: Fix odd fp register warnings with MIPS64r2 dm: fix race between dm_get_from_kobject() and __dm_destroy() MIPS: pci: Remove KERN_WARN instance inside the mt7620 driver dm: allocate struct mapped_device with kvzalloc dm bufio: fix integer overflow when limiting maximum cache size ALSA: hda: Add Raven PCI ID PCI: Set Cavium ACS capability quirk flags to assert RR/CR/SV/UF MIPS: ralink: Fix typo in mt7628 pinmux function MIPS: ralink: Fix MT7628 pinmux ARM: 8721/1: mm: dump: check hardware RO bit for LPAE ARM: 8722/1: mm: make STRICT_KERNEL_RWX effective for LPAE arm64: Implement arch-specific pte_access_permitted() x86/entry/64: Add missing irqflags tracing to native_load_gs_index() x86/decoder: Add new TEST instruction pattern lib/mpi: call cond_resched() from mpi_powm() loop sched: Make resched_cpu() unconditional vsock: use new wait API for vsock_stream_sendmsg() ipv6: only call ip6_route_dev_notify() once for NETDEV_UNREGISTER x86/mm: fix use-after-free of vma during userfaultfd fault ACPI / EC: Fix regression related to triggering source of EC event handling s390/disassembler: increase show_code buffer size s390/disassembler: add missing end marker for e7 table s390/runtime instrumention: fix possible memory corruption s390: fix transactional execution control register handling Conflicts: drivers/android/binder_alloc.c drivers/android/binder_alloc.h drivers/android/binder_alloc_selftest.c drivers/mmc/core/bus.c drivers/mmc/host/sdhci-msm.c drivers/thermal/step_wise.c kernel/cpu.c mm/oom_kill.c sound/usb/mixer.c Change-Id: Id01eb66cafc5970b460321e44ec8ffcfa76971a6 Signed-off-by: Kyle Yan <kyan@codeaurora.org>
3333 lines
81 KiB
C
3333 lines
81 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 <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 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);
|
|
|
|
/*
|
|
* 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;
|
|
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));
|
|
|
|
sock->sk->sk_uid = iattr->ia_uid;
|
|
}
|
|
|
|
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.
|
|
*/
|
|
|
|
void sock_release(struct socket *sock)
|
|
{
|
|
if (sock->ops) {
|
|
struct module *owner = sock->ops->owner;
|
|
|
|
sock->ops->release(sock);
|
|
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;
|
|
}
|
|
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));
|
|
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;
|
|
|
|
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);
|
|
}
|
|
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 = 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);
|
|
|
|
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;
|
|
|
|
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);
|
|
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) {
|
|
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;
|
|
|
|
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) ||
|
|
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 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);
|