a6b9d0d53d
* remotes/origin/tmp-e699d54: ANDROID: HID: Only utilise UHID provided exports if UHID is enabled ANDROID: HID; Over-ride default maximum buffer size when using UHID Revert "ANDROID: AVB error handler to invalidate vbmeta partition." UPSTREAM: mailbox: mailbox-test: fix a locking issue in mbox_test_message_write() UPSTREAM: mailbox: mailbox-test: Fix potential double-free in mbox_test_message_write() UPSTREAM: efi: rt-wrapper: Add missing include BACKPORT: arm64: efi: Execute runtime services from a dedicated stack UPSTREAM: io_uring: have io_kill_timeout() honor the request references UPSTREAM: io_uring: don't drop completion lock before timer is fully initialized UPSTREAM: io_uring: always grab lock in io_cancel_async_work() UPSTREAM: net: cdc_ncm: Deal with too low values of dwNtbOutMaxSize UPSTREAM: cdc_ncm: Fix the build warning UPSTREAM: cdc_ncm: Implement the 32-bit version of NCM Transfer Block UPSTREAM: ext4: avoid a potential slab-out-of-bounds in ext4_group_desc_csum UPSTREAM: ext4: fix invalid free tracking in ext4_xattr_move_to_block() Revert "Revert "mm/rmap: Fix anon_vma->degree ambiguity leading to double-reuse"" FROMLIST: binder: fix UAF caused by faulty buffer cleanup UPSTREAM: usb: musb: mediatek: don't unregister something that wasn't registered UPSTREAM: net: fix NULL pointer in skb_segment_list UPSTREAM: xfrm/compat: prevent potential spectre v1 gadget in xfrm_xlate32_attr() UPSTREAM: xfrm: compat: change expression for switch in xfrm_xlate64 UPSTREAM: perf/core: Call LSM hook after copying perf_event_attr UPSTREAM: ext4: fix use-after-free in ext4_xattr_set_entry UPSTREAM: ext4: remove duplicate definition of ext4_xattr_ibody_inline_set() UPSTREAM: Revert "ext4: fix use-after-free in ext4_xattr_set_entry" Linux 5.4.242 ASN.1: Fix check for strdup() success iio: adc: at91-sama5d2_adc: fix an error code in at91_adc_allocate_trigger() pwm: meson: Explicitly set .polarity in .get_state() xfs: fix forkoff miscalculation related to XFS_LITINO(mp) sctp: Call inet6_destroy_sock() via sk->sk_destruct(). dccp: Call inet6_destroy_sock() via sk->sk_destruct(). inet6: Remove inet6_destroy_sock() in sk->sk_prot->destroy(). tcp/udp: Call inet6_destroy_sock() in IPv6 sk->sk_destruct(). udp: Call inet6_destroy_sock() in setsockopt(IPV6_ADDRFORM). ext4: fix use-after-free in ext4_xattr_set_entry ext4: remove duplicate definition of ext4_xattr_ibody_inline_set() Revert "ext4: fix use-after-free in ext4_xattr_set_entry" x86/purgatory: Don't generate debug info for purgatory.ro MIPS: Define RUNTIME_DISCARD_EXIT in LD script mmc: sdhci_am654: Set HIGH_SPEED_ENA for SDR12 and SDR25 memstick: fix memory leak if card device is never registered nilfs2: initialize unused bytes in segment summary blocks iio: light: tsl2772: fix reading proximity-diodes from device tree xen/netback: use same error messages for same errors nvme-tcp: fix a possible UAF when failing to allocate an io queue s390/ptrace: fix PTRACE_GET_LAST_BREAK error handling net: dsa: b53: mmap: add phy ops scsi: core: Improve scsi_vpd_inquiry() checks scsi: megaraid_sas: Fix fw_crash_buffer_show() selftests: sigaltstack: fix -Wuninitialized Input: i8042 - add quirk for Fujitsu Lifebook A574/H f2fs: Fix f2fs_truncate_partial_nodes ftrace event e1000e: Disable TSO on i219-LM card to increase speed bpf: Fix incorrect verifier pruning due to missing register precision taints mlxfw: fix null-ptr-deref in mlxfw_mfa2_tlv_next() i40e: fix i40e_setup_misc_vector() error handling i40e: fix accessing vsi->active_filters without holding lock netfilter: nf_tables: fix ifdef to also consider nf_tables=m virtio_net: bugfix overflow inside xdp_linearize_page() net: sched: sch_qfq: prevent slab-out-of-bounds in qfq_activate_agg regulator: fan53555: Explicitly include bits header netfilter: br_netfilter: fix recent physdev match breakage arm64: dts: meson-g12-common: specify full DMC range ARM: dts: rockchip: fix a typo error for rk3288 spdif node Linux 5.4.241 xfs: force log and push AIL to clear pinned inodes when aborting mount xfs: don't reuse busy extents on extent trim xfs: consider shutdown in bmapbt cursor delete assert xfs: shut down the filesystem if we screw up quota reservation xfs: report corruption only as a regular error xfs: set inode size after creating symlink xfs: fix up non-directory creation in SGID directories xfs: remove the di_version field from struct icdinode xfs: simplify a check in xfs_ioctl_setattr_check_cowextsize xfs: simplify di_flags2 inheritance in xfs_ialloc xfs: only check the superblock version for dinode size calculation xfs: add a new xfs_sb_version_has_v3inode helper xfs: remove the kuid/kgid conversion wrappers xfs: remove the icdinode di_uid/di_gid members xfs: ensure that the inode uid/gid match values match the icdinode ones xfs: merge the projid fields in struct xfs_icdinode xfs: show the proper user quota options coresight-etm4: Fix for() loop drvdata->nr_addr_cmp range bug watchdog: sbsa_wdog: Make sure the timeout programming is within the limits i2c: ocores: generate stop condition after timeout in polling mode ubi: Fix deadlock caused by recursively holding work_sem mtd: ubi: wl: Fix a couple of kernel-doc issues ubi: Fix failure attaching when vid_hdr offset equals to (sub)page size asymmetric_keys: log on fatal failures in PE/pkcs7 verify_pefile: relax wrapper length check drm: panel-orientation-quirks: Add quirk for Lenovo Yoga Book X90F efi: sysfb_efi: Add quirk for Lenovo Yoga Book X91F/L i2c: imx-lpi2c: clean rx/tx buffers upon new message power: supply: cros_usbpd: reclassify "default case!" as debug net: macb: fix a memory corruption in extended buffer descriptor mode udp6: fix potential access to stale information RDMA/core: Fix GID entry ref leak when create_ah fails sctp: fix a potential overflow in sctp_ifwdtsn_skip qlcnic: check pci_reset_function result niu: Fix missing unwind goto in niu_alloc_channels() 9p/xen : Fix use after free bug in xen_9pfs_front_remove due to race condition mtd: rawnand: stm32_fmc2: remove unsupported EDO mode mtd: rawnand: meson: fix bitmask for length in command word mtdblock: tolerate corrected bit-flips btrfs: fix fast csum implementation detection btrfs: print checksum type and implementation at mount time Bluetooth: Fix race condition in hidp_session_thread Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp} ALSA: hda/sigmatel: fix S/PDIF out on Intel D*45* motherboards ALSA: firewire-tascam: add missing unwind goto in snd_tscm_stream_start_duplex() ALSA: i2c/cs8427: fix iec958 mixer control deactivation ALSA: hda/sigmatel: add pin overrides for Intel DP45SG motherboard ALSA: emu10k1: fix capture interrupt handler unlinking Revert "pinctrl: amd: Disable and mask interrupts on resume" irqdomain: Fix mapping-creation race irqdomain: Refactor __irq_domain_alloc_irqs() irqdomain: Look for existing mapping only once mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() ring-buffer: Fix race while reader and writer are on the same page drm/panfrost: Fix the panfrost_mmu_map_fault_addr() error path net_sched: prevent NULL dereference if default qdisc setup failed tracing: Free error logs of tracing instances can: j1939: j1939_tp_tx_dat_new(): fix out-of-bounds memory access ftrace: Mark get_lock_parent_ip() __always_inline perf/core: Fix the same task check in perf_event_set_output ALSA: hda/realtek: Add quirk for Clevo X370SNW nilfs2: fix sysfs interface lifetime nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread() tty: serial: fsl_lpuart: avoid checking for transfer complete when UARTCTRL_SBK is asserted in lpuart32_tx_empty tty: serial: sh-sci: Fix Rx on RZ/G2L SCI tty: serial: sh-sci: Fix transmit end interrupt handler iio: dac: cio-dac: Fix max DAC write value check for 12-bit iio: adc: ti-ads7950: Set `can_sleep` flag for GPIO chip USB: serial: option: add Quectel RM500U-CN modem USB: serial: option: add Telit FE990 compositions usb: typec: altmodes/displayport: Fix configure initial pin assignment USB: serial: cp210x: add Silicon Labs IFS-USB-DATACABLE IDs xhci: also avoid the XHCI_ZERO_64B_REGS quirk with a passthrough iommu NFSD: callback request does not use correct credential for AUTH_SYS sunrpc: only free unix grouplist after RCU settles gpio: davinci: Add irq chip flag to skip set wake ipv6: Fix an uninit variable access bug in __ip6_make_skb() sctp: check send stream number after wait_for_sndbuf net: don't let netpoll invoke NAPI if in xmit context icmp: guard against too small mtu wifi: mac80211: fix invalid drv_sta_pre_rcu_remove calls for non-uploaded sta pwm: sprd: Explicitly set .polarity in .get_state() pwm: cros-ec: Explicitly set .polarity in .get_state() pinctrl: amd: Disable and mask interrupts on resume pinctrl: amd: disable and mask interrupts on probe pinctrl: amd: Use irqchip template smb3: fix problem with null cifs super block with previous patch treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD() Revert "treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD()" cgroup/cpuset: Wake up cpuset_attach_wq tasks in cpuset_cancel_attach() x86/PCI: Add quirk for AMD XHCI controller that loses MSI-X state in D3hot scsi: ses: Handle enclosure with just a primary component gracefully Linux 5.4.240 gfs2: Always check inode size of inline inodes firmware: arm_scmi: Fix device node validation for mailbox transport net: sched: fix race condition in qdisc_graft() net_sched: add __rcu annotation to netdev->qdisc ext4: fix kernel BUG in 'ext4_write_inline_data_end()' btrfs: scan device in non-exclusive mode s390/uaccess: add missing earlyclobber annotations to __clear_user() drm/etnaviv: fix reference leak when mmaping imported buffer ALSA: usb-audio: Fix regression on detection of Roland VS-100 ALSA: hda/conexant: Partial revert of a quirk for Lenovo NFSv4: Fix hangs when recovering open state after a server reboot pinctrl: at91-pio4: fix domain name assignment xen/netback: don't do grant copy across page boundary Input: goodix - add Lenovo Yoga Book X90F to nine_bytes_report DMI table cifs: fix DFS traversal oops without CONFIG_CIFS_DFS_UPCALL cifs: prevent infinite recursion in CIFSGetDFSRefer() Input: focaltech - use explicitly signed char type Input: alps - fix compatibility with -funsigned-char pinctrl: ocelot: Fix alt mode for ocelot net: mvneta: make tx buffer array agnostic net: dsa: mv88e6xxx: Enable IGMP snooping on user ports only bnxt_en: Fix typo in PCI id to device description string mapping i40e: fix registers dump after run ethtool adapter self test s390/vfio-ap: fix memory leak in vfio_ap device driver can: bcm: bcm_tx_setup(): fix KMSAN uninit-value in vfs_write net/net_failover: fix txq exceeding warning regulator: Handle deferred clk regulator: fix spelling mistake "Cant" -> "Can't" ptp_qoriq: fix memory leak in probe() scsi: megaraid_sas: Fix crash after a double completion mtd: rawnand: meson: invalidate cache on polling ECC bit mips: bmips: BCM6358: disable RAC flush for TP1 dma-mapping: drop the dev argument to arch_sync_dma_for_* ca8210: Fix unsigned mac_len comparison with zero in ca8210_skb_tx() fbdev: au1200fb: Fix potential divide by zero fbdev: lxfb: Fix potential divide by zero fbdev: intelfb: Fix potential divide by zero fbdev: nvidia: Fix potential divide by zero sched_getaffinity: don't assume 'cpumask_size()' is fully initialized fbdev: tgafb: Fix potential divide by zero ALSA: hda/ca0132: fixup buffer overrun at tuning_ctl_set() ALSA: asihpi: check pao in control_message() md: avoid signed overflow in slot_store() bus: imx-weim: fix branch condition evaluates to a garbage value fsverity: don't drop pagecache at end of FS_IOC_ENABLE_VERITY ocfs2: fix data corruption after failed write tun: avoid double free in tun_free_netdev sched/fair: Sanitize vruntime of entity being migrated sched/fair: sanitize vruntime of entity being placed dm crypt: add cond_resched() to dmcrypt_write() dm stats: check for and propagate alloc_percpu failure i2c: xgene-slimpro: Fix out-of-bounds bug in xgene_slimpro_i2c_xfer() nilfs2: fix kernel-infoleak in nilfs_ioctl_wrap_copy() wifi: mac80211: fix qos on mesh interfaces usb: chipidea: core: fix possible concurrent when switch role usb: chipdea: core: fix return -EINVAL if request role is the same with current role usb: cdns3: Fix issue with using incorrect PCI device function dm thin: fix deadlock when swapping to thin device igb: revert rtnl_lock() that causes deadlock fsverity: Remove WQ_UNBOUND from fsverity read workqueue usb: gadget: u_audio: don't let userspace block driver unbind scsi: core: Add BLIST_SKIP_VPD_PAGES for SKhynix H28U74301AMR cifs: empty interface list when server doesn't support query interfaces sh: sanitize the flags on sigreturn net: usb: qmi_wwan: add Telit 0x1080 composition net: usb: cdc_mbim: avoid altsetting toggling for Telit FE990 scsi: lpfc: Avoid usage of list iterator variable after loop scsi: ufs: core: Add soft dependency on governor_simpleondemand scsi: target: iscsi: Fix an error message in iscsi_check_key() selftests/bpf: check that modifier resolves after pointer m68k: Only force 030 bus error if PC not in exception table ca8210: fix mac_len negative array access riscv: Bump COMMAND_LINE_SIZE value to 1024 thunderbolt: Use const qualifier for `ring_interrupt_index` uas: Add US_FL_NO_REPORT_OPCODES for JMicron JMS583Gen 2 scsi: qla2xxx: Perform lockless command completion in abort path hwmon (it87): Fix voltage scaling for chips with 10.9mV ADCs platform/chrome: cros_ec_chardev: fix kernel data leak from ioctl Bluetooth: btsdio: fix use after free bug in btsdio_remove due to unfinished work Bluetooth: btqcomsmd: Fix command timeout after setting BD address net: mdio: thunder: Add missing fwnode_handle_put() hvc/xen: prevent concurrent accesses to the shared ring nvme-tcp: fix nvme_tcp_term_pdu to match spec net/sonic: use dma_mapping_error() for error check erspan: do not use skb_mac_header() in ndo_start_xmit() atm: idt77252: fix kmemleak when rmmod idt77252 net/mlx5: Read the TC mapping of all priorities on ETS query bpf: Adjust insufficient default bpf_jit_limit keys: Do not cache key in task struct if key is requested from kernel thread net/ps3_gelic_net: Use dma_mapping_error net/ps3_gelic_net: Fix RX sk_buff length net: qcom/emac: Fix use after free bug in emac_remove due to race condition xirc2ps_cs: Fix use after free bug in xirc2ps_detach qed/qed_sriov: guard against NULL derefs from qed_iov_get_vf_info net: usb: smsc95xx: Limit packet length to skb->len scsi: scsi_dh_alua: Fix memleak for 'qdata' in alua_activate() i2c: imx-lpi2c: check only for enabled interrupt flags igbvf: Regard vf reset nack as success intel/igbvf: free irq on the error path in igbvf_request_msix() iavf: fix non-tunneled IPv6 UDP packet type and hashing iavf: fix inverted Rx hash condition leading to disabled hash power: supply: da9150: Fix use after free bug in da9150_charger_remove due to race condition net: tls: fix possible race condition between do_tls_getsockopt_conf() and do_tls_setsockopt_conf() Linux 5.4.239 selftests: Fix the executable permissions for fib_tests.sh BACKPORT: mac80211_hwsim: notify wmediumd of used MAC addresses FROMGIT: mac80211_hwsim: add concurrent channels scanning support over virtio Revert "HID: core: Provide new max_buffer_size attribute to over-ride the default" Revert "HID: uhid: Over-ride the default maximum data buffer value with our own" Linux 5.4.238 HID: uhid: Over-ride the default maximum data buffer value with our own HID: core: Provide new max_buffer_size attribute to over-ride the default PCI: Unify delay handling for reset and resume s390/ipl: add missing intersection check to ipl_report handling serial: 8250_em: Fix UART port type drm/i915: Don't use stolen memory for ring buffers with LLC x86/mm: Fix use of uninitialized buffer in sme_enable() fbdev: stifb: Provide valid pixelclock and add fb_check_var() checks ftrace: Fix invalid address access in lookup_rec() when index is 0 KVM: nVMX: add missing consistency checks for CR0 and CR4 tracing: Make tracepoint lockdep check actually test something tracing: Check field value in hist_field_name() interconnect: fix mem leak when freeing nodes tty: serial: fsl_lpuart: skip waiting for transmission complete when UARTCTRL_SBK is asserted ext4: fix possible double unlock when moving a directory sh: intc: Avoid spurious sizeof-pointer-div warning drm/amdkfd: Fix an illegal memory access ext4: fix task hung in ext4_xattr_delete_inode ext4: fail ext4_iget if special inode unallocated jffs2: correct logic when creating a hole in jffs2_write_begin mmc: atmel-mci: fix race between stop command and start of next command media: m5mols: fix off-by-one loop termination error hwmon: (ina3221) return prober error code hwmon: (xgene) Fix use after free bug in xgene_hwmon_remove due to race condition hwmon: (adt7475) Fix masking of hysteresis registers hwmon: (adt7475) Display smoothing attributes in correct order ethernet: sun: add check for the mdesc_grab() net/iucv: Fix size of interrupt data net: usb: smsc75xx: Move packet length check to prevent kernel panic in skb_pull ipv4: Fix incorrect table ID in IOCTL path block: sunvdc: add check for mdesc_grab() returning NULL nvmet: avoid potential UAF in nvmet_req_complete() net: usb: smsc75xx: Limit packet length to skb->len nfc: st-nci: Fix use after free bug in ndlc_remove due to race condition net: phy: smsc: bail out in lan87xx_read_status if genphy_read_status fails net: tunnels: annotate lockless accesses to dev->needed_headroom qed/qed_dev: guard against a possible division by zero i40e: Fix kernel crash during reboot when adapter is in recovery mode ipvlan: Make skb->skb_iif track skb->dev for l3s mode nfc: pn533: initialize struct pn533_out_arg properly tcp: tcp_make_synack() can be called from process context scsi: core: Fix a procfs host directory removal regression scsi: core: Fix a comment in function scsi_host_dev_release() netfilter: nft_redir: correct value of inet type `.maxattrs` ALSA: hda: Match only Intel devices with CONTROLLER_IN_GPU() ALSA: hda: Add Intel DG2 PCI ID and HDMI codec vid ALSA: hda: Add Alderlake-S PCI ID and HDMI codec vid ALSA: hda - controller is in GPU on the DG1 ALSA: hda - add Intel DG1 PCI and HDMI ids scsi: mpt3sas: Fix NULL pointer access in mpt3sas_transport_port_add() docs: Correct missing "d_" prefix for dentry_operations member d_weak_revalidate clk: HI655X: select REGMAP instead of depending on it drm/meson: fix 1px pink line on GXM when scaling video overlay cifs: Move the in_send statistic to __smb_send_rqst() drm/panfrost: Don't sync rpm suspension after mmu flushing xfrm: Allow transport-mode states with AF_UNSPEC selector ext4: fix cgroup writeback accounting with fs-layer encryption ANDROID: preserve CRC for __irq_domain_add() Revert "drm/exynos: Don't reset bridge->next" Revert "drm/bridge: Rename bridge helpers targeting a bridge chain" Revert "drm/bridge: Introduce drm_bridge_get_next_bridge()" Revert "drm: Initialize struct drm_crtc_state.no_vblank from device settings" Revert "drm/msm/mdp5: Add check for kzalloc" Linux 5.4.237 s390/dasd: add missing discipline function UML: define RUNTIME_DISCARD_EXIT sh: define RUNTIME_DISCARD_EXIT s390: define RUNTIME_DISCARD_EXIT to fix link error with GNU ld < 2.36 powerpc/vmlinux.lds: Don't discard .rela* for relocatable builds powerpc/vmlinux.lds: Define RUNTIME_DISCARD_EXIT arch: fix broken BuildID for arm64 and riscv x86, vmlinux.lds: Add RUNTIME_DISCARD_EXIT to generic DISCARDS drm/i915: Don't use BAR mappings for ring buffers with LLC ipmi:watchdog: Set panic count to proper value on a panic ipmi/watchdog: replace atomic_add() and atomic_sub() media: ov5640: Fix analogue gain control PCI: Add SolidRun vendor ID macintosh: windfarm: Use unsigned type for 1-bit bitfields alpha: fix R_ALPHA_LITERAL reloc for large modules MIPS: Fix a compilation issue ext4: Fix deadlock during directory rename riscv: Use READ_ONCE_NOCHECK in imprecise unwinding stack mode net/smc: fix fallback failed while sendmsg with fastopen scsi: megaraid_sas: Update max supported LD IDs to 240 btf: fix resolving BTF_KIND_VAR after ARRAY, STRUCT, UNION, PTR netfilter: tproxy: fix deadlock due to missing BH disable bnxt_en: Avoid order-5 memory allocation for TPA data net: caif: Fix use-after-free in cfusbl_device_notify() net: lan78xx: fix accessing the LAN7800's internal phy specific registers from the MAC driver net: usb: lan78xx: Remove lots of set but unused 'ret' variables selftests: nft_nat: ensuring the listening side is up before starting the client ila: do not generate empty messages in ila_xlat_nl_cmd_get_mapping() nfc: fdp: add null check of devm_kmalloc_array in fdp_nci_i2c_read_device_properties drm/msm/a5xx: fix setting of the CP_PREEMPT_ENABLE_LOCAL register ext4: Fix possible corruption when moving a directory scsi: core: Remove the /proc/scsi/${proc_name} directory earlier cifs: Fix uninitialized memory read in smb3_qfs_tcon() SMB3: Backup intent flag missing from some more ops iommu/vt-d: Fix PASID directory pointer coherency irqdomain: Fix domain registration race irqdomain: Change the type of 'size' in __irq_domain_add() to be consistent ipmi:ssif: Add a timer between request retries ipmi:ssif: Increase the message retry time ipmi:ssif: Remove rtc_us_timer ipmi:ssif: resend_msg() cannot fail ipmi:ssif: make ssif_i2c_send() void iommu/amd: Add a length limitation for the ivrs_acpihid command-line parameter iommu/amd: Fix ill-formed ivrs_ioapic, ivrs_hpet and ivrs_acpihid options iommu/amd: Add PCI segment support for ivrs_[ioapic/hpet/acpihid] commands nfc: change order inside nfc_se_io error path ext4: zero i_disksize when initializing the bootloader inode ext4: fix WARNING in ext4_update_inline_data ext4: move where set the MAY_INLINE_DATA flag is set ext4: fix another off-by-one fsmap error on 1k block filesystems ext4: fix RENAME_WHITEOUT handling for inline directories drm/connector: print max_requested_bpc in state debugfs x86/CPU/AMD: Disable XSAVES on AMD family 0x17 fs: prevent out-of-bounds array speculation when closing a file descriptor Linux 5.4.236 staging: rtl8192e: Remove call_usermodehelper starting RadioPower.sh staging: rtl8192e: Remove function ..dm_check_ac_dc_power calling a script wifi: cfg80211: Partial revert "wifi: cfg80211: Fix use after free for wext" Linux 5.4.235 dt-bindings: rtc: sun6i-a31-rtc: Loosen the requirements on the clocks media: uvcvideo: Fix race condition with usb_kill_urb media: uvcvideo: Provide sync and async uvc_ctrl_status_event tcp: Fix listen() regression in 5.4.229. Bluetooth: hci_sock: purge socket queues in the destruct() callback x86/resctl: fix scheduler confusion with 'current' x86/resctrl: Apply READ_ONCE/WRITE_ONCE to task_struct.{rmid,closid} net: tls: avoid hanging tasks on the tx_lock phy: rockchip-typec: Fix unsigned comparison with less than zero PCI: Add ACS quirk for Wangxun NICs kernel/fail_function: fix memory leak with using debugfs_lookup() usb: uvc: Enumerate valid values for color matching USB: ene_usb6250: Allocate enough memory for full object usb: host: xhci: mvebu: Iterate over array indexes instead of using pointer math iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_config_word() iio: accel: mma9551_core: Prevent uninitialized variable in mma9551_read_status_word() tools/iio/iio_utils:fix memory leak mei: bus-fixup:upon error print return values of send and receive tty: serial: fsl_lpuart: disable the CTS when send break signal tty: fix out-of-bounds access in tty_driver_lookup_tty() staging: emxx_udc: Add checks for dma_alloc_coherent() media: uvcvideo: Silence memcpy() run-time false positive warnings media: uvcvideo: Quirk for autosuspend in Logitech B910 and C910 media: uvcvideo: Handle errors from calls to usb_string media: uvcvideo: Handle cameras with invalid descriptors mfd: arizona: Use pm_runtime_resume_and_get() to prevent refcnt leak firmware/efi sysfb_efi: Add quirk for Lenovo IdeaPad Duet 3 tracing: Add NULL checks for buffer in ring_buffer_free_read_page() thermal: intel: BXT_PMIC: select REGMAP instead of depending on it thermal: intel: quark_dts: fix error pointer dereference scsi: ipr: Work around fortify-string warning rtc: sun6i: Always export the internal oscillator rtc: sun6i: Make external 32k oscillator optional vc_screen: modify vcs_size() handling in vcs_read() tcp: tcp_check_req() can be called from process context ARM: dts: spear320-hmi: correct STMPE GPIO compatible net/sched: act_sample: fix action bind logic nfc: fix memory leak of se_io context in nfc_genl_se_io net/mlx5: Geneve, Fix handling of Geneve object id as error code 9p/rdma: unmap receive dma buffer in rdma_request()/post_recv() 9p/xen: fix connection sequence 9p/xen: fix version parsing net: fix __dev_kfree_skb_any() vs drop monitor sctp: add a refcnt in sctp_stream_priorities to avoid a nested loop ipv6: Add lwtunnel encap size of all siblings in nexthop calculation netfilter: ctnetlink: fix possible refcount leak in ctnetlink_create_conntrack() watchdog: pcwd_usb: Fix attempting to access uninitialized memory watchdog: Fix kmemleak in watchdog_cdev_register watchdog: at91sam9_wdt: use devm_request_irq to avoid missing free_irq() in error path x86: um: vdso: Add '%rcx' and '%r11' to the syscall clobber list ubi: ubi_wl_put_peb: Fix infinite loop when wear-leveling work failed ubi: Fix UAF wear-leveling entry in eraseblk_count_seq_show() ubifs: ubifs_writepage: Mark page dirty after writing inode failed ubifs: dirty_cow_znode: Fix memleak in error handling path ubifs: Re-statistic cleaned znode count if commit failed ubi: Fix possible null-ptr-deref in ubi_free_volume() ubifs: Fix memory leak in alloc_wbufs() ubi: Fix unreferenced object reported by kmemleak in ubi_resize_volume() ubi: Fix use-after-free when volume resizing failed ubifs: Reserve one leb for each journal head while doing budget ubifs: do_rename: Fix wrong space budget when target inode's nlink > 1 ubifs: Fix wrong dirty space budget for dirty inode ubifs: Rectify space budget for ubifs_xrename() ubifs: Rectify space budget for ubifs_symlink() if symlink is encrypted ubifs: Fix build errors as symbol undefined ubi: ensure that VID header offset + VID header size <= alloc, size um: vector: Fix memory leak in vector_config fs: f2fs: initialize fsdata in pagecache_write() f2fs: use memcpy_{to,from}_page() where possible pwm: stm32-lp: fix the check on arr and cmp registers update pwm: sifive: Always let the first pwm_apply_state succeed pwm: sifive: Reduce time the controller lock is held fs/jfs: fix shift exponent db_agl2size negative net/sched: Retire tcindex classifier kbuild: Port silent mode detection to future gnu make. wifi: ath9k: use proper statements in conditionals drm/radeon: Fix eDP for single-display iMac11,2 drm/i915/quirks: Add inverted backlight quirk for HP 14-r206nv PCI: Avoid FLR for AMD FCH AHCI adapters PCI: hotplug: Allow marking devices as disconnected during bind/unbind PCI/PM: Observe reset delay irrespective of bridge_d3 scsi: ses: Fix slab-out-of-bounds in ses_intf_remove() scsi: ses: Fix possible desc_ptr out-of-bounds accesses scsi: ses: Fix possible addl_desc_ptr out-of-bounds accesses scsi: ses: Fix slab-out-of-bounds in ses_enclosure_data_process() scsi: ses: Don't attach if enclosure has no components scsi: qla2xxx: Fix erroneous link down scsi: qla2xxx: Fix DMA-API call trace on NVMe LS requests scsi: qla2xxx: Fix link failure in NPIV environment ktest.pl: Add RUN_TIMEOUT option with default unlimited ktest.pl: Fix missing "end_monitor" when machine check fails ktest.pl: Give back console on Ctrt^C on monitor mm/thp: check and bail out if page in deferred queue already mm: memcontrol: deprecate charge moving media: ipu3-cio2: Fix PM runtime usage_count in driver unbind mips: fix syscall_get_nr alpha: fix FEN fault handling rbd: avoid use-after-free in do_rbd_add() when rbd_dev_create() fails ARM: dts: exynos: correct TMU phandle in Odroid XU ARM: dts: exynos: correct TMU phandle in Exynos4 dm flakey: don't corrupt the zero page dm flakey: fix logic when corrupting a bio thermal: intel: powerclamp: Fix cur_state for multi package system wifi: cfg80211: Fix use after free for wext wifi: rtl8xxxu: Use a longer retry limit of 48 ext4: refuse to create ea block when umounted ext4: optimize ea_inode block expansion ALSA: hda/realtek: Add quirk for HP EliteDesk 800 G6 Tower PC ALSA: ice1712: Do not left ice->gpio_mutex locked in aureon_add_controls() irqdomain: Drop bogus fwspec-mapping error handling irqdomain: Fix disassociation race irqdomain: Fix association race ima: Align ima_file_mmap() parameters with mmap_file LSM hook Documentation/hw-vuln: Document the interaction between IBRS and STIBP x86/speculation: Allow enabling STIBP with legacy IBRS x86/microcode/AMD: Fix mixed steppings support x86/microcode/AMD: Add a @cpu parameter to the reloading functions x86/microcode/amd: Remove load_microcode_amd()'s bsp parameter x86/kprobes: Fix arch_check_optimized_kprobe check within optimized_kprobe range x86/kprobes: Fix __recover_optprobed_insn check optimizing logic x86/reboot: Disable SVM, not just VMX, when stopping CPUs x86/reboot: Disable virtualization in an emergency if SVM is supported x86/crash: Disable virt in core NMI crash handler to avoid double shootdown x86/virt: Force GIF=1 prior to disabling SVM (for reboot flows) KVM: s390: disable migration mode when dirty tracking is disabled KVM: Destroy target device if coalesced MMIO unregistration fails udf: Fix file corruption when appending just after end of preallocated extent udf: Detect system inodes linked into directory hierarchy udf: Preserve link count of system files udf: Do not update file length for failed writes to inline files udf: Do not bother merging very long extents udf: Truncate added extents on failed expansion ocfs2: fix non-auto defrag path not working issue ocfs2: fix defrag path triggering jbd2 ASSERT f2fs: fix cgroup writeback accounting with fs-layer encryption f2fs: fix information leak in f2fs_move_inline_dirents() fs: hfsplus: fix UAF issue in hfsplus_put_super hfs: fix missing hfs_bnode_get() in __hfs_bnode_create ARM: dts: exynos: correct HDMI phy compatible in Exynos4 s390/kprobes: fix current_kprobe never cleared after kprobes reenter s390/kprobes: fix irq mask clobbering on kprobe reenter from post_handler s390: discard .interp section ipmi_ssif: Rename idle state and check rtc: pm8xxx: fix set-alarm race firmware: coreboot: framebuffer: Ignore reserved pixel color bits wifi: rtl8xxxu: fixing transmisison failure for rtl8192eu nfsd: zero out pointers after putting nfsd_files on COPY setup error dm cache: add cond_resched() to various workqueue loops dm thin: add cond_resched() to various workqueue loops drm: panel-orientation-quirks: Add quirk for Lenovo IdeaPad Duet 3 10IGL5 pinctrl: at91: use devm_kasprintf() to avoid potential leaks hwmon: (coretemp) Simplify platform device handling regulator: s5m8767: Bounds check id indexing into arrays regulator: max77802: Bounds check regulator id against opmode ASoC: kirkwood: Iterate over array indexes instead of using pointer math docs/scripts/gdb: add necessary make scripts_gdb step drm/msm/dsi: Add missing check for alloc_ordered_workqueue drm/radeon: free iio for atombios when driver shutdown HID: Add Mapping for System Microphone Mute drm/omap: dsi: Fix excessive stack usage drm/amd/display: Fix potential null-deref in dm_resume uaccess: Add minimum bounds check on kernel buffer size coda: Avoid partial allocation of sig_inputArgs net/mlx5: fw_tracer: Fix debug print ACPI: video: Fix Lenovo Ideapad Z570 DMI match wifi: mt76: dma: free rx_head in mt76_dma_rx_cleanup m68k: Check syscall_trace_enter() return code net: bcmgenet: Add a check for oversized packets ACPI: Don't build ACPICA with '-Os' ice: add missing checks for PF vsi type inet: fix fast path in __inet_hash_connect() wifi: mt7601u: fix an integer underflow wifi: brcmfmac: ensure CLM version is null-terminated to prevent stack-out-of-bounds x86/bugs: Reset speculation control settings on init timers: Prevent union confusion from unexpected restart_syscall() thermal: intel: Fix unsigned comparison with less than zero rcu: Suppress smp_processor_id() complaint in synchronize_rcu_expedited_wait() wifi: brcmfmac: Fix potential stack-out-of-bounds in brcmf_c_preinit_dcmds() blk-iocost: fix divide by 0 error in calc_lcoefs() ARM: dts: exynos: Use Exynos5420 compatible for the MIPI video phy udf: Define EFSCORRUPTED error code rpmsg: glink: Avoid infinite loop on intent for missing channel media: usb: siano: Fix use after free bugs caused by do_submit_urb media: i2c: ov7670: 0 instead of -EINVAL was returned media: rc: Fix use-after-free bugs caused by ene_tx_irqsim() media: i2c: ov772x: Fix memleak in ov772x_probe() media: ov5675: Fix memleak in ov5675_init_controls() powerpc: Remove linker flag from KBUILD_AFLAGS media: platform: ti: Add missing check for devm_regulator_get remoteproc: qcom_q6v5_mss: Use a carveout to authenticate modem headers MIPS: vpe-mt: drop physical_memsize MIPS: SMP-CPS: fix build error when HOTPLUG_CPU not set powerpc/eeh: Set channel state after notifying the drivers powerpc/eeh: Small refactor of eeh_handle_normal_event() powerpc/rtas: ensure 4KB alignment for rtas_data_buf powerpc/rtas: make all exports GPL powerpc/pseries/lparcfg: add missing RTAS retry status handling powerpc/pseries/lpar: add missing RTAS retry status handling clk: Honor CLK_OPS_PARENT_ENABLE in clk_core_is_enabled() powerpc/powernv/ioda: Skip unallocated resources when mapping to PE clk: qcom: gpucc-sdm845: fix clk_dis_wait being programmed for CX GDSC Input: ads7846 - don't check penirq immediately for 7845 Input: ads7846 - don't report pressure for ads7845 clk: renesas: cpg-mssr: Remove superfluous check in resume code clk: renesas: cpg-mssr: Use enum clk_reg_layout instead of a boolean flag clk: renesas: cpg-mssr: Fix use after free if cpg_mssr_common_init() failed mtd: rawnand: sunxi: Fix the size of the last OOB region clk: qcom: gcc-qcs404: fix names of the DSI clocks used as parents clk: qcom: gcc-qcs404: disable gpll[04]_out_aux parents mfd: pcf50633-adc: Fix potential memleak in pcf50633_adc_async_read() selftests/ftrace: Fix bash specific "==" operator sparc: allow PM configs for sparc32 COMPILE_TEST perf tools: Fix auto-complete on aarch64 perf llvm: Fix inadvertent file creation gfs2: jdata writepage fix cifs: Fix warning and UAF when destroy the MR list cifs: Fix lost destroy smbd connection when MR allocate failed nfsd: fix race to check ls_layouts hid: bigben_probe(): validate report count HID: asus: Fix mute and touchpad-toggle keys on Medion Akoya E1239T HID: asus: Add support for multi-touch touchpad on Medion Akoya E1239T HID: asus: Add report_size to struct asus_touchpad_info HID: asus: Only set EV_REP if we are adding a mapping HID: bigben: use spinlock to safely schedule workers HID: bigben_worker() remove unneeded check on report_field HID: bigben: use spinlock to protect concurrent accesses ASoC: soc-dapm.h: fixup warning struct snd_pcm_substream not declared ASoC: dapm: declare missing structure prototypes spi: synquacer: Fix timeout handling in synquacer_spi_transfer_one() dm: remove flush_scheduled_work() during local_exit() hwmon: (mlxreg-fan) Return zero speed for broken fan spi: bcm63xx-hsspi: Fix multi-bit mode setting spi: bcm63xx-hsspi: fix pm_runtime scsi: aic94xx: Add missing check for dma_map_single() hwmon: (ltc2945) Handle error case in ltc2945_value_store gpio: vf610: connect GPIO label to dev name ASoC: soc-compress.c: fixup private_data on snd_soc_new_compress() drm/mediatek: Clean dangling pointer on bind error path drm/mediatek: Drop unbalanced obj unref drm/mediatek: Use NULL instead of 0 for NULL pointer drm/mediatek: remove cast to pointers passed to kfree gpu: host1x: Don't skip assigning syncpoints to channels drm/msm/mdp5: Add check for kzalloc drm: Initialize struct drm_crtc_state.no_vblank from device settings drm/bridge: Introduce drm_bridge_get_next_bridge() drm/bridge: Rename bridge helpers targeting a bridge chain drm/exynos: Don't reset bridge->next drm/msm/dpu: Add check for pstates drm/msm/dpu: Add check for cstate drm/msm: use strscpy instead of strncpy drm/mipi-dsi: Fix byte order of 16-bit DCS set/get brightness ALSA: hda/ca0132: minor fix for allocation size ASoC: fsl_sai: initialize is_dsp_mode flag pinctrl: stm32: Fix refcount leak in stm32_pctrl_get_irq_domain drm/msm/hdmi: Add missing check for alloc_ordered_workqueue gpu: ipu-v3: common: Add of_node_put() for reference returned by of_graph_get_port_by_id() drm/vc4: dpi: Fix format mapping for RGB565 drm/vc4: dpi: Add option for inverting pixel clock and output enable drm/bridge: megachips: Fix error handling in i2c_register_driver() drm: mxsfb: DRM_MXSFB should depend on ARCH_MXS || ARCH_MXC drm/fourcc: Add missing big-endian XRGB1555 and RGB565 formats selftest: fib_tests: Always cleanup before exit selftests/net: Interpret UDP_GRO cmsg data as an int value irqchip/irq-bcm7120-l2: Set IRQ_LEVEL for level triggered interrupts irqchip/irq-brcmstb-l2: Set IRQ_LEVEL for level triggered interrupts can: esd_usb: Move mislocated storage of SJA1000_ECC_SEG bits in case of a bus error thermal/drivers/hisi: Drop second sensor hi3660 wifi: mac80211: make rate u32 in sta_set_rate_info_rx() crypto: crypto4xx - Call dma_unmap_page when done wifi: mwifiex: fix loop iterator in mwifiex_update_ampdu_txwinsize() wifi: iwl4965: Add missing check for create_singlethread_workqueue() wifi: iwl3945: Add missing check for create_singlethread_workqueue treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD() usb: gadget: udc: Avoid tasklet passing a global RISC-V: time: initialize hrtimer based broadcast clock event device m68k: /proc/hardware should depend on PROC_FS crypto: rsa-pkcs1pad - Use akcipher_request_complete rds: rds_rm_zerocopy_callback() correct order for list_add_tail() libbpf: Fix alen calculation in libbpf_nla_dump_errormsg() Bluetooth: L2CAP: Fix potential user-after-free OPP: fix error checking in opp_migrate_dentry() tap: tap_open(): correctly initialize socket uid tun: tun_chr_open(): correctly initialize socket uid net: add sock_init_data_uid() mptcp: add sk_stop_timer_sync helper irqchip/ti-sci: Fix refcount leak in ti_sci_intr_irq_domain_probe irqchip/irq-mvebu-gicp: Fix refcount leak in mvebu_gicp_probe irqchip/alpine-msi: Fix refcount leak in alpine_msix_init_domains net/mlx5: Enhance debug print in page allocation failure powercap: fix possible name leak in powercap_register_zone() crypto: seqiv - Handle EBUSY correctly crypto: essiv - Handle EBUSY correctly crypto: essiv - remove redundant null pointer check before kfree crypto: ccp - Failure on re-initialization due to duplicate sysfs filename ACPI: battery: Fix missing NUL-termination with large strings wifi: ath9k: Fix potential stack-out-of-bounds write in ath9k_wmi_rsp_callback() wifi: ath9k: hif_usb: clean up skbs if ath9k_hif_usb_rx_stream() fails ath9k: htc: clean up statistics macros ath9k: hif_usb: simplify if-if to if-else wifi: ath9k: htc_hst: free skb in ath9k_htc_rx_msg() if there is no callback function wifi: orinoco: check return value of hermes_write_wordrec() ACPICA: nsrepair: handle cases without a return value correctly lib/mpi: Fix buffer overrun when SG is too long genirq: Fix the return type of kstat_cpu_irqs_sum() ACPICA: Drop port I/O validation for some regions crypto: x86/ghash - fix unaligned access in ghash_setkey() wifi: wl3501_cs: don't call kfree_skb() under spin_lock_irqsave() wifi: libertas: cmdresp: don't call kfree_skb() under spin_lock_irqsave() wifi: libertas: main: don't call kfree_skb() under spin_lock_irqsave() wifi: libertas: if_usb: don't call kfree_skb() under spin_lock_irqsave() wifi: libertas_tf: don't call kfree_skb() under spin_lock_irqsave() wifi: brcmfmac: unmap dma buffer in brcmf_msgbuf_alloc_pktid() wifi: brcmfmac: fix potential memory leak in brcmf_netdev_start_xmit() wifi: wilc1000: fix potential memory leak in wilc_mac_xmit() wilc1000: let wilc_mac_xmit() return NETDEV_TX_OK wifi: ipw2200: fix memory leak in ipw_wdev_init() wifi: ipw2x00: don't call dev_kfree_skb() under spin_lock_irqsave() ipw2x00: switch from 'pci_' to 'dma_' API wifi: rtlwifi: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit() rtlwifi: fix -Wpointer-sign warning wifi: rtl8xxxu: don't call dev_kfree_skb() under spin_lock_irqsave() wifi: libertas: fix memory leak in lbs_init_adapter() wifi: iwlegacy: common: don't call dev_kfree_skb() under spin_lock_irqsave() net/wireless: Delete unnecessary checks before the macro call “dev_kfree_skb” wifi: rsi: Fix memory leak in rsi_coex_attach() block: bio-integrity: Copy flags when bio_integrity_payload is cloned sched/rt: pick_next_rt_entity(): check list_entry sched/deadline,rt: Remove unused parameter from pick_next_[rt|dl]_entity() s390/dasd: Fix potential memleak in dasd_eckd_init() s390/dasd: Prepare for additional path event handling blk-mq: correct stale comment of .get_budget blk-mq: wait on correct sbitmap_queue in blk_mq_mark_tag_wait blk-mq: remove stale comment for blk_mq_sched_mark_restart_hctx block: Limit number of items taken from the I/O scheduler in one go Revert "scsi: core: run queue if SCSI device queue isn't ready and queue is idle" arm64: dts: mediatek: mt7622: Add missing pwm-cells to pwm node ARM: dts: imx7s: correct iomuxc gpr mux controller cells arm64: dts: amlogic: meson-gxl-s905d-phicomm-n1: fix led node name arm64: dts: amlogic: meson-gxl: add missing unit address to eth-phy-mux node name arm64: dts: amlogic: meson-gx: add missing unit address to rng node name arm64: dts: amlogic: meson-gx: add missing SCPI sensors compatible arm64: dts: amlogic: meson-axg: fix SCPI clock dvfs node name arm64: dts: amlogic: meson-gx: fix SCPI clock dvfs node name ARM: imx: Call ida_simple_remove() for ida_simple_get ARM: dts: exynos: correct wr-active property in Exynos3250 Rinato ARM: OMAP1: call platform_device_put() in error case in omap1_dm_timer_init() arm64: dts: meson: remove CPU opps below 1GHz for G12A boards arm64: dts: meson-gx: Fix the SCPI DVFS node name and unit address arm64: dts: meson-g12a: Fix internal Ethernet PHY unit name arm64: dts: meson-gx: Fix Ethernet MAC address unit name ARM: zynq: Fix refcount leak in zynq_early_slcr_init arm64: dts: qcom: qcs404: use symbol names for PCIe resets ARM: OMAP2+: Fix memory leak in realtime_counter_init() HID: asus: use spinlock to safely schedule workers HID: asus: use spinlock to protect concurrent accesses HID: asus: Remove check for same LED brightness on set Linux 5.4.234 USB: core: Don't hold device lock while reading the "descriptors" sysfs file USB: serial: option: add support for VW/Skoda "Carstick LTE" dmaengine: sh: rcar-dmac: Check for error num after dma_set_max_seg_size vc_screen: don't clobber return value in vcs_read net: Remove WARN_ON_ONCE(sk->sk_forward_alloc) from sk_stream_kill_queues(). bpf: bpf_fib_lookup should not return neigh in NUD_FAILED state HID: core: Fix deadloop in hid_apply_multiplier. neigh: make sure used and confirmed times are valid IB/hfi1: Assign npages earlier btrfs: send: limit number of clones and allocated memory size ACPI: NFIT: fix a potential deadlock during NFIT teardown ARM: dts: rockchip: add power-domains property to dp node on rk3288 arm64: dts: rockchip: drop unused LED mode property from rk3328-roc-cc Conflicts: Documentation/devicetree/bindings Documentation/devicetree/bindings/rtc/allwinner,sun6i-a31-rtc.yaml arch/arm/mm/dma-mapping.c drivers/clk/qcom/gcc-qcs404.c drivers/iommu/dma-iommu.c drivers/mtd/ubi/wl.c kernel/dma/direct.c Change-Id: I5797c8cb2276354d851af215d431950eec734174 Signed-off-by: Srinivasarao Pathipati <quic_c_spathi@quicinc.com>
3117 lines
79 KiB
C
3117 lines
79 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* INET An implementation of the TCP/IP protocol suite for the LINUX
|
|
* operating system. INET is implemented using the BSD Socket
|
|
* interface as the means of communication with the user level.
|
|
*
|
|
* The User Datagram Protocol (UDP).
|
|
*
|
|
* Authors: Ross Biro
|
|
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
|
|
* Arnt Gulbrandsen, <agulbra@nvg.unit.no>
|
|
* Alan Cox, <alan@lxorguk.ukuu.org.uk>
|
|
* Hirokazu Takahashi, <taka@valinux.co.jp>
|
|
*
|
|
* Fixes:
|
|
* Alan Cox : verify_area() calls
|
|
* Alan Cox : stopped close while in use off icmp
|
|
* messages. Not a fix but a botch that
|
|
* for udp at least is 'valid'.
|
|
* Alan Cox : Fixed icmp handling properly
|
|
* Alan Cox : Correct error for oversized datagrams
|
|
* Alan Cox : Tidied select() semantics.
|
|
* Alan Cox : udp_err() fixed properly, also now
|
|
* select and read wake correctly on errors
|
|
* Alan Cox : udp_send verify_area moved to avoid mem leak
|
|
* Alan Cox : UDP can count its memory
|
|
* Alan Cox : send to an unknown connection causes
|
|
* an ECONNREFUSED off the icmp, but
|
|
* does NOT close.
|
|
* Alan Cox : Switched to new sk_buff handlers. No more backlog!
|
|
* Alan Cox : Using generic datagram code. Even smaller and the PEEK
|
|
* bug no longer crashes it.
|
|
* Fred Van Kempen : Net2e support for sk->broadcast.
|
|
* Alan Cox : Uses skb_free_datagram
|
|
* Alan Cox : Added get/set sockopt support.
|
|
* Alan Cox : Broadcasting without option set returns EACCES.
|
|
* Alan Cox : No wakeup calls. Instead we now use the callbacks.
|
|
* Alan Cox : Use ip_tos and ip_ttl
|
|
* Alan Cox : SNMP Mibs
|
|
* Alan Cox : MSG_DONTROUTE, and 0.0.0.0 support.
|
|
* Matt Dillon : UDP length checks.
|
|
* Alan Cox : Smarter af_inet used properly.
|
|
* Alan Cox : Use new kernel side addressing.
|
|
* Alan Cox : Incorrect return on truncated datagram receive.
|
|
* Arnt Gulbrandsen : New udp_send and stuff
|
|
* Alan Cox : Cache last socket
|
|
* Alan Cox : Route cache
|
|
* Jon Peatfield : Minor efficiency fix to sendto().
|
|
* Mike Shaver : RFC1122 checks.
|
|
* Alan Cox : Nonblocking error fix.
|
|
* Willy Konynenberg : Transparent proxying support.
|
|
* Mike McLagan : Routing by source
|
|
* David S. Miller : New socket lookup architecture.
|
|
* Last socket cache retained as it
|
|
* does have a high hit rate.
|
|
* Olaf Kirch : Don't linearise iovec on sendmsg.
|
|
* Andi Kleen : Some cleanups, cache destination entry
|
|
* for connect.
|
|
* Vitaly E. Lavrov : Transparent proxy revived after year coma.
|
|
* Melvin Smith : Check msg_name not msg_namelen in sendto(),
|
|
* return ENOTCONN for unconnected sockets (POSIX)
|
|
* Janos Farkas : don't deliver multi/broadcasts to a different
|
|
* bound-to-device socket
|
|
* Hirokazu Takahashi : HW checksumming for outgoing UDP
|
|
* datagrams.
|
|
* Hirokazu Takahashi : sendfile() on UDP works now.
|
|
* Arnaldo C. Melo : convert /proc/net/udp to seq_file
|
|
* YOSHIFUJI Hideaki @USAGI and: Support IPV6_V6ONLY socket option, which
|
|
* Alexey Kuznetsov: allow both IPv4 and IPv6 sockets to bind
|
|
* a single port at the same time.
|
|
* Derek Atkins <derek@ihtfp.com>: Add Encapulation Support
|
|
* James Chapman : Add L2TP encapsulation type.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "UDP: " fmt
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <asm/ioctls.h>
|
|
#include <linux/memblock.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/types.h>
|
|
#include <linux/fcntl.h>
|
|
#include <linux/module.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/sockios.h>
|
|
#include <linux/igmp.h>
|
|
#include <linux/inetdevice.h>
|
|
#include <linux/in.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/inet.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/slab.h>
|
|
#include <net/tcp_states.h>
|
|
#include <linux/skbuff.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/seq_file.h>
|
|
#include <net/net_namespace.h>
|
|
#include <net/icmp.h>
|
|
#include <net/inet_hashtables.h>
|
|
#include <net/ip_tunnels.h>
|
|
#include <net/route.h>
|
|
#include <net/checksum.h>
|
|
#include <net/xfrm.h>
|
|
#include <trace/events/udp.h>
|
|
#include <linux/static_key.h>
|
|
#include <trace/events/skb.h>
|
|
#include <net/busy_poll.h>
|
|
#include "udp_impl.h"
|
|
#include <net/sock_reuseport.h>
|
|
#include <net/addrconf.h>
|
|
#include <net/udp_tunnel.h>
|
|
|
|
struct udp_table udp_table __read_mostly;
|
|
EXPORT_SYMBOL(udp_table);
|
|
|
|
long sysctl_udp_mem[3] __read_mostly;
|
|
EXPORT_SYMBOL(sysctl_udp_mem);
|
|
|
|
atomic_long_t udp_memory_allocated;
|
|
EXPORT_SYMBOL(udp_memory_allocated);
|
|
|
|
#define MAX_UDP_PORTS 65536
|
|
#define PORTS_PER_CHAIN (MAX_UDP_PORTS / UDP_HTABLE_SIZE_MIN)
|
|
|
|
static int udp_lib_lport_inuse(struct net *net, __u16 num,
|
|
const struct udp_hslot *hslot,
|
|
unsigned long *bitmap,
|
|
struct sock *sk, unsigned int log)
|
|
{
|
|
struct sock *sk2;
|
|
kuid_t uid = sock_i_uid(sk);
|
|
|
|
sk_for_each(sk2, &hslot->head) {
|
|
if (net_eq(sock_net(sk2), net) &&
|
|
sk2 != sk &&
|
|
(bitmap || udp_sk(sk2)->udp_port_hash == num) &&
|
|
(!sk2->sk_reuse || !sk->sk_reuse) &&
|
|
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if ||
|
|
sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
|
|
inet_rcv_saddr_equal(sk, sk2, true)) {
|
|
if (sk2->sk_reuseport && sk->sk_reuseport &&
|
|
!rcu_access_pointer(sk->sk_reuseport_cb) &&
|
|
uid_eq(uid, sock_i_uid(sk2))) {
|
|
if (!bitmap)
|
|
return 0;
|
|
} else {
|
|
if (!bitmap)
|
|
return 1;
|
|
__set_bit(udp_sk(sk2)->udp_port_hash >> log,
|
|
bitmap);
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Note: we still hold spinlock of primary hash chain, so no other writer
|
|
* can insert/delete a socket with local_port == num
|
|
*/
|
|
static int udp_lib_lport_inuse2(struct net *net, __u16 num,
|
|
struct udp_hslot *hslot2,
|
|
struct sock *sk)
|
|
{
|
|
struct sock *sk2;
|
|
kuid_t uid = sock_i_uid(sk);
|
|
int res = 0;
|
|
|
|
spin_lock(&hslot2->lock);
|
|
udp_portaddr_for_each_entry(sk2, &hslot2->head) {
|
|
if (net_eq(sock_net(sk2), net) &&
|
|
sk2 != sk &&
|
|
(udp_sk(sk2)->udp_port_hash == num) &&
|
|
(!sk2->sk_reuse || !sk->sk_reuse) &&
|
|
(!sk2->sk_bound_dev_if || !sk->sk_bound_dev_if ||
|
|
sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
|
|
inet_rcv_saddr_equal(sk, sk2, true)) {
|
|
if (sk2->sk_reuseport && sk->sk_reuseport &&
|
|
!rcu_access_pointer(sk->sk_reuseport_cb) &&
|
|
uid_eq(uid, sock_i_uid(sk2))) {
|
|
res = 0;
|
|
} else {
|
|
res = 1;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
spin_unlock(&hslot2->lock);
|
|
return res;
|
|
}
|
|
|
|
static int udp_reuseport_add_sock(struct sock *sk, struct udp_hslot *hslot)
|
|
{
|
|
struct net *net = sock_net(sk);
|
|
kuid_t uid = sock_i_uid(sk);
|
|
struct sock *sk2;
|
|
|
|
sk_for_each(sk2, &hslot->head) {
|
|
if (net_eq(sock_net(sk2), net) &&
|
|
sk2 != sk &&
|
|
sk2->sk_family == sk->sk_family &&
|
|
ipv6_only_sock(sk2) == ipv6_only_sock(sk) &&
|
|
(udp_sk(sk2)->udp_port_hash == udp_sk(sk)->udp_port_hash) &&
|
|
(sk2->sk_bound_dev_if == sk->sk_bound_dev_if) &&
|
|
sk2->sk_reuseport && uid_eq(uid, sock_i_uid(sk2)) &&
|
|
inet_rcv_saddr_equal(sk, sk2, false)) {
|
|
return reuseport_add_sock(sk, sk2,
|
|
inet_rcv_saddr_any(sk));
|
|
}
|
|
}
|
|
|
|
return reuseport_alloc(sk, inet_rcv_saddr_any(sk));
|
|
}
|
|
|
|
/**
|
|
* udp_lib_get_port - UDP/-Lite port lookup for IPv4 and IPv6
|
|
*
|
|
* @sk: socket struct in question
|
|
* @snum: port number to look up
|
|
* @hash2_nulladdr: AF-dependent hash value in secondary hash chains,
|
|
* with NULL address
|
|
*/
|
|
int udp_lib_get_port(struct sock *sk, unsigned short snum,
|
|
unsigned int hash2_nulladdr)
|
|
{
|
|
struct udp_hslot *hslot, *hslot2;
|
|
struct udp_table *udptable = sk->sk_prot->h.udp_table;
|
|
int error = 1;
|
|
struct net *net = sock_net(sk);
|
|
|
|
if (!snum) {
|
|
int low, high, remaining;
|
|
unsigned int rand;
|
|
unsigned short first, last;
|
|
DECLARE_BITMAP(bitmap, PORTS_PER_CHAIN);
|
|
|
|
inet_get_local_port_range(net, &low, &high);
|
|
remaining = (high - low) + 1;
|
|
|
|
rand = prandom_u32();
|
|
first = reciprocal_scale(rand, remaining) + low;
|
|
/*
|
|
* force rand to be an odd multiple of UDP_HTABLE_SIZE
|
|
*/
|
|
rand = (rand | 1) * (udptable->mask + 1);
|
|
last = first + udptable->mask + 1;
|
|
do {
|
|
hslot = udp_hashslot(udptable, net, first);
|
|
bitmap_zero(bitmap, PORTS_PER_CHAIN);
|
|
spin_lock_bh(&hslot->lock);
|
|
udp_lib_lport_inuse(net, snum, hslot, bitmap, sk,
|
|
udptable->log);
|
|
|
|
snum = first;
|
|
/*
|
|
* Iterate on all possible values of snum for this hash.
|
|
* Using steps of an odd multiple of UDP_HTABLE_SIZE
|
|
* give us randomization and full range coverage.
|
|
*/
|
|
do {
|
|
if (low <= snum && snum <= high &&
|
|
!test_bit(snum >> udptable->log, bitmap) &&
|
|
!inet_is_local_reserved_port(net, snum))
|
|
goto found;
|
|
snum += rand;
|
|
} while (snum != first);
|
|
spin_unlock_bh(&hslot->lock);
|
|
cond_resched();
|
|
} while (++first != last);
|
|
goto fail;
|
|
} else {
|
|
hslot = udp_hashslot(udptable, net, snum);
|
|
spin_lock_bh(&hslot->lock);
|
|
if (hslot->count > 10) {
|
|
int exist;
|
|
unsigned int slot2 = udp_sk(sk)->udp_portaddr_hash ^ snum;
|
|
|
|
slot2 &= udptable->mask;
|
|
hash2_nulladdr &= udptable->mask;
|
|
|
|
hslot2 = udp_hashslot2(udptable, slot2);
|
|
if (hslot->count < hslot2->count)
|
|
goto scan_primary_hash;
|
|
|
|
exist = udp_lib_lport_inuse2(net, snum, hslot2, sk);
|
|
if (!exist && (hash2_nulladdr != slot2)) {
|
|
hslot2 = udp_hashslot2(udptable, hash2_nulladdr);
|
|
exist = udp_lib_lport_inuse2(net, snum, hslot2,
|
|
sk);
|
|
}
|
|
if (exist)
|
|
goto fail_unlock;
|
|
else
|
|
goto found;
|
|
}
|
|
scan_primary_hash:
|
|
if (udp_lib_lport_inuse(net, snum, hslot, NULL, sk, 0))
|
|
goto fail_unlock;
|
|
}
|
|
found:
|
|
inet_sk(sk)->inet_num = snum;
|
|
udp_sk(sk)->udp_port_hash = snum;
|
|
udp_sk(sk)->udp_portaddr_hash ^= snum;
|
|
if (sk_unhashed(sk)) {
|
|
if (sk->sk_reuseport &&
|
|
udp_reuseport_add_sock(sk, hslot)) {
|
|
inet_sk(sk)->inet_num = 0;
|
|
udp_sk(sk)->udp_port_hash = 0;
|
|
udp_sk(sk)->udp_portaddr_hash ^= snum;
|
|
goto fail_unlock;
|
|
}
|
|
|
|
sk_add_node_rcu(sk, &hslot->head);
|
|
hslot->count++;
|
|
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
|
|
|
|
hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash);
|
|
spin_lock(&hslot2->lock);
|
|
if (IS_ENABLED(CONFIG_IPV6) && sk->sk_reuseport &&
|
|
sk->sk_family == AF_INET6)
|
|
hlist_add_tail_rcu(&udp_sk(sk)->udp_portaddr_node,
|
|
&hslot2->head);
|
|
else
|
|
hlist_add_head_rcu(&udp_sk(sk)->udp_portaddr_node,
|
|
&hslot2->head);
|
|
hslot2->count++;
|
|
spin_unlock(&hslot2->lock);
|
|
}
|
|
sock_set_flag(sk, SOCK_RCU_FREE);
|
|
error = 0;
|
|
fail_unlock:
|
|
spin_unlock_bh(&hslot->lock);
|
|
fail:
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL(udp_lib_get_port);
|
|
|
|
int udp_v4_get_port(struct sock *sk, unsigned short snum)
|
|
{
|
|
unsigned int hash2_nulladdr =
|
|
ipv4_portaddr_hash(sock_net(sk), htonl(INADDR_ANY), snum);
|
|
unsigned int hash2_partial =
|
|
ipv4_portaddr_hash(sock_net(sk), inet_sk(sk)->inet_rcv_saddr, 0);
|
|
|
|
/* precompute partial secondary hash */
|
|
udp_sk(sk)->udp_portaddr_hash = hash2_partial;
|
|
return udp_lib_get_port(sk, snum, hash2_nulladdr);
|
|
}
|
|
|
|
static int compute_score(struct sock *sk, struct net *net,
|
|
__be32 saddr, __be16 sport,
|
|
__be32 daddr, unsigned short hnum,
|
|
int dif, int sdif)
|
|
{
|
|
int score;
|
|
struct inet_sock *inet;
|
|
bool dev_match;
|
|
|
|
if (!net_eq(sock_net(sk), net) ||
|
|
udp_sk(sk)->udp_port_hash != hnum ||
|
|
ipv6_only_sock(sk))
|
|
return -1;
|
|
|
|
if (sk->sk_rcv_saddr != daddr)
|
|
return -1;
|
|
|
|
score = (sk->sk_family == PF_INET) ? 2 : 1;
|
|
|
|
inet = inet_sk(sk);
|
|
if (inet->inet_daddr) {
|
|
if (inet->inet_daddr != saddr)
|
|
return -1;
|
|
score += 4;
|
|
}
|
|
|
|
if (inet->inet_dport) {
|
|
if (inet->inet_dport != sport)
|
|
return -1;
|
|
score += 4;
|
|
}
|
|
|
|
dev_match = udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if,
|
|
dif, sdif);
|
|
if (!dev_match)
|
|
return -1;
|
|
if (sk->sk_bound_dev_if)
|
|
score += 4;
|
|
|
|
if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
|
|
score++;
|
|
return score;
|
|
}
|
|
|
|
static u32 udp_ehashfn(const struct net *net, const __be32 laddr,
|
|
const __u16 lport, const __be32 faddr,
|
|
const __be16 fport)
|
|
{
|
|
static u32 udp_ehash_secret __read_mostly;
|
|
|
|
net_get_random_once(&udp_ehash_secret, sizeof(udp_ehash_secret));
|
|
|
|
return __inet_ehashfn(laddr, lport, faddr, fport,
|
|
udp_ehash_secret + net_hash_mix(net));
|
|
}
|
|
|
|
/* called with rcu_read_lock() */
|
|
static struct sock *udp4_lib_lookup2(struct net *net,
|
|
__be32 saddr, __be16 sport,
|
|
__be32 daddr, unsigned int hnum,
|
|
int dif, int sdif,
|
|
struct udp_hslot *hslot2,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct sock *sk, *result, *reuseport_result;
|
|
int score, badness;
|
|
u32 hash = 0;
|
|
|
|
result = NULL;
|
|
badness = 0;
|
|
udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
|
|
score = compute_score(sk, net, saddr, sport,
|
|
daddr, hnum, dif, sdif);
|
|
if (score > badness) {
|
|
reuseport_result = NULL;
|
|
|
|
if (sk->sk_reuseport &&
|
|
sk->sk_state != TCP_ESTABLISHED) {
|
|
hash = udp_ehashfn(net, daddr, hnum,
|
|
saddr, sport);
|
|
reuseport_result = reuseport_select_sock(sk, hash, skb,
|
|
sizeof(struct udphdr));
|
|
if (reuseport_result && !reuseport_has_conns(sk, false))
|
|
return reuseport_result;
|
|
}
|
|
|
|
result = reuseport_result ? : sk;
|
|
badness = score;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/* UDP is nearly always wildcards out the wazoo, it makes no sense to try
|
|
* harder than this. -DaveM
|
|
*/
|
|
struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
|
|
__be16 sport, __be32 daddr, __be16 dport, int dif,
|
|
int sdif, struct udp_table *udptable, struct sk_buff *skb)
|
|
{
|
|
struct sock *result;
|
|
unsigned short hnum = ntohs(dport);
|
|
unsigned int hash2, slot2;
|
|
struct udp_hslot *hslot2;
|
|
|
|
hash2 = ipv4_portaddr_hash(net, daddr, hnum);
|
|
slot2 = hash2 & udptable->mask;
|
|
hslot2 = &udptable->hash2[slot2];
|
|
|
|
result = udp4_lib_lookup2(net, saddr, sport,
|
|
daddr, hnum, dif, sdif,
|
|
hslot2, skb);
|
|
if (!result) {
|
|
hash2 = ipv4_portaddr_hash(net, htonl(INADDR_ANY), hnum);
|
|
slot2 = hash2 & udptable->mask;
|
|
hslot2 = &udptable->hash2[slot2];
|
|
|
|
result = udp4_lib_lookup2(net, saddr, sport,
|
|
htonl(INADDR_ANY), hnum, dif, sdif,
|
|
hslot2, skb);
|
|
}
|
|
if (IS_ERR(result))
|
|
return NULL;
|
|
return result;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__udp4_lib_lookup);
|
|
|
|
static inline struct sock *__udp4_lib_lookup_skb(struct sk_buff *skb,
|
|
__be16 sport, __be16 dport,
|
|
struct udp_table *udptable)
|
|
{
|
|
const struct iphdr *iph = ip_hdr(skb);
|
|
|
|
return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport,
|
|
iph->daddr, dport, inet_iif(skb),
|
|
inet_sdif(skb), udptable, skb);
|
|
}
|
|
|
|
struct sock *udp4_lib_lookup_skb(struct sk_buff *skb,
|
|
__be16 sport, __be16 dport)
|
|
{
|
|
const struct iphdr *iph = ip_hdr(skb);
|
|
|
|
return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport,
|
|
iph->daddr, dport, inet_iif(skb),
|
|
inet_sdif(skb), &udp_table, NULL);
|
|
}
|
|
EXPORT_SYMBOL_GPL(udp4_lib_lookup_skb);
|
|
|
|
/* Must be called under rcu_read_lock().
|
|
* Does increment socket refcount.
|
|
*/
|
|
#if IS_ENABLED(CONFIG_NF_TPROXY_IPV4) || IS_ENABLED(CONFIG_NF_SOCKET_IPV4)
|
|
struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
|
|
__be32 daddr, __be16 dport, int dif)
|
|
{
|
|
struct sock *sk;
|
|
|
|
sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport,
|
|
dif, 0, &udp_table, NULL);
|
|
if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
|
|
sk = NULL;
|
|
return sk;
|
|
}
|
|
EXPORT_SYMBOL_GPL(udp4_lib_lookup);
|
|
#endif
|
|
|
|
static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
|
|
__be16 loc_port, __be32 loc_addr,
|
|
__be16 rmt_port, __be32 rmt_addr,
|
|
int dif, int sdif, unsigned short hnum)
|
|
{
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
|
|
if (!net_eq(sock_net(sk), net) ||
|
|
udp_sk(sk)->udp_port_hash != hnum ||
|
|
(inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
|
|
(inet->inet_dport != rmt_port && inet->inet_dport) ||
|
|
(inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
|
|
ipv6_only_sock(sk) ||
|
|
!udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif))
|
|
return false;
|
|
if (!ip_mc_sf_allow(sk, loc_addr, rmt_addr, dif, sdif))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
DEFINE_STATIC_KEY_FALSE(udp_encap_needed_key);
|
|
void udp_encap_enable(void)
|
|
{
|
|
static_branch_inc(&udp_encap_needed_key);
|
|
}
|
|
EXPORT_SYMBOL(udp_encap_enable);
|
|
|
|
void udp_encap_disable(void)
|
|
{
|
|
static_branch_dec(&udp_encap_needed_key);
|
|
}
|
|
EXPORT_SYMBOL(udp_encap_disable);
|
|
|
|
/* Handler for tunnels with arbitrary destination ports: no socket lookup, go
|
|
* through error handlers in encapsulations looking for a match.
|
|
*/
|
|
static int __udp4_lib_err_encap_no_sk(struct sk_buff *skb, u32 info)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_IPTUN_ENCAP_OPS; i++) {
|
|
int (*handler)(struct sk_buff *skb, u32 info);
|
|
const struct ip_tunnel_encap_ops *encap;
|
|
|
|
encap = rcu_dereference(iptun_encaps[i]);
|
|
if (!encap)
|
|
continue;
|
|
handler = encap->err_handler;
|
|
if (handler && !handler(skb, info))
|
|
return 0;
|
|
}
|
|
|
|
return -ENOENT;
|
|
}
|
|
|
|
/* Try to match ICMP errors to UDP tunnels by looking up a socket without
|
|
* reversing source and destination port: this will match tunnels that force the
|
|
* same destination port on both endpoints (e.g. VXLAN, GENEVE). Note that
|
|
* lwtunnels might actually break this assumption by being configured with
|
|
* different destination ports on endpoints, in this case we won't be able to
|
|
* trace ICMP messages back to them.
|
|
*
|
|
* If this doesn't match any socket, probe tunnels with arbitrary destination
|
|
* ports (e.g. FoU, GUE): there, the receiving socket is useless, as the port
|
|
* we've sent packets to won't necessarily match the local destination port.
|
|
*
|
|
* Then ask the tunnel implementation to match the error against a valid
|
|
* association.
|
|
*
|
|
* Return an error if we can't find a match, the socket if we need further
|
|
* processing, zero otherwise.
|
|
*/
|
|
static struct sock *__udp4_lib_err_encap(struct net *net,
|
|
const struct iphdr *iph,
|
|
struct udphdr *uh,
|
|
struct udp_table *udptable,
|
|
struct sk_buff *skb, u32 info)
|
|
{
|
|
int network_offset, transport_offset;
|
|
struct sock *sk;
|
|
|
|
network_offset = skb_network_offset(skb);
|
|
transport_offset = skb_transport_offset(skb);
|
|
|
|
/* Network header needs to point to the outer IPv4 header inside ICMP */
|
|
skb_reset_network_header(skb);
|
|
|
|
/* Transport header needs to point to the UDP header */
|
|
skb_set_transport_header(skb, iph->ihl << 2);
|
|
|
|
sk = __udp4_lib_lookup(net, iph->daddr, uh->source,
|
|
iph->saddr, uh->dest, skb->dev->ifindex, 0,
|
|
udptable, NULL);
|
|
if (sk) {
|
|
int (*lookup)(struct sock *sk, struct sk_buff *skb);
|
|
struct udp_sock *up = udp_sk(sk);
|
|
|
|
lookup = READ_ONCE(up->encap_err_lookup);
|
|
if (!lookup || lookup(sk, skb))
|
|
sk = NULL;
|
|
}
|
|
|
|
if (!sk)
|
|
sk = ERR_PTR(__udp4_lib_err_encap_no_sk(skb, info));
|
|
|
|
skb_set_transport_header(skb, transport_offset);
|
|
skb_set_network_header(skb, network_offset);
|
|
|
|
return sk;
|
|
}
|
|
|
|
/*
|
|
* This routine is called by the ICMP module when it gets some
|
|
* sort of error condition. If err < 0 then the socket should
|
|
* be closed and the error returned to the user. If err > 0
|
|
* it's just the icmp type << 8 | icmp code.
|
|
* Header points to the ip header of the error packet. We move
|
|
* on past this. Then (as it used to claim before adjustment)
|
|
* header points to the first 8 bytes of the udp header. We need
|
|
* to find the appropriate port.
|
|
*/
|
|
|
|
int __udp4_lib_err(struct sk_buff *skb, u32 info, struct udp_table *udptable)
|
|
{
|
|
struct inet_sock *inet;
|
|
const struct iphdr *iph = (const struct iphdr *)skb->data;
|
|
struct udphdr *uh = (struct udphdr *)(skb->data+(iph->ihl<<2));
|
|
const int type = icmp_hdr(skb)->type;
|
|
const int code = icmp_hdr(skb)->code;
|
|
bool tunnel = false;
|
|
struct sock *sk;
|
|
int harderr;
|
|
int err;
|
|
struct net *net = dev_net(skb->dev);
|
|
|
|
sk = __udp4_lib_lookup(net, iph->daddr, uh->dest,
|
|
iph->saddr, uh->source, skb->dev->ifindex,
|
|
inet_sdif(skb), udptable, NULL);
|
|
if (!sk) {
|
|
/* No socket for error: try tunnels before discarding */
|
|
sk = ERR_PTR(-ENOENT);
|
|
if (static_branch_unlikely(&udp_encap_needed_key)) {
|
|
sk = __udp4_lib_err_encap(net, iph, uh, udptable, skb,
|
|
info);
|
|
if (!sk)
|
|
return 0;
|
|
}
|
|
|
|
if (IS_ERR(sk)) {
|
|
__ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
|
|
return PTR_ERR(sk);
|
|
}
|
|
|
|
tunnel = true;
|
|
}
|
|
|
|
err = 0;
|
|
harderr = 0;
|
|
inet = inet_sk(sk);
|
|
|
|
switch (type) {
|
|
default:
|
|
case ICMP_TIME_EXCEEDED:
|
|
err = EHOSTUNREACH;
|
|
break;
|
|
case ICMP_SOURCE_QUENCH:
|
|
goto out;
|
|
case ICMP_PARAMETERPROB:
|
|
err = EPROTO;
|
|
harderr = 1;
|
|
break;
|
|
case ICMP_DEST_UNREACH:
|
|
if (code == ICMP_FRAG_NEEDED) { /* Path MTU discovery */
|
|
ipv4_sk_update_pmtu(skb, sk, info);
|
|
if (inet->pmtudisc != IP_PMTUDISC_DONT) {
|
|
err = EMSGSIZE;
|
|
harderr = 1;
|
|
break;
|
|
}
|
|
goto out;
|
|
}
|
|
err = EHOSTUNREACH;
|
|
if (code <= NR_ICMP_UNREACH) {
|
|
harderr = icmp_err_convert[code].fatal;
|
|
err = icmp_err_convert[code].errno;
|
|
}
|
|
break;
|
|
case ICMP_REDIRECT:
|
|
ipv4_sk_redirect(skb, sk);
|
|
goto out;
|
|
}
|
|
|
|
/*
|
|
* RFC1122: OK. Passes ICMP errors back to application, as per
|
|
* 4.1.3.3.
|
|
*/
|
|
if (tunnel) {
|
|
/* ...not for tunnels though: we don't have a sending socket */
|
|
goto out;
|
|
}
|
|
if (!inet->recverr) {
|
|
if (!harderr || sk->sk_state != TCP_ESTABLISHED)
|
|
goto out;
|
|
} else
|
|
ip_icmp_error(sk, skb, err, uh->dest, info, (u8 *)(uh+1));
|
|
|
|
sk->sk_err = err;
|
|
sk->sk_error_report(sk);
|
|
out:
|
|
return 0;
|
|
}
|
|
|
|
int udp_err(struct sk_buff *skb, u32 info)
|
|
{
|
|
return __udp4_lib_err(skb, info, &udp_table);
|
|
}
|
|
|
|
/*
|
|
* Throw away all pending data and cancel the corking. Socket is locked.
|
|
*/
|
|
void udp_flush_pending_frames(struct sock *sk)
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
|
|
if (up->pending) {
|
|
up->len = 0;
|
|
up->pending = 0;
|
|
ip_flush_pending_frames(sk);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(udp_flush_pending_frames);
|
|
|
|
/**
|
|
* udp4_hwcsum - handle outgoing HW checksumming
|
|
* @skb: sk_buff containing the filled-in UDP header
|
|
* (checksum field must be zeroed out)
|
|
* @src: source IP address
|
|
* @dst: destination IP address
|
|
*/
|
|
void udp4_hwcsum(struct sk_buff *skb, __be32 src, __be32 dst)
|
|
{
|
|
struct udphdr *uh = udp_hdr(skb);
|
|
int offset = skb_transport_offset(skb);
|
|
int len = skb->len - offset;
|
|
int hlen = len;
|
|
__wsum csum = 0;
|
|
|
|
if (!skb_has_frag_list(skb)) {
|
|
/*
|
|
* Only one fragment on the socket.
|
|
*/
|
|
skb->csum_start = skb_transport_header(skb) - skb->head;
|
|
skb->csum_offset = offsetof(struct udphdr, check);
|
|
uh->check = ~csum_tcpudp_magic(src, dst, len,
|
|
IPPROTO_UDP, 0);
|
|
} else {
|
|
struct sk_buff *frags;
|
|
|
|
/*
|
|
* HW-checksum won't work as there are two or more
|
|
* fragments on the socket so that all csums of sk_buffs
|
|
* should be together
|
|
*/
|
|
skb_walk_frags(skb, frags) {
|
|
csum = csum_add(csum, frags->csum);
|
|
hlen -= frags->len;
|
|
}
|
|
|
|
csum = skb_checksum(skb, offset, hlen, csum);
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
uh->check = csum_tcpudp_magic(src, dst, len, IPPROTO_UDP, csum);
|
|
if (uh->check == 0)
|
|
uh->check = CSUM_MANGLED_0;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(udp4_hwcsum);
|
|
|
|
/* Function to set UDP checksum for an IPv4 UDP packet. This is intended
|
|
* for the simple case like when setting the checksum for a UDP tunnel.
|
|
*/
|
|
void udp_set_csum(bool nocheck, struct sk_buff *skb,
|
|
__be32 saddr, __be32 daddr, int len)
|
|
{
|
|
struct udphdr *uh = udp_hdr(skb);
|
|
|
|
if (nocheck) {
|
|
uh->check = 0;
|
|
} else if (skb_is_gso(skb)) {
|
|
uh->check = ~udp_v4_check(len, saddr, daddr, 0);
|
|
} else if (skb->ip_summed == CHECKSUM_PARTIAL) {
|
|
uh->check = 0;
|
|
uh->check = udp_v4_check(len, saddr, daddr, lco_csum(skb));
|
|
if (uh->check == 0)
|
|
uh->check = CSUM_MANGLED_0;
|
|
} else {
|
|
skb->ip_summed = CHECKSUM_PARTIAL;
|
|
skb->csum_start = skb_transport_header(skb) - skb->head;
|
|
skb->csum_offset = offsetof(struct udphdr, check);
|
|
uh->check = ~udp_v4_check(len, saddr, daddr, 0);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(udp_set_csum);
|
|
|
|
static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,
|
|
struct inet_cork *cork)
|
|
{
|
|
struct sock *sk = skb->sk;
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
struct udphdr *uh;
|
|
int err = 0;
|
|
int is_udplite = IS_UDPLITE(sk);
|
|
int offset = skb_transport_offset(skb);
|
|
int len = skb->len - offset;
|
|
int datalen = len - sizeof(*uh);
|
|
__wsum csum = 0;
|
|
|
|
/*
|
|
* Create a UDP header
|
|
*/
|
|
uh = udp_hdr(skb);
|
|
uh->source = inet->inet_sport;
|
|
uh->dest = fl4->fl4_dport;
|
|
uh->len = htons(len);
|
|
uh->check = 0;
|
|
|
|
if (cork->gso_size) {
|
|
const int hlen = skb_network_header_len(skb) +
|
|
sizeof(struct udphdr);
|
|
|
|
if (hlen + cork->gso_size > cork->fragsize) {
|
|
kfree_skb(skb);
|
|
return -EINVAL;
|
|
}
|
|
if (datalen > cork->gso_size * UDP_MAX_SEGMENTS) {
|
|
kfree_skb(skb);
|
|
return -EINVAL;
|
|
}
|
|
if (sk->sk_no_check_tx) {
|
|
kfree_skb(skb);
|
|
return -EINVAL;
|
|
}
|
|
if (skb->ip_summed != CHECKSUM_PARTIAL || is_udplite ||
|
|
dst_xfrm(skb_dst(skb))) {
|
|
kfree_skb(skb);
|
|
return -EIO;
|
|
}
|
|
|
|
if (datalen > cork->gso_size) {
|
|
skb_shinfo(skb)->gso_size = cork->gso_size;
|
|
skb_shinfo(skb)->gso_type = SKB_GSO_UDP_L4;
|
|
skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(datalen,
|
|
cork->gso_size);
|
|
}
|
|
goto csum_partial;
|
|
}
|
|
|
|
if (is_udplite) /* UDP-Lite */
|
|
csum = udplite_csum(skb);
|
|
|
|
else if (sk->sk_no_check_tx) { /* UDP csum off */
|
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
goto send;
|
|
|
|
} else if (skb->ip_summed == CHECKSUM_PARTIAL) { /* UDP hardware csum */
|
|
csum_partial:
|
|
|
|
udp4_hwcsum(skb, fl4->saddr, fl4->daddr);
|
|
goto send;
|
|
|
|
} else
|
|
csum = udp_csum(skb);
|
|
|
|
/* add protocol-dependent pseudo-header */
|
|
uh->check = csum_tcpudp_magic(fl4->saddr, fl4->daddr, len,
|
|
sk->sk_protocol, csum);
|
|
if (uh->check == 0)
|
|
uh->check = CSUM_MANGLED_0;
|
|
|
|
send:
|
|
err = ip_send_skb(sock_net(sk), skb);
|
|
if (err) {
|
|
if (err == -ENOBUFS && !inet->recverr) {
|
|
UDP_INC_STATS(sock_net(sk),
|
|
UDP_MIB_SNDBUFERRORS, is_udplite);
|
|
err = 0;
|
|
}
|
|
} else
|
|
UDP_INC_STATS(sock_net(sk),
|
|
UDP_MIB_OUTDATAGRAMS, is_udplite);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Push out all pending data as one UDP datagram. Socket is locked.
|
|
*/
|
|
int udp_push_pending_frames(struct sock *sk)
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
struct flowi4 *fl4 = &inet->cork.fl.u.ip4;
|
|
struct sk_buff *skb;
|
|
int err = 0;
|
|
|
|
skb = ip_finish_skb(sk, fl4);
|
|
if (!skb)
|
|
goto out;
|
|
|
|
err = udp_send_skb(skb, fl4, &inet->cork.base);
|
|
|
|
out:
|
|
up->len = 0;
|
|
up->pending = 0;
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(udp_push_pending_frames);
|
|
|
|
static int __udp_cmsg_send(struct cmsghdr *cmsg, u16 *gso_size)
|
|
{
|
|
switch (cmsg->cmsg_type) {
|
|
case UDP_SEGMENT:
|
|
if (cmsg->cmsg_len != CMSG_LEN(sizeof(__u16)))
|
|
return -EINVAL;
|
|
*gso_size = *(__u16 *)CMSG_DATA(cmsg);
|
|
return 0;
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
int udp_cmsg_send(struct sock *sk, struct msghdr *msg, u16 *gso_size)
|
|
{
|
|
struct cmsghdr *cmsg;
|
|
bool need_ip = false;
|
|
int err;
|
|
|
|
for_each_cmsghdr(cmsg, msg) {
|
|
if (!CMSG_OK(msg, cmsg))
|
|
return -EINVAL;
|
|
|
|
if (cmsg->cmsg_level != SOL_UDP) {
|
|
need_ip = true;
|
|
continue;
|
|
}
|
|
|
|
err = __udp_cmsg_send(cmsg, gso_size);
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
return need_ip;
|
|
}
|
|
EXPORT_SYMBOL_GPL(udp_cmsg_send);
|
|
|
|
int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
|
|
{
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
struct udp_sock *up = udp_sk(sk);
|
|
DECLARE_SOCKADDR(struct sockaddr_in *, usin, msg->msg_name);
|
|
struct flowi4 fl4_stack;
|
|
struct flowi4 *fl4;
|
|
int ulen = len;
|
|
struct ipcm_cookie ipc;
|
|
struct rtable *rt = NULL;
|
|
int free = 0;
|
|
int connected = 0;
|
|
__be32 daddr, faddr, saddr;
|
|
__be16 dport;
|
|
u8 tos;
|
|
int err, is_udplite = IS_UDPLITE(sk);
|
|
int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE;
|
|
int (*getfrag)(void *, char *, int, int, int, struct sk_buff *);
|
|
struct sk_buff *skb;
|
|
struct ip_options_data opt_copy;
|
|
|
|
if (len > 0xFFFF)
|
|
return -EMSGSIZE;
|
|
|
|
/*
|
|
* Check the flags.
|
|
*/
|
|
|
|
if (msg->msg_flags & MSG_OOB) /* Mirror BSD error message compatibility */
|
|
return -EOPNOTSUPP;
|
|
|
|
getfrag = is_udplite ? udplite_getfrag : ip_generic_getfrag;
|
|
|
|
fl4 = &inet->cork.fl.u.ip4;
|
|
if (up->pending) {
|
|
/*
|
|
* There are pending frames.
|
|
* The socket lock must be held while it's corked.
|
|
*/
|
|
lock_sock(sk);
|
|
if (likely(up->pending)) {
|
|
if (unlikely(up->pending != AF_INET)) {
|
|
release_sock(sk);
|
|
return -EINVAL;
|
|
}
|
|
goto do_append_data;
|
|
}
|
|
release_sock(sk);
|
|
}
|
|
ulen += sizeof(struct udphdr);
|
|
|
|
/*
|
|
* Get and verify the address.
|
|
*/
|
|
if (usin) {
|
|
if (msg->msg_namelen < sizeof(*usin))
|
|
return -EINVAL;
|
|
if (usin->sin_family != AF_INET) {
|
|
if (usin->sin_family != AF_UNSPEC)
|
|
return -EAFNOSUPPORT;
|
|
}
|
|
|
|
daddr = usin->sin_addr.s_addr;
|
|
dport = usin->sin_port;
|
|
if (dport == 0)
|
|
return -EINVAL;
|
|
} else {
|
|
if (sk->sk_state != TCP_ESTABLISHED)
|
|
return -EDESTADDRREQ;
|
|
daddr = inet->inet_daddr;
|
|
dport = inet->inet_dport;
|
|
/* Open fast path for connected socket.
|
|
Route will not be used, if at least one option is set.
|
|
*/
|
|
connected = 1;
|
|
}
|
|
|
|
ipcm_init_sk(&ipc, inet);
|
|
ipc.gso_size = READ_ONCE(up->gso_size);
|
|
|
|
if (msg->msg_controllen) {
|
|
err = udp_cmsg_send(sk, msg, &ipc.gso_size);
|
|
if (err > 0)
|
|
err = ip_cmsg_send(sk, msg, &ipc,
|
|
sk->sk_family == AF_INET6);
|
|
if (unlikely(err < 0)) {
|
|
kfree(ipc.opt);
|
|
return err;
|
|
}
|
|
if (ipc.opt)
|
|
free = 1;
|
|
connected = 0;
|
|
}
|
|
if (!ipc.opt) {
|
|
struct ip_options_rcu *inet_opt;
|
|
|
|
rcu_read_lock();
|
|
inet_opt = rcu_dereference(inet->inet_opt);
|
|
if (inet_opt) {
|
|
memcpy(&opt_copy, inet_opt,
|
|
sizeof(*inet_opt) + inet_opt->opt.optlen);
|
|
ipc.opt = &opt_copy.opt;
|
|
}
|
|
rcu_read_unlock();
|
|
}
|
|
|
|
if (cgroup_bpf_enabled && !connected) {
|
|
err = BPF_CGROUP_RUN_PROG_UDP4_SENDMSG_LOCK(sk,
|
|
(struct sockaddr *)usin, &ipc.addr);
|
|
if (err)
|
|
goto out_free;
|
|
if (usin) {
|
|
if (usin->sin_port == 0) {
|
|
/* BPF program set invalid port. Reject it. */
|
|
err = -EINVAL;
|
|
goto out_free;
|
|
}
|
|
daddr = usin->sin_addr.s_addr;
|
|
dport = usin->sin_port;
|
|
}
|
|
}
|
|
|
|
saddr = ipc.addr;
|
|
ipc.addr = faddr = daddr;
|
|
|
|
if (ipc.opt && ipc.opt->opt.srr) {
|
|
if (!daddr) {
|
|
err = -EINVAL;
|
|
goto out_free;
|
|
}
|
|
faddr = ipc.opt->opt.faddr;
|
|
connected = 0;
|
|
}
|
|
tos = get_rttos(&ipc, inet);
|
|
if (sock_flag(sk, SOCK_LOCALROUTE) ||
|
|
(msg->msg_flags & MSG_DONTROUTE) ||
|
|
(ipc.opt && ipc.opt->opt.is_strictroute)) {
|
|
tos |= RTO_ONLINK;
|
|
connected = 0;
|
|
}
|
|
|
|
if (ipv4_is_multicast(daddr)) {
|
|
if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif))
|
|
ipc.oif = inet->mc_index;
|
|
if (!saddr)
|
|
saddr = inet->mc_addr;
|
|
connected = 0;
|
|
} else if (!ipc.oif) {
|
|
ipc.oif = inet->uc_index;
|
|
} else if (ipv4_is_lbcast(daddr) && inet->uc_index) {
|
|
/* oif is set, packet is to local broadcast and
|
|
* and uc_index is set. oif is most likely set
|
|
* by sk_bound_dev_if. If uc_index != oif check if the
|
|
* oif is an L3 master and uc_index is an L3 slave.
|
|
* If so, we want to allow the send using the uc_index.
|
|
*/
|
|
if (ipc.oif != inet->uc_index &&
|
|
ipc.oif == l3mdev_master_ifindex_by_index(sock_net(sk),
|
|
inet->uc_index)) {
|
|
ipc.oif = inet->uc_index;
|
|
}
|
|
}
|
|
|
|
if (connected)
|
|
rt = (struct rtable *)sk_dst_check(sk, 0);
|
|
|
|
if (!rt) {
|
|
struct net *net = sock_net(sk);
|
|
__u8 flow_flags = inet_sk_flowi_flags(sk);
|
|
|
|
fl4 = &fl4_stack;
|
|
|
|
flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, tos,
|
|
RT_SCOPE_UNIVERSE, sk->sk_protocol,
|
|
flow_flags,
|
|
faddr, saddr, dport, inet->inet_sport,
|
|
sk->sk_uid);
|
|
|
|
security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
|
|
rt = ip_route_output_flow(net, fl4, sk);
|
|
if (IS_ERR(rt)) {
|
|
err = PTR_ERR(rt);
|
|
rt = NULL;
|
|
if (err == -ENETUNREACH)
|
|
IP_INC_STATS(net, IPSTATS_MIB_OUTNOROUTES);
|
|
goto out;
|
|
}
|
|
|
|
err = -EACCES;
|
|
if ((rt->rt_flags & RTCF_BROADCAST) &&
|
|
!sock_flag(sk, SOCK_BROADCAST))
|
|
goto out;
|
|
if (connected)
|
|
sk_dst_set(sk, dst_clone(&rt->dst));
|
|
}
|
|
|
|
if (msg->msg_flags&MSG_CONFIRM)
|
|
goto do_confirm;
|
|
back_from_confirm:
|
|
|
|
saddr = fl4->saddr;
|
|
if (!ipc.addr)
|
|
daddr = ipc.addr = fl4->daddr;
|
|
|
|
/* Lockless fast path for the non-corking case. */
|
|
if (!corkreq) {
|
|
struct inet_cork cork;
|
|
|
|
skb = ip_make_skb(sk, fl4, getfrag, msg, ulen,
|
|
sizeof(struct udphdr), &ipc, &rt,
|
|
&cork, msg->msg_flags);
|
|
err = PTR_ERR(skb);
|
|
if (!IS_ERR_OR_NULL(skb))
|
|
err = udp_send_skb(skb, fl4, &cork);
|
|
goto out;
|
|
}
|
|
|
|
lock_sock(sk);
|
|
if (unlikely(up->pending)) {
|
|
/* The socket is already corked while preparing it. */
|
|
/* ... which is an evident application bug. --ANK */
|
|
release_sock(sk);
|
|
|
|
net_dbg_ratelimited("socket already corked\n");
|
|
err = -EINVAL;
|
|
goto out;
|
|
}
|
|
/*
|
|
* Now cork the socket to pend data.
|
|
*/
|
|
fl4 = &inet->cork.fl.u.ip4;
|
|
fl4->daddr = daddr;
|
|
fl4->saddr = saddr;
|
|
fl4->fl4_dport = dport;
|
|
fl4->fl4_sport = inet->inet_sport;
|
|
up->pending = AF_INET;
|
|
|
|
do_append_data:
|
|
up->len += ulen;
|
|
err = ip_append_data(sk, fl4, getfrag, msg, ulen,
|
|
sizeof(struct udphdr), &ipc, &rt,
|
|
corkreq ? msg->msg_flags|MSG_MORE : msg->msg_flags);
|
|
if (err)
|
|
udp_flush_pending_frames(sk);
|
|
else if (!corkreq)
|
|
err = udp_push_pending_frames(sk);
|
|
else if (unlikely(skb_queue_empty(&sk->sk_write_queue)))
|
|
up->pending = 0;
|
|
release_sock(sk);
|
|
|
|
out:
|
|
ip_rt_put(rt);
|
|
out_free:
|
|
if (free)
|
|
kfree(ipc.opt);
|
|
if (!err)
|
|
return len;
|
|
/*
|
|
* ENOBUFS = no kernel mem, SOCK_NOSPACE = no sndbuf space. Reporting
|
|
* ENOBUFS might not be good (it's not tunable per se), but otherwise
|
|
* we don't have a good statistic (IpOutDiscards but it can be too many
|
|
* things). We could add another new stat but at least for now that
|
|
* seems like overkill.
|
|
*/
|
|
if (err == -ENOBUFS || test_bit(SOCK_NOSPACE, &sk->sk_socket->flags)) {
|
|
UDP_INC_STATS(sock_net(sk),
|
|
UDP_MIB_SNDBUFERRORS, is_udplite);
|
|
}
|
|
return err;
|
|
|
|
do_confirm:
|
|
if (msg->msg_flags & MSG_PROBE)
|
|
dst_confirm_neigh(&rt->dst, &fl4->daddr);
|
|
if (!(msg->msg_flags&MSG_PROBE) || len)
|
|
goto back_from_confirm;
|
|
err = 0;
|
|
goto out;
|
|
}
|
|
EXPORT_SYMBOL(udp_sendmsg);
|
|
|
|
int udp_sendpage(struct sock *sk, struct page *page, int offset,
|
|
size_t size, int flags)
|
|
{
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
struct udp_sock *up = udp_sk(sk);
|
|
int ret;
|
|
|
|
if (flags & MSG_SENDPAGE_NOTLAST)
|
|
flags |= MSG_MORE;
|
|
|
|
if (!up->pending) {
|
|
struct msghdr msg = { .msg_flags = flags|MSG_MORE };
|
|
|
|
/* Call udp_sendmsg to specify destination address which
|
|
* sendpage interface can't pass.
|
|
* This will succeed only when the socket is connected.
|
|
*/
|
|
ret = udp_sendmsg(sk, &msg, 0);
|
|
if (ret < 0)
|
|
return ret;
|
|
}
|
|
|
|
lock_sock(sk);
|
|
|
|
if (unlikely(!up->pending)) {
|
|
release_sock(sk);
|
|
|
|
net_dbg_ratelimited("cork failed\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = ip_append_page(sk, &inet->cork.fl.u.ip4,
|
|
page, offset, size, flags);
|
|
if (ret == -EOPNOTSUPP) {
|
|
release_sock(sk);
|
|
return sock_no_sendpage(sk->sk_socket, page, offset,
|
|
size, flags);
|
|
}
|
|
if (ret < 0) {
|
|
udp_flush_pending_frames(sk);
|
|
goto out;
|
|
}
|
|
|
|
up->len += size;
|
|
if (!(READ_ONCE(up->corkflag) || (flags&MSG_MORE)))
|
|
ret = udp_push_pending_frames(sk);
|
|
if (!ret)
|
|
ret = size;
|
|
out:
|
|
release_sock(sk);
|
|
return ret;
|
|
}
|
|
|
|
#define UDP_SKB_IS_STATELESS 0x80000000
|
|
|
|
/* all head states (dst, sk, nf conntrack) except skb extensions are
|
|
* cleared by udp_rcv().
|
|
*
|
|
* We need to preserve secpath, if present, to eventually process
|
|
* IP_CMSG_PASSSEC at recvmsg() time.
|
|
*
|
|
* Other extensions can be cleared.
|
|
*/
|
|
static bool udp_try_make_stateless(struct sk_buff *skb)
|
|
{
|
|
if (!skb_has_extensions(skb))
|
|
return true;
|
|
|
|
if (!secpath_exists(skb)) {
|
|
skb_ext_reset(skb);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static void udp_set_dev_scratch(struct sk_buff *skb)
|
|
{
|
|
struct udp_dev_scratch *scratch = udp_skb_scratch(skb);
|
|
|
|
BUILD_BUG_ON(sizeof(struct udp_dev_scratch) > sizeof(long));
|
|
scratch->_tsize_state = skb->truesize;
|
|
#if BITS_PER_LONG == 64
|
|
scratch->len = skb->len;
|
|
scratch->csum_unnecessary = !!skb_csum_unnecessary(skb);
|
|
scratch->is_linear = !skb_is_nonlinear(skb);
|
|
#endif
|
|
if (udp_try_make_stateless(skb))
|
|
scratch->_tsize_state |= UDP_SKB_IS_STATELESS;
|
|
}
|
|
|
|
static void udp_skb_csum_unnecessary_set(struct sk_buff *skb)
|
|
{
|
|
/* We come here after udp_lib_checksum_complete() returned 0.
|
|
* This means that __skb_checksum_complete() might have
|
|
* set skb->csum_valid to 1.
|
|
* On 64bit platforms, we can set csum_unnecessary
|
|
* to true, but only if the skb is not shared.
|
|
*/
|
|
#if BITS_PER_LONG == 64
|
|
if (!skb_shared(skb))
|
|
udp_skb_scratch(skb)->csum_unnecessary = true;
|
|
#endif
|
|
}
|
|
|
|
static int udp_skb_truesize(struct sk_buff *skb)
|
|
{
|
|
return udp_skb_scratch(skb)->_tsize_state & ~UDP_SKB_IS_STATELESS;
|
|
}
|
|
|
|
static bool udp_skb_has_head_state(struct sk_buff *skb)
|
|
{
|
|
return !(udp_skb_scratch(skb)->_tsize_state & UDP_SKB_IS_STATELESS);
|
|
}
|
|
|
|
/* fully reclaim rmem/fwd memory allocated for skb */
|
|
static void udp_rmem_release(struct sock *sk, int size, int partial,
|
|
bool rx_queue_lock_held)
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
struct sk_buff_head *sk_queue;
|
|
int amt;
|
|
|
|
if (likely(partial)) {
|
|
up->forward_deficit += size;
|
|
size = up->forward_deficit;
|
|
if (size < (sk->sk_rcvbuf >> 2) &&
|
|
!skb_queue_empty(&up->reader_queue))
|
|
return;
|
|
} else {
|
|
size += up->forward_deficit;
|
|
}
|
|
up->forward_deficit = 0;
|
|
|
|
/* acquire the sk_receive_queue for fwd allocated memory scheduling,
|
|
* if the called don't held it already
|
|
*/
|
|
sk_queue = &sk->sk_receive_queue;
|
|
if (!rx_queue_lock_held)
|
|
spin_lock(&sk_queue->lock);
|
|
|
|
|
|
sk->sk_forward_alloc += size;
|
|
amt = (sk->sk_forward_alloc - partial) & ~(SK_MEM_QUANTUM - 1);
|
|
sk->sk_forward_alloc -= amt;
|
|
|
|
if (amt)
|
|
__sk_mem_reduce_allocated(sk, amt >> SK_MEM_QUANTUM_SHIFT);
|
|
|
|
atomic_sub(size, &sk->sk_rmem_alloc);
|
|
|
|
/* this can save us from acquiring the rx queue lock on next receive */
|
|
skb_queue_splice_tail_init(sk_queue, &up->reader_queue);
|
|
|
|
if (!rx_queue_lock_held)
|
|
spin_unlock(&sk_queue->lock);
|
|
}
|
|
|
|
/* Note: called with reader_queue.lock held.
|
|
* Instead of using skb->truesize here, find a copy of it in skb->dev_scratch
|
|
* This avoids a cache line miss while receive_queue lock is held.
|
|
* Look at __udp_enqueue_schedule_skb() to find where this copy is done.
|
|
*/
|
|
void udp_skb_destructor(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
prefetch(&skb->data);
|
|
udp_rmem_release(sk, udp_skb_truesize(skb), 1, false);
|
|
}
|
|
EXPORT_SYMBOL(udp_skb_destructor);
|
|
|
|
/* as above, but the caller held the rx queue lock, too */
|
|
static void udp_skb_dtor_locked(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
prefetch(&skb->data);
|
|
udp_rmem_release(sk, udp_skb_truesize(skb), 1, true);
|
|
}
|
|
|
|
/* Idea of busylocks is to let producers grab an extra spinlock
|
|
* to relieve pressure on the receive_queue spinlock shared by consumer.
|
|
* Under flood, this means that only one producer can be in line
|
|
* trying to acquire the receive_queue spinlock.
|
|
* These busylock can be allocated on a per cpu manner, instead of a
|
|
* per socket one (that would consume a cache line per socket)
|
|
*/
|
|
static int udp_busylocks_log __read_mostly;
|
|
static spinlock_t *udp_busylocks __read_mostly;
|
|
|
|
static spinlock_t *busylock_acquire(void *ptr)
|
|
{
|
|
spinlock_t *busy;
|
|
|
|
busy = udp_busylocks + hash_ptr(ptr, udp_busylocks_log);
|
|
spin_lock(busy);
|
|
return busy;
|
|
}
|
|
|
|
static void busylock_release(spinlock_t *busy)
|
|
{
|
|
if (busy)
|
|
spin_unlock(busy);
|
|
}
|
|
|
|
int __udp_enqueue_schedule_skb(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
struct sk_buff_head *list = &sk->sk_receive_queue;
|
|
int rmem, delta, amt, err = -ENOMEM;
|
|
spinlock_t *busy = NULL;
|
|
int size;
|
|
|
|
/* try to avoid the costly atomic add/sub pair when the receive
|
|
* queue is full; always allow at least a packet
|
|
*/
|
|
rmem = atomic_read(&sk->sk_rmem_alloc);
|
|
if (rmem > sk->sk_rcvbuf)
|
|
goto drop;
|
|
|
|
/* Under mem pressure, it might be helpful to help udp_recvmsg()
|
|
* having linear skbs :
|
|
* - Reduce memory overhead and thus increase receive queue capacity
|
|
* - Less cache line misses at copyout() time
|
|
* - Less work at consume_skb() (less alien page frag freeing)
|
|
*/
|
|
if (rmem > (sk->sk_rcvbuf >> 1)) {
|
|
skb_condense(skb);
|
|
|
|
busy = busylock_acquire(sk);
|
|
}
|
|
size = skb->truesize;
|
|
udp_set_dev_scratch(skb);
|
|
|
|
/* we drop only if the receive buf is full and the receive
|
|
* queue contains some other skb
|
|
*/
|
|
rmem = atomic_add_return(size, &sk->sk_rmem_alloc);
|
|
if (rmem > (size + (unsigned int)sk->sk_rcvbuf))
|
|
goto uncharge_drop;
|
|
|
|
spin_lock(&list->lock);
|
|
if (size >= sk->sk_forward_alloc) {
|
|
amt = sk_mem_pages(size);
|
|
delta = amt << SK_MEM_QUANTUM_SHIFT;
|
|
if (!__sk_mem_raise_allocated(sk, delta, amt, SK_MEM_RECV)) {
|
|
err = -ENOBUFS;
|
|
spin_unlock(&list->lock);
|
|
goto uncharge_drop;
|
|
}
|
|
|
|
sk->sk_forward_alloc += delta;
|
|
}
|
|
|
|
sk->sk_forward_alloc -= size;
|
|
|
|
/* no need to setup a destructor, we will explicitly release the
|
|
* forward allocated memory on dequeue
|
|
*/
|
|
sock_skb_set_dropcount(sk, skb);
|
|
|
|
__skb_queue_tail(list, skb);
|
|
spin_unlock(&list->lock);
|
|
|
|
if (!sock_flag(sk, SOCK_DEAD))
|
|
sk->sk_data_ready(sk);
|
|
|
|
busylock_release(busy);
|
|
return 0;
|
|
|
|
uncharge_drop:
|
|
atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
|
|
|
|
drop:
|
|
atomic_inc(&sk->sk_drops);
|
|
busylock_release(busy);
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__udp_enqueue_schedule_skb);
|
|
|
|
void udp_destruct_common(struct sock *sk)
|
|
{
|
|
/* reclaim completely the forward allocated memory */
|
|
struct udp_sock *up = udp_sk(sk);
|
|
unsigned int total = 0;
|
|
struct sk_buff *skb;
|
|
|
|
skb_queue_splice_tail_init(&sk->sk_receive_queue, &up->reader_queue);
|
|
while ((skb = __skb_dequeue(&up->reader_queue)) != NULL) {
|
|
total += skb->truesize;
|
|
kfree_skb(skb);
|
|
}
|
|
udp_rmem_release(sk, total, 0, true);
|
|
}
|
|
EXPORT_SYMBOL_GPL(udp_destruct_common);
|
|
|
|
static void udp_destruct_sock(struct sock *sk)
|
|
{
|
|
udp_destruct_common(sk);
|
|
inet_sock_destruct(sk);
|
|
}
|
|
|
|
int udp_init_sock(struct sock *sk)
|
|
{
|
|
skb_queue_head_init(&udp_sk(sk)->reader_queue);
|
|
sk->sk_destruct = udp_destruct_sock;
|
|
return 0;
|
|
}
|
|
|
|
void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len)
|
|
{
|
|
if (unlikely(READ_ONCE(sk->sk_peek_off) >= 0)) {
|
|
bool slow = lock_sock_fast(sk);
|
|
|
|
sk_peek_offset_bwd(sk, len);
|
|
unlock_sock_fast(sk, slow);
|
|
}
|
|
|
|
if (!skb_unref(skb))
|
|
return;
|
|
|
|
/* In the more common cases we cleared the head states previously,
|
|
* see __udp_queue_rcv_skb().
|
|
*/
|
|
if (unlikely(udp_skb_has_head_state(skb)))
|
|
skb_release_head_state(skb);
|
|
__consume_stateless_skb(skb);
|
|
}
|
|
EXPORT_SYMBOL_GPL(skb_consume_udp);
|
|
|
|
static struct sk_buff *__first_packet_length(struct sock *sk,
|
|
struct sk_buff_head *rcvq,
|
|
int *total)
|
|
{
|
|
struct sk_buff *skb;
|
|
|
|
while ((skb = skb_peek(rcvq)) != NULL) {
|
|
if (udp_lib_checksum_complete(skb)) {
|
|
__UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS,
|
|
IS_UDPLITE(sk));
|
|
__UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS,
|
|
IS_UDPLITE(sk));
|
|
atomic_inc(&sk->sk_drops);
|
|
__skb_unlink(skb, rcvq);
|
|
*total += skb->truesize;
|
|
kfree_skb(skb);
|
|
} else {
|
|
udp_skb_csum_unnecessary_set(skb);
|
|
break;
|
|
}
|
|
}
|
|
return skb;
|
|
}
|
|
|
|
/**
|
|
* first_packet_length - return length of first packet in receive queue
|
|
* @sk: socket
|
|
*
|
|
* Drops all bad checksum frames, until a valid one is found.
|
|
* Returns the length of found skb, or -1 if none is found.
|
|
*/
|
|
static int first_packet_length(struct sock *sk)
|
|
{
|
|
struct sk_buff_head *rcvq = &udp_sk(sk)->reader_queue;
|
|
struct sk_buff_head *sk_queue = &sk->sk_receive_queue;
|
|
struct sk_buff *skb;
|
|
int total = 0;
|
|
int res;
|
|
|
|
spin_lock_bh(&rcvq->lock);
|
|
skb = __first_packet_length(sk, rcvq, &total);
|
|
if (!skb && !skb_queue_empty_lockless(sk_queue)) {
|
|
spin_lock(&sk_queue->lock);
|
|
skb_queue_splice_tail_init(sk_queue, rcvq);
|
|
spin_unlock(&sk_queue->lock);
|
|
|
|
skb = __first_packet_length(sk, rcvq, &total);
|
|
}
|
|
res = skb ? skb->len : -1;
|
|
if (total)
|
|
udp_rmem_release(sk, total, 1, false);
|
|
spin_unlock_bh(&rcvq->lock);
|
|
return res;
|
|
}
|
|
|
|
/*
|
|
* IOCTL requests applicable to the UDP protocol
|
|
*/
|
|
|
|
int udp_ioctl(struct sock *sk, int cmd, unsigned long arg)
|
|
{
|
|
switch (cmd) {
|
|
case SIOCOUTQ:
|
|
{
|
|
int amount = sk_wmem_alloc_get(sk);
|
|
|
|
return put_user(amount, (int __user *)arg);
|
|
}
|
|
|
|
case SIOCINQ:
|
|
{
|
|
int amount = max_t(int, 0, first_packet_length(sk));
|
|
|
|
return put_user(amount, (int __user *)arg);
|
|
}
|
|
|
|
default:
|
|
return -ENOIOCTLCMD;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(udp_ioctl);
|
|
|
|
struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
|
|
int noblock, int *off, int *err)
|
|
{
|
|
struct sk_buff_head *sk_queue = &sk->sk_receive_queue;
|
|
struct sk_buff_head *queue;
|
|
struct sk_buff *last;
|
|
long timeo;
|
|
int error;
|
|
|
|
queue = &udp_sk(sk)->reader_queue;
|
|
flags |= noblock ? MSG_DONTWAIT : 0;
|
|
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
|
|
do {
|
|
struct sk_buff *skb;
|
|
|
|
error = sock_error(sk);
|
|
if (error)
|
|
break;
|
|
|
|
error = -EAGAIN;
|
|
do {
|
|
spin_lock_bh(&queue->lock);
|
|
skb = __skb_try_recv_from_queue(sk, queue, flags,
|
|
udp_skb_destructor,
|
|
off, err, &last);
|
|
if (skb) {
|
|
spin_unlock_bh(&queue->lock);
|
|
return skb;
|
|
}
|
|
|
|
if (skb_queue_empty_lockless(sk_queue)) {
|
|
spin_unlock_bh(&queue->lock);
|
|
goto busy_check;
|
|
}
|
|
|
|
/* refill the reader queue and walk it again
|
|
* keep both queues locked to avoid re-acquiring
|
|
* the sk_receive_queue lock if fwd memory scheduling
|
|
* is needed.
|
|
*/
|
|
spin_lock(&sk_queue->lock);
|
|
skb_queue_splice_tail_init(sk_queue, queue);
|
|
|
|
skb = __skb_try_recv_from_queue(sk, queue, flags,
|
|
udp_skb_dtor_locked,
|
|
off, err, &last);
|
|
spin_unlock(&sk_queue->lock);
|
|
spin_unlock_bh(&queue->lock);
|
|
if (skb)
|
|
return skb;
|
|
|
|
busy_check:
|
|
if (!sk_can_busy_loop(sk))
|
|
break;
|
|
|
|
sk_busy_loop(sk, flags & MSG_DONTWAIT);
|
|
} while (!skb_queue_empty_lockless(sk_queue));
|
|
|
|
/* sk_queue is empty, reader_queue may contain peeked packets */
|
|
} while (timeo &&
|
|
!__skb_wait_for_more_packets(sk, &error, &timeo,
|
|
(struct sk_buff *)sk_queue));
|
|
|
|
*err = error;
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL(__skb_recv_udp);
|
|
|
|
/*
|
|
* This should be easy, if there is something there we
|
|
* return it, otherwise we block.
|
|
*/
|
|
|
|
int udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,
|
|
int flags, int *addr_len)
|
|
{
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
DECLARE_SOCKADDR(struct sockaddr_in *, sin, msg->msg_name);
|
|
struct sk_buff *skb;
|
|
unsigned int ulen, copied;
|
|
int off, err, peeking = flags & MSG_PEEK;
|
|
int is_udplite = IS_UDPLITE(sk);
|
|
bool checksum_valid = false;
|
|
|
|
if (flags & MSG_ERRQUEUE)
|
|
return ip_recv_error(sk, msg, len, addr_len);
|
|
|
|
try_again:
|
|
off = sk_peek_offset(sk, flags);
|
|
skb = __skb_recv_udp(sk, flags, noblock, &off, &err);
|
|
if (!skb)
|
|
return err;
|
|
|
|
ulen = udp_skb_len(skb);
|
|
copied = len;
|
|
if (copied > ulen - off)
|
|
copied = ulen - off;
|
|
else if (copied < ulen)
|
|
msg->msg_flags |= MSG_TRUNC;
|
|
|
|
/*
|
|
* If checksum is needed at all, try to do it while copying the
|
|
* data. If the data is truncated, or if we only want a partial
|
|
* coverage checksum (UDP-Lite), do it before the copy.
|
|
*/
|
|
|
|
if (copied < ulen || peeking ||
|
|
(is_udplite && UDP_SKB_CB(skb)->partial_cov)) {
|
|
checksum_valid = udp_skb_csum_unnecessary(skb) ||
|
|
!__udp_lib_checksum_complete(skb);
|
|
if (!checksum_valid)
|
|
goto csum_copy_err;
|
|
}
|
|
|
|
if (checksum_valid || udp_skb_csum_unnecessary(skb)) {
|
|
if (udp_skb_is_linear(skb))
|
|
err = copy_linear_skb(skb, copied, off, &msg->msg_iter);
|
|
else
|
|
err = skb_copy_datagram_msg(skb, off, msg, copied);
|
|
} else {
|
|
err = skb_copy_and_csum_datagram_msg(skb, off, msg);
|
|
|
|
if (err == -EINVAL)
|
|
goto csum_copy_err;
|
|
}
|
|
|
|
if (unlikely(err)) {
|
|
if (!peeking) {
|
|
atomic_inc(&sk->sk_drops);
|
|
UDP_INC_STATS(sock_net(sk),
|
|
UDP_MIB_INERRORS, is_udplite);
|
|
}
|
|
kfree_skb(skb);
|
|
return err;
|
|
}
|
|
|
|
if (!peeking)
|
|
UDP_INC_STATS(sock_net(sk),
|
|
UDP_MIB_INDATAGRAMS, is_udplite);
|
|
|
|
sock_recv_ts_and_drops(msg, sk, skb);
|
|
|
|
/* Copy the address. */
|
|
if (sin) {
|
|
sin->sin_family = AF_INET;
|
|
sin->sin_port = udp_hdr(skb)->source;
|
|
sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
|
|
memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
|
|
*addr_len = sizeof(*sin);
|
|
|
|
if (cgroup_bpf_enabled)
|
|
BPF_CGROUP_RUN_PROG_UDP4_RECVMSG_LOCK(sk,
|
|
(struct sockaddr *)sin);
|
|
}
|
|
|
|
if (udp_sk(sk)->gro_enabled)
|
|
udp_cmsg_recv(msg, sk, skb);
|
|
|
|
if (inet->cmsg_flags)
|
|
ip_cmsg_recv_offset(msg, sk, skb, sizeof(struct udphdr), off);
|
|
|
|
err = copied;
|
|
if (flags & MSG_TRUNC)
|
|
err = ulen;
|
|
|
|
skb_consume_udp(sk, skb, peeking ? -err : err);
|
|
return err;
|
|
|
|
csum_copy_err:
|
|
if (!__sk_queue_drop_skb(sk, &udp_sk(sk)->reader_queue, skb, flags,
|
|
udp_skb_destructor)) {
|
|
UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
|
|
UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
|
|
}
|
|
kfree_skb(skb);
|
|
|
|
/* starting over for a new packet, but check if we need to yield */
|
|
cond_resched();
|
|
msg->msg_flags &= ~MSG_TRUNC;
|
|
goto try_again;
|
|
}
|
|
|
|
int udp_pre_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
|
|
{
|
|
/* This check is replicated from __ip4_datagram_connect() and
|
|
* intended to prevent BPF program called below from accessing bytes
|
|
* that are out of the bound specified by user in addr_len.
|
|
*/
|
|
if (addr_len < sizeof(struct sockaddr_in))
|
|
return -EINVAL;
|
|
|
|
return BPF_CGROUP_RUN_PROG_INET4_CONNECT_LOCK(sk, uaddr);
|
|
}
|
|
EXPORT_SYMBOL(udp_pre_connect);
|
|
|
|
int __udp_disconnect(struct sock *sk, int flags)
|
|
{
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
/*
|
|
* 1003.1g - break association.
|
|
*/
|
|
|
|
sk->sk_state = TCP_CLOSE;
|
|
inet->inet_daddr = 0;
|
|
inet->inet_dport = 0;
|
|
sock_rps_reset_rxhash(sk);
|
|
sk->sk_bound_dev_if = 0;
|
|
if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) {
|
|
inet_reset_saddr(sk);
|
|
if (sk->sk_prot->rehash &&
|
|
(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
|
|
sk->sk_prot->rehash(sk);
|
|
}
|
|
|
|
if (!(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) {
|
|
sk->sk_prot->unhash(sk);
|
|
inet->inet_sport = 0;
|
|
}
|
|
sk_dst_reset(sk);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(__udp_disconnect);
|
|
|
|
int udp_disconnect(struct sock *sk, int flags)
|
|
{
|
|
lock_sock(sk);
|
|
__udp_disconnect(sk, flags);
|
|
release_sock(sk);
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(udp_disconnect);
|
|
|
|
void udp_lib_unhash(struct sock *sk)
|
|
{
|
|
if (sk_hashed(sk)) {
|
|
struct udp_table *udptable = sk->sk_prot->h.udp_table;
|
|
struct udp_hslot *hslot, *hslot2;
|
|
|
|
hslot = udp_hashslot(udptable, sock_net(sk),
|
|
udp_sk(sk)->udp_port_hash);
|
|
hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash);
|
|
|
|
spin_lock_bh(&hslot->lock);
|
|
if (rcu_access_pointer(sk->sk_reuseport_cb))
|
|
reuseport_detach_sock(sk);
|
|
if (sk_del_node_init_rcu(sk)) {
|
|
hslot->count--;
|
|
inet_sk(sk)->inet_num = 0;
|
|
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
|
|
|
|
spin_lock(&hslot2->lock);
|
|
hlist_del_init_rcu(&udp_sk(sk)->udp_portaddr_node);
|
|
hslot2->count--;
|
|
spin_unlock(&hslot2->lock);
|
|
}
|
|
spin_unlock_bh(&hslot->lock);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(udp_lib_unhash);
|
|
|
|
/*
|
|
* inet_rcv_saddr was changed, we must rehash secondary hash
|
|
*/
|
|
void udp_lib_rehash(struct sock *sk, u16 newhash)
|
|
{
|
|
if (sk_hashed(sk)) {
|
|
struct udp_table *udptable = sk->sk_prot->h.udp_table;
|
|
struct udp_hslot *hslot, *hslot2, *nhslot2;
|
|
|
|
hslot2 = udp_hashslot2(udptable, udp_sk(sk)->udp_portaddr_hash);
|
|
nhslot2 = udp_hashslot2(udptable, newhash);
|
|
udp_sk(sk)->udp_portaddr_hash = newhash;
|
|
|
|
if (hslot2 != nhslot2 ||
|
|
rcu_access_pointer(sk->sk_reuseport_cb)) {
|
|
hslot = udp_hashslot(udptable, sock_net(sk),
|
|
udp_sk(sk)->udp_port_hash);
|
|
/* we must lock primary chain too */
|
|
spin_lock_bh(&hslot->lock);
|
|
if (rcu_access_pointer(sk->sk_reuseport_cb))
|
|
reuseport_detach_sock(sk);
|
|
|
|
if (hslot2 != nhslot2) {
|
|
spin_lock(&hslot2->lock);
|
|
hlist_del_init_rcu(&udp_sk(sk)->udp_portaddr_node);
|
|
hslot2->count--;
|
|
spin_unlock(&hslot2->lock);
|
|
|
|
spin_lock(&nhslot2->lock);
|
|
hlist_add_head_rcu(&udp_sk(sk)->udp_portaddr_node,
|
|
&nhslot2->head);
|
|
nhslot2->count++;
|
|
spin_unlock(&nhslot2->lock);
|
|
}
|
|
|
|
spin_unlock_bh(&hslot->lock);
|
|
}
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(udp_lib_rehash);
|
|
|
|
void udp_v4_rehash(struct sock *sk)
|
|
{
|
|
u16 new_hash = ipv4_portaddr_hash(sock_net(sk),
|
|
inet_sk(sk)->inet_rcv_saddr,
|
|
inet_sk(sk)->inet_num);
|
|
udp_lib_rehash(sk, new_hash);
|
|
}
|
|
|
|
static int __udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
int rc;
|
|
|
|
if (inet_sk(sk)->inet_daddr) {
|
|
sock_rps_save_rxhash(sk, skb);
|
|
sk_mark_napi_id(sk, skb);
|
|
sk_incoming_cpu_update(sk);
|
|
} else {
|
|
sk_mark_napi_id_once(sk, skb);
|
|
}
|
|
|
|
rc = __udp_enqueue_schedule_skb(sk, skb);
|
|
if (rc < 0) {
|
|
int is_udplite = IS_UDPLITE(sk);
|
|
|
|
/* Note that an ENOMEM error is charged twice */
|
|
if (rc == -ENOMEM)
|
|
UDP_INC_STATS(sock_net(sk), UDP_MIB_RCVBUFERRORS,
|
|
is_udplite);
|
|
UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
|
|
kfree_skb(skb);
|
|
trace_udp_fail_queue_rcv_skb(rc, sk);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* returns:
|
|
* -1: error
|
|
* 0: success
|
|
* >0: "udp encap" protocol resubmission
|
|
*
|
|
* Note that in the success and error cases, the skb is assumed to
|
|
* have either been requeued or freed.
|
|
*/
|
|
static int udp_queue_rcv_one_skb(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
int is_udplite = IS_UDPLITE(sk);
|
|
|
|
/*
|
|
* Charge it to the socket, dropping if the queue is full.
|
|
*/
|
|
if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
|
|
goto drop;
|
|
nf_reset_ct(skb);
|
|
|
|
if (static_branch_unlikely(&udp_encap_needed_key) && up->encap_type) {
|
|
int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
|
|
|
|
/*
|
|
* This is an encapsulation socket so pass the skb to
|
|
* the socket's udp_encap_rcv() hook. Otherwise, just
|
|
* fall through and pass this up the UDP socket.
|
|
* up->encap_rcv() returns the following value:
|
|
* =0 if skb was successfully passed to the encap
|
|
* handler or was discarded by it.
|
|
* >0 if skb should be passed on to UDP.
|
|
* <0 if skb should be resubmitted as proto -N
|
|
*/
|
|
|
|
/* if we're overly short, let UDP handle it */
|
|
encap_rcv = READ_ONCE(up->encap_rcv);
|
|
if (encap_rcv) {
|
|
int ret;
|
|
|
|
/* Verify checksum before giving to encap */
|
|
if (udp_lib_checksum_complete(skb))
|
|
goto csum_error;
|
|
|
|
ret = encap_rcv(sk, skb);
|
|
if (ret <= 0) {
|
|
__UDP_INC_STATS(sock_net(sk),
|
|
UDP_MIB_INDATAGRAMS,
|
|
is_udplite);
|
|
return -ret;
|
|
}
|
|
}
|
|
|
|
/* FALLTHROUGH -- it's a UDP Packet */
|
|
}
|
|
|
|
/*
|
|
* UDP-Lite specific tests, ignored on UDP sockets
|
|
*/
|
|
if ((up->pcflag & UDPLITE_RECV_CC) && UDP_SKB_CB(skb)->partial_cov) {
|
|
|
|
/*
|
|
* MIB statistics other than incrementing the error count are
|
|
* disabled for the following two types of errors: these depend
|
|
* on the application settings, not on the functioning of the
|
|
* protocol stack as such.
|
|
*
|
|
* RFC 3828 here recommends (sec 3.3): "There should also be a
|
|
* way ... to ... at least let the receiving application block
|
|
* delivery of packets with coverage values less than a value
|
|
* provided by the application."
|
|
*/
|
|
if (up->pcrlen == 0) { /* full coverage was set */
|
|
net_dbg_ratelimited("UDPLite: partial coverage %d while full coverage %d requested\n",
|
|
UDP_SKB_CB(skb)->cscov, skb->len);
|
|
goto drop;
|
|
}
|
|
/* The next case involves violating the min. coverage requested
|
|
* by the receiver. This is subtle: if receiver wants x and x is
|
|
* greater than the buffersize/MTU then receiver will complain
|
|
* that it wants x while sender emits packets of smaller size y.
|
|
* Therefore the above ...()->partial_cov statement is essential.
|
|
*/
|
|
if (UDP_SKB_CB(skb)->cscov < up->pcrlen) {
|
|
net_dbg_ratelimited("UDPLite: coverage %d too small, need min %d\n",
|
|
UDP_SKB_CB(skb)->cscov, up->pcrlen);
|
|
goto drop;
|
|
}
|
|
}
|
|
|
|
prefetch(&sk->sk_rmem_alloc);
|
|
if (rcu_access_pointer(sk->sk_filter) &&
|
|
udp_lib_checksum_complete(skb))
|
|
goto csum_error;
|
|
|
|
if (sk_filter_trim_cap(sk, skb, sizeof(struct udphdr)))
|
|
goto drop;
|
|
|
|
udp_csum_pull_header(skb);
|
|
|
|
ipv4_pktinfo_prepare(sk, skb);
|
|
return __udp_queue_rcv_skb(sk, skb);
|
|
|
|
csum_error:
|
|
__UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
|
|
drop:
|
|
__UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
|
|
atomic_inc(&sk->sk_drops);
|
|
kfree_skb(skb);
|
|
return -1;
|
|
}
|
|
|
|
static int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
struct sk_buff *next, *segs;
|
|
int ret;
|
|
|
|
if (likely(!udp_unexpected_gso(sk, skb)))
|
|
return udp_queue_rcv_one_skb(sk, skb);
|
|
|
|
BUILD_BUG_ON(sizeof(struct udp_skb_cb) > SKB_SGO_CB_OFFSET);
|
|
__skb_push(skb, -skb_mac_offset(skb));
|
|
segs = udp_rcv_segment(sk, skb, true);
|
|
for (skb = segs; skb; skb = next) {
|
|
next = skb->next;
|
|
__skb_pull(skb, skb_transport_offset(skb));
|
|
ret = udp_queue_rcv_one_skb(sk, skb);
|
|
if (ret > 0)
|
|
ip_protocol_deliver_rcu(dev_net(skb->dev), skb, ret);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* For TCP sockets, sk_rx_dst is protected by socket lock
|
|
* For UDP, we use xchg() to guard against concurrent changes.
|
|
*/
|
|
bool udp_sk_rx_dst_set(struct sock *sk, struct dst_entry *dst)
|
|
{
|
|
struct dst_entry *old;
|
|
|
|
if (dst_hold_safe(dst)) {
|
|
old = xchg((__force struct dst_entry **)&sk->sk_rx_dst, dst);
|
|
dst_release(old);
|
|
return old != dst;
|
|
}
|
|
return false;
|
|
}
|
|
EXPORT_SYMBOL(udp_sk_rx_dst_set);
|
|
|
|
/*
|
|
* Multicasts and broadcasts go to each listener.
|
|
*
|
|
* Note: called only from the BH handler context.
|
|
*/
|
|
static int __udp4_lib_mcast_deliver(struct net *net, struct sk_buff *skb,
|
|
struct udphdr *uh,
|
|
__be32 saddr, __be32 daddr,
|
|
struct udp_table *udptable,
|
|
int proto)
|
|
{
|
|
struct sock *sk, *first = NULL;
|
|
unsigned short hnum = ntohs(uh->dest);
|
|
struct udp_hslot *hslot = udp_hashslot(udptable, net, hnum);
|
|
unsigned int hash2 = 0, hash2_any = 0, use_hash2 = (hslot->count > 10);
|
|
unsigned int offset = offsetof(typeof(*sk), sk_node);
|
|
int dif = skb->dev->ifindex;
|
|
int sdif = inet_sdif(skb);
|
|
struct hlist_node *node;
|
|
struct sk_buff *nskb;
|
|
|
|
if (use_hash2) {
|
|
hash2_any = ipv4_portaddr_hash(net, htonl(INADDR_ANY), hnum) &
|
|
udptable->mask;
|
|
hash2 = ipv4_portaddr_hash(net, daddr, hnum) & udptable->mask;
|
|
start_lookup:
|
|
hslot = &udptable->hash2[hash2];
|
|
offset = offsetof(typeof(*sk), __sk_common.skc_portaddr_node);
|
|
}
|
|
|
|
sk_for_each_entry_offset_rcu(sk, node, &hslot->head, offset) {
|
|
if (!__udp_is_mcast_sock(net, sk, uh->dest, daddr,
|
|
uh->source, saddr, dif, sdif, hnum))
|
|
continue;
|
|
|
|
if (!first) {
|
|
first = sk;
|
|
continue;
|
|
}
|
|
nskb = skb_clone(skb, GFP_ATOMIC);
|
|
|
|
if (unlikely(!nskb)) {
|
|
atomic_inc(&sk->sk_drops);
|
|
__UDP_INC_STATS(net, UDP_MIB_RCVBUFERRORS,
|
|
IS_UDPLITE(sk));
|
|
__UDP_INC_STATS(net, UDP_MIB_INERRORS,
|
|
IS_UDPLITE(sk));
|
|
continue;
|
|
}
|
|
if (udp_queue_rcv_skb(sk, nskb) > 0)
|
|
consume_skb(nskb);
|
|
}
|
|
|
|
/* Also lookup *:port if we are using hash2 and haven't done so yet. */
|
|
if (use_hash2 && hash2 != hash2_any) {
|
|
hash2 = hash2_any;
|
|
goto start_lookup;
|
|
}
|
|
|
|
if (first) {
|
|
if (udp_queue_rcv_skb(first, skb) > 0)
|
|
consume_skb(skb);
|
|
} else {
|
|
kfree_skb(skb);
|
|
__UDP_INC_STATS(net, UDP_MIB_IGNOREDMULTI,
|
|
proto == IPPROTO_UDPLITE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* Initialize UDP checksum. If exited with zero value (success),
|
|
* CHECKSUM_UNNECESSARY means, that no more checks are required.
|
|
* Otherwise, csum completion requires checksumming packet body,
|
|
* including udp header and folding it to skb->csum.
|
|
*/
|
|
static inline int udp4_csum_init(struct sk_buff *skb, struct udphdr *uh,
|
|
int proto)
|
|
{
|
|
int err;
|
|
|
|
UDP_SKB_CB(skb)->partial_cov = 0;
|
|
UDP_SKB_CB(skb)->cscov = skb->len;
|
|
|
|
if (proto == IPPROTO_UDPLITE) {
|
|
err = udplite_checksum_init(skb, uh);
|
|
if (err)
|
|
return err;
|
|
|
|
if (UDP_SKB_CB(skb)->partial_cov) {
|
|
skb->csum = inet_compute_pseudo(skb, proto);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/* Note, we are only interested in != 0 or == 0, thus the
|
|
* force to int.
|
|
*/
|
|
err = (__force int)skb_checksum_init_zero_check(skb, proto, uh->check,
|
|
inet_compute_pseudo);
|
|
if (err)
|
|
return err;
|
|
|
|
if (skb->ip_summed == CHECKSUM_COMPLETE && !skb->csum_valid) {
|
|
/* If SW calculated the value, we know it's bad */
|
|
if (skb->csum_complete_sw)
|
|
return 1;
|
|
|
|
/* HW says the value is bad. Let's validate that.
|
|
* skb->csum is no longer the full packet checksum,
|
|
* so don't treat it as such.
|
|
*/
|
|
skb_checksum_complete_unset(skb);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* wrapper for udp_queue_rcv_skb tacking care of csum conversion and
|
|
* return code conversion for ip layer consumption
|
|
*/
|
|
static int udp_unicast_rcv_skb(struct sock *sk, struct sk_buff *skb,
|
|
struct udphdr *uh)
|
|
{
|
|
int ret;
|
|
|
|
if (inet_get_convert_csum(sk) && uh->check && !IS_UDPLITE(sk))
|
|
skb_checksum_try_convert(skb, IPPROTO_UDP, inet_compute_pseudo);
|
|
|
|
ret = udp_queue_rcv_skb(sk, skb);
|
|
|
|
/* a return value > 0 means to resubmit the input, but
|
|
* it wants the return to be -protocol, or 0
|
|
*/
|
|
if (ret > 0)
|
|
return -ret;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* All we need to do is get the socket, and then do a checksum.
|
|
*/
|
|
|
|
int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
|
|
int proto)
|
|
{
|
|
struct sock *sk;
|
|
struct udphdr *uh;
|
|
unsigned short ulen;
|
|
struct rtable *rt = skb_rtable(skb);
|
|
__be32 saddr, daddr;
|
|
struct net *net = dev_net(skb->dev);
|
|
|
|
/*
|
|
* Validate the packet.
|
|
*/
|
|
if (!pskb_may_pull(skb, sizeof(struct udphdr)))
|
|
goto drop; /* No space for header. */
|
|
|
|
uh = udp_hdr(skb);
|
|
ulen = ntohs(uh->len);
|
|
saddr = ip_hdr(skb)->saddr;
|
|
daddr = ip_hdr(skb)->daddr;
|
|
|
|
if (ulen > skb->len)
|
|
goto short_packet;
|
|
|
|
if (proto == IPPROTO_UDP) {
|
|
/* UDP validates ulen. */
|
|
if (ulen < sizeof(*uh) || pskb_trim_rcsum(skb, ulen))
|
|
goto short_packet;
|
|
uh = udp_hdr(skb);
|
|
}
|
|
|
|
if (udp4_csum_init(skb, uh, proto))
|
|
goto csum_error;
|
|
|
|
sk = skb_steal_sock(skb);
|
|
if (sk) {
|
|
struct dst_entry *dst = skb_dst(skb);
|
|
int ret;
|
|
|
|
if (unlikely(rcu_dereference(sk->sk_rx_dst) != dst))
|
|
udp_sk_rx_dst_set(sk, dst);
|
|
|
|
ret = udp_unicast_rcv_skb(sk, skb, uh);
|
|
sock_put(sk);
|
|
return ret;
|
|
}
|
|
|
|
if (rt->rt_flags & (RTCF_BROADCAST|RTCF_MULTICAST))
|
|
return __udp4_lib_mcast_deliver(net, skb, uh,
|
|
saddr, daddr, udptable, proto);
|
|
|
|
sk = __udp4_lib_lookup_skb(skb, uh->source, uh->dest, udptable);
|
|
if (sk)
|
|
return udp_unicast_rcv_skb(sk, skb, uh);
|
|
|
|
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
|
|
goto drop;
|
|
nf_reset_ct(skb);
|
|
|
|
/* No socket. Drop packet silently, if checksum is wrong */
|
|
if (udp_lib_checksum_complete(skb))
|
|
goto csum_error;
|
|
|
|
__UDP_INC_STATS(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
|
|
icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
|
|
|
|
/*
|
|
* Hmm. We got an UDP packet to a port to which we
|
|
* don't wanna listen. Ignore it.
|
|
*/
|
|
kfree_skb(skb);
|
|
return 0;
|
|
|
|
short_packet:
|
|
net_dbg_ratelimited("UDP%s: short packet: From %pI4:%u %d/%d to %pI4:%u\n",
|
|
proto == IPPROTO_UDPLITE ? "Lite" : "",
|
|
&saddr, ntohs(uh->source),
|
|
ulen, skb->len,
|
|
&daddr, ntohs(uh->dest));
|
|
goto drop;
|
|
|
|
csum_error:
|
|
/*
|
|
* RFC1122: OK. Discards the bad packet silently (as far as
|
|
* the network is concerned, anyway) as per 4.1.3.4 (MUST).
|
|
*/
|
|
net_dbg_ratelimited("UDP%s: bad checksum. From %pI4:%u to %pI4:%u ulen %d\n",
|
|
proto == IPPROTO_UDPLITE ? "Lite" : "",
|
|
&saddr, ntohs(uh->source), &daddr, ntohs(uh->dest),
|
|
ulen);
|
|
__UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, proto == IPPROTO_UDPLITE);
|
|
drop:
|
|
__UDP_INC_STATS(net, UDP_MIB_INERRORS, proto == IPPROTO_UDPLITE);
|
|
kfree_skb(skb);
|
|
return 0;
|
|
}
|
|
|
|
/* We can only early demux multicast if there is a single matching socket.
|
|
* If more than one socket found returns NULL
|
|
*/
|
|
static struct sock *__udp4_lib_mcast_demux_lookup(struct net *net,
|
|
__be16 loc_port, __be32 loc_addr,
|
|
__be16 rmt_port, __be32 rmt_addr,
|
|
int dif, int sdif)
|
|
{
|
|
struct sock *sk, *result;
|
|
unsigned short hnum = ntohs(loc_port);
|
|
unsigned int slot = udp_hashfn(net, hnum, udp_table.mask);
|
|
struct udp_hslot *hslot = &udp_table.hash[slot];
|
|
|
|
/* Do not bother scanning a too big list */
|
|
if (hslot->count > 10)
|
|
return NULL;
|
|
|
|
result = NULL;
|
|
sk_for_each_rcu(sk, &hslot->head) {
|
|
if (__udp_is_mcast_sock(net, sk, loc_port, loc_addr,
|
|
rmt_port, rmt_addr, dif, sdif, hnum)) {
|
|
if (result)
|
|
return NULL;
|
|
result = sk;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/* For unicast we should only early demux connected sockets or we can
|
|
* break forwarding setups. The chains here can be long so only check
|
|
* if the first socket is an exact match and if not move on.
|
|
*/
|
|
static struct sock *__udp4_lib_demux_lookup(struct net *net,
|
|
__be16 loc_port, __be32 loc_addr,
|
|
__be16 rmt_port, __be32 rmt_addr,
|
|
int dif, int sdif)
|
|
{
|
|
unsigned short hnum = ntohs(loc_port);
|
|
unsigned int hash2 = ipv4_portaddr_hash(net, loc_addr, hnum);
|
|
unsigned int slot2 = hash2 & udp_table.mask;
|
|
struct udp_hslot *hslot2 = &udp_table.hash2[slot2];
|
|
INET_ADDR_COOKIE(acookie, rmt_addr, loc_addr);
|
|
const __portpair ports = INET_COMBINED_PORTS(rmt_port, hnum);
|
|
struct sock *sk;
|
|
|
|
udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
|
|
if (INET_MATCH(sk, net, acookie, rmt_addr,
|
|
loc_addr, ports, dif, sdif))
|
|
return sk;
|
|
/* Only check first socket in chain */
|
|
break;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
int udp_v4_early_demux(struct sk_buff *skb)
|
|
{
|
|
struct net *net = dev_net(skb->dev);
|
|
struct in_device *in_dev = NULL;
|
|
const struct iphdr *iph;
|
|
const struct udphdr *uh;
|
|
struct sock *sk = NULL;
|
|
struct dst_entry *dst;
|
|
int dif = skb->dev->ifindex;
|
|
int sdif = inet_sdif(skb);
|
|
int ours;
|
|
|
|
/* validate the packet */
|
|
if (!pskb_may_pull(skb, skb_transport_offset(skb) + sizeof(struct udphdr)))
|
|
return 0;
|
|
|
|
iph = ip_hdr(skb);
|
|
uh = udp_hdr(skb);
|
|
|
|
if (skb->pkt_type == PACKET_MULTICAST) {
|
|
in_dev = __in_dev_get_rcu(skb->dev);
|
|
|
|
if (!in_dev)
|
|
return 0;
|
|
|
|
ours = ip_check_mc_rcu(in_dev, iph->daddr, iph->saddr,
|
|
iph->protocol);
|
|
if (!ours)
|
|
return 0;
|
|
|
|
sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr,
|
|
uh->source, iph->saddr,
|
|
dif, sdif);
|
|
} else if (skb->pkt_type == PACKET_HOST) {
|
|
sk = __udp4_lib_demux_lookup(net, uh->dest, iph->daddr,
|
|
uh->source, iph->saddr, dif, sdif);
|
|
}
|
|
|
|
if (!sk || !refcount_inc_not_zero(&sk->sk_refcnt))
|
|
return 0;
|
|
|
|
skb->sk = sk;
|
|
skb->destructor = sock_efree;
|
|
dst = rcu_dereference(sk->sk_rx_dst);
|
|
|
|
if (dst)
|
|
dst = dst_check(dst, 0);
|
|
if (dst) {
|
|
u32 itag = 0;
|
|
|
|
/* set noref for now.
|
|
* any place which wants to hold dst has to call
|
|
* dst_hold_safe()
|
|
*/
|
|
skb_dst_set_noref(skb, dst);
|
|
|
|
/* for unconnected multicast sockets we need to validate
|
|
* the source on each packet
|
|
*/
|
|
if (!inet_sk(sk)->inet_daddr && in_dev)
|
|
return ip_mc_validate_source(skb, iph->daddr,
|
|
iph->saddr,
|
|
iph->tos & IPTOS_RT_MASK,
|
|
skb->dev, in_dev, &itag);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int udp_rcv(struct sk_buff *skb)
|
|
{
|
|
return __udp4_lib_rcv(skb, &udp_table, IPPROTO_UDP);
|
|
}
|
|
|
|
void udp_destroy_sock(struct sock *sk)
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
bool slow = lock_sock_fast(sk);
|
|
|
|
/* protects from races with udp_abort() */
|
|
sock_set_flag(sk, SOCK_DEAD);
|
|
udp_flush_pending_frames(sk);
|
|
unlock_sock_fast(sk, slow);
|
|
if (static_branch_unlikely(&udp_encap_needed_key)) {
|
|
if (up->encap_type) {
|
|
void (*encap_destroy)(struct sock *sk);
|
|
encap_destroy = READ_ONCE(up->encap_destroy);
|
|
if (encap_destroy)
|
|
encap_destroy(sk);
|
|
}
|
|
if (up->encap_enabled)
|
|
static_branch_dec(&udp_encap_needed_key);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Socket option code for UDP
|
|
*/
|
|
int udp_lib_setsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, unsigned int optlen,
|
|
int (*push_pending_frames)(struct sock *))
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
int val, valbool;
|
|
int err = 0;
|
|
int is_udplite = IS_UDPLITE(sk);
|
|
|
|
if (optlen < sizeof(int))
|
|
return -EINVAL;
|
|
|
|
if (get_user(val, (int __user *)optval))
|
|
return -EFAULT;
|
|
|
|
valbool = val ? 1 : 0;
|
|
|
|
switch (optname) {
|
|
case UDP_CORK:
|
|
if (val != 0) {
|
|
WRITE_ONCE(up->corkflag, 1);
|
|
} else {
|
|
WRITE_ONCE(up->corkflag, 0);
|
|
lock_sock(sk);
|
|
push_pending_frames(sk);
|
|
release_sock(sk);
|
|
}
|
|
break;
|
|
|
|
case UDP_ENCAP:
|
|
switch (val) {
|
|
case 0:
|
|
case UDP_ENCAP_ESPINUDP:
|
|
case UDP_ENCAP_ESPINUDP_NON_IKE:
|
|
up->encap_rcv = xfrm4_udp_encap_rcv;
|
|
/* FALLTHROUGH */
|
|
case UDP_ENCAP_L2TPINUDP:
|
|
up->encap_type = val;
|
|
lock_sock(sk);
|
|
udp_tunnel_encap_enable(sk->sk_socket);
|
|
release_sock(sk);
|
|
break;
|
|
default:
|
|
err = -ENOPROTOOPT;
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case UDP_NO_CHECK6_TX:
|
|
up->no_check6_tx = valbool;
|
|
break;
|
|
|
|
case UDP_NO_CHECK6_RX:
|
|
up->no_check6_rx = valbool;
|
|
break;
|
|
|
|
case UDP_SEGMENT:
|
|
if (val < 0 || val > USHRT_MAX)
|
|
return -EINVAL;
|
|
WRITE_ONCE(up->gso_size, val);
|
|
break;
|
|
|
|
case UDP_GRO:
|
|
lock_sock(sk);
|
|
|
|
/* when enabling GRO, accept the related GSO packet type */
|
|
if (valbool)
|
|
udp_tunnel_encap_enable(sk->sk_socket);
|
|
up->gro_enabled = valbool;
|
|
up->accept_udp_l4 = valbool;
|
|
release_sock(sk);
|
|
break;
|
|
|
|
/*
|
|
* UDP-Lite's partial checksum coverage (RFC 3828).
|
|
*/
|
|
/* The sender sets actual checksum coverage length via this option.
|
|
* The case coverage > packet length is handled by send module. */
|
|
case UDPLITE_SEND_CSCOV:
|
|
if (!is_udplite) /* Disable the option on UDP sockets */
|
|
return -ENOPROTOOPT;
|
|
if (val != 0 && val < 8) /* Illegal coverage: use default (8) */
|
|
val = 8;
|
|
else if (val > USHRT_MAX)
|
|
val = USHRT_MAX;
|
|
up->pcslen = val;
|
|
up->pcflag |= UDPLITE_SEND_CC;
|
|
break;
|
|
|
|
/* The receiver specifies a minimum checksum coverage value. To make
|
|
* sense, this should be set to at least 8 (as done below). If zero is
|
|
* used, this again means full checksum coverage. */
|
|
case UDPLITE_RECV_CSCOV:
|
|
if (!is_udplite) /* Disable the option on UDP sockets */
|
|
return -ENOPROTOOPT;
|
|
if (val != 0 && val < 8) /* Avoid silly minimal values. */
|
|
val = 8;
|
|
else if (val > USHRT_MAX)
|
|
val = USHRT_MAX;
|
|
up->pcrlen = val;
|
|
up->pcflag |= UDPLITE_RECV_CC;
|
|
break;
|
|
|
|
default:
|
|
err = -ENOPROTOOPT;
|
|
break;
|
|
}
|
|
|
|
return err;
|
|
}
|
|
EXPORT_SYMBOL(udp_lib_setsockopt);
|
|
|
|
int udp_setsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, unsigned int optlen)
|
|
{
|
|
if (level == SOL_UDP || level == SOL_UDPLITE)
|
|
return udp_lib_setsockopt(sk, level, optname, optval, optlen,
|
|
udp_push_pending_frames);
|
|
return ip_setsockopt(sk, level, optname, optval, optlen);
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
int compat_udp_setsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, unsigned int optlen)
|
|
{
|
|
if (level == SOL_UDP || level == SOL_UDPLITE)
|
|
return udp_lib_setsockopt(sk, level, optname, optval, optlen,
|
|
udp_push_pending_frames);
|
|
return compat_ip_setsockopt(sk, level, optname, optval, optlen);
|
|
}
|
|
#endif
|
|
|
|
int udp_lib_getsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, int __user *optlen)
|
|
{
|
|
struct udp_sock *up = udp_sk(sk);
|
|
int val, len;
|
|
|
|
if (get_user(len, optlen))
|
|
return -EFAULT;
|
|
|
|
len = min_t(unsigned int, len, sizeof(int));
|
|
|
|
if (len < 0)
|
|
return -EINVAL;
|
|
|
|
switch (optname) {
|
|
case UDP_CORK:
|
|
val = READ_ONCE(up->corkflag);
|
|
break;
|
|
|
|
case UDP_ENCAP:
|
|
val = up->encap_type;
|
|
break;
|
|
|
|
case UDP_NO_CHECK6_TX:
|
|
val = up->no_check6_tx;
|
|
break;
|
|
|
|
case UDP_NO_CHECK6_RX:
|
|
val = up->no_check6_rx;
|
|
break;
|
|
|
|
case UDP_SEGMENT:
|
|
val = READ_ONCE(up->gso_size);
|
|
break;
|
|
|
|
case UDP_GRO:
|
|
val = up->gro_enabled;
|
|
break;
|
|
|
|
/* The following two cannot be changed on UDP sockets, the return is
|
|
* always 0 (which corresponds to the full checksum coverage of UDP). */
|
|
case UDPLITE_SEND_CSCOV:
|
|
val = up->pcslen;
|
|
break;
|
|
|
|
case UDPLITE_RECV_CSCOV:
|
|
val = up->pcrlen;
|
|
break;
|
|
|
|
default:
|
|
return -ENOPROTOOPT;
|
|
}
|
|
|
|
if (put_user(len, optlen))
|
|
return -EFAULT;
|
|
if (copy_to_user(optval, &val, len))
|
|
return -EFAULT;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(udp_lib_getsockopt);
|
|
|
|
int udp_getsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, int __user *optlen)
|
|
{
|
|
if (level == SOL_UDP || level == SOL_UDPLITE)
|
|
return udp_lib_getsockopt(sk, level, optname, optval, optlen);
|
|
return ip_getsockopt(sk, level, optname, optval, optlen);
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
int compat_udp_getsockopt(struct sock *sk, int level, int optname,
|
|
char __user *optval, int __user *optlen)
|
|
{
|
|
if (level == SOL_UDP || level == SOL_UDPLITE)
|
|
return udp_lib_getsockopt(sk, level, optname, optval, optlen);
|
|
return compat_ip_getsockopt(sk, level, optname, optval, optlen);
|
|
}
|
|
#endif
|
|
/**
|
|
* udp_poll - wait for a UDP event.
|
|
* @file - file struct
|
|
* @sock - socket
|
|
* @wait - poll table
|
|
*
|
|
* This is same as datagram poll, except for the special case of
|
|
* blocking sockets. If application is using a blocking fd
|
|
* and a packet with checksum error is in the queue;
|
|
* then it could get return from select indicating data available
|
|
* but then block when reading it. Add special case code
|
|
* to work around these arguably broken applications.
|
|
*/
|
|
__poll_t udp_poll(struct file *file, struct socket *sock, poll_table *wait)
|
|
{
|
|
__poll_t mask = datagram_poll(file, sock, wait);
|
|
struct sock *sk = sock->sk;
|
|
|
|
if (!skb_queue_empty_lockless(&udp_sk(sk)->reader_queue))
|
|
mask |= EPOLLIN | EPOLLRDNORM;
|
|
|
|
/* Check for false positives due to checksum errors */
|
|
if ((mask & EPOLLRDNORM) && !(file->f_flags & O_NONBLOCK) &&
|
|
!(sk->sk_shutdown & RCV_SHUTDOWN) && first_packet_length(sk) == -1)
|
|
mask &= ~(EPOLLIN | EPOLLRDNORM);
|
|
|
|
return mask;
|
|
|
|
}
|
|
EXPORT_SYMBOL(udp_poll);
|
|
|
|
int udp_abort(struct sock *sk, int err)
|
|
{
|
|
lock_sock(sk);
|
|
|
|
/* udp{v6}_destroy_sock() sets it under the sk lock, avoid racing
|
|
* with close()
|
|
*/
|
|
if (sock_flag(sk, SOCK_DEAD))
|
|
goto out;
|
|
|
|
sk->sk_err = err;
|
|
sk->sk_error_report(sk);
|
|
__udp_disconnect(sk, 0);
|
|
|
|
out:
|
|
release_sock(sk);
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL_GPL(udp_abort);
|
|
|
|
struct proto udp_prot = {
|
|
.name = "UDP",
|
|
.owner = THIS_MODULE,
|
|
.close = udp_lib_close,
|
|
.pre_connect = udp_pre_connect,
|
|
.connect = ip4_datagram_connect,
|
|
.disconnect = udp_disconnect,
|
|
.ioctl = udp_ioctl,
|
|
.init = udp_init_sock,
|
|
.destroy = udp_destroy_sock,
|
|
.setsockopt = udp_setsockopt,
|
|
.getsockopt = udp_getsockopt,
|
|
.sendmsg = udp_sendmsg,
|
|
.recvmsg = udp_recvmsg,
|
|
.sendpage = udp_sendpage,
|
|
.release_cb = ip4_datagram_release_cb,
|
|
.hash = udp_lib_hash,
|
|
.unhash = udp_lib_unhash,
|
|
.rehash = udp_v4_rehash,
|
|
.get_port = udp_v4_get_port,
|
|
.memory_allocated = &udp_memory_allocated,
|
|
.sysctl_mem = sysctl_udp_mem,
|
|
.sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_udp_wmem_min),
|
|
.sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_udp_rmem_min),
|
|
.obj_size = sizeof(struct udp_sock),
|
|
.h.udp_table = &udp_table,
|
|
#ifdef CONFIG_COMPAT
|
|
.compat_setsockopt = compat_udp_setsockopt,
|
|
.compat_getsockopt = compat_udp_getsockopt,
|
|
#endif
|
|
.diag_destroy = udp_abort,
|
|
};
|
|
EXPORT_SYMBOL(udp_prot);
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
static struct sock *udp_get_first(struct seq_file *seq, int start)
|
|
{
|
|
struct sock *sk;
|
|
struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
|
|
struct udp_iter_state *state = seq->private;
|
|
struct net *net = seq_file_net(seq);
|
|
|
|
for (state->bucket = start; state->bucket <= afinfo->udp_table->mask;
|
|
++state->bucket) {
|
|
struct udp_hslot *hslot = &afinfo->udp_table->hash[state->bucket];
|
|
|
|
if (hlist_empty(&hslot->head))
|
|
continue;
|
|
|
|
spin_lock_bh(&hslot->lock);
|
|
sk_for_each(sk, &hslot->head) {
|
|
if (!net_eq(sock_net(sk), net))
|
|
continue;
|
|
if (sk->sk_family == afinfo->family)
|
|
goto found;
|
|
}
|
|
spin_unlock_bh(&hslot->lock);
|
|
}
|
|
sk = NULL;
|
|
found:
|
|
return sk;
|
|
}
|
|
|
|
static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
|
|
{
|
|
struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
|
|
struct udp_iter_state *state = seq->private;
|
|
struct net *net = seq_file_net(seq);
|
|
|
|
do {
|
|
sk = sk_next(sk);
|
|
} while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != afinfo->family));
|
|
|
|
if (!sk) {
|
|
if (state->bucket <= afinfo->udp_table->mask)
|
|
spin_unlock_bh(&afinfo->udp_table->hash[state->bucket].lock);
|
|
return udp_get_first(seq, state->bucket + 1);
|
|
}
|
|
return sk;
|
|
}
|
|
|
|
static struct sock *udp_get_idx(struct seq_file *seq, loff_t pos)
|
|
{
|
|
struct sock *sk = udp_get_first(seq, 0);
|
|
|
|
if (sk)
|
|
while (pos && (sk = udp_get_next(seq, sk)) != NULL)
|
|
--pos;
|
|
return pos ? NULL : sk;
|
|
}
|
|
|
|
void *udp_seq_start(struct seq_file *seq, loff_t *pos)
|
|
{
|
|
struct udp_iter_state *state = seq->private;
|
|
state->bucket = MAX_UDP_PORTS;
|
|
|
|
return *pos ? udp_get_idx(seq, *pos-1) : SEQ_START_TOKEN;
|
|
}
|
|
EXPORT_SYMBOL(udp_seq_start);
|
|
|
|
void *udp_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
{
|
|
struct sock *sk;
|
|
|
|
if (v == SEQ_START_TOKEN)
|
|
sk = udp_get_idx(seq, 0);
|
|
else
|
|
sk = udp_get_next(seq, v);
|
|
|
|
++*pos;
|
|
return sk;
|
|
}
|
|
EXPORT_SYMBOL(udp_seq_next);
|
|
|
|
void udp_seq_stop(struct seq_file *seq, void *v)
|
|
{
|
|
struct udp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file));
|
|
struct udp_iter_state *state = seq->private;
|
|
|
|
if (state->bucket <= afinfo->udp_table->mask)
|
|
spin_unlock_bh(&afinfo->udp_table->hash[state->bucket].lock);
|
|
}
|
|
EXPORT_SYMBOL(udp_seq_stop);
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
static void udp4_format_sock(struct sock *sp, struct seq_file *f,
|
|
int bucket)
|
|
{
|
|
struct inet_sock *inet = inet_sk(sp);
|
|
__be32 dest = inet->inet_daddr;
|
|
__be32 src = inet->inet_rcv_saddr;
|
|
__u16 destp = ntohs(inet->inet_dport);
|
|
__u16 srcp = ntohs(inet->inet_sport);
|
|
__u8 state = sp->sk_state;
|
|
|
|
if (inet->transparent)
|
|
state |= 0x80;
|
|
|
|
seq_printf(f, "%5d: %08X:%04X %08X:%04X"
|
|
" %02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %u",
|
|
bucket, src, srcp, dest, destp, state,
|
|
sk_wmem_alloc_get(sp),
|
|
udp_rqueue_get(sp),
|
|
0, 0L, 0,
|
|
from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
|
|
0, sock_i_ino(sp),
|
|
refcount_read(&sp->sk_refcnt), sp,
|
|
atomic_read(&sp->sk_drops));
|
|
}
|
|
|
|
int udp4_seq_show(struct seq_file *seq, void *v)
|
|
{
|
|
seq_setwidth(seq, 127);
|
|
if (v == SEQ_START_TOKEN)
|
|
seq_puts(seq, " sl local_address rem_address st tx_queue "
|
|
"rx_queue tr tm->when retrnsmt uid timeout "
|
|
"inode ref pointer drops");
|
|
else {
|
|
struct udp_iter_state *state = seq->private;
|
|
|
|
udp4_format_sock(v, seq, state->bucket);
|
|
}
|
|
seq_pad(seq, '\n');
|
|
return 0;
|
|
}
|
|
|
|
const struct seq_operations udp_seq_ops = {
|
|
.start = udp_seq_start,
|
|
.next = udp_seq_next,
|
|
.stop = udp_seq_stop,
|
|
.show = udp4_seq_show,
|
|
};
|
|
EXPORT_SYMBOL(udp_seq_ops);
|
|
|
|
static struct udp_seq_afinfo udp4_seq_afinfo = {
|
|
.family = AF_INET,
|
|
.udp_table = &udp_table,
|
|
};
|
|
|
|
static int __net_init udp4_proc_init_net(struct net *net)
|
|
{
|
|
if (!proc_create_net_data("udp", 0444, net->proc_net, &udp_seq_ops,
|
|
sizeof(struct udp_iter_state), &udp4_seq_afinfo))
|
|
return -ENOMEM;
|
|
return 0;
|
|
}
|
|
|
|
static void __net_exit udp4_proc_exit_net(struct net *net)
|
|
{
|
|
remove_proc_entry("udp", net->proc_net);
|
|
}
|
|
|
|
static struct pernet_operations udp4_net_ops = {
|
|
.init = udp4_proc_init_net,
|
|
.exit = udp4_proc_exit_net,
|
|
};
|
|
|
|
int __init udp4_proc_init(void)
|
|
{
|
|
return register_pernet_subsys(&udp4_net_ops);
|
|
}
|
|
|
|
void udp4_proc_exit(void)
|
|
{
|
|
unregister_pernet_subsys(&udp4_net_ops);
|
|
}
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
static __initdata unsigned long uhash_entries;
|
|
static int __init set_uhash_entries(char *str)
|
|
{
|
|
ssize_t ret;
|
|
|
|
if (!str)
|
|
return 0;
|
|
|
|
ret = kstrtoul(str, 0, &uhash_entries);
|
|
if (ret)
|
|
return 0;
|
|
|
|
if (uhash_entries && uhash_entries < UDP_HTABLE_SIZE_MIN)
|
|
uhash_entries = UDP_HTABLE_SIZE_MIN;
|
|
return 1;
|
|
}
|
|
__setup("uhash_entries=", set_uhash_entries);
|
|
|
|
void __init udp_table_init(struct udp_table *table, const char *name)
|
|
{
|
|
unsigned int i;
|
|
|
|
table->hash = alloc_large_system_hash(name,
|
|
2 * sizeof(struct udp_hslot),
|
|
uhash_entries,
|
|
21, /* one slot per 2 MB */
|
|
0,
|
|
&table->log,
|
|
&table->mask,
|
|
UDP_HTABLE_SIZE_MIN,
|
|
64 * 1024);
|
|
|
|
table->hash2 = table->hash + (table->mask + 1);
|
|
for (i = 0; i <= table->mask; i++) {
|
|
INIT_HLIST_HEAD(&table->hash[i].head);
|
|
table->hash[i].count = 0;
|
|
spin_lock_init(&table->hash[i].lock);
|
|
}
|
|
for (i = 0; i <= table->mask; i++) {
|
|
INIT_HLIST_HEAD(&table->hash2[i].head);
|
|
table->hash2[i].count = 0;
|
|
spin_lock_init(&table->hash2[i].lock);
|
|
}
|
|
}
|
|
|
|
u32 udp_flow_hashrnd(void)
|
|
{
|
|
static u32 hashrnd __read_mostly;
|
|
|
|
net_get_random_once(&hashrnd, sizeof(hashrnd));
|
|
|
|
return hashrnd;
|
|
}
|
|
EXPORT_SYMBOL(udp_flow_hashrnd);
|
|
|
|
static void __udp_sysctl_init(struct net *net)
|
|
{
|
|
net->ipv4.sysctl_udp_rmem_min = SK_MEM_QUANTUM;
|
|
net->ipv4.sysctl_udp_wmem_min = SK_MEM_QUANTUM;
|
|
|
|
#ifdef CONFIG_NET_L3_MASTER_DEV
|
|
net->ipv4.sysctl_udp_l3mdev_accept = 0;
|
|
#endif
|
|
}
|
|
|
|
static int __net_init udp_sysctl_init(struct net *net)
|
|
{
|
|
__udp_sysctl_init(net);
|
|
return 0;
|
|
}
|
|
|
|
static struct pernet_operations __net_initdata udp_sysctl_ops = {
|
|
.init = udp_sysctl_init,
|
|
};
|
|
|
|
void __init udp_init(void)
|
|
{
|
|
unsigned long limit;
|
|
unsigned int i;
|
|
|
|
udp_table_init(&udp_table, "UDP");
|
|
limit = nr_free_buffer_pages() / 8;
|
|
limit = max(limit, 128UL);
|
|
sysctl_udp_mem[0] = limit / 4 * 3;
|
|
sysctl_udp_mem[1] = limit;
|
|
sysctl_udp_mem[2] = sysctl_udp_mem[0] * 2;
|
|
|
|
__udp_sysctl_init(&init_net);
|
|
|
|
/* 16 spinlocks per cpu */
|
|
udp_busylocks_log = ilog2(nr_cpu_ids) + 4;
|
|
udp_busylocks = kmalloc(sizeof(spinlock_t) << udp_busylocks_log,
|
|
GFP_KERNEL);
|
|
if (!udp_busylocks)
|
|
panic("UDP: failed to alloc udp_busylocks\n");
|
|
for (i = 0; i < (1U << udp_busylocks_log); i++)
|
|
spin_lock_init(udp_busylocks + i);
|
|
|
|
if (register_pernet_subsys(&udp_sysctl_ops))
|
|
panic("UDP: failed to init sysctl parameters.\n");
|
|
}
|