
Changes in 5.10.137 Makefile: link with -z noexecstack --no-warn-rwx-segments x86: link vdso and boot with -z noexecstack --no-warn-rwx-segments Revert "pNFS: nfs3_set_ds_client should set NFS_CS_NOPING" scsi: Revert "scsi: qla2xxx: Fix disk failure to rediscover" ALSA: bcd2000: Fix a UAF bug on the error path of probing ALSA: hda/realtek: Add quirk for Clevo NV45PZ ALSA: hda/realtek: Add quirk for HP Spectre x360 15-eb0xxx wifi: mac80211_hwsim: fix race condition in pending packet wifi: mac80211_hwsim: add back erroneously removed cast wifi: mac80211_hwsim: use 32-bit skb cookie add barriers to buffer_uptodate and set_buffer_uptodate HID: wacom: Only report rotation for art pen HID: wacom: Don't register pad_input for touch switch KVM: nVMX: Snapshot pre-VM-Enter BNDCFGS for !nested_run_pending case KVM: nVMX: Snapshot pre-VM-Enter DEBUGCTL for !nested_run_pending case KVM: SVM: Don't BUG if userspace injects an interrupt with GIF=0 KVM: s390: pv: don't present the ecall interrupt twice KVM: nVMX: Let userspace set nVMX MSR to any _host_ supported value KVM: x86: Mark TSS busy during LTR emulation _after_ all fault checks KVM: x86: Set error code to segment selector on LLDT/LTR non-canonical #GP KVM: x86: Tag kvm_mmu_x86_module_init() with __init riscv: set default pm_power_off to NULL mm: Add kvrealloc() xfs: only set IOMAP_F_SHARED when providing a srcmap to a write xfs: fix I_DONTCACHE mm/mremap: hold the rmap lock in write mode when moving page table entries. ALSA: hda/conexant: Add quirk for LENOVO 20149 Notebook model ALSA: hda/cirrus - support for iMac 12,1 model ALSA: hda/realtek: Add quirk for another Asus K42JZ model ALSA: hda/realtek: Add a quirk for HP OMEN 15 (8786) mute LED tty: vt: initialize unicode screen buffer vfs: Check the truncate maximum size in inode_newsize_ok() fs: Add missing umask strip in vfs_tmpfile thermal: sysfs: Fix cooling_device_stats_setup() error code path fbcon: Fix boundary checks for fbcon=vc:n1-n2 parameters fbcon: Fix accelerated fbdev scrolling while logo is still shown usbnet: Fix linkwatch use-after-free on disconnect ovl: drop WARN_ON() dentry is NULL in ovl_encode_fh() parisc: Fix device names in /proc/iomem parisc: Check the return value of ioremap() in lba_driver_probe() parisc: io_pgetevents_time64() needs compat syscall in 32-bit compat mode drm/gem: Properly annotate WW context on drm_gem_lock_reservations() error drm/vc4: hdmi: Disable audio if dmas property is present but empty drm/nouveau: fix another off-by-one in nvbios_addr drm/nouveau: Don't pm_runtime_put_sync(), only pm_runtime_put_autosuspend() drm/nouveau/acpi: Don't print error when we get -EINPROGRESS from pm_runtime drm/amdgpu: Check BO's requested pinning domains against its preferred_domains mtd: rawnand: arasan: Update NAND bus clock instead of system clock iio: light: isl29028: Fix the warning in isl29028_remove() scsi: sg: Allow waiting for commands to complete on removed device scsi: qla2xxx: Fix incorrect display of max frame size scsi: qla2xxx: Zero undefined mailbox IN registers fuse: limit nsec serial: mvebu-uart: uart2 error bits clearing md-raid: destroy the bitmap after destroying the thread md-raid10: fix KASAN warning media: [PATCH] pci: atomisp_cmd: fix three missing checks on list iterator ia64, processor: fix -Wincompatible-pointer-types in ia64_get_irr() PCI: Add defines for normal and subtractive PCI bridges powerpc/fsl-pci: Fix Class Code of PCIe Root Port powerpc/ptdump: Fix display of RW pages on FSL_BOOK3E powerpc/powernv: Avoid crashing if rng is NULL MIPS: cpuinfo: Fix a warning for CONFIG_CPUMASK_OFFSTACK coresight: Clear the connection field properly usb: typec: ucsi: Acknowledge the GET_ERROR_STATUS command completion USB: HCD: Fix URB giveback issue in tasklet function ARM: dts: uniphier: Fix USB interrupts for PXs2 SoC arm64: dts: uniphier: Fix USB interrupts for PXs3 SoC usb: dwc3: gadget: refactor dwc3_repare_one_trb usb: dwc3: gadget: fix high speed multiplier setting lockdep: Allow tuning tracing capacity constants. netfilter: nf_tables: do not allow SET_ID to refer to another table netfilter: nf_tables: do not allow CHAIN_ID to refer to another table netfilter: nf_tables: do not allow RULE_ID to refer to another chain netfilter: nf_tables: fix null deref due to zeroed list head epoll: autoremove wakers even more aggressively x86: Handle idle=nomwait cmdline properly for x86_idle arm64: Do not forget syscall when starting a new thread. arm64: fix oops in concurrently setting insn_emulation sysctls ext2: Add more validity checks for inode counts genirq: Don't return error on missing optional irq_request_resources() irqchip/mips-gic: Only register IPI domain when SMP is enabled genirq: GENERIC_IRQ_IPI depends on SMP irqchip/mips-gic: Check the return value of ioremap() in gic_of_init() wait: Fix __wait_event_hrtimeout for RT/DL tasks ARM: dts: imx6ul: add missing properties for sram ARM: dts: imx6ul: change operating-points to uint32-matrix ARM: dts: imx6ul: fix keypad compatible ARM: dts: imx6ul: fix csi node compatible ARM: dts: imx6ul: fix lcdif node compatible ARM: dts: imx6ul: fix qspi node compatible ARM: dts: BCM5301X: Add DT for Meraki MR26 spi: synquacer: Add missing clk_disable_unprepare() ARM: OMAP2+: display: Fix refcount leak bug ACPI: EC: Remove duplicate ThinkPad X1 Carbon 6th entry from DMI quirks ACPI: EC: Drop the EC_FLAGS_IGNORE_DSDT_GPE quirk ACPI: PM: save NVS memory for Lenovo G40-45 ACPI: LPSS: Fix missing check in register_device_clock() arm64: dts: qcom: ipq8074: fix NAND node name arm64: dts: allwinner: a64: orangepi-win: Fix LED node name ARM: shmobile: rcar-gen2: Increase refcount for new reference firmware: tegra: Fix error check return value of debugfs_create_file() PM: hibernate: defer device probing when resuming from hibernation selinux: Add boundary check in put_entry() powerpc/64s: Disable stack variable initialisation for prom_init spi: spi-rspi: Fix PIO fallback on RZ platforms ARM: findbit: fix overflowing offset meson-mx-socinfo: Fix refcount leak in meson_mx_socinfo_init arm64: dts: renesas: beacon: Fix regulator node names ARM: bcm: Fix refcount leak in bcm_kona_smc_init ACPI: processor/idle: Annotate more functions to live in cpuidle section ARM: dts: imx7d-colibri-emmc: add cpu1 supply Input: atmel_mxt_ts - fix up inverted RESET handler soc: renesas: r8a779a0-sysc: Fix A2DP1 and A2CV[2357] PDR values soc: amlogic: Fix refcount leak in meson-secure-pwrc.c arm64: dts: renesas: Fix thermal-sensors on single-zone sensors x86/pmem: Fix platform-device leak in error path ARM: dts: ast2500-evb: fix board compatible ARM: dts: ast2600-evb: fix board compatible hexagon: select ARCH_WANT_LD_ORPHAN_WARN arm64: cpufeature: Allow different PMU versions in ID_DFR0_EL1 locking/lockdep: Fix lockdep_init_map_*() confusion soc: fsl: guts: machine variable might be unset block: fix infinite loop for invalid zone append ARM: dts: qcom: mdm9615: add missing PMIC GPIO reg ARM: OMAP2+: Fix refcount leak in omapdss_init_of ARM: OMAP2+: Fix refcount leak in omap3xxx_prm_late_init cpufreq: zynq: Fix refcount leak in zynq_get_revision regulator: qcom_smd: Fix pm8916_pldo range ACPI: APEI: Fix _EINJ vs EFI_MEMORY_SP soc: qcom: ocmem: Fix refcount leak in of_get_ocmem soc: qcom: aoss: Fix refcount leak in qmp_cooling_devices_register ARM: dts: qcom: pm8841: add required thermal-sensor-cells bus: hisi_lpc: fix missing platform_device_put() in hisi_lpc_acpi_probe() arm64: dts: mt7622: fix BPI-R64 WPS button arm64: tegra: Fix SDMMC1 CD on P2888 erofs: avoid consecutive detection for Highmem memory blk-mq: don't create hctx debugfs dir until q->debugfs_dir is created hwmon: (drivetemp) Add module alias block: remove the request_queue to argument request based tracepoints blktrace: Trace remapped requests correctly regulator: of: Fix refcount leak bug in of_get_regulation_constraints() soc: qcom: Make QCOM_RPMPD depend on PM arm64: dts: qcom: qcs404: Fix incorrect USB2 PHYs assignment drivers/perf: arm_spe: Fix consistency of SYS_PMSCR_EL1.CX nohz/full, sched/rt: Fix missed tick-reenabling bug in dequeue_task_rt() selftests/seccomp: Fix compile warning when CC=clang thermal/tools/tmon: Include pthread and time headers in tmon.h dm: return early from dm_pr_call() if DM device is suspended pwm: sifive: Don't check the return code of pwmchip_remove() pwm: sifive: Simplify offset calculation for PWMCMP registers pwm: sifive: Ensure the clk is enabled exactly once per running PWM pwm: sifive: Shut down hardware only after pwmchip_remove() completed pwm: lpc18xx-sct: Convert to devm_platform_ioremap_resource() drm/bridge: tc358767: Move (e)DP bridge endpoint parsing into dedicated function drm/bridge: tc358767: Make sure Refclk clock are enabled ath10k: do not enforce interrupt trigger type drm/st7735r: Fix module autoloading for Okaya RH128128T wifi: rtlwifi: fix error codes in rtl_debugfs_set_write_h2c() ath11k: fix netdev open race drm/mipi-dbi: align max_chunk to 2 in spi_transfer ath11k: Fix incorrect debug_mask mappings drm/radeon: fix potential buffer overflow in ni_set_mc_special_registers() drm/mediatek: Modify dsi funcs to atomic operations drm/mediatek: Separate poweron/poweroff from enable/disable and define new funcs drm/mediatek: Add pull-down MIPI operation in mtk_dsi_poweroff function i2c: npcm: Remove own slave addresses 2:10 i2c: npcm: Correct slave role behavior virtio-gpu: fix a missing check to avoid NULL dereference drm: adv7511: override i2c address of cec before accessing it crypto: sun8i-ss - do not allocate memory when handling hash requests crypto: sun8i-ss - fix error codes in allocate_flows() net: fix sk_wmem_schedule() and sk_rmem_schedule() errors i2c: Fix a potential use after free crypto: sun8i-ss - fix infinite loop in sun8i_ss_setup_ivs() media: tw686x: Register the irq at the end of probe ath9k: fix use-after-free in ath9k_hif_usb_rx_cb wifi: iwlegacy: 4965: fix potential off-by-one overflow in il4965_rs_fill_link_cmd() drm/radeon: fix incorrrect SPDX-License-Identifiers test_bpf: fix incorrect netdev features crypto: ccp - During shutdown, check SEV data pointer before using drm: bridge: adv7511: Add check for mipi_dsi_driver_register drm/mcde: Fix refcount leak in mcde_dsi_bind media: hdpvr: fix error value returns in hdpvr_read media: v4l2-mem2mem: prevent pollerr when last_buffer_dequeued is set media: tw686x: Fix memory leak in tw686x_video_init drm/vc4: plane: Remove subpixel positioning check drm/vc4: plane: Fix margin calculations for the right/bottom edges drm/vc4: dsi: Correct DSI divider calculations drm/vc4: dsi: Correct pixel order for DSI0 drm/vc4: drv: Remove the DSI pointer in vc4_drv drm/vc4: dsi: Use snprintf for the PHY clocks instead of an array drm/vc4: dsi: Introduce a variant structure drm/vc4: dsi: Register dsi0 as the correct vc4 encoder type drm/vc4: dsi: Fix dsi0 interrupt support drm/vc4: dsi: Add correct stop condition to vc4_dsi_encoder_disable iteration drm/vc4: hdmi: Remove firmware logic for MAI threshold setting drm/vc4: hdmi: Avoid full hdmi audio fifo writes drm/vc4: hdmi: Don't access the connector state in reset if kmalloc fails drm/vc4: hdmi: Limit the BCM2711 to the max without scrambling drm/vc4: hdmi: Fix timings for interlaced modes drm/vc4: hdmi: Correct HDMI timing registers for interlaced modes crypto: arm64/gcm - Select AEAD for GHASH_ARM64_CE selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0 drm/rockchip: vop: Don't crash for invalid duplicate_state() drm/rockchip: Fix an error handling path rockchip_dp_probe() drm/mediatek: dpi: Remove output format of YUV drm/mediatek: dpi: Only enable dpi after the bridge is enabled drm: bridge: sii8620: fix possible off-by-one lib: bitmap: order includes alphabetically lib: bitmap: provide devm_bitmap_alloc() and devm_bitmap_zalloc() hinic: Use the bitmap API when applicable net: hinic: fix bug that ethtool get wrong stats net: hinic: avoid kernel hung in hinic_get_stats64() drm/msm/mdp5: Fix global state lock backoff crypto: hisilicon/sec - fixes some coding style crypto: hisilicon/sec - don't sleep when in softirq crypto: hisilicon - Kunpeng916 crypto driver don't sleep when in softirq media: platform: mtk-mdp: Fix mdp_ipi_comm structure alignment mt76: mt76x02u: fix possible memory leak in __mt76x02u_mcu_send_msg mediatek: mt76: mac80211: Fix missing of_node_put() in mt76_led_init() drm/exynos/exynos7_drm_decon: free resources when clk_set_parent() failed. tcp: make retransmitted SKB fit into the send window libbpf: Fix the name of a reused map selftests: timers: valid-adjtimex: build fix for newer toolchains selftests: timers: clocksource-switch: fix passing errors from child bpf: Fix subprog names in stack traces. fs: check FMODE_LSEEK to control internal pipe splicing wifi: wil6210: debugfs: fix info leak in wil_write_file_wmi() wifi: p54: Fix an error handling path in p54spi_probe() wifi: p54: add missing parentheses in p54_flush() selftests/bpf: fix a test for snprintf() overflow can: pch_can: do not report txerr and rxerr during bus-off can: rcar_can: do not report txerr and rxerr during bus-off can: sja1000: do not report txerr and rxerr during bus-off can: hi311x: do not report txerr and rxerr during bus-off can: sun4i_can: do not report txerr and rxerr during bus-off can: kvaser_usb_hydra: do not report txerr and rxerr during bus-off can: kvaser_usb_leaf: do not report txerr and rxerr during bus-off can: usb_8dev: do not report txerr and rxerr during bus-off can: error: specify the values of data[5..7] of CAN error frames can: pch_can: pch_can_error(): initialize errc before using it Bluetooth: hci_intel: Add check for platform_driver_register i2c: cadence: Support PEC for SMBus block read i2c: mux-gpmux: Add of_node_put() when breaking out of loop wifi: wil6210: debugfs: fix uninitialized variable use in `wil_write_file_wmi()` wifi: iwlwifi: mvm: fix double list_add at iwl_mvm_mac_wake_tx_queue wifi: libertas: Fix possible refcount leak in if_usb_probe() media: cedrus: hevc: Add check for invalid timestamp net/mlx5e: Remove WARN_ON when trying to offload an unsupported TLS cipher/version net/mlx5e: Fix the value of MLX5E_MAX_RQ_NUM_MTTS crypto: hisilicon/hpre - don't use GFP_KERNEL to alloc mem during softirq crypto: inside-secure - Add missing MODULE_DEVICE_TABLE for of crypto: hisilicon/sec - fix auth key size error inet: add READ_ONCE(sk->sk_bound_dev_if) in INET_MATCH() tcp: sk->sk_bound_dev_if once in inet_request_bound_dev_if() ipv6: add READ_ONCE(sk->sk_bound_dev_if) in INET6_MATCH() tcp: Fix data-races around sysctl_tcp_l3mdev_accept. net: allow unbound socket for packets in VRF when tcp_l3mdev_accept set iavf: Fix max_rate limiting netdevsim: Avoid allocation warnings triggered from user space net: rose: fix netdev reference changes net: ionic: fix error check for vlan flags in ionic_set_nic_features() dccp: put dccp_qpolicy_full() and dccp_qpolicy_push() in the same lock wireguard: ratelimiter: use hrtimer in selftest wireguard: allowedips: don't corrupt stack when detecting overflow clk: renesas: r9a06g032: Fix UART clkgrp bitsel mtd: maps: Fix refcount leak in of_flash_probe_versatile mtd: maps: Fix refcount leak in ap_flash_init mtd: rawnand: meson: Fix a potential double free issue PCI: tegra194: Fix PM error handling in tegra_pcie_config_ep() HID: cp2112: prevent a buffer overflow in cp2112_xfer() mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release mtd: partitions: Fix refcount leak in parse_redboot_of mtd: st_spi_fsm: Add a clk_disable_unprepare() in .probe()'s error path fpga: altera-pr-ip: fix unsigned comparison with less than zero usb: host: Fix refcount leak in ehci_hcd_ppc_of_probe usb: ohci-nxp: Fix refcount leak in ohci_hcd_nxp_probe usb: gadget: tegra-xudc: Fix error check in tegra_xudc_powerdomain_init() usb: xhci: tegra: Fix error check netfilter: xtables: Bring SPDX identifier back iio: accel: bma400: Fix the scale min and max macro values platform/chrome: cros_ec: Always expose last resume result iio: accel: bma400: Reordering of header files clk: mediatek: reset: Fix written reset bit offset KVM: Don't set Accessed/Dirty bits for ZERO_PAGE mwifiex: Ignore BTCOEX events from the 88W8897 firmware mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv dmaengine: dw-edma: Fix eDMA Rd/Wr-channels and DMA-direction semantics misc: rtsx: Fix an error handling path in rtsx_pci_probe() driver core: fix potential deadlock in __driver_attach clk: qcom: clk-krait: unlock spin after mux completion usb: host: xhci: use snprintf() in xhci_decode_trb() clk: qcom: ipq8074: fix NSS core PLL-s clk: qcom: ipq8074: SW workaround for UBI32 PLL lock clk: qcom: ipq8074: fix NSS port frequency tables clk: qcom: ipq8074: set BRANCH_HALT_DELAY flag for UBI clocks clk: qcom: camcc-sdm845: Fix topology around titan_top power domain PCI: dwc: Add unroll iATU space support to dw_pcie_disable_atu() PCI: dwc: Deallocate EPC memory on dw_pcie_ep_init() errors PCI: dwc: Always enable CDM check if "snps,enable-cdm-check" exists soundwire: bus_type: fix remove and shutdown support KVM: arm64: Don't return from void function dmaengine: sf-pdma: apply proper spinlock flags in sf_pdma_prep_dma_memcpy() dmaengine: sf-pdma: Add multithread support for a DMA channel PCI: endpoint: Don't stop controller when unbinding endpoint function intel_th: Fix a resource leak in an error handling path intel_th: msu-sink: Potential dereference of null pointer intel_th: msu: Fix vmalloced buffers staging: rtl8192u: Fix sleep in atomic context bug in dm_fsync_timer_callback mmc: sdhci-of-esdhc: Fix refcount leak in esdhc_signal_voltage_switch memstick/ms_block: Fix some incorrect memory allocation memstick/ms_block: Fix a memory leak mmc: sdhci-of-at91: fix set_uhs_signaling rewriting of MC1R mmc: block: Add single read for 4k sector cards KVM: s390: pv: leak the topmost page table when destroy fails PCI/portdrv: Don't disable AER reporting in get_port_device_capability() PCI: qcom: Set up rev 2.1.0 PARF_PHY before enabling clocks scsi: smartpqi: Fix DMA direction for RAID requests xtensa: iss/network: provide release() callback xtensa: iss: fix handling error cases in iss_net_configure() usb: gadget: udc: amd5536 depends on HAS_DMA usb: aspeed-vhub: Fix refcount leak bug in ast_vhub_init_desc() usb: dwc3: core: Deprecate GCTL.CORESOFTRESET usb: dwc3: core: Do not perform GCTL_CORE_SOFTRESET during bootup usb: dwc3: qcom: fix missing optional irq warnings eeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write() interconnect: imx: fix max_node_id um: random: Don't initialise hwrng struct with zero RDMA/rtrs: Define MIN_CHUNK_SIZE RDMA/rtrs: Avoid Wtautological-constant-out-of-range-compare RDMA/rtrs-srv: Fix modinfo output for stringify RDMA/qedr: Improve error logs for rdma_alloc_tid error return RDMA/qedr: Fix potential memory leak in __qedr_alloc_mr() RDMA/hns: Fix incorrect clearing of interrupt status register RDMA/siw: Fix duplicated reported IW_CM_EVENT_CONNECT_REPLY event RDMA/hfi1: fix potential memory leak in setup_base_ctxt() gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data() HID: mcp2221: prevent a buffer overflow in mcp_smbus_write() mmc: cavium-octeon: Add of_node_put() when breaking out of loop mmc: cavium-thunderx: Add of_node_put() when breaking out of loop HID: alps: Declare U1_UNICORN_LEGACY support PCI: tegra194: Fix Root Port interrupt handling PCI: tegra194: Fix link up retry sequence USB: serial: fix tty-port initialized comments usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable() platform/olpc: Fix uninitialized data in debugfs write RDMA/srpt: Duplicate port name members RDMA/srpt: Introduce a reference count in struct srpt_device RDMA/srpt: Fix a use-after-free mm/mmap.c: fix missing call to vm_unacct_memory in mmap_region selftests: kvm: set rax before vmcall RDMA/mlx5: Add missing check for return value in get namespace flow RDMA/rxe: Fix error unwind in rxe_create_qp() null_blk: fix ida error handling in null_add_dev() nvme: use command_id instead of req->tag in trace_nvme_complete_rq() jbd2: fix outstanding credits assert in jbd2_journal_commit_transaction() ext4: recover csum seed of tmp_inode after migrating to extents jbd2: fix assertion 'jh->b_frozen_data == NULL' failure when journal aborted usb: cdns3: Don't use priv_dev uninitialized in cdns3_gadget_ep_enable() opp: Fix error check in dev_pm_opp_attach_genpd() ASoC: cros_ec_codec: Fix refcount leak in cros_ec_codec_platform_probe ASoC: samsung: Fix error handling in aries_audio_probe ASoC: mediatek: mt8173: Fix refcount leak in mt8173_rt5650_rt5676_dev_probe ASoC: mt6797-mt6351: Fix refcount leak in mt6797_mt6351_dev_probe ASoC: codecs: da7210: add check for i2c_add_driver ASoC: mediatek: mt8173-rt5650: Fix refcount leak in mt8173_rt5650_dev_probe serial: 8250: Export ICR access helpers for internal use serial: 8250_dw: Store LSR into lsr_saved_flags in dw8250_tx_wait_empty() ASoC: codecs: msm8916-wcd-digital: move gains from SX_TLV to S8_TLV ASoC: codecs: wcd9335: move gains from SX_TLV to S8_TLV rpmsg: mtk_rpmsg: Fix circular locking dependency remoteproc: k3-r5: Fix refcount leak in k3_r5_cluster_of_init selftests/livepatch: better synchronize test_klp_callbacks_busy profiling: fix shift too large makes kernel panic ASoC: samsung: h1940_uda1380: include proepr GPIO consumer header powerpc/perf: Optimize clearing the pending PMI and remove WARN_ON for PMI check in power_pmu_disable ASoC: samsung: change gpiod_speaker_power and rx1950_audio from global to static variables tty: n_gsm: Delete gsmtty open SABM frame when config requester tty: n_gsm: fix user open not possible at responder until initiator open tty: n_gsm: fix wrong queuing behavior in gsm_dlci_data_output() tty: n_gsm: fix non flow control frames during mux flow off tty: n_gsm: fix packet re-transmission without open control channel tty: n_gsm: fix race condition in gsmld_write() ASoC: qcom: Fix missing of_node_put() in asoc_qcom_lpass_cpu_platform_probe() remoteproc: qcom: wcnss: Fix handling of IRQs vfio: Remove extra put/gets around vfio_device->group vfio: Simplify the lifetime logic for vfio_device vfio: Split creation of a vfio_device into init and register ops vfio/mdev: Make to_mdev_device() into a static inline vfio/ccw: Do not change FSM state in subchannel event tty: n_gsm: fix wrong T1 retry count handling tty: n_gsm: fix DM command tty: n_gsm: fix missing corner cases in gsmld_poll() iommu/exynos: Handle failed IOMMU device registration properly rpmsg: qcom_smd: Fix refcount leak in qcom_smd_parse_edge kfifo: fix kfifo_to_user() return type lib/smp_processor_id: fix imbalanced instrumentation_end() call remoteproc: sysmon: Wait for SSCTL service to come up mfd: t7l66xb: Drop platform disable callback mfd: max77620: Fix refcount leak in max77620_initialise_fps iommu/arm-smmu: qcom_iommu: Add of_node_put() when breaking out of loop perf tools: Fix dso_id inode generation comparison s390/dump: fix old lowcore virtual vs physical address confusion s390/zcore: fix race when reading from hardware system area ASoC: fsl_easrc: use snd_pcm_format_t type for sample_format ASoC: qcom: q6dsp: Fix an off-by-one in q6adm_alloc_copp() fuse: Remove the control interface for virtio-fs ASoC: audio-graph-card: Add of_node_put() in fail path watchdog: armada_37xx_wdt: check the return value of devm_ioremap() in armada_37xx_wdt_probe() video: fbdev: amba-clcd: Fix refcount leak bugs video: fbdev: sis: fix typos in SiS_GetModeID() ASoC: mchp-spdifrx: disable end of block interrupt on failures powerpc/32: Do not allow selection of e5500 or e6500 CPUs on PPC32 powerpc/pci: Prefer PCI domain assignment via DT 'linux,pci-domain' and alias f2fs: don't set GC_FAILURE_PIN for background GC f2fs: write checkpoint during FG_GC f2fs: fix to remove F2FS_COMPR_FL and tag F2FS_NOCOMP_FL at the same time powerpc/spufs: Fix refcount leak in spufs_init_isolated_loader powerpc/xive: Fix refcount leak in xive_get_max_prio powerpc/cell/axon_msi: Fix refcount leak in setup_msi_msg_address perf symbol: Fail to read phdr workaround kprobes: Forbid probing on trampoline and BPF code areas powerpc/pci: Fix PHB numbering when using opal-phbid genelf: Use HAVE_LIBCRYPTO_SUPPORT, not the never defined HAVE_LIBCRYPTO scripts/faddr2line: Fix vmlinux detection on arm64 sched/deadline: Merge dl_task_can_attach() and dl_cpu_busy() sched, cpuset: Fix dl_cpu_busy() panic due to empty cs->cpus_allowed x86/numa: Use cpumask_available instead of hardcoded NULL check video: fbdev: arkfb: Fix a divide-by-zero bug in ark_set_pixclock() tools/thermal: Fix possible path truncations sched: Fix the check of nr_running at queue wakelist x86/entry: Build thunk_$(BITS) only if CONFIG_PREEMPTION=y video: fbdev: vt8623fb: Check the size of screen before memset_io() video: fbdev: arkfb: Check the size of screen before memset_io() video: fbdev: s3fb: Check the size of screen before memset_io() scsi: zfcp: Fix missing auto port scan and thus missing target ports scsi: qla2xxx: Fix discovery issues in FC-AL topology scsi: qla2xxx: Turn off multi-queue for 8G adapters scsi: qla2xxx: Fix erroneous mailbox timeout after PCI error injection scsi: qla2xxx: Fix losing FCP-2 targets on long port disable with I/Os scsi: qla2xxx: Fix losing FCP-2 targets during port perturbation tests x86/bugs: Enable STIBP for IBPB mitigated RETBleed ftrace/x86: Add back ftrace_expected assignment x86/olpc: fix 'logical not is only applied to the left hand side' posix-cpu-timers: Cleanup CPU timers before freeing them during exec Input: gscps2 - check return value of ioremap() in gscps2_probe() __follow_mount_rcu(): verify that mount_lock remains unchanged spmi: trace: fix stack-out-of-bound access in SPMI tracing functions drm/i915/dg1: Update DMC_DEBUG3 register drm/mediatek: Allow commands to be sent during video mode drm/mediatek: Keep dsi as LP00 before dcs cmds transfer HID: Ignore battery for Elan touchscreen on HP Spectre X360 15-df0xxx HID: hid-input: add Surface Go battery quirk drm/vc4: drv: Adopt the dma configuration from the HVS or V3D component mtd: rawnand: Add a helper to clarify the interface configuration mtd: rawnand: arasan: Check the proposed data interface is supported mtd: rawnand: Add NV-DDR timings mtd: rawnand: arasan: Fix a macro parameter mtd: rawnand: arasan: Support NV-DDR interface mtd: rawnand: arasan: Fix clock rate in NV-DDR usbnet: smsc95xx: Don't clear read-only PHY interrupt usbnet: smsc95xx: Avoid link settings race on interrupt reception firmware: arm_scpi: Ensure scpi_info is not assigned if the probe fails intel_th: pci: Add Meteor Lake-P support intel_th: pci: Add Raptor Lake-S PCH support intel_th: pci: Add Raptor Lake-S CPU support KVM: set_msr_mce: Permit guests to ignore single-bit ECC errors KVM: x86: Signal #GP, not -EPERM, on bad WRMSR(MCi_CTL/STATUS) iommu/vt-d: avoid invalid memory access via node_online(NUMA_NO_NODE) PCI/AER: Write AER Capability only when we control it PCI/ERR: Bind RCEC devices to the Root Port driver PCI/ERR: Rename reset_link() to reset_subordinates() PCI/ERR: Simplify by using pci_upstream_bridge() PCI/ERR: Simplify by computing pci_pcie_type() once PCI/ERR: Use "bridge" for clarity in pcie_do_recovery() PCI/ERR: Avoid negated conditional for clarity PCI/ERR: Add pci_walk_bridge() to pcie_do_recovery() PCI/ERR: Recover from RCEC AER errors PCI/AER: Iterate over error counters instead of error strings serial: 8250: Dissociate 4MHz Titan ports from Oxford ports serial: 8250: Correct the clock for OxSemi PCIe devices serial: 8250_pci: Refactor the loop in pci_ite887x_init() serial: 8250_pci: Replace dev_*() by pci_*() macros serial: 8250: Fold EndRun device support into OxSemi Tornado code dm writecache: set a default MAX_WRITEBACK_JOBS kexec, KEYS, s390: Make use of built-in and secondary keyring for signature verification dm thin: fix use-after-free crash in dm_sm_register_threshold_callback timekeeping: contribute wall clock to rng on time change um: Allow PM with suspend-to-idle btrfs: reject log replay if there is unsupported RO compat flag btrfs: reset block group chunk force if we have to wait ACPI: CPPC: Do not prevent CPPC from working in the future KVM: VMX: Drop guest CPUID check for VMXE in vmx_set_cr4() KVM: VMX: Drop explicit 'nested' check from vmx_set_cr4() KVM: SVM: Drop VMXE check from svm_set_cr4() KVM: x86: Move vendor CR4 validity check to dedicated kvm_x86_ops hook KVM: nVMX: Inject #UD if VMXON is attempted with incompatible CR0/CR4 KVM: x86/pmu: preserve IA32_PERF_CAPABILITIES across CPUID refresh KVM: x86/pmu: Use binary search to check filtered events KVM: x86/pmu: Use different raw event masks for AMD and Intel KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter KVM: VMX: Mark all PERF_GLOBAL_(OVF)_CTRL bits reserved if there's no vPMU KVM: x86/pmu: Ignore pmu->global_ctrl check if vPMU doesn't support global_ctrl xen-blkback: fix persistent grants negotiation xen-blkback: Apply 'feature_persistent' parameter when connect xen-blkfront: Apply 'feature_persistent' parameter when connect KEYS: asymmetric: enforce SM2 signature use pkey algo tpm: eventlog: Fix section mismatch for DEBUG_SECTION_MISMATCH tracing: Use a struct alignof to determine trace event field alignment ext4: check if directory block is within i_size ext4: add EXT4_INODE_HAS_XATTR_SPACE macro in xattr.h ext4: fix warning in ext4_iomap_begin as race between bmap and write ext4: make sure ext4_append() always allocates new block ext4: fix use-after-free in ext4_xattr_set_entry ext4: update s_overhead_clusters in the superblock during an on-line resize ext4: fix extent status tree race in writeback error recovery path ext4: correct max_inline_xattr_value_size computing ext4: correct the misjudgment in ext4_iget_extra_inode dm raid: fix address sanitizer warning in raid_resume dm raid: fix address sanitizer warning in raid_status net_sched: cls_route: remove from list when handle is 0 KVM: Add infrastructure and macro to mark VM as bugged KVM: x86: Check lapic_in_kernel() before attempting to set a SynIC irq KVM: x86: Avoid theoretical NULL pointer dereference in kvm_irq_delivery_to_apic_fast() mac80211: fix a memory leak where sta_info is not freed tcp: fix over estimation in sk_forced_mem_schedule() Revert "mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv" drm/bridge: tc358767: Fix (e)DP bridge endpoint parsing in dedicated function drm/vc4: change vc4_dma_range_matches from a global to static Revert "net: usb: ax88179_178a needs FLAG_SEND_ZLP" Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression mtd: rawnand: arasan: Prevent an unsupported configuration kvm: x86/pmu: Fix the compare function used by the pmu event filter tee: add overflow check in register_shm_helper() net/9p: Initialize the iounit field during fid creation net_sched: cls_route: disallow handle of 0 sched/fair: Fix fault in reweight_entity btrfs: only write the sectors in the vertical stripe which has data stripes btrfs: raid56: don't trust any cached sector in __raid56_parity_recover() Linux 5.10.137 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I5775ddfad6460c5a737b1ad3f8e0b8f798338786
2125 lines
50 KiB
C
2125 lines
50 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* linux/fs/exec.c
|
|
*
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
*/
|
|
|
|
/*
|
|
* #!-checking implemented by tytso.
|
|
*/
|
|
/*
|
|
* Demand-loading implemented 01.12.91 - no need to read anything but
|
|
* the header into memory. The inode of the executable is put into
|
|
* "current->executable", and page faults do the actual loading. Clean.
|
|
*
|
|
* Once more I can proudly say that linux stood up to being changed: it
|
|
* was less than 2 hours work to get demand-loading completely implemented.
|
|
*
|
|
* Demand loading changed July 1993 by Eric Youngdale. Use mmap instead,
|
|
* current->executable is only used by the procfs. This allows a dispatch
|
|
* table to check for several different types of binary formats. We keep
|
|
* trying until we recognize the file or we run out of supported binary
|
|
* formats.
|
|
*/
|
|
|
|
#include <linux/kernel_read_file.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/file.h>
|
|
#include <linux/fdtable.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/vmacache.h>
|
|
#include <linux/stat.h>
|
|
#include <linux/fcntl.h>
|
|
#include <linux/swap.h>
|
|
#include <linux/string.h>
|
|
#include <linux/init.h>
|
|
#include <linux/sched/mm.h>
|
|
#include <linux/sched/coredump.h>
|
|
#include <linux/sched/signal.h>
|
|
#include <linux/sched/numa_balancing.h>
|
|
#include <linux/sched/task.h>
|
|
#include <linux/pagemap.h>
|
|
#include <linux/perf_event.h>
|
|
#include <linux/highmem.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/key.h>
|
|
#include <linux/personality.h>
|
|
#include <linux/binfmts.h>
|
|
#include <linux/utsname.h>
|
|
#include <linux/pid_namespace.h>
|
|
#include <linux/module.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/security.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/tsacct_kern.h>
|
|
#include <linux/cn_proc.h>
|
|
#include <linux/audit.h>
|
|
#include <linux/tracehook.h>
|
|
#include <linux/kmod.h>
|
|
#include <linux/fsnotify.h>
|
|
#include <linux/fs_struct.h>
|
|
#include <linux/oom.h>
|
|
#include <linux/compat.h>
|
|
#include <linux/vmalloc.h>
|
|
#include <linux/io_uring.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <asm/tlb.h>
|
|
|
|
#include <trace/events/task.h>
|
|
#include "internal.h"
|
|
|
|
#include <trace/events/sched.h>
|
|
|
|
EXPORT_TRACEPOINT_SYMBOL_GPL(task_rename);
|
|
|
|
static int bprm_creds_from_file(struct linux_binprm *bprm);
|
|
|
|
int suid_dumpable = 0;
|
|
|
|
static LIST_HEAD(formats);
|
|
static DEFINE_RWLOCK(binfmt_lock);
|
|
|
|
void __register_binfmt(struct linux_binfmt * fmt, int insert)
|
|
{
|
|
BUG_ON(!fmt);
|
|
if (WARN_ON(!fmt->load_binary))
|
|
return;
|
|
write_lock(&binfmt_lock);
|
|
insert ? list_add(&fmt->lh, &formats) :
|
|
list_add_tail(&fmt->lh, &formats);
|
|
write_unlock(&binfmt_lock);
|
|
}
|
|
|
|
EXPORT_SYMBOL(__register_binfmt);
|
|
|
|
void unregister_binfmt(struct linux_binfmt * fmt)
|
|
{
|
|
write_lock(&binfmt_lock);
|
|
list_del(&fmt->lh);
|
|
write_unlock(&binfmt_lock);
|
|
}
|
|
|
|
EXPORT_SYMBOL(unregister_binfmt);
|
|
|
|
static inline void put_binfmt(struct linux_binfmt * fmt)
|
|
{
|
|
module_put(fmt->module);
|
|
}
|
|
|
|
bool path_noexec(const struct path *path)
|
|
{
|
|
return (path->mnt->mnt_flags & MNT_NOEXEC) ||
|
|
(path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
|
|
}
|
|
|
|
#ifdef CONFIG_USELIB
|
|
/*
|
|
* Note that a shared library must be both readable and executable due to
|
|
* security reasons.
|
|
*
|
|
* Also note that we take the address to load from from the file itself.
|
|
*/
|
|
SYSCALL_DEFINE1(uselib, const char __user *, library)
|
|
{
|
|
struct linux_binfmt *fmt;
|
|
struct file *file;
|
|
struct filename *tmp = getname(library);
|
|
int error = PTR_ERR(tmp);
|
|
static const struct open_flags uselib_flags = {
|
|
.open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
|
|
.acc_mode = MAY_READ | MAY_EXEC,
|
|
.intent = LOOKUP_OPEN,
|
|
.lookup_flags = LOOKUP_FOLLOW,
|
|
};
|
|
|
|
if (IS_ERR(tmp))
|
|
goto out;
|
|
|
|
file = do_filp_open(AT_FDCWD, tmp, &uselib_flags);
|
|
putname(tmp);
|
|
error = PTR_ERR(file);
|
|
if (IS_ERR(file))
|
|
goto out;
|
|
|
|
/*
|
|
* may_open() has already checked for this, so it should be
|
|
* impossible to trip now. But we need to be extra cautious
|
|
* and check again at the very end too.
|
|
*/
|
|
error = -EACCES;
|
|
if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode) ||
|
|
path_noexec(&file->f_path)))
|
|
goto exit;
|
|
|
|
fsnotify_open(file);
|
|
|
|
error = -ENOEXEC;
|
|
|
|
read_lock(&binfmt_lock);
|
|
list_for_each_entry(fmt, &formats, lh) {
|
|
if (!fmt->load_shlib)
|
|
continue;
|
|
if (!try_module_get(fmt->module))
|
|
continue;
|
|
read_unlock(&binfmt_lock);
|
|
error = fmt->load_shlib(file);
|
|
read_lock(&binfmt_lock);
|
|
put_binfmt(fmt);
|
|
if (error != -ENOEXEC)
|
|
break;
|
|
}
|
|
read_unlock(&binfmt_lock);
|
|
exit:
|
|
fput(file);
|
|
out:
|
|
return error;
|
|
}
|
|
#endif /* #ifdef CONFIG_USELIB */
|
|
|
|
#ifdef CONFIG_MMU
|
|
/*
|
|
* The nascent bprm->mm is not visible until exec_mmap() but it can
|
|
* use a lot of memory, account these pages in current->mm temporary
|
|
* for oom_badness()->get_mm_rss(). Once exec succeeds or fails, we
|
|
* change the counter back via acct_arg_size(0).
|
|
*/
|
|
static void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
|
|
{
|
|
struct mm_struct *mm = current->mm;
|
|
long diff = (long)(pages - bprm->vma_pages);
|
|
|
|
if (!mm || !diff)
|
|
return;
|
|
|
|
bprm->vma_pages = pages;
|
|
add_mm_counter(mm, MM_ANONPAGES, diff);
|
|
}
|
|
|
|
static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
|
|
int write)
|
|
{
|
|
struct page *page;
|
|
int ret;
|
|
unsigned int gup_flags = FOLL_FORCE;
|
|
|
|
#ifdef CONFIG_STACK_GROWSUP
|
|
if (write) {
|
|
ret = expand_downwards(bprm->vma, pos);
|
|
if (ret < 0)
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
if (write)
|
|
gup_flags |= FOLL_WRITE;
|
|
|
|
/*
|
|
* We are doing an exec(). 'current' is the process
|
|
* doing the exec and bprm->mm is the new process's mm.
|
|
*/
|
|
ret = get_user_pages_remote(bprm->mm, pos, 1, gup_flags,
|
|
&page, NULL, NULL);
|
|
if (ret <= 0)
|
|
return NULL;
|
|
|
|
if (write)
|
|
acct_arg_size(bprm, vma_pages(bprm->vma));
|
|
|
|
return page;
|
|
}
|
|
|
|
static void put_arg_page(struct page *page)
|
|
{
|
|
put_user_page(page);
|
|
}
|
|
|
|
static void free_arg_pages(struct linux_binprm *bprm)
|
|
{
|
|
}
|
|
|
|
static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos,
|
|
struct page *page)
|
|
{
|
|
flush_cache_page(bprm->vma, pos, page_to_pfn(page));
|
|
}
|
|
|
|
static int __bprm_mm_init(struct linux_binprm *bprm)
|
|
{
|
|
int err;
|
|
struct vm_area_struct *vma = NULL;
|
|
struct mm_struct *mm = bprm->mm;
|
|
|
|
bprm->vma = vma = vm_area_alloc(mm);
|
|
if (!vma)
|
|
return -ENOMEM;
|
|
vma_set_anonymous(vma);
|
|
|
|
if (mmap_write_lock_killable(mm)) {
|
|
err = -EINTR;
|
|
goto err_free;
|
|
}
|
|
|
|
/*
|
|
* Place the stack at the largest stack address the architecture
|
|
* supports. Later, we'll move this to an appropriate place. We don't
|
|
* use STACK_TOP because that can depend on attributes which aren't
|
|
* configured yet.
|
|
*/
|
|
BUILD_BUG_ON(VM_STACK_FLAGS & VM_STACK_INCOMPLETE_SETUP);
|
|
vma->vm_end = STACK_TOP_MAX;
|
|
vma->vm_start = vma->vm_end - PAGE_SIZE;
|
|
vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
|
|
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
|
|
|
|
err = insert_vm_struct(mm, vma);
|
|
if (err)
|
|
goto err;
|
|
|
|
mm->stack_vm = mm->total_vm = 1;
|
|
mmap_write_unlock(mm);
|
|
bprm->p = vma->vm_end - sizeof(void *);
|
|
return 0;
|
|
err:
|
|
mmap_write_unlock(mm);
|
|
err_free:
|
|
bprm->vma = NULL;
|
|
vm_area_free(vma);
|
|
return err;
|
|
}
|
|
|
|
static bool valid_arg_len(struct linux_binprm *bprm, long len)
|
|
{
|
|
return len <= MAX_ARG_STRLEN;
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void acct_arg_size(struct linux_binprm *bprm, unsigned long pages)
|
|
{
|
|
}
|
|
|
|
static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
|
|
int write)
|
|
{
|
|
struct page *page;
|
|
|
|
page = bprm->page[pos / PAGE_SIZE];
|
|
if (!page && write) {
|
|
page = alloc_page(GFP_HIGHUSER|__GFP_ZERO);
|
|
if (!page)
|
|
return NULL;
|
|
bprm->page[pos / PAGE_SIZE] = page;
|
|
}
|
|
|
|
return page;
|
|
}
|
|
|
|
static void put_arg_page(struct page *page)
|
|
{
|
|
}
|
|
|
|
static void free_arg_page(struct linux_binprm *bprm, int i)
|
|
{
|
|
if (bprm->page[i]) {
|
|
__free_page(bprm->page[i]);
|
|
bprm->page[i] = NULL;
|
|
}
|
|
}
|
|
|
|
static void free_arg_pages(struct linux_binprm *bprm)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_ARG_PAGES; i++)
|
|
free_arg_page(bprm, i);
|
|
}
|
|
|
|
static void flush_arg_page(struct linux_binprm *bprm, unsigned long pos,
|
|
struct page *page)
|
|
{
|
|
}
|
|
|
|
static int __bprm_mm_init(struct linux_binprm *bprm)
|
|
{
|
|
bprm->p = PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *);
|
|
return 0;
|
|
}
|
|
|
|
static bool valid_arg_len(struct linux_binprm *bprm, long len)
|
|
{
|
|
return len <= bprm->p;
|
|
}
|
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
/*
|
|
* Create a new mm_struct and populate it with a temporary stack
|
|
* vm_area_struct. We don't have enough context at this point to set the stack
|
|
* flags, permissions, and offset, so we use temporary values. We'll update
|
|
* them later in setup_arg_pages().
|
|
*/
|
|
static int bprm_mm_init(struct linux_binprm *bprm)
|
|
{
|
|
int err;
|
|
struct mm_struct *mm = NULL;
|
|
|
|
bprm->mm = mm = mm_alloc();
|
|
err = -ENOMEM;
|
|
if (!mm)
|
|
goto err;
|
|
|
|
/* Save current stack limit for all calculations made during exec. */
|
|
task_lock(current->group_leader);
|
|
bprm->rlim_stack = current->signal->rlim[RLIMIT_STACK];
|
|
task_unlock(current->group_leader);
|
|
|
|
err = __bprm_mm_init(bprm);
|
|
if (err)
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
err:
|
|
if (mm) {
|
|
bprm->mm = NULL;
|
|
mmdrop(mm);
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
struct user_arg_ptr {
|
|
#ifdef CONFIG_COMPAT
|
|
bool is_compat;
|
|
#endif
|
|
union {
|
|
const char __user *const __user *native;
|
|
#ifdef CONFIG_COMPAT
|
|
const compat_uptr_t __user *compat;
|
|
#endif
|
|
} ptr;
|
|
};
|
|
|
|
static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
|
|
{
|
|
const char __user *native;
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
if (unlikely(argv.is_compat)) {
|
|
compat_uptr_t compat;
|
|
|
|
if (get_user(compat, argv.ptr.compat + nr))
|
|
return ERR_PTR(-EFAULT);
|
|
|
|
return compat_ptr(compat);
|
|
}
|
|
#endif
|
|
|
|
if (get_user(native, argv.ptr.native + nr))
|
|
return ERR_PTR(-EFAULT);
|
|
|
|
return native;
|
|
}
|
|
|
|
/*
|
|
* count() counts the number of strings in array ARGV.
|
|
*/
|
|
static int count(struct user_arg_ptr argv, int max)
|
|
{
|
|
int i = 0;
|
|
|
|
if (argv.ptr.native != NULL) {
|
|
for (;;) {
|
|
const char __user *p = get_user_arg_ptr(argv, i);
|
|
|
|
if (!p)
|
|
break;
|
|
|
|
if (IS_ERR(p))
|
|
return -EFAULT;
|
|
|
|
if (i >= max)
|
|
return -E2BIG;
|
|
++i;
|
|
|
|
if (fatal_signal_pending(current))
|
|
return -ERESTARTNOHAND;
|
|
cond_resched();
|
|
}
|
|
}
|
|
return i;
|
|
}
|
|
|
|
static int count_strings_kernel(const char *const *argv)
|
|
{
|
|
int i;
|
|
|
|
if (!argv)
|
|
return 0;
|
|
|
|
for (i = 0; argv[i]; ++i) {
|
|
if (i >= MAX_ARG_STRINGS)
|
|
return -E2BIG;
|
|
if (fatal_signal_pending(current))
|
|
return -ERESTARTNOHAND;
|
|
cond_resched();
|
|
}
|
|
return i;
|
|
}
|
|
|
|
static int bprm_stack_limits(struct linux_binprm *bprm)
|
|
{
|
|
unsigned long limit, ptr_size;
|
|
|
|
/*
|
|
* Limit to 1/4 of the max stack size or 3/4 of _STK_LIM
|
|
* (whichever is smaller) for the argv+env strings.
|
|
* This ensures that:
|
|
* - the remaining binfmt code will not run out of stack space,
|
|
* - the program will have a reasonable amount of stack left
|
|
* to work from.
|
|
*/
|
|
limit = _STK_LIM / 4 * 3;
|
|
limit = min(limit, bprm->rlim_stack.rlim_cur / 4);
|
|
/*
|
|
* We've historically supported up to 32 pages (ARG_MAX)
|
|
* of argument strings even with small stacks
|
|
*/
|
|
limit = max_t(unsigned long, limit, ARG_MAX);
|
|
/*
|
|
* We must account for the size of all the argv and envp pointers to
|
|
* the argv and envp strings, since they will also take up space in
|
|
* the stack. They aren't stored until much later when we can't
|
|
* signal to the parent that the child has run out of stack space.
|
|
* Instead, calculate it here so it's possible to fail gracefully.
|
|
*
|
|
* In the case of argc = 0, make sure there is space for adding a
|
|
* empty string (which will bump argc to 1), to ensure confused
|
|
* userspace programs don't start processing from argv[1], thinking
|
|
* argc can never be 0, to keep them from walking envp by accident.
|
|
* See do_execveat_common().
|
|
*/
|
|
ptr_size = (max(bprm->argc, 1) + bprm->envc) * sizeof(void *);
|
|
if (limit <= ptr_size)
|
|
return -E2BIG;
|
|
limit -= ptr_size;
|
|
|
|
bprm->argmin = bprm->p - limit;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* 'copy_strings()' copies argument/environment strings from the old
|
|
* processes's memory to the new process's stack. The call to get_user_pages()
|
|
* ensures the destination page is created and not swapped out.
|
|
*/
|
|
static int copy_strings(int argc, struct user_arg_ptr argv,
|
|
struct linux_binprm *bprm)
|
|
{
|
|
struct page *kmapped_page = NULL;
|
|
char *kaddr = NULL;
|
|
unsigned long kpos = 0;
|
|
int ret;
|
|
|
|
while (argc-- > 0) {
|
|
const char __user *str;
|
|
int len;
|
|
unsigned long pos;
|
|
|
|
ret = -EFAULT;
|
|
str = get_user_arg_ptr(argv, argc);
|
|
if (IS_ERR(str))
|
|
goto out;
|
|
|
|
len = strnlen_user(str, MAX_ARG_STRLEN);
|
|
if (!len)
|
|
goto out;
|
|
|
|
ret = -E2BIG;
|
|
if (!valid_arg_len(bprm, len))
|
|
goto out;
|
|
|
|
/* We're going to work our way backwords. */
|
|
pos = bprm->p;
|
|
str += len;
|
|
bprm->p -= len;
|
|
#ifdef CONFIG_MMU
|
|
if (bprm->p < bprm->argmin)
|
|
goto out;
|
|
#endif
|
|
|
|
while (len > 0) {
|
|
int offset, bytes_to_copy;
|
|
|
|
if (fatal_signal_pending(current)) {
|
|
ret = -ERESTARTNOHAND;
|
|
goto out;
|
|
}
|
|
cond_resched();
|
|
|
|
offset = pos % PAGE_SIZE;
|
|
if (offset == 0)
|
|
offset = PAGE_SIZE;
|
|
|
|
bytes_to_copy = offset;
|
|
if (bytes_to_copy > len)
|
|
bytes_to_copy = len;
|
|
|
|
offset -= bytes_to_copy;
|
|
pos -= bytes_to_copy;
|
|
str -= bytes_to_copy;
|
|
len -= bytes_to_copy;
|
|
|
|
if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
|
|
struct page *page;
|
|
|
|
page = get_arg_page(bprm, pos, 1);
|
|
if (!page) {
|
|
ret = -E2BIG;
|
|
goto out;
|
|
}
|
|
|
|
if (kmapped_page) {
|
|
flush_kernel_dcache_page(kmapped_page);
|
|
kunmap(kmapped_page);
|
|
put_arg_page(kmapped_page);
|
|
}
|
|
kmapped_page = page;
|
|
kaddr = kmap(kmapped_page);
|
|
kpos = pos & PAGE_MASK;
|
|
flush_arg_page(bprm, kpos, kmapped_page);
|
|
}
|
|
if (copy_from_user(kaddr+offset, str, bytes_to_copy)) {
|
|
ret = -EFAULT;
|
|
goto out;
|
|
}
|
|
}
|
|
}
|
|
ret = 0;
|
|
out:
|
|
if (kmapped_page) {
|
|
flush_kernel_dcache_page(kmapped_page);
|
|
kunmap(kmapped_page);
|
|
put_arg_page(kmapped_page);
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* Copy and argument/environment string from the kernel to the processes stack.
|
|
*/
|
|
int copy_string_kernel(const char *arg, struct linux_binprm *bprm)
|
|
{
|
|
int len = strnlen(arg, MAX_ARG_STRLEN) + 1 /* terminating NUL */;
|
|
unsigned long pos = bprm->p;
|
|
|
|
if (len == 0)
|
|
return -EFAULT;
|
|
if (!valid_arg_len(bprm, len))
|
|
return -E2BIG;
|
|
|
|
/* We're going to work our way backwards. */
|
|
arg += len;
|
|
bprm->p -= len;
|
|
if (IS_ENABLED(CONFIG_MMU) && bprm->p < bprm->argmin)
|
|
return -E2BIG;
|
|
|
|
while (len > 0) {
|
|
unsigned int bytes_to_copy = min_t(unsigned int, len,
|
|
min_not_zero(offset_in_page(pos), PAGE_SIZE));
|
|
struct page *page;
|
|
char *kaddr;
|
|
|
|
pos -= bytes_to_copy;
|
|
arg -= bytes_to_copy;
|
|
len -= bytes_to_copy;
|
|
|
|
page = get_arg_page(bprm, pos, 1);
|
|
if (!page)
|
|
return -E2BIG;
|
|
kaddr = kmap_atomic(page);
|
|
flush_arg_page(bprm, pos & PAGE_MASK, page);
|
|
memcpy(kaddr + offset_in_page(pos), arg, bytes_to_copy);
|
|
flush_kernel_dcache_page(page);
|
|
kunmap_atomic(kaddr);
|
|
put_arg_page(page);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(copy_string_kernel);
|
|
|
|
static int copy_strings_kernel(int argc, const char *const *argv,
|
|
struct linux_binprm *bprm)
|
|
{
|
|
while (argc-- > 0) {
|
|
int ret = copy_string_kernel(argv[argc], bprm);
|
|
if (ret < 0)
|
|
return ret;
|
|
if (fatal_signal_pending(current))
|
|
return -ERESTARTNOHAND;
|
|
cond_resched();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
/*
|
|
* During bprm_mm_init(), we create a temporary stack at STACK_TOP_MAX. Once
|
|
* the binfmt code determines where the new stack should reside, we shift it to
|
|
* its final location. The process proceeds as follows:
|
|
*
|
|
* 1) Use shift to calculate the new vma endpoints.
|
|
* 2) Extend vma to cover both the old and new ranges. This ensures the
|
|
* arguments passed to subsequent functions are consistent.
|
|
* 3) Move vma's page tables to the new range.
|
|
* 4) Free up any cleared pgd range.
|
|
* 5) Shrink the vma to cover only the new range.
|
|
*/
|
|
static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
|
|
{
|
|
struct mm_struct *mm = vma->vm_mm;
|
|
unsigned long old_start = vma->vm_start;
|
|
unsigned long old_end = vma->vm_end;
|
|
unsigned long length = old_end - old_start;
|
|
unsigned long new_start = old_start - shift;
|
|
unsigned long new_end = old_end - shift;
|
|
struct mmu_gather tlb;
|
|
|
|
BUG_ON(new_start > new_end);
|
|
|
|
/*
|
|
* ensure there are no vmas between where we want to go
|
|
* and where we are
|
|
*/
|
|
if (vma != find_vma(mm, new_start))
|
|
return -EFAULT;
|
|
|
|
/*
|
|
* cover the whole range: [new_start, old_end)
|
|
*/
|
|
if (vma_adjust(vma, new_start, old_end, vma->vm_pgoff, NULL))
|
|
return -ENOMEM;
|
|
|
|
/*
|
|
* move the page tables downwards, on failure we rely on
|
|
* process cleanup to remove whatever mess we made.
|
|
*/
|
|
if (length != move_page_tables(vma, old_start,
|
|
vma, new_start, length, false))
|
|
return -ENOMEM;
|
|
|
|
lru_add_drain();
|
|
tlb_gather_mmu(&tlb, mm, old_start, old_end);
|
|
if (new_end > old_start) {
|
|
/*
|
|
* when the old and new regions overlap clear from new_end.
|
|
*/
|
|
free_pgd_range(&tlb, new_end, old_end, new_end,
|
|
vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
|
|
} else {
|
|
/*
|
|
* otherwise, clean from old_start; this is done to not touch
|
|
* the address space in [new_end, old_start) some architectures
|
|
* have constraints on va-space that make this illegal (IA64) -
|
|
* for the others its just a little faster.
|
|
*/
|
|
free_pgd_range(&tlb, old_start, old_end, new_end,
|
|
vma->vm_next ? vma->vm_next->vm_start : USER_PGTABLES_CEILING);
|
|
}
|
|
tlb_finish_mmu(&tlb, old_start, old_end);
|
|
|
|
/*
|
|
* Shrink the vma to just the new range. Always succeeds.
|
|
*/
|
|
vma_adjust(vma, new_start, new_end, vma->vm_pgoff, NULL);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Finalizes the stack vm_area_struct. The flags and permissions are updated,
|
|
* the stack is optionally relocated, and some extra space is added.
|
|
*/
|
|
int setup_arg_pages(struct linux_binprm *bprm,
|
|
unsigned long stack_top,
|
|
int executable_stack)
|
|
{
|
|
unsigned long ret;
|
|
unsigned long stack_shift;
|
|
struct mm_struct *mm = current->mm;
|
|
struct vm_area_struct *vma = bprm->vma;
|
|
struct vm_area_struct *prev = NULL;
|
|
unsigned long vm_flags;
|
|
unsigned long stack_base;
|
|
unsigned long stack_size;
|
|
unsigned long stack_expand;
|
|
unsigned long rlim_stack;
|
|
|
|
#ifdef CONFIG_STACK_GROWSUP
|
|
/* Limit stack size */
|
|
stack_base = bprm->rlim_stack.rlim_max;
|
|
if (stack_base > STACK_SIZE_MAX)
|
|
stack_base = STACK_SIZE_MAX;
|
|
|
|
/* Add space for stack randomization. */
|
|
stack_base += (STACK_RND_MASK << PAGE_SHIFT);
|
|
|
|
/* Make sure we didn't let the argument array grow too large. */
|
|
if (vma->vm_end - vma->vm_start > stack_base)
|
|
return -ENOMEM;
|
|
|
|
stack_base = PAGE_ALIGN(stack_top - stack_base);
|
|
|
|
stack_shift = vma->vm_start - stack_base;
|
|
mm->arg_start = bprm->p - stack_shift;
|
|
bprm->p = vma->vm_end - stack_shift;
|
|
#else
|
|
stack_top = arch_align_stack(stack_top);
|
|
stack_top = PAGE_ALIGN(stack_top);
|
|
|
|
if (unlikely(stack_top < mmap_min_addr) ||
|
|
unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
|
|
return -ENOMEM;
|
|
|
|
stack_shift = vma->vm_end - stack_top;
|
|
|
|
bprm->p -= stack_shift;
|
|
mm->arg_start = bprm->p;
|
|
#endif
|
|
|
|
if (bprm->loader)
|
|
bprm->loader -= stack_shift;
|
|
bprm->exec -= stack_shift;
|
|
|
|
if (mmap_write_lock_killable(mm))
|
|
return -EINTR;
|
|
|
|
vm_flags = VM_STACK_FLAGS;
|
|
|
|
/*
|
|
* Adjust stack execute permissions; explicitly enable for
|
|
* EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
|
|
* (arch default) otherwise.
|
|
*/
|
|
if (unlikely(executable_stack == EXSTACK_ENABLE_X))
|
|
vm_flags |= VM_EXEC;
|
|
else if (executable_stack == EXSTACK_DISABLE_X)
|
|
vm_flags &= ~VM_EXEC;
|
|
vm_flags |= mm->def_flags;
|
|
vm_flags |= VM_STACK_INCOMPLETE_SETUP;
|
|
|
|
ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
|
|
vm_flags);
|
|
if (ret)
|
|
goto out_unlock;
|
|
BUG_ON(prev != vma);
|
|
|
|
if (unlikely(vm_flags & VM_EXEC)) {
|
|
pr_warn_once("process '%pD4' started with executable stack\n",
|
|
bprm->file);
|
|
}
|
|
|
|
/* Move stack pages down in memory. */
|
|
if (stack_shift) {
|
|
ret = shift_arg_pages(vma, stack_shift);
|
|
if (ret)
|
|
goto out_unlock;
|
|
}
|
|
|
|
/* mprotect_fixup is overkill to remove the temporary stack flags */
|
|
vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
|
|
|
|
stack_expand = 131072UL; /* randomly 32*4k (or 2*64k) pages */
|
|
stack_size = vma->vm_end - vma->vm_start;
|
|
/*
|
|
* Align this down to a page boundary as expand_stack
|
|
* will align it up.
|
|
*/
|
|
rlim_stack = bprm->rlim_stack.rlim_cur & PAGE_MASK;
|
|
#ifdef CONFIG_STACK_GROWSUP
|
|
if (stack_size + stack_expand > rlim_stack)
|
|
stack_base = vma->vm_start + rlim_stack;
|
|
else
|
|
stack_base = vma->vm_end + stack_expand;
|
|
#else
|
|
if (stack_size + stack_expand > rlim_stack)
|
|
stack_base = vma->vm_end - rlim_stack;
|
|
else
|
|
stack_base = vma->vm_start - stack_expand;
|
|
#endif
|
|
current->mm->start_stack = bprm->p;
|
|
ret = expand_stack(vma, stack_base);
|
|
if (ret)
|
|
ret = -EFAULT;
|
|
|
|
out_unlock:
|
|
mmap_write_unlock(mm);
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(setup_arg_pages);
|
|
|
|
#else
|
|
|
|
/*
|
|
* Transfer the program arguments and environment from the holding pages
|
|
* onto the stack. The provided stack pointer is adjusted accordingly.
|
|
*/
|
|
int transfer_args_to_stack(struct linux_binprm *bprm,
|
|
unsigned long *sp_location)
|
|
{
|
|
unsigned long index, stop, sp;
|
|
int ret = 0;
|
|
|
|
stop = bprm->p >> PAGE_SHIFT;
|
|
sp = *sp_location;
|
|
|
|
for (index = MAX_ARG_PAGES - 1; index >= stop; index--) {
|
|
unsigned int offset = index == stop ? bprm->p & ~PAGE_MASK : 0;
|
|
char *src = kmap(bprm->page[index]) + offset;
|
|
sp -= PAGE_SIZE - offset;
|
|
if (copy_to_user((void *) sp, src, PAGE_SIZE - offset) != 0)
|
|
ret = -EFAULT;
|
|
kunmap(bprm->page[index]);
|
|
if (ret)
|
|
goto out;
|
|
}
|
|
|
|
*sp_location = sp;
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(transfer_args_to_stack);
|
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
static struct file *do_open_execat(int fd, struct filename *name, int flags)
|
|
{
|
|
struct file *file;
|
|
int err;
|
|
struct open_flags open_exec_flags = {
|
|
.open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC,
|
|
.acc_mode = MAY_EXEC,
|
|
.intent = LOOKUP_OPEN,
|
|
.lookup_flags = LOOKUP_FOLLOW,
|
|
};
|
|
|
|
if ((flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
|
|
return ERR_PTR(-EINVAL);
|
|
if (flags & AT_SYMLINK_NOFOLLOW)
|
|
open_exec_flags.lookup_flags &= ~LOOKUP_FOLLOW;
|
|
if (flags & AT_EMPTY_PATH)
|
|
open_exec_flags.lookup_flags |= LOOKUP_EMPTY;
|
|
|
|
file = do_filp_open(fd, name, &open_exec_flags);
|
|
if (IS_ERR(file))
|
|
goto out;
|
|
|
|
/*
|
|
* may_open() has already checked for this, so it should be
|
|
* impossible to trip now. But we need to be extra cautious
|
|
* and check again at the very end too.
|
|
*/
|
|
err = -EACCES;
|
|
if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode) ||
|
|
path_noexec(&file->f_path)))
|
|
goto exit;
|
|
|
|
err = deny_write_access(file);
|
|
if (err)
|
|
goto exit;
|
|
|
|
if (name->name[0] != '\0')
|
|
fsnotify_open(file);
|
|
|
|
out:
|
|
return file;
|
|
|
|
exit:
|
|
fput(file);
|
|
return ERR_PTR(err);
|
|
}
|
|
|
|
struct file *open_exec(const char *name)
|
|
{
|
|
struct filename *filename = getname_kernel(name);
|
|
struct file *f = ERR_CAST(filename);
|
|
|
|
if (!IS_ERR(filename)) {
|
|
f = do_open_execat(AT_FDCWD, filename, 0);
|
|
putname(filename);
|
|
}
|
|
return f;
|
|
}
|
|
EXPORT_SYMBOL(open_exec);
|
|
|
|
#if defined(CONFIG_HAVE_AOUT) || defined(CONFIG_BINFMT_FLAT) || \
|
|
defined(CONFIG_BINFMT_ELF_FDPIC)
|
|
ssize_t read_code(struct file *file, unsigned long addr, loff_t pos, size_t len)
|
|
{
|
|
ssize_t res = vfs_read(file, (void __user *)addr, len, &pos);
|
|
if (res > 0)
|
|
flush_icache_user_range(addr, addr + len);
|
|
return res;
|
|
}
|
|
EXPORT_SYMBOL(read_code);
|
|
#endif
|
|
|
|
/*
|
|
* Maps the mm_struct mm into the current task struct.
|
|
* On success, this function returns with exec_update_lock
|
|
* held for writing.
|
|
*/
|
|
static int exec_mmap(struct mm_struct *mm)
|
|
{
|
|
struct task_struct *tsk;
|
|
struct mm_struct *old_mm, *active_mm;
|
|
int ret;
|
|
|
|
/* Notify parent that we're no longer interested in the old VM */
|
|
tsk = current;
|
|
old_mm = current->mm;
|
|
exec_mm_release(tsk, old_mm);
|
|
if (old_mm)
|
|
sync_mm_rss(old_mm);
|
|
|
|
ret = down_write_killable(&tsk->signal->exec_update_lock);
|
|
if (ret)
|
|
return ret;
|
|
|
|
if (old_mm) {
|
|
/*
|
|
* Make sure that if there is a core dump in progress
|
|
* for the old mm, we get out and die instead of going
|
|
* through with the exec. We must hold mmap_lock around
|
|
* checking core_state and changing tsk->mm.
|
|
*/
|
|
mmap_read_lock(old_mm);
|
|
if (unlikely(old_mm->core_state)) {
|
|
mmap_read_unlock(old_mm);
|
|
up_write(&tsk->signal->exec_update_lock);
|
|
return -EINTR;
|
|
}
|
|
}
|
|
|
|
task_lock(tsk);
|
|
membarrier_exec_mmap(mm);
|
|
|
|
local_irq_disable();
|
|
active_mm = tsk->active_mm;
|
|
tsk->active_mm = mm;
|
|
tsk->mm = mm;
|
|
/*
|
|
* This prevents preemption while active_mm is being loaded and
|
|
* it and mm are being updated, which could cause problems for
|
|
* lazy tlb mm refcounting when these are updated by context
|
|
* switches. Not all architectures can handle irqs off over
|
|
* activate_mm yet.
|
|
*/
|
|
if (!IS_ENABLED(CONFIG_ARCH_WANT_IRQS_OFF_ACTIVATE_MM))
|
|
local_irq_enable();
|
|
activate_mm(active_mm, mm);
|
|
if (IS_ENABLED(CONFIG_ARCH_WANT_IRQS_OFF_ACTIVATE_MM))
|
|
local_irq_enable();
|
|
tsk->mm->vmacache_seqnum = 0;
|
|
vmacache_flush(tsk);
|
|
task_unlock(tsk);
|
|
if (old_mm) {
|
|
mmap_read_unlock(old_mm);
|
|
BUG_ON(active_mm != old_mm);
|
|
setmax_mm_hiwater_rss(&tsk->signal->maxrss, old_mm);
|
|
mm_update_next_owner(old_mm);
|
|
mmput(old_mm);
|
|
return 0;
|
|
}
|
|
mmdrop(active_mm);
|
|
return 0;
|
|
}
|
|
|
|
static int de_thread(struct task_struct *tsk)
|
|
{
|
|
struct signal_struct *sig = tsk->signal;
|
|
struct sighand_struct *oldsighand = tsk->sighand;
|
|
spinlock_t *lock = &oldsighand->siglock;
|
|
|
|
if (thread_group_empty(tsk))
|
|
goto no_thread_group;
|
|
|
|
/*
|
|
* Kill all other threads in the thread group.
|
|
*/
|
|
spin_lock_irq(lock);
|
|
if (signal_group_exit(sig)) {
|
|
/*
|
|
* Another group action in progress, just
|
|
* return so that the signal is processed.
|
|
*/
|
|
spin_unlock_irq(lock);
|
|
return -EAGAIN;
|
|
}
|
|
|
|
sig->group_exit_task = tsk;
|
|
sig->notify_count = zap_other_threads(tsk);
|
|
if (!thread_group_leader(tsk))
|
|
sig->notify_count--;
|
|
|
|
while (sig->notify_count) {
|
|
__set_current_state(TASK_KILLABLE);
|
|
spin_unlock_irq(lock);
|
|
schedule();
|
|
if (__fatal_signal_pending(tsk))
|
|
goto killed;
|
|
spin_lock_irq(lock);
|
|
}
|
|
spin_unlock_irq(lock);
|
|
|
|
/*
|
|
* At this point all other threads have exited, all we have to
|
|
* do is to wait for the thread group leader to become inactive,
|
|
* and to assume its PID:
|
|
*/
|
|
if (!thread_group_leader(tsk)) {
|
|
struct task_struct *leader = tsk->group_leader;
|
|
|
|
for (;;) {
|
|
cgroup_threadgroup_change_begin(tsk);
|
|
write_lock_irq(&tasklist_lock);
|
|
/*
|
|
* Do this under tasklist_lock to ensure that
|
|
* exit_notify() can't miss ->group_exit_task
|
|
*/
|
|
sig->notify_count = -1;
|
|
if (likely(leader->exit_state))
|
|
break;
|
|
__set_current_state(TASK_KILLABLE);
|
|
write_unlock_irq(&tasklist_lock);
|
|
cgroup_threadgroup_change_end(tsk);
|
|
schedule();
|
|
if (__fatal_signal_pending(tsk))
|
|
goto killed;
|
|
}
|
|
|
|
/*
|
|
* The only record we have of the real-time age of a
|
|
* process, regardless of execs it's done, is start_time.
|
|
* All the past CPU time is accumulated in signal_struct
|
|
* from sister threads now dead. But in this non-leader
|
|
* exec, nothing survives from the original leader thread,
|
|
* whose birth marks the true age of this process now.
|
|
* When we take on its identity by switching to its PID, we
|
|
* also take its birthdate (always earlier than our own).
|
|
*/
|
|
tsk->start_time = leader->start_time;
|
|
tsk->start_boottime = leader->start_boottime;
|
|
|
|
BUG_ON(!same_thread_group(leader, tsk));
|
|
/*
|
|
* An exec() starts a new thread group with the
|
|
* TGID of the previous thread group. Rehash the
|
|
* two threads with a switched PID, and release
|
|
* the former thread group leader:
|
|
*/
|
|
|
|
/* Become a process group leader with the old leader's pid.
|
|
* The old leader becomes a thread of the this thread group.
|
|
*/
|
|
exchange_tids(tsk, leader);
|
|
transfer_pid(leader, tsk, PIDTYPE_TGID);
|
|
transfer_pid(leader, tsk, PIDTYPE_PGID);
|
|
transfer_pid(leader, tsk, PIDTYPE_SID);
|
|
|
|
list_replace_rcu(&leader->tasks, &tsk->tasks);
|
|
list_replace_init(&leader->sibling, &tsk->sibling);
|
|
|
|
tsk->group_leader = tsk;
|
|
leader->group_leader = tsk;
|
|
|
|
tsk->exit_signal = SIGCHLD;
|
|
leader->exit_signal = -1;
|
|
|
|
BUG_ON(leader->exit_state != EXIT_ZOMBIE);
|
|
leader->exit_state = EXIT_DEAD;
|
|
|
|
/*
|
|
* We are going to release_task()->ptrace_unlink() silently,
|
|
* the tracer can sleep in do_wait(). EXIT_DEAD guarantees
|
|
* the tracer wont't block again waiting for this thread.
|
|
*/
|
|
if (unlikely(leader->ptrace))
|
|
__wake_up_parent(leader, leader->parent);
|
|
write_unlock_irq(&tasklist_lock);
|
|
cgroup_threadgroup_change_end(tsk);
|
|
|
|
release_task(leader);
|
|
}
|
|
|
|
sig->group_exit_task = NULL;
|
|
sig->notify_count = 0;
|
|
|
|
no_thread_group:
|
|
/* we have changed execution domain */
|
|
tsk->exit_signal = SIGCHLD;
|
|
|
|
BUG_ON(!thread_group_leader(tsk));
|
|
return 0;
|
|
|
|
killed:
|
|
/* protects against exit_notify() and __exit_signal() */
|
|
read_lock(&tasklist_lock);
|
|
sig->group_exit_task = NULL;
|
|
sig->notify_count = 0;
|
|
read_unlock(&tasklist_lock);
|
|
return -EAGAIN;
|
|
}
|
|
|
|
|
|
/*
|
|
* This function makes sure the current process has its own signal table,
|
|
* so that flush_signal_handlers can later reset the handlers without
|
|
* disturbing other processes. (Other processes might share the signal
|
|
* table via the CLONE_SIGHAND option to clone().)
|
|
*/
|
|
static int unshare_sighand(struct task_struct *me)
|
|
{
|
|
struct sighand_struct *oldsighand = me->sighand;
|
|
|
|
if (refcount_read(&oldsighand->count) != 1) {
|
|
struct sighand_struct *newsighand;
|
|
/*
|
|
* This ->sighand is shared with the CLONE_SIGHAND
|
|
* but not CLONE_THREAD task, switch to the new one.
|
|
*/
|
|
newsighand = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
|
|
if (!newsighand)
|
|
return -ENOMEM;
|
|
|
|
refcount_set(&newsighand->count, 1);
|
|
memcpy(newsighand->action, oldsighand->action,
|
|
sizeof(newsighand->action));
|
|
|
|
write_lock_irq(&tasklist_lock);
|
|
spin_lock(&oldsighand->siglock);
|
|
rcu_assign_pointer(me->sighand, newsighand);
|
|
spin_unlock(&oldsighand->siglock);
|
|
write_unlock_irq(&tasklist_lock);
|
|
|
|
__cleanup_sighand(oldsighand);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk)
|
|
{
|
|
task_lock(tsk);
|
|
strncpy(buf, tsk->comm, buf_size);
|
|
task_unlock(tsk);
|
|
return buf;
|
|
}
|
|
EXPORT_SYMBOL_GPL(__get_task_comm);
|
|
|
|
/*
|
|
* These functions flushes out all traces of the currently running executable
|
|
* so that a new one can be started
|
|
*/
|
|
|
|
void __set_task_comm(struct task_struct *tsk, const char *buf, bool exec)
|
|
{
|
|
task_lock(tsk);
|
|
trace_task_rename(tsk, buf);
|
|
strlcpy(tsk->comm, buf, sizeof(tsk->comm));
|
|
task_unlock(tsk);
|
|
perf_event_comm(tsk, exec);
|
|
}
|
|
|
|
/*
|
|
* Calling this is the point of no return. None of the failures will be
|
|
* seen by userspace since either the process is already taking a fatal
|
|
* signal (via de_thread() or coredump), or will have SEGV raised
|
|
* (after exec_mmap()) by search_binary_handler (see below).
|
|
*/
|
|
int begin_new_exec(struct linux_binprm * bprm)
|
|
{
|
|
struct task_struct *me = current;
|
|
int retval;
|
|
|
|
/* Once we are committed compute the creds */
|
|
retval = bprm_creds_from_file(bprm);
|
|
if (retval)
|
|
return retval;
|
|
|
|
/*
|
|
* Ensure all future errors are fatal.
|
|
*/
|
|
bprm->point_of_no_return = true;
|
|
|
|
/*
|
|
* Make this the only thread in the thread group.
|
|
*/
|
|
retval = de_thread(me);
|
|
if (retval)
|
|
goto out;
|
|
|
|
/*
|
|
* Must be called _before_ exec_mmap() as bprm->mm is
|
|
* not visibile until then. This also enables the update
|
|
* to be lockless.
|
|
*/
|
|
set_mm_exe_file(bprm->mm, bprm->file);
|
|
|
|
/* If the binary is not readable then enforce mm->dumpable=0 */
|
|
would_dump(bprm, bprm->file);
|
|
if (bprm->have_execfd)
|
|
would_dump(bprm, bprm->executable);
|
|
|
|
/*
|
|
* Release all of the old mmap stuff
|
|
*/
|
|
acct_arg_size(bprm, 0);
|
|
retval = exec_mmap(bprm->mm);
|
|
if (retval)
|
|
goto out;
|
|
|
|
bprm->mm = NULL;
|
|
|
|
#ifdef CONFIG_POSIX_TIMERS
|
|
spin_lock_irq(&me->sighand->siglock);
|
|
posix_cpu_timers_exit(me);
|
|
spin_unlock_irq(&me->sighand->siglock);
|
|
exit_itimers(me);
|
|
flush_itimer_signals();
|
|
#endif
|
|
|
|
/*
|
|
* Make the signal table private.
|
|
*/
|
|
retval = unshare_sighand(me);
|
|
if (retval)
|
|
goto out_unlock;
|
|
|
|
/*
|
|
* Ensure that the uaccess routines can actually operate on userspace
|
|
* pointers:
|
|
*/
|
|
force_uaccess_begin();
|
|
|
|
me->flags &= ~(PF_RANDOMIZE | PF_FORKNOEXEC | PF_KTHREAD |
|
|
PF_NOFREEZE | PF_NO_SETAFFINITY);
|
|
flush_thread();
|
|
me->personality &= ~bprm->per_clear;
|
|
|
|
/*
|
|
* We have to apply CLOEXEC before we change whether the process is
|
|
* dumpable (in setup_new_exec) to avoid a race with a process in userspace
|
|
* trying to access the should-be-closed file descriptors of a process
|
|
* undergoing exec(2).
|
|
*/
|
|
do_close_on_exec(me->files);
|
|
|
|
if (bprm->secureexec) {
|
|
/* Make sure parent cannot signal privileged process. */
|
|
me->pdeath_signal = 0;
|
|
|
|
/*
|
|
* For secureexec, reset the stack limit to sane default to
|
|
* avoid bad behavior from the prior rlimits. This has to
|
|
* happen before arch_pick_mmap_layout(), which examines
|
|
* RLIMIT_STACK, but after the point of no return to avoid
|
|
* needing to clean up the change on failure.
|
|
*/
|
|
if (bprm->rlim_stack.rlim_cur > _STK_LIM)
|
|
bprm->rlim_stack.rlim_cur = _STK_LIM;
|
|
}
|
|
|
|
me->sas_ss_sp = me->sas_ss_size = 0;
|
|
|
|
/*
|
|
* Figure out dumpability. Note that this checking only of current
|
|
* is wrong, but userspace depends on it. This should be testing
|
|
* bprm->secureexec instead.
|
|
*/
|
|
if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP ||
|
|
!(uid_eq(current_euid(), current_uid()) &&
|
|
gid_eq(current_egid(), current_gid())))
|
|
set_dumpable(current->mm, suid_dumpable);
|
|
else
|
|
set_dumpable(current->mm, SUID_DUMP_USER);
|
|
|
|
perf_event_exec();
|
|
__set_task_comm(me, kbasename(bprm->filename), true);
|
|
|
|
/* An exec changes our domain. We are no longer part of the thread
|
|
group */
|
|
WRITE_ONCE(me->self_exec_id, me->self_exec_id + 1);
|
|
flush_signal_handlers(me, 0);
|
|
|
|
/*
|
|
* install the new credentials for this executable
|
|
*/
|
|
security_bprm_committing_creds(bprm);
|
|
|
|
commit_creds(bprm->cred);
|
|
bprm->cred = NULL;
|
|
|
|
/*
|
|
* Disable monitoring for regular users
|
|
* when executing setuid binaries. Must
|
|
* wait until new credentials are committed
|
|
* by commit_creds() above
|
|
*/
|
|
if (get_dumpable(me->mm) != SUID_DUMP_USER)
|
|
perf_event_exit_task(me);
|
|
/*
|
|
* cred_guard_mutex must be held at least to this point to prevent
|
|
* ptrace_attach() from altering our determination of the task's
|
|
* credentials; any time after this it may be unlocked.
|
|
*/
|
|
security_bprm_committed_creds(bprm);
|
|
|
|
/* Pass the opened binary to the interpreter. */
|
|
if (bprm->have_execfd) {
|
|
retval = get_unused_fd_flags(0);
|
|
if (retval < 0)
|
|
goto out_unlock;
|
|
fd_install(retval, bprm->executable);
|
|
bprm->executable = NULL;
|
|
bprm->execfd = retval;
|
|
}
|
|
return 0;
|
|
|
|
out_unlock:
|
|
up_write(&me->signal->exec_update_lock);
|
|
out:
|
|
return retval;
|
|
}
|
|
EXPORT_SYMBOL(begin_new_exec);
|
|
|
|
void would_dump(struct linux_binprm *bprm, struct file *file)
|
|
{
|
|
struct inode *inode = file_inode(file);
|
|
if (inode_permission(inode, MAY_READ) < 0) {
|
|
struct user_namespace *old, *user_ns;
|
|
bprm->interp_flags |= BINPRM_FLAGS_ENFORCE_NONDUMP;
|
|
|
|
/* Ensure mm->user_ns contains the executable */
|
|
user_ns = old = bprm->mm->user_ns;
|
|
while ((user_ns != &init_user_ns) &&
|
|
!privileged_wrt_inode_uidgid(user_ns, inode))
|
|
user_ns = user_ns->parent;
|
|
|
|
if (old != user_ns) {
|
|
bprm->mm->user_ns = get_user_ns(user_ns);
|
|
put_user_ns(old);
|
|
}
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(would_dump);
|
|
|
|
void setup_new_exec(struct linux_binprm * bprm)
|
|
{
|
|
/* Setup things that can depend upon the personality */
|
|
struct task_struct *me = current;
|
|
|
|
arch_pick_mmap_layout(me->mm, &bprm->rlim_stack);
|
|
|
|
arch_setup_new_exec();
|
|
|
|
/* Set the new mm task size. We have to do that late because it may
|
|
* depend on TIF_32BIT which is only updated in flush_thread() on
|
|
* some architectures like powerpc
|
|
*/
|
|
me->mm->task_size = TASK_SIZE;
|
|
up_write(&me->signal->exec_update_lock);
|
|
mutex_unlock(&me->signal->cred_guard_mutex);
|
|
}
|
|
EXPORT_SYMBOL(setup_new_exec);
|
|
|
|
/* Runs immediately before start_thread() takes over. */
|
|
void finalize_exec(struct linux_binprm *bprm)
|
|
{
|
|
/* Store any stack rlimit changes before starting thread. */
|
|
task_lock(current->group_leader);
|
|
current->signal->rlim[RLIMIT_STACK] = bprm->rlim_stack;
|
|
task_unlock(current->group_leader);
|
|
}
|
|
EXPORT_SYMBOL(finalize_exec);
|
|
|
|
/*
|
|
* Prepare credentials and lock ->cred_guard_mutex.
|
|
* setup_new_exec() commits the new creds and drops the lock.
|
|
* Or, if exec fails before, free_bprm() should release ->cred and
|
|
* and unlock.
|
|
*/
|
|
static int prepare_bprm_creds(struct linux_binprm *bprm)
|
|
{
|
|
if (mutex_lock_interruptible(¤t->signal->cred_guard_mutex))
|
|
return -ERESTARTNOINTR;
|
|
|
|
bprm->cred = prepare_exec_creds();
|
|
if (likely(bprm->cred))
|
|
return 0;
|
|
|
|
mutex_unlock(¤t->signal->cred_guard_mutex);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
static void free_bprm(struct linux_binprm *bprm)
|
|
{
|
|
if (bprm->mm) {
|
|
acct_arg_size(bprm, 0);
|
|
mmput(bprm->mm);
|
|
}
|
|
free_arg_pages(bprm);
|
|
if (bprm->cred) {
|
|
mutex_unlock(¤t->signal->cred_guard_mutex);
|
|
abort_creds(bprm->cred);
|
|
}
|
|
if (bprm->file) {
|
|
allow_write_access(bprm->file);
|
|
fput(bprm->file);
|
|
}
|
|
if (bprm->executable)
|
|
fput(bprm->executable);
|
|
/* If a binfmt changed the interp, free it. */
|
|
if (bprm->interp != bprm->filename)
|
|
kfree(bprm->interp);
|
|
kfree(bprm->fdpath);
|
|
kfree(bprm);
|
|
}
|
|
|
|
static struct linux_binprm *alloc_bprm(int fd, struct filename *filename)
|
|
{
|
|
struct linux_binprm *bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
|
|
int retval = -ENOMEM;
|
|
if (!bprm)
|
|
goto out;
|
|
|
|
if (fd == AT_FDCWD || filename->name[0] == '/') {
|
|
bprm->filename = filename->name;
|
|
} else {
|
|
if (filename->name[0] == '\0')
|
|
bprm->fdpath = kasprintf(GFP_KERNEL, "/dev/fd/%d", fd);
|
|
else
|
|
bprm->fdpath = kasprintf(GFP_KERNEL, "/dev/fd/%d/%s",
|
|
fd, filename->name);
|
|
if (!bprm->fdpath)
|
|
goto out_free;
|
|
|
|
bprm->filename = bprm->fdpath;
|
|
}
|
|
bprm->interp = bprm->filename;
|
|
|
|
retval = bprm_mm_init(bprm);
|
|
if (retval)
|
|
goto out_free;
|
|
return bprm;
|
|
|
|
out_free:
|
|
free_bprm(bprm);
|
|
out:
|
|
return ERR_PTR(retval);
|
|
}
|
|
|
|
int bprm_change_interp(const char *interp, struct linux_binprm *bprm)
|
|
{
|
|
/* If a binfmt changed the interp, free it first. */
|
|
if (bprm->interp != bprm->filename)
|
|
kfree(bprm->interp);
|
|
bprm->interp = kstrdup(interp, GFP_KERNEL);
|
|
if (!bprm->interp)
|
|
return -ENOMEM;
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(bprm_change_interp);
|
|
|
|
/*
|
|
* determine how safe it is to execute the proposed program
|
|
* - the caller must hold ->cred_guard_mutex to protect against
|
|
* PTRACE_ATTACH or seccomp thread-sync
|
|
*/
|
|
static void check_unsafe_exec(struct linux_binprm *bprm)
|
|
{
|
|
struct task_struct *p = current, *t;
|
|
unsigned n_fs;
|
|
|
|
if (p->ptrace)
|
|
bprm->unsafe |= LSM_UNSAFE_PTRACE;
|
|
|
|
/*
|
|
* This isn't strictly necessary, but it makes it harder for LSMs to
|
|
* mess up.
|
|
*/
|
|
if (task_no_new_privs(current))
|
|
bprm->unsafe |= LSM_UNSAFE_NO_NEW_PRIVS;
|
|
|
|
t = p;
|
|
n_fs = 1;
|
|
spin_lock(&p->fs->lock);
|
|
rcu_read_lock();
|
|
while_each_thread(p, t) {
|
|
if (t->fs == p->fs)
|
|
n_fs++;
|
|
}
|
|
rcu_read_unlock();
|
|
|
|
if (p->fs->users > n_fs)
|
|
bprm->unsafe |= LSM_UNSAFE_SHARE;
|
|
else
|
|
p->fs->in_exec = 1;
|
|
spin_unlock(&p->fs->lock);
|
|
}
|
|
|
|
static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
|
|
{
|
|
/* Handle suid and sgid on files */
|
|
struct inode *inode;
|
|
unsigned int mode;
|
|
kuid_t uid;
|
|
kgid_t gid;
|
|
|
|
if (!mnt_may_suid(file->f_path.mnt))
|
|
return;
|
|
|
|
if (task_no_new_privs(current))
|
|
return;
|
|
|
|
inode = file->f_path.dentry->d_inode;
|
|
mode = READ_ONCE(inode->i_mode);
|
|
if (!(mode & (S_ISUID|S_ISGID)))
|
|
return;
|
|
|
|
/* Be careful if suid/sgid is set */
|
|
inode_lock(inode);
|
|
|
|
/* reload atomically mode/uid/gid now that lock held */
|
|
mode = inode->i_mode;
|
|
uid = inode->i_uid;
|
|
gid = inode->i_gid;
|
|
inode_unlock(inode);
|
|
|
|
/* We ignore suid/sgid if there are no mappings for them in the ns */
|
|
if (!kuid_has_mapping(bprm->cred->user_ns, uid) ||
|
|
!kgid_has_mapping(bprm->cred->user_ns, gid))
|
|
return;
|
|
|
|
if (mode & S_ISUID) {
|
|
bprm->per_clear |= PER_CLEAR_ON_SETID;
|
|
bprm->cred->euid = uid;
|
|
}
|
|
|
|
if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
|
|
bprm->per_clear |= PER_CLEAR_ON_SETID;
|
|
bprm->cred->egid = gid;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Compute brpm->cred based upon the final binary.
|
|
*/
|
|
static int bprm_creds_from_file(struct linux_binprm *bprm)
|
|
{
|
|
/* Compute creds based on which file? */
|
|
struct file *file = bprm->execfd_creds ? bprm->executable : bprm->file;
|
|
|
|
bprm_fill_uid(bprm, file);
|
|
return security_bprm_creds_from_file(bprm, file);
|
|
}
|
|
|
|
/*
|
|
* Fill the binprm structure from the inode.
|
|
* Read the first BINPRM_BUF_SIZE bytes
|
|
*
|
|
* This may be called multiple times for binary chains (scripts for example).
|
|
*/
|
|
static int prepare_binprm(struct linux_binprm *bprm)
|
|
{
|
|
loff_t pos = 0;
|
|
|
|
memset(bprm->buf, 0, BINPRM_BUF_SIZE);
|
|
return kernel_read(bprm->file, bprm->buf, BINPRM_BUF_SIZE, &pos);
|
|
}
|
|
|
|
/*
|
|
* Arguments are '\0' separated strings found at the location bprm->p
|
|
* points to; chop off the first by relocating brpm->p to right after
|
|
* the first '\0' encountered.
|
|
*/
|
|
int remove_arg_zero(struct linux_binprm *bprm)
|
|
{
|
|
int ret = 0;
|
|
unsigned long offset;
|
|
char *kaddr;
|
|
struct page *page;
|
|
|
|
if (!bprm->argc)
|
|
return 0;
|
|
|
|
do {
|
|
offset = bprm->p & ~PAGE_MASK;
|
|
page = get_arg_page(bprm, bprm->p, 0);
|
|
if (!page) {
|
|
ret = -EFAULT;
|
|
goto out;
|
|
}
|
|
kaddr = kmap_atomic(page);
|
|
|
|
for (; offset < PAGE_SIZE && kaddr[offset];
|
|
offset++, bprm->p++)
|
|
;
|
|
|
|
kunmap_atomic(kaddr);
|
|
put_arg_page(page);
|
|
} while (offset == PAGE_SIZE);
|
|
|
|
bprm->p++;
|
|
bprm->argc--;
|
|
ret = 0;
|
|
|
|
out:
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL(remove_arg_zero);
|
|
|
|
#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
|
|
/*
|
|
* cycle the list of binary formats handler, until one recognizes the image
|
|
*/
|
|
static int search_binary_handler(struct linux_binprm *bprm)
|
|
{
|
|
bool need_retry = IS_ENABLED(CONFIG_MODULES);
|
|
struct linux_binfmt *fmt;
|
|
int retval;
|
|
|
|
retval = prepare_binprm(bprm);
|
|
if (retval < 0)
|
|
return retval;
|
|
|
|
retval = security_bprm_check(bprm);
|
|
if (retval)
|
|
return retval;
|
|
|
|
retval = -ENOENT;
|
|
retry:
|
|
read_lock(&binfmt_lock);
|
|
list_for_each_entry(fmt, &formats, lh) {
|
|
if (!try_module_get(fmt->module))
|
|
continue;
|
|
read_unlock(&binfmt_lock);
|
|
|
|
retval = fmt->load_binary(bprm);
|
|
|
|
read_lock(&binfmt_lock);
|
|
put_binfmt(fmt);
|
|
if (bprm->point_of_no_return || (retval != -ENOEXEC)) {
|
|
read_unlock(&binfmt_lock);
|
|
return retval;
|
|
}
|
|
}
|
|
read_unlock(&binfmt_lock);
|
|
|
|
if (need_retry) {
|
|
if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
|
|
printable(bprm->buf[2]) && printable(bprm->buf[3]))
|
|
return retval;
|
|
if (request_module("binfmt-%04x", *(ushort *)(bprm->buf + 2)) < 0)
|
|
return retval;
|
|
need_retry = false;
|
|
goto retry;
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
static int exec_binprm(struct linux_binprm *bprm)
|
|
{
|
|
pid_t old_pid, old_vpid;
|
|
int ret, depth;
|
|
|
|
/* Need to fetch pid before load_binary changes it */
|
|
old_pid = current->pid;
|
|
rcu_read_lock();
|
|
old_vpid = task_pid_nr_ns(current, task_active_pid_ns(current->parent));
|
|
rcu_read_unlock();
|
|
|
|
/* This allows 4 levels of binfmt rewrites before failing hard. */
|
|
for (depth = 0;; depth++) {
|
|
struct file *exec;
|
|
if (depth > 5)
|
|
return -ELOOP;
|
|
|
|
ret = search_binary_handler(bprm);
|
|
if (ret < 0)
|
|
return ret;
|
|
if (!bprm->interpreter)
|
|
break;
|
|
|
|
exec = bprm->file;
|
|
bprm->file = bprm->interpreter;
|
|
bprm->interpreter = NULL;
|
|
|
|
allow_write_access(exec);
|
|
if (unlikely(bprm->have_execfd)) {
|
|
if (bprm->executable) {
|
|
fput(exec);
|
|
return -ENOEXEC;
|
|
}
|
|
bprm->executable = exec;
|
|
} else
|
|
fput(exec);
|
|
}
|
|
|
|
audit_bprm(bprm);
|
|
trace_sched_process_exec(current, old_pid, bprm);
|
|
ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
|
|
proc_exec_connector(current);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* sys_execve() executes a new program.
|
|
*/
|
|
static int bprm_execve(struct linux_binprm *bprm,
|
|
int fd, struct filename *filename, int flags)
|
|
{
|
|
struct file *file;
|
|
struct files_struct *displaced;
|
|
int retval;
|
|
|
|
/*
|
|
* Cancel any io_uring activity across execve
|
|
*/
|
|
io_uring_task_cancel();
|
|
|
|
retval = unshare_files(&displaced);
|
|
if (retval)
|
|
return retval;
|
|
|
|
retval = prepare_bprm_creds(bprm);
|
|
if (retval)
|
|
goto out_files;
|
|
|
|
check_unsafe_exec(bprm);
|
|
current->in_execve = 1;
|
|
|
|
file = do_open_execat(fd, filename, flags);
|
|
retval = PTR_ERR(file);
|
|
if (IS_ERR(file))
|
|
goto out_unmark;
|
|
|
|
sched_exec();
|
|
|
|
bprm->file = file;
|
|
/*
|
|
* Record that a name derived from an O_CLOEXEC fd will be
|
|
* inaccessible after exec. Relies on having exclusive access to
|
|
* current->files (due to unshare_files above).
|
|
*/
|
|
if (bprm->fdpath &&
|
|
close_on_exec(fd, rcu_dereference_raw(current->files->fdt)))
|
|
bprm->interp_flags |= BINPRM_FLAGS_PATH_INACCESSIBLE;
|
|
|
|
/* Set the unchanging part of bprm->cred */
|
|
retval = security_bprm_creds_for_exec(bprm);
|
|
if (retval)
|
|
goto out;
|
|
|
|
retval = exec_binprm(bprm);
|
|
if (retval < 0)
|
|
goto out;
|
|
|
|
/* execve succeeded */
|
|
current->fs->in_exec = 0;
|
|
current->in_execve = 0;
|
|
rseq_execve(current);
|
|
acct_update_integrals(current);
|
|
task_numa_free(current, false);
|
|
if (displaced)
|
|
put_files_struct(displaced);
|
|
return retval;
|
|
|
|
out:
|
|
/*
|
|
* If past the point of no return ensure the the code never
|
|
* returns to the userspace process. Use an existing fatal
|
|
* signal if present otherwise terminate the process with
|
|
* SIGSEGV.
|
|
*/
|
|
if (bprm->point_of_no_return && !fatal_signal_pending(current))
|
|
force_sigsegv(SIGSEGV);
|
|
|
|
out_unmark:
|
|
current->fs->in_exec = 0;
|
|
current->in_execve = 0;
|
|
|
|
out_files:
|
|
if (displaced)
|
|
reset_files_struct(displaced);
|
|
|
|
return retval;
|
|
}
|
|
|
|
static int do_execveat_common(int fd, struct filename *filename,
|
|
struct user_arg_ptr argv,
|
|
struct user_arg_ptr envp,
|
|
int flags)
|
|
{
|
|
struct linux_binprm *bprm;
|
|
int retval;
|
|
|
|
if (IS_ERR(filename))
|
|
return PTR_ERR(filename);
|
|
|
|
/*
|
|
* We move the actual failure in case of RLIMIT_NPROC excess from
|
|
* set*uid() to execve() because too many poorly written programs
|
|
* don't check setuid() return code. Here we additionally recheck
|
|
* whether NPROC limit is still exceeded.
|
|
*/
|
|
if ((current->flags & PF_NPROC_EXCEEDED) &&
|
|
atomic_read(¤t_user()->processes) > rlimit(RLIMIT_NPROC)) {
|
|
retval = -EAGAIN;
|
|
goto out_ret;
|
|
}
|
|
|
|
/* We're below the limit (still or again), so we don't want to make
|
|
* further execve() calls fail. */
|
|
current->flags &= ~PF_NPROC_EXCEEDED;
|
|
|
|
bprm = alloc_bprm(fd, filename);
|
|
if (IS_ERR(bprm)) {
|
|
retval = PTR_ERR(bprm);
|
|
goto out_ret;
|
|
}
|
|
|
|
retval = count(argv, MAX_ARG_STRINGS);
|
|
if (retval == 0)
|
|
pr_warn_once("process '%s' launched '%s' with NULL argv: empty string added\n",
|
|
current->comm, bprm->filename);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->argc = retval;
|
|
|
|
retval = count(envp, MAX_ARG_STRINGS);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->envc = retval;
|
|
|
|
retval = bprm_stack_limits(bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
|
|
retval = copy_string_kernel(bprm->filename, bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->exec = bprm->p;
|
|
|
|
retval = copy_strings(bprm->envc, envp, bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
|
|
retval = copy_strings(bprm->argc, argv, bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
|
|
/*
|
|
* When argv is empty, add an empty string ("") as argv[0] to
|
|
* ensure confused userspace programs that start processing
|
|
* from argv[1] won't end up walking envp. See also
|
|
* bprm_stack_limits().
|
|
*/
|
|
if (bprm->argc == 0) {
|
|
retval = copy_string_kernel("", bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->argc = 1;
|
|
}
|
|
|
|
retval = bprm_execve(bprm, fd, filename, flags);
|
|
out_free:
|
|
free_bprm(bprm);
|
|
|
|
out_ret:
|
|
putname(filename);
|
|
return retval;
|
|
}
|
|
|
|
int kernel_execve(const char *kernel_filename,
|
|
const char *const *argv, const char *const *envp)
|
|
{
|
|
struct filename *filename;
|
|
struct linux_binprm *bprm;
|
|
int fd = AT_FDCWD;
|
|
int retval;
|
|
|
|
filename = getname_kernel(kernel_filename);
|
|
if (IS_ERR(filename))
|
|
return PTR_ERR(filename);
|
|
|
|
bprm = alloc_bprm(fd, filename);
|
|
if (IS_ERR(bprm)) {
|
|
retval = PTR_ERR(bprm);
|
|
goto out_ret;
|
|
}
|
|
|
|
retval = count_strings_kernel(argv);
|
|
if (WARN_ON_ONCE(retval == 0))
|
|
retval = -EINVAL;
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->argc = retval;
|
|
|
|
retval = count_strings_kernel(envp);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->envc = retval;
|
|
|
|
retval = bprm_stack_limits(bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
|
|
retval = copy_string_kernel(bprm->filename, bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
bprm->exec = bprm->p;
|
|
|
|
retval = copy_strings_kernel(bprm->envc, envp, bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
|
|
retval = copy_strings_kernel(bprm->argc, argv, bprm);
|
|
if (retval < 0)
|
|
goto out_free;
|
|
|
|
retval = bprm_execve(bprm, fd, filename, 0);
|
|
out_free:
|
|
free_bprm(bprm);
|
|
out_ret:
|
|
putname(filename);
|
|
return retval;
|
|
}
|
|
|
|
static int do_execve(struct filename *filename,
|
|
const char __user *const __user *__argv,
|
|
const char __user *const __user *__envp)
|
|
{
|
|
struct user_arg_ptr argv = { .ptr.native = __argv };
|
|
struct user_arg_ptr envp = { .ptr.native = __envp };
|
|
return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
|
|
}
|
|
|
|
static int do_execveat(int fd, struct filename *filename,
|
|
const char __user *const __user *__argv,
|
|
const char __user *const __user *__envp,
|
|
int flags)
|
|
{
|
|
struct user_arg_ptr argv = { .ptr.native = __argv };
|
|
struct user_arg_ptr envp = { .ptr.native = __envp };
|
|
|
|
return do_execveat_common(fd, filename, argv, envp, flags);
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
static int compat_do_execve(struct filename *filename,
|
|
const compat_uptr_t __user *__argv,
|
|
const compat_uptr_t __user *__envp)
|
|
{
|
|
struct user_arg_ptr argv = {
|
|
.is_compat = true,
|
|
.ptr.compat = __argv,
|
|
};
|
|
struct user_arg_ptr envp = {
|
|
.is_compat = true,
|
|
.ptr.compat = __envp,
|
|
};
|
|
return do_execveat_common(AT_FDCWD, filename, argv, envp, 0);
|
|
}
|
|
|
|
static int compat_do_execveat(int fd, struct filename *filename,
|
|
const compat_uptr_t __user *__argv,
|
|
const compat_uptr_t __user *__envp,
|
|
int flags)
|
|
{
|
|
struct user_arg_ptr argv = {
|
|
.is_compat = true,
|
|
.ptr.compat = __argv,
|
|
};
|
|
struct user_arg_ptr envp = {
|
|
.is_compat = true,
|
|
.ptr.compat = __envp,
|
|
};
|
|
return do_execveat_common(fd, filename, argv, envp, flags);
|
|
}
|
|
#endif
|
|
|
|
void set_binfmt(struct linux_binfmt *new)
|
|
{
|
|
struct mm_struct *mm = current->mm;
|
|
|
|
if (mm->binfmt)
|
|
module_put(mm->binfmt->module);
|
|
|
|
mm->binfmt = new;
|
|
if (new)
|
|
__module_get(new->module);
|
|
}
|
|
EXPORT_SYMBOL(set_binfmt);
|
|
|
|
/*
|
|
* set_dumpable stores three-value SUID_DUMP_* into mm->flags.
|
|
*/
|
|
void set_dumpable(struct mm_struct *mm, int value)
|
|
{
|
|
if (WARN_ON((unsigned)value > SUID_DUMP_ROOT))
|
|
return;
|
|
|
|
set_mask_bits(&mm->flags, MMF_DUMPABLE_MASK, value);
|
|
}
|
|
|
|
SYSCALL_DEFINE3(execve,
|
|
const char __user *, filename,
|
|
const char __user *const __user *, argv,
|
|
const char __user *const __user *, envp)
|
|
{
|
|
return do_execve(getname(filename), argv, envp);
|
|
}
|
|
|
|
SYSCALL_DEFINE5(execveat,
|
|
int, fd, const char __user *, filename,
|
|
const char __user *const __user *, argv,
|
|
const char __user *const __user *, envp,
|
|
int, flags)
|
|
{
|
|
int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
|
|
|
|
return do_execveat(fd,
|
|
getname_flags(filename, lookup_flags, NULL),
|
|
argv, envp, flags);
|
|
}
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
|
|
const compat_uptr_t __user *, argv,
|
|
const compat_uptr_t __user *, envp)
|
|
{
|
|
return compat_do_execve(getname(filename), argv, envp);
|
|
}
|
|
|
|
COMPAT_SYSCALL_DEFINE5(execveat, int, fd,
|
|
const char __user *, filename,
|
|
const compat_uptr_t __user *, argv,
|
|
const compat_uptr_t __user *, envp,
|
|
int, flags)
|
|
{
|
|
int lookup_flags = (flags & AT_EMPTY_PATH) ? LOOKUP_EMPTY : 0;
|
|
|
|
return compat_do_execveat(fd,
|
|
getname_flags(filename, lookup_flags, NULL),
|
|
argv, envp, flags);
|
|
}
|
|
#endif
|