7.2.5-rc1 review
Greg Kroah-Hartman
maintainercover 7.2.5-rc1 review
This is the start of the stable review cycle for the 7.2.5 release. There are 556 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 11 Sep 2026 13:40:31 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v7.x/stable-review/patch-7.2.5-rc1.gz
or in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git linux-7.2.y
and the diffstat can be found below.
thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
Greg Kroah-Hartman <[email protected]>
Linux 7.2.5-rc1
Farhan Ali <[email protected]>
PCI: Allow per function PCI slots to fix slot reset on s390
Farhan Ali <[email protected]>
PCI: Introduce PCI_SLOT_PLACEHOLDER constant for slot_nr placeholder value
SJ Park <[email protected]>
mm/damon/vaddr: drop last same folio access check optimization
SJ Park <[email protected]>
mm/damon/paddr: drop last same folio access check reuse optimization
SJ Park <[email protected]>
mm/damon/ops-common: use nr_accesses moving sum for quota score
SJ Park <[email protected]>
mm/damon/core: avoid infinite kdamond_merge_regions() internal loop
Fan Wu <[email protected]>
power: supply: ab8500_fg: fix use-after-free on remove
Pan Chuang <[email protected]>
power: supply: ab8500_fg: Remove redundant dev_err()/dev_err_probe()
Mukesh Ojha <[email protected]>
remoteproc: qcom: pas: Guard dtb metadata release with dtb_pas_id check
Chuck Lever <[email protected]>
rpcrdma: arm rn_done before publishing the notification
Jiri Olsa <[email protected]>
bpf: Disable preemption in bpf_get_stackid
Jiri Olsa <[email protected]>
bpf: Use stack id functions instead of __bpf_get_stackid
Jiri Olsa <[email protected]>
bpf: Factor stackid_new_bucket from __bpf_get_stackid
Jiri Olsa <[email protected]>
bpf: Factor stackid_fastpath function from __bpf_get_stackid
Jiri Olsa <[email protected]>
bpf: Factor stackid_init function from __bpf_get_stackid
Abdifatah Suruur <[email protected]>
ksmbd: fix use-after-free in oplock break notification
Mohamed Ahmed <[email protected]>
drm/nouveau/gsp: fix vblank interrupts on GB20x
Mohamed Ahmed <[email protected]>
drm/nouveau/disp: fix head state readback on GB20x
Mohamed Ahmed <[email protected]>
drm/nouveau/disp: fix HDMI GCP AVMute register offsets on GB20x
Mohamed Ahmed <[email protected]>
drm/nouveau/disp: fix HDMI vendor infoframes on GB20x
Mohamed Ahmed <[email protected]>
drm/nouveau/disp: route GSP-RM display MMIO through nvkm_disp_func hooks
Mohamed Ahmed <[email protected]>
drm/nouveau/disp: move the GSP HDMI GCP AVMute write to engine/disp
Mohamed Ahmed <[email protected]>
drm/nouveau/disp: move GSP head-timing ISR and vblank helpers to tu102.c
Zhenhao Wan <[email protected]>
drm/nouveau/uvmm: clear the dirty flag when unwinding an OP_UNMAP_SPARSE
Zhenhao Wan <[email protected]>
drm/nouveau/uvmm: fix premature region free on failed OP_UNMAP_SPARSE
Zhenhao Wan <[email protected]>
drm/nouveau/uvmm: fix NULL deref unwinding an OP_MAP_SPARSE op
Faith Ekstrand <[email protected]>
drm/nouveau: Use write-combined maps for coherent
Marek Czernohous <[email protected]>
drm/nouveau: unsubscribe the channel-kill event before the fence context
Mohamed Ahmed <[email protected]>
drm/nouveau/gsp: use per-version DP_CONFIG_STREAM params on r570 firmware
Zhenhao Wan <[email protected]>
drm/nouveau/dmem: fix mismatched DMA unmap size for large folios
Zhenhao Wan <[email protected]>
drm/nouveau/dmem: fix callocated underflow on large folio split
Matthew Brost <[email protected]>
drm/pagemap: Fix folio allocation fallback and use-after-put
Shixiong Ou <[email protected]>
drm/sysfb: ofdrm: Fix is_avivo() constant comparison bug
Shixiong Ou <[email protected]>
drm/sysfb: ofdrm: Fix integer overflow in fb_size calculation
Thomas Zimmermann <[email protected]>
drm/sysfb: simpledrm: Improve stride validation
Thomas Zimmermann <[email protected]>
drm/sysfb: simpledrm: Improve panel-size validation
Thomas Zimmermann <[email protected]>
drm/sysfb: simpledrm: Improve framebuffer-size validation
Sunday Clement <[email protected]>
drm/amdkfd: Reject zero-sized AQL queue allocations after size halving
Vladimir Marioukhine <[email protected]>
drm/amdkfd: guard against NULL restore_mqd in CRIU queue restore
Xiaogang Chen <[email protected]>
drm/amdkfd: Fix the case that vm range is hole at svm_migrate_copy_to_vram
Mario Limonciello <[email protected]>
drm/amdkfd: fix scope of mqd_mgr dereference in pqm_debugfs_mqds
Xiaogang Chen <[email protected]>
drm/amdkfd: Fix error path at svm_migrate_copy_to_ram
Priya Hosur <[email protected]>
drm/amdkfd: Add TLB flush after MES queue eviction/suspension
Sunil Khatri <[email protected]>
drm/amdgpu: use AMDGPU_GPU_PAGE_SHIFT instead of PAGE_SHIFT
Sunil Khatri <[email protected]>
drm/amdgpu: update the fw version for gfx12 userqueues
Sunil Khatri <[email protected]>
drm/amdgpu: update the fw version for gfx11 userqueues
Kanala Ramalingeswara Reddy <[email protected]>
drm/amdgpu: Skip accessing psp rum time db for APUs
Jesse Zhang <[email protected]>
drm/amdgpu: force complete the MES ring fences on reset
Jesse Zhang <[email protected]>
drm/amdgpu: force complete the KIQ ring fences on reset
Sunil Khatri <[email protected]>
drm/amdgpu: fix Idle BOs list in VM debugfs status info
Sunil Khatri <[email protected]>
drm/amdgpu: fix byte/dword unit mismatch in coredump IB dump
Guangshuo Li <[email protected]>
drm/amdgpu: fix autosuspend cleanup during removal
Yang Wang <[email protected]>
drm/amdgpu: Disable runtime PM for externally attached dGPUs
Xiang Liu <[email protected]>
drm/amdgpu: clamp the isolation index for rings outside a partition
Pierre-Eric Pelloux-Prayer <[email protected]>
drm/amdgpu: delay ttm buffer func enablement on xgmi
Yang Wang <[email protected]>
drm/amdgpu: check thunderbolt before switcheroo registration
Matthew Brost <[email protected]>
drm/ttm: Drop tt->restore after successful restore
Thadeu Lima de Souza Cascardo <[email protected]>
drm: Fix drm_crtc_commit leak if signaled when PAGE_FLIP_EVENT is used
Kavan Smith <[email protected]>
drm/msm/dsi: round 6G byte clock rate to the PLL-achievable value
Tao Yu <[email protected]>
drm/gud: validate TV mode names before creating enum property
Deepanshu Kartikey <[email protected]>
drm/gud: NUL-terminate TV mode names read from the device
David (Ming Qiang) Wu <[email protected]>
drm/amdgpu/vcn: fix integer overflow in dec_msg buffer count check
Alex Deucher <[email protected]>
drm/amdgpu/gfx8: only apply compute quantums to KCQs
Roman Li <[email protected]>
drm/amd/display: Set gpuvm min page size to 4K on dcn35/36
Austin Zheng <[email protected]>
drm/amd/display: Remove const Qualifier From Non-Pointer Fields
Harry Wentland <[email protected]>
drm/amd/display: validate plane degamma LUT size for private color prop
Timur Kristóf <[email protected]>
drm/amd/display: Fix HPD consideration for VGA/LVDS connectors on DCE
Linkai Gong <[email protected]>
drm/amd/display: fix dc_lock leak on GPU reset error paths
Harry Wentland <[email protected]>
drm/amd/display: avoid divide-by-zero in __is_lut_linear()
Thomas Zimmermann <[email protected]>
drm/hibmc: Use drm_atomic_helper_check_plane_state()
Thomas Zimmermann <[email protected]>
drm/hibmc: Fix list of formats on the primary plane
Lyude Paul <[email protected]>
drm/nouveau/disp/r535: Add scanline position support + head state support
Amit Barzilai <[email protected]>
drm/ssd130x: fix column and row end address in partial updates in ssd133x
Wentao Liang <[email protected]>
drm/sun4i: fix refcount leak in sun4i_backend_init_sat()
Amit Barzilai <[email protected]>
drm/ssd130x: fix column and row end address in partial updates for ssd132x
Deepanshu Kartikey <[email protected]>
drm/i915: Guard against NULL driver_data in i915_pci_probe()
Nemesa Garg <[email protected]>
drm/i915/display: Clear SEL_FETCH_PLANE_CTL on plane disable
Danilo Krummrich <[email protected]>
drm: fix race between partial drm_dev_register() failure and ioctl
Johan Hovold <[email protected]>
drm/panel-edp: fix i2c adapter leak on probe failure
Johan Hovold <[email protected]>
drm/bridge: dw-hdmi: fix i2c adapter leak on probe failure
Osama Abdelkader <[email protected]>
drm/panthor: fix firmware control interface bounds checks
Osama Abdelkader <[email protected]>
drm/panthor: harden firmware build-info bounds checks
Matthew Auld <[email protected]>
drm/xe/vram: report FLAT_CCS base misalignment
Bob Zhou <[email protected]>
drm/amdgpu: avoid force-completing uninitialized UVD rings
Thomas Hellström <[email protected]>
drm/amdgpu: Fix init ordering in amdgpu_vram_mgr_init()
Chao Yu <[email protected]>
f2fs: fix to zero post-EOF data when extending file size
Chao Yu <[email protected]>
f2fs: fix to pass folio->index to f2fs_sanity_check_node_footer()
Chao Yu <[email protected]>
f2fs: fix to reclaim space in f2fs_allocate_pinning_section()
Chen Changcheng <[email protected]>
f2fs: fix valid block count leak on data block allocation failure
Wenjie Qi <[email protected]>
f2fs: protect critical_task_priority updates with s_umount
Chao Yu <[email protected]>
f2fs: fix to clear dirty flag on folio in error path
Chao Yu <[email protected]>
f2fs: fix to off-by-one issue in f2fs_zero_post_eof_page()
Chao Yu <[email protected]>
f2fs: fix to return -EFSCORRUPTED in f2fs_get_node_info() correctly
Zhan Xusheng <[email protected]>
f2fs: fix i_size when pinned fallocate partially fails
Chao Yu <[email protected]>
f2fs: fix to avoid potential deadloop in f2fs_fsync_node_pages()
Daeho Jeong <[email protected]>
f2fs: fix to migrate all curseg types during free_segment_range
Wenjie Qi <[email protected]>
f2fs: avoid NULL checkpoint thread access in sysfs
Zhaoyang Huang <[email protected]>
f2fs: fix folio_nr_pages() race after put in large folio invalidate
Guanghui Yang <[email protected]>
f2fs: fix dentry folio leak in find_in_level
Chao Yu <[email protected]>
f2fs: embed f2fs_gc_kthread in f2fs_sb_info
Chao Yu <[email protected]>
f2fs: fix to avoid potential section-unaligned pinfile
Zhan Xusheng <[email protected]>
f2fs: don't drop the top folio order in the f2fs_iostat tracepoint
Wenjie Qi <[email protected]>
f2fs: limit recovery filename logging to stored length
Wenjie Qi <[email protected]>
f2fs: return writeback error from collapse range
Zhan Xusheng <[email protected]>
f2fs: use the mount idmap for the owner check in f2fs_xattr_advise_set()
Joanne Chang <[email protected]>
f2fs: dirty directory inodes on mtime/ctime update
Wenjie Qi <[email protected]>
f2fs: validate MOVE_RANGE destination size
Chao Yu <[email protected]>
f2fs: fix to avoid move_range and defragment on device_alias file
Wenjie Qi <[email protected]>
f2fs: only redirty pinned folios in redirty_blocks
Hao-Qun Huang <[email protected]>
f2fs: reject overlapping move range after len expansion
Wenjie Qi <[email protected]>
f2fs: return symlink writeback errors
Nilesh Javali <[email protected]>
scsi: qla2xxx: Skip NVMe LS reject IOCB when FW not started
Nilesh Javali <[email protected]>
scsi: qla2xxx: Zero-init bsg stack buffers to avoid info leak
Nilesh Javali <[email protected]>
scsi: qla2xxx: Use coherent DMA buffer for D_Port diagnostics
Nilesh Javali <[email protected]>
scsi: qla2xxx: Hold vport_slock for host map update in report ID acquisition
Nilesh Javali <[email protected]>
scsi: qla2xxx: Drop vport reference under lock in report ID acquisition
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix NVMe abort reference leak on repeated abort
Nilesh Javali <[email protected]>
scsi: qla2xxx: Avoid req_q_map double-read in qla2x00_error_entry()
Nilesh Javali <[email protected]>
scsi: qla2xxx: Bound rsp_info_len to avoid OOB sense-data read
Nilesh Javali <[email protected]>
scsi: qla2xxx: Avoid double completion in async IOCB timeout
Nilesh Javali <[email protected]>
scsi: qla2xxx: Quiesce response IRQ before freeing request queue
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix response queue over-consumption in __qla_consume_iocb()
Nilesh Javali <[email protected]>
scsi: qla2xxx: Reject non-SCSI SRB on status IOCB fast path
Nilesh Javali <[email protected]>
scsi: qla2xxx: Don't query firmware state while chip is down
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix FCE trace enable parsing in debugfs
Nilesh Javali <[email protected]>
scsi: qla2xxx: Zero mailbox struct in qla2x00_get_firmware_state()
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix FCE trace use-after-free during firmware dump
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix cs84xx use-after-free on host teardown
Nilesh Javali <[email protected]>
scsi: qla2xxx: Serialize flash version read in reset handler
Nilesh Javali <[email protected]>
scsi: qla2xxx: Clamp MSI-X derived queue counts to avoid truncation
Nilesh Javali <[email protected]>
scsi: qla2xxx: Hold qpair lock when sending NVMe LS reject
Nilesh Javali <[email protected]>
scsi: qla2xxx: Bound image count in qla2x00_update_fru_versions()
Nilesh Javali <[email protected]>
scsi: qla2xxx: Zero dport diagnostics buffer to avoid info leak
Nilesh Javali <[email protected]>
scsi: qla2xxx: Check entry_status in qla24xx_modify_vp_config()
Nilesh Javali <[email protected]>
scsi: qla2xxx: Initialize NVMe abort_work once at submission
Nilesh Javali <[email protected]>
scsi: qla2xxx: Hold vport reference in qla24xx_report_id_acquisition()
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix BSG job leak on validate flash image error path
Nilesh Javali <[email protected]>
scsi: qla2xxx: Fix Name Server logout detection on FWI2 adapters
Nilesh Javali <[email protected]>
scsi: qla2xxx: edif: Fix NULL pointer deref in RX SA delete check
Nilesh Javali <[email protected]>
scsi: qla2xxx: Bound i2c->length in I2C bsg handlers
Nilesh Javali <[email protected]>
scsi: qla2xxx: Zero SFP DMA buffer in FRU/I2C bsg handlers
Jackson Lee <[email protected]>
media: chips-media: wave5: Resume device before setting EOS flag
Jackson Lee <[email protected]>
media: chips-media: wave5: Fix pipeline stall when queuing fails
Jackson Lee <[email protected]>
media: chips-media: wave5: Defer job_finish() only when a DEC_PIC was queued
Jackson Lee <[email protected]>
media: chips-media: wave5: Add timeout while stop_streaming
Jackson Lee <[email protected]>
media: chips-media: wave5: avoid skipping device_run while VPU has work
Jackson Lee <[email protected]>
media: chips-media: wave5: Set inst->std during default format initialization
Jackson Lee <[email protected]>
media: chips-media: wave5: Guard bit depth check with initial_info_obtained
Wangao Wang <[email protected]>
media: qcom: iris: fix missing hfi_id in gen1 GOP_SIZE cap
Hungyu Lin <[email protected]>
media: qcom: iris: use disable_irq() during power-off
Dikshita Agarwal <[email protected]>
media: qcom: iris: fix state-change debug log printing stale value
Ruoyu Wang <[email protected]>
media: zoran: Avoid freeing a registered video_device twice
Arash Golgol <[email protected]>
media: vimc: fix pixel format lookup in enum_framesizes
Uday Khare <[email protected]>
media: video-i2c: fix kthread error pointer left in kthread_vid_cap on failure
Mohammed EL Kadiri <[email protected]>
media: venus: fix payload size calculation in parse_raw_formats()
Mohammed EL Kadiri <[email protected]>
media: venus: fix payload size returned by parse_caps() and parse_alloc_mode()
Biren Pandya <[email protected]>
media: v4l2-fwnode: Fix fwnode leak in v4l2_fwnode_parse_link
Ming Qian <[email protected]>
media: v4l2-ctrls: Allow unknown HDR10 white point and luminance
Michael Bommarito <[email protected]>
media: v4l2-ctrls: validate HEVC EXT SPS RPS counts
Xu Rao <[email protected]>
media: v4l2-async: avoid deleting unlinked ASC entry on link error
Fan Wu <[email protected]>
media: ti: vpe: quiesce overflow recovery before freeing streams
Ilya Krutskih <[email protected]>
media: tda18250: fix possible integer overflow
Guangshuo Li <[email protected]>
media: saa7164: fix cleanup on resource allocation failure
Lei Huang <[email protected]>
media: s2255: check firmware size before reading trailing marker
HyeongJun An <[email protected]>
media: s2255: bound JPEG frame size before copying into the buffer
Tommaso Merciai <[email protected]>
media: rzg2l-cru: Align bytesperline to hardware DMA stride requirement
Valery Borovsky <[email protected]>
media: rtl2832_sdr: release URBs and stream buffers on start_streaming() failure
Valery Borovsky <[email protected]>
media: rtl2832_sdr: use vb2_video_unregister_device() on remove to fix DMA leak
Michael Bommarito <[email protected]>
media: rkvdec: hevc: guard INTER_REF_PIC_SET_PRED index underflow
Michael Bommarito <[email protected]>
media: rkvdec: hevc: tighten EXT SPS RPS control dimensions
Narasimharao Vadlamudi <[email protected]>
media: rkvdec: Propagate platform_get_irq() errors
Sven Püschel <[email protected]>
media: rockchip: rga: don't change RGB quantization
Myeonghun Pak <[email protected]>
media: rc: sunxi-cir: Unregister rc device on probe failure
David Carlier <[email protected]>
media: mali-c55: Fix scaler factor overflow for large crop sizes
David Carlier <[email protected]>
media: mali-c55: Fix AEXP IHIST disable bit shift
David Carlier <[email protected]>
media: mali-c55: Fix clock leak on reset deassert failure
David Carlier <[email protected]>
media: mali-c55: fix dropped last AEC histogram zone weight
Guoniu Zhou <[email protected]>
media: nxp: imx8-isi: Use BIT_ULL() for 64-bit stream masks
Guoniu Zhou <[email protected]>
media: nxp: imx8-isi: Correct color map between V4L2 and ISI
Guoniu Zhou <[email protected]>
media: nxp: imx8-isi: Fix stream ID validation bypass in crossbar routing
Johan Hovold <[email protected]>
media: platform: mtk-mdp3: fix NULL deref on failed SCP lookup
Guangshuo Li <[email protected]>
media: platform: mtk-mdp3: Fix SCP device refcounting
Christian Hewitt <[email protected]>
media: meson: vdec: fix NULL pointer deref in vdec_try_fmt_common
Bryan O'Donoghue <[email protected]>
media: iris: Enumerate cap->bus_info to differentiate between encoder and decoder
José María Martín <[email protected]>
media: ipu-bridge: check all DMI entries when overriding sensor rotation
Cong Nguyen <[email protected]>
media: intel/ipu6: fix async notifier cleanup leak on parse error
Dave Stevenson <[email protected]>
media: imx355: Avoid calling imx355_power_off twice in error path
Benjamin Mugnier <[email protected]>
media: i2c: vd55g1: Fix media bus code initialization
Benjamin Mugnier <[email protected]>
media: i2c: vd55g1: Fix manual digital gain on color variant
Richard Leitner <[email protected]>
media: i2c: ov9282: restore flash duration calculation
Biren Pandya <[email protected]>
media: i2c: ov7740: fix use-after-destroy in remove
Biren Pandya <[email protected]>
media: i2c: ov02a10: fix endpoint parsing use-after-free
Narasimharao Vadlamudi <[email protected]>
media: i2c: imx415: Return test pattern write errors
Narasimharao Vadlamudi <[email protected]>
media: i2c: imx415: Release runtime PM reference on VBLANK error
Martin Hecht <[email protected]>
media: i2c: alvium: Fix: Correct name of register in alvium_set_ctrl_auto_exposure
Shuangpeng Bai <[email protected]>
media: go7007: defer the ALSA v4l2 put until card release
Jiangong.Han <[email protected]>
media: em28xx: fix use-after-free of dev_next->devlist on disconnect
Diego Fernando Mancera Gomez <[email protected]>
media: em28xx: defer audio-only extension registration
Guoniu Zhou <[email protected]>
media: dt-bindings: nxp,imx8-isi: Drop fsl,blk-ctrl requirement for i.MX8ULP
Fan Wu <[email protected]>
media: cx23885: cancel NetUP CI work before teardown
Bryam Vargas <[email protected]>
media: cx231xx: reject geometry changes while the VBI queue is busy
Ruoyu Wang <[email protected]>
media: cobalt: Avoid freeing ALSA private data twice
Dawei Feng <[email protected]>
media: cedrus: fix memory leak in cedrus_init_ctrls()
Ruoyu Wang <[email protected]>
media: cec: Serialize exclusive follower delivery
Yi Ding <[email protected]>
media: cec: meson: ao-cec-g12a: name the CEC core regmap to avoid debugfs clash
Hans Verkuil <[email protected]>
media: cec: extron-da-hd-4k-plus: add sanity check
Biren Pandya <[email protected]>
media: cec: disable delayed work before freeing an interrupted transmit
Jonas Karlman <[email protected]>
media: cec: core: Fix kmemleak due to missed rc_free_device() call
Eugen Hristev <[email protected]>
media: bcm2835-unicam: Fix pipeline wrong validation for unpacked formats
Ming Qian <[email protected]>
media: amphion: Remove obsolete frame_count check in venc_start_session
Valery Borovsky <[email protected]>
media: airspy: use vb2_video_unregister_device() on disconnect to fix NULL deref
Danilo Krummrich <[email protected]>
rust: drm: ioctl: fix unbounded lifetimes in ioctl handler arguments
Jérémy Jean <[email protected]>
LoongArch: Avoid preempt count underflow without probe
Wentao Guan <[email protected]>
LoongArch: Do not save/restore percpu base register in rethook trampoline
Nathan Chancellor <[email protected]>
LoongArch: Do not select HAVE_RUST when KASAN is enabled
Bibo Mao <[email protected]>
LoongArch: Fix acpi_package_ids[] array overflow
Tiezhu Yang <[email protected]>
LoongArch: BPF: Fix off-by-one error for insn_is_cast_user()
Tiezhu Yang <[email protected]>
LoongArch: BPF: Move arena register slot below TCC context
Tiezhu Yang <[email protected]>
LoongArch: Expand module virtual address space to 2GB
Tiezhu Yang <[email protected]>
LoongArch: BPF: Refactor jump offset calculation in tail call
Tiezhu Yang <[email protected]>
LoongArch: BPF: Optimize redundant TCC loads in epilogue
Han Gao <[email protected]>
LoongArch: Add DIRECT_MAP_PHYSMEM_END definition
Zeng Chi <[email protected]>
LoongArch: KVM: Validate MSI data before routing it to EIOINTC
Zeng Chi <[email protected]>
LoongArch: KVM: Preserve memslot arch flags on KVM_MR_FLAGS_ONLY
Chaithanya Lagisetty <[email protected]>
LoongArch: KVM: Free init resources if kvm_init() fails
Tao Cui <[email protected]>
LoongArch: KVM: Fix TOCTOU race on pv_features
Chaithanya Lagisetty <[email protected]>
LoongArch: KVM: Fix resource leak in kvm_loongarch_env_init() error path
Chaithanya Lagisetty <[email protected]>
LoongArch: KVM: Add unregister helpers for the KVM interrupt devices
Zeng Chi <[email protected]>
LoongArch: KVM: Fix PC double advance in kernel MMIO read fast path
Bibo Mao <[email protected]>
LoongArch: KVM: Fix uninitialized stack variable issue with dmsintc
Bibo Mao <[email protected]>
LoongArch: KVM: Set vcpu->cpu before IN_GUEST_MODE is set
Marc Zyngier <[email protected]>
KVM: arm64: Correctly cap TLBI Range to the architural limit
Fuad Tabba <[email protected]>
KVM: arm64: vgic-its: Don't dereference a NULL collection on ITT save
Fuad Tabba <[email protected]>
KVM: arm64: vgic: Reset in_kernel on private IRQ allocation failure
Kajetan Puchalski <[email protected]>
KVM: arm64: vgic: Fix detection of MI on no pending LR
Qihang <[email protected]>
KVM: arm64: vgic-v3: take an LPI reference in vgic_v3_save_pending_tables
Marc Zyngier <[email protected]>
KVM: arm64: Sign-extend VA for range-based TLBI invalidation
Marc Zyngier <[email protected]>
KVM: arm64: Remove VM-wide VNCR mapping counter
Marc Zyngier <[email protected]>
KVM: arm64: Make VNCR invalidation participate in MMU invalidation retry
Marc Zyngier <[email protected]>
KVM: arm64: Handle VNCR TLB invalidation race with vcpu_put() VNCR unmapping
Marc Zyngier <[email protected]>
KVM: arm64: Correctly handle end of VA space TLBI invalidation
Marc Zyngier <[email protected]>
KVM: arm64: Handle negative S1 walk levels in VNCR TLB size evaluation
Marc Zyngier <[email protected]>
KVM: arm64: Consider SCTLR_EL2.M when mapping the L1 VNCR page
Christian Borntraeger <[email protected]>
KVM: s390: Restore sigset on error path
Christian Borntraeger <[email protected]>
KVM: s390: pv: Fix rc/rrc offset for PVM_DUMP
Christian Borntraeger <[email protected]>
KVM: s390: keyop: use mmu_lock to read gmap->asce
Christian Borntraeger <[email protected]>
KVM: s390: Fix memory corruption by not reinjecting CK machine checks
Christian Borntraeger <[email protected]>
KVM: s390: Zero initialize irq in reinject_machine_check
Christian Borntraeger <[email protected]>
KVM: s390: Zero initialize data structures for inject_pfault_token
Christian Borntraeger <[email protected]>
KVM: s390: Take srcu when importing watchpoint data
Christian Borntraeger <[email protected]>
KVM: s390: Free guest debug data on vcpu destroy
Christian Borntraeger <[email protected]>
KVM: s390: Fix old_data leak in guest debug error path
Christian Borntraeger <[email protected]>
KVM: s390: Fix memory leak in guest debug handling
Christian Borntraeger <[email protected]>
KVM: s390: Fix length check __import_wp_info()
Yosry Ahmed <[email protected]>
KVM: x86: Move enabling EFER.SVME and EFER.LMSLE to generic EFER setup
Sean Christopherson <[email protected]>
KVM: x86: Ensure runtime reads of disabled_quirks are resolved once
Sean Christopherson <[email protected]>
KVM: x86: Serialize writes to disabled_quirks using kvm->lock
Carlos López <[email protected]>
KVM: x86: hyper-v: Clamp stimer deadline to avoid livelock
Phil Rosenthal <[email protected]>
KVM: x86/mmu: Consume the locked rmap value in the lockless rmap walk
Sean Christopherson <[email protected]>
KVM: x86/mmu: Use CMPXCHG when clearing Accessed bit in TDP MMU
Yosry Ahmed <[email protected]>
KVM: nVM: Ensure INVVPID is emulated on the correct physical CPU
Yosry Ahmed <[email protected]>
KVM: nVMX: Service local TLB flushes on failed nested VM-Enter
Sean Christopherson <[email protected]>
KVM: nVMX: Ensure KVM_REQ_GET_NESTED_STATE_PAGES is cleared on VM-Exit
Sean Christopherson <[email protected]>
KVM: nVMX: Decouple INVVPID operand checks from flushing of vpid02
Yosry Ahmed <[email protected]>
KVM: nVMX: Always flush vpid02 on first use
Amit Machhiwal <[email protected]>
KVM: PPC: Book3S HV: Validate arch_compat against host compatibility mode
Nikhil Gautam <[email protected]>
iio: light: opt4001: Fix reversed GENMASK() arguments in fault count mask
Nikhil Gautam <[email protected]>
iio: light: opt4001: Reject integration times with a non-zero seconds part
Nikhil Gautam <[email protected]>
iio: light: opt4001: Fix incompatible pointer type passed to div_u64_rem()
Nikhil Gautam <[email protected]>
iio: light: opt4001: Fix power down clearing bits of the wrong register
Vidhu Sarwal <[email protected]>
iio: light: opt4060: Fix incorrect register name in threshold read error message
Vidhu Sarwal <[email protected]>
iio: light: opt4060: Reject integration times with a non-zero seconds part
Paul Geurts <[email protected]>
iio: ti-ads7138: Disable STATS_EN bit while reading conversion results
Sanjay Chitroda <[email protected]>
iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register()
Cong Nguyen <[email protected]>
iio: srf04: fix pm_runtime handling on probe error path
Can Peng <[email protected]>
iio: pressure: mpl115: Fix runtime PM cleanup
Rupesh Majhi <[email protected]>
iio: pressure: dps310: fix NULL pointer dereference on ACPI probe
Vidhu Sarwal <[email protected]>
iio: light: ltrf216a: fix runtime PM reference leak in error path
Laxman Acharya Padhya <[email protected]>
iio: light: gp2ap002: Disable regulators on resume failure
Giorgi Tchankvetadze <[email protected]>
iio: light: cm32181: return zero after writing calibscale
Moksh Panicker <[email protected]>
iio: light: apds9306: fix PM reference leak in apds9306_read_data()
Francesco Lavra <[email protected]>
iio: imu: st_lsm6dsx: Update enable mask when using sensor fusion
Cong Nguyen <[email protected]>
iio: gyro: mpu3050: fix sign of raw angular velocity readings
Joshua Crofts <[email protected]>
iio: dac: mcp47feb02: add missing 'select REGMAP_I2C' to Kconfig
Erick Henrique <[email protected]>
iio: dac: m62332: Fix regulator reference count imbalance
Can Peng <[email protected]>
iio: dac: ad5446: fix OF module device table
Babanpreet Singh <[email protected]>
iio: dac: ad3552r-hs: fix scnprintf() buffer bound in data source show
Linmao Li <[email protected]>
iio: chemical: sgp30: Handle IAQ thread creation failure
Fan Wu <[email protected]>
iio: chemical: atlas-sensor: use iio_trigger_poll_nested() to fix remove UAF
Moksh Panicker <[email protected]>
iio: chemical: atlas-sensor: fix PM reference leak in buffer postenable
Lars-Peter Clausen <[email protected]>
iio: buffer: Tie IIO dma fence lock lifetime to the fence
Lars-Peter Clausen <[email protected]>
iio: buffer: Make IIO DMA fence release RCU-safe
Lars-Peter Clausen <[email protected]>
iio: buffer: Fix potential use-after-free in anonymous buffer release
Cong Nguyen <[email protected]>
iio: adc: pac1921: fix wrong channel used in trigger handler read
Joshua Crofts <[email protected]>
iio: adc: max34408: add missing 'select REGMAP_I2C' to Kconfig
Joshua Crofts <[email protected]>
iio: adc: max14001: add missing 'select REGMAP' to Kconfig
Antoniu Miclaus <[email protected]>
iio: adc: adi-axi-adc: add data size support for AD408X backend
Antoniu Miclaus <[email protected]>
iio: adc: ad4080: configure backend data size
Peter Ujfalusi <[email protected]>
ASoC: tas2783-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: tas2783-sdw: drop duplicate reg_default entry
Peter Ujfalusi <[email protected]>
ASoC: tas2780: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: tas2764: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: tas2552: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: sti-sas: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: sgtl5000: sort the register default table
WenTao Liang <[email protected]>
ASoC: samsung: aries_audio_probe: double of_node_put due to direct assignment without of_node_get
Peter Ujfalusi <[email protected]>
ASoC: rt721-sdca-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt715: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt715-sdca: sort the register default tables
Peter Ujfalusi <[email protected]>
ASoC: rt715-sdca: drop duplicate reg_default entries
Peter Ujfalusi <[email protected]>
ASoC: rt712-sdca-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt712-sdca-dmic: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt711: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt711-sdca: sort the register default tables
Peter Ujfalusi <[email protected]>
ASoC: rt700: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt700: drop duplicate reg_default entry
Peter Ujfalusi <[email protected]>
ASoC: rt298: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt286: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt274: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt1318: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt1318-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt1316-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: rt1017-sdca-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: pm4125-sdw: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: pcm512x: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: ml26124: sort the register default table
Peter Ujfalusi <[email protected]>
ASoC: max9860: sort the register default table
Binbin Zhou <[email protected]>
ASoC: loongson: Fix error handling in ACPI property parsing
Haoxiang Li <[email protected]>
AsoC: intel: sst: fix PCI device reference leak on probe failure
Haoxiang Li <[email protected]>
ASoC: hdac_hda: Fix hlink refcount leak on component registration failure
Peter Ujfalusi <[email protected]>
ASoC: fsl_easrc: sort the register default table
wangdicheng <[email protected]>
ASoC: fsl_easrc: Use div64_u64 for 64-by-64 division
Haoxiang Li <[email protected]>
ASoC: fsl: mpc5200-i2s: Free DMA resources on probe failure
Peter Ujfalusi <[email protected]>
ASoC: cx2072x: sort the register default table
Runyu Xiao <[email protected]>
ASoC: cs35l34: drain threaded IRQ before runtime suspend
Runyu Xiao <[email protected]>
ASoC: cs35l33: drain threaded IRQ before runtime suspend
Peter Ujfalusi <[email protected]>
ASoC: adau1761: sort the register default table
Linkai Gong <[email protected]>
i2c: mux: demux-pinctrl: fix OF node leak on kstrdup failure
Stephan Gerhold <[email protected]>
clk: qcom: gcc-mdm9607: Drop incorrect BIMC PLL and related clocks
Stephan Gerhold <[email protected]>
clk: qcom: gcc-mdm9607: Fix halt_reg for gcc_apss_axi_clk
Stephan Gerhold <[email protected]>
clk: qcom: gcc-mdm9607: Fix enable_reg for gcc_blsp1_sleep_clk
Stephan Gerhold <[email protected]>
clk: qcom: gcc-mdm9607: Drop incorrect system_noc_bfdcd_clk_src
Stephan Gerhold <[email protected]>
clk: qcom: gcc-mdm9607: Drop incorrect apss_tcu_clk_src
Heiko Stuebner <[email protected]>
clk: rockchip: rk3588: Don't change PLL rates when setting dclk_vop2_src
Stephan Gerhold <[email protected]>
clk: qcom: gcc-msm8939: Fix enable_reg for gcc_blsp1_sleep_clk
Stephan Gerhold <[email protected]>
clk: qcom: gcc-msm8916: Fix enable_reg for gcc_blsp1_sleep_clk
Pedro Kopper <[email protected]>
clk: microchip: mpfs: fix regmap_update_bits() mask/val order
Martin Blumenstingl <[email protected]>
clk: meson: align gxbb_32k_clk_sel number of parents with actual count
Akari Tsuyukusa <[email protected]>
clk: mediatek: mt8196: Select REGMAP_MMIO for vlpckgen
Pavel Löbl <[email protected]>
clk: clocking-wizard: fix integer overflow in rate calculation
Sven Eckelmann <[email protected]>
batman-adv: bla: prevent CRC corruptions after claim flush
Sven Eckelmann <[email protected]>
batman-adv: bla: fix freeing of claims on meshif deletion
Sven Eckelmann <[email protected]>
batman-adv: dat: avoid unaligned fault in IP extraction
Sven Eckelmann <[email protected]>
batman-adv: mcast: linearize skbuff for packet generation
Sven Eckelmann <[email protected]>
batman-adv: mcast: ensure unshared skb for multicast packets
Sven Eckelmann <[email protected]>
batman-adv: fix TX priority extraction for BATADV_FORW_MCAST
Zhiling Zou <[email protected]>
batman-adv: fix stale receive device on merged fragments
Pengpeng Hou <[email protected]>
mtd: rawnand: validate ONFI extended parameter page sections
James Hilliard <[email protected]>
mtd: rawnand: sunxi: fix H6/H616 controller timings
James Hilliard <[email protected]>
mtd: rawnand: sunxi: describe tADL and tWHR delays
James Hilliard <[email protected]>
mtd: rawnand: sunxi: group controller delay tables
Miquel Raynal (DAVE) <[email protected]>
mtd: rawnand: pl353: Make sure we use the monolithic helpers for raw accesses
Pengpeng Hou <[email protected]>
mtd: nand: realtek-ecc: add missing MODULE_DEVICE_TABLE()
Xu Rao <[email protected]>
mtd: mtdoops: free page bitmap when the backing MTD is removed
Pengpeng Hou <[email protected]>
mtd: afs: validate v2 image info bounds
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix required lock not held during update of ap_matrix_mdev object
Anthony Krowiak <[email protected]>
s390/vfio-ap: fix potential use of uninitialized apm_filtered bitmap
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix NULL deref in status_show() during queue probe
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix missing lock required to access list of ap_matrix_mdev objects
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix hot-unplug skipped when last AP adapter or domain removed
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix control domain removal in vfio_ap_mdev_cfg_remove
Anthony Krowiak <[email protected]>
s390/vfio-ap: Fix stale do_remove flag across iterations in vfio_ap_mdev_cfg_remove
Anthony Krowiak <[email protected]>
s390/vfio-ap: fix stale pqap_hook pointer on error in vfio_ap_mdev_set_kvm()
Sourabh Jain <[email protected]>
powerpc/crash: stop watchdogs before booting kdump kernel
Sourabh Jain <[email protected]>
powerpc/pseries: Move H_WATCHDOG definitions to a common header
Sourabh Jain <[email protected]>
powerpc/pseries: Handle and log pseries-wdt registration failures
Muchun Song <[email protected]>
powerpc/mm: fix wrong addr_pfn tracking in compound vmemmap population
Jinjie Ruan <[email protected]>
powerpc/kexec_file: Prevent kexec range truncation
Jinjie Ruan <[email protected]>
powerpc/kexec_file: Fix null-ptr-def in extra size calculation
Helge Deller <[email protected]>
parisc: Fix alignment of asm statements in head.S
Pei Xiao <[email protected]>
parisc: eisa: Fix infinite loop when parsing invalid IRQ value
Bryam Vargas <[email protected]>
nvdimm/btt: reject an arena whose nfree is below the lane count
Narek Jilavyan <[email protected]>
mm/hugetlb_cgroup: call page_counter_set_max() outside VM_BUG_ON()
Longlong Xia <[email protected]>
mm/hugetlb: keep max_huge_pages when dissolving surplus folios
Sourav Panda <[email protected]>
mm/hugetlb_cma: fix null nodemask dereference in hugetlb_cma_alloc_frozen_folio
Wupeng Ma <[email protected]>
mm/hugetlb: fix missing migratable flag on same-node hugetlb migration
Hui Su <[email protected]>
mm/migrate_device: avoid out-of-bounds writes for compound folios
Baolin Wang <[email protected]>
mm: fix incorrect vm_flags usage when checking allowable orders for tmpfs
Abel Vesa <[email protected]>
Revert "pmdomain: qcom: rpmhpd: Add missing MXC and MMCX power domains for Eliza"
Eric Dumazet <[email protected]>
Revert "once: don't use a work queue to reset sleepable static key"
caina <[email protected]>
Revert "irqchip/mbigen: Fix mbigen node address layout"
Christian Marangi <[email protected]>
pmdomain: airoha: fix unselectable AIROHA_CPU_PM_DOMAIN kconfig
Shivam Kumar <[email protected]>
nvmet-tcp: reject unsolicited H2CData PDUs
Shivam Kumar <[email protected]>
nvmet-tcp: fix out-of-bounds write when receiving an over-long PDU
Kazuki Hanai <[email protected]>
nvmet-auth: Synchronize timeout work during SQ teardown
Chao Shi <[email protected]>
nvme: skip the zoned limits update if the zone info query failed
Tristan Madani <[email protected]>
nvme: add missing SRCU grace period in error path
Yehyeong Lee <[email protected]>
nvme-tcp: check the data direction of a C2HData PDU
Niklas Cassel <[email protected]>
nvme-fc: fix double free of fabrics options when nvme_add_ctrl() fails
Xu Rao <[email protected]>
nvme-fabrics: fix DHCHAP secret leak on parse failure
GuoHan Zhao <[email protected]>
accel/ethosu: fix job completion fence cleanup
GuoHan Zhao <[email protected]>
accel/ethosu: check MMIO mapping errors in probe
Taimuraz Kaitmazov <[email protected]>
accel/amdxdna: return early from a zero-length flush
Vincent Donnefort <[email protected]>
ring-buffer: Allow splice reads on static buffers
Takashi Iwai <[email protected]>
ALSA: pcm: Fix race between non-atomic ops and trigger-start
Runyu Xiao <[email protected]>
ALSA: harmony: initialize locks before requesting IRQ
HyeongJun An <[email protected]>
ALSA: rawmidi: Return the error from snd_rawmidi_input_params()
Khushit Shah <[email protected]>
arm64: errata: pass REVIDR when matching target implementation CPUs
Fuad Tabba <[email protected]>
arm64: Don't read GMID_EL1 when MTE is disabled
Karl Mehltretter <[email protected]>
arm64: mm: Fix the lockless page-table walk in show_pte()
Guangshuo Li <[email protected]>
i2c: qcom-cci: fix autosuspend cleanup
Ahmad Byagowi <[email protected]>
i2c: mux: Fix channel node leak on adapter add failure
Vasileios Almpanis <[email protected]>
i2c: core: fix debugfs UAF on adapter removal
Kathiravan Thirumoorthy <[email protected]>
i2c: qcom-geni: update frequency table to fix timing parameters
Hongbo Yao <[email protected]>
i2c: designware: Enable interrupt mask workaround for HJMC3001
Yilin Zhang <[email protected]>
perf: Fix use-after-free when perf mmap() revival races with the last munmap()
Haiyong Sun <[email protected]>
perf build: Add clang and rust target flags for LoongArch
Sizhe Liu <[email protected]>
perf hisi-ptt: Fix PTT trace TLP header parsing
Viktor Malik <[email protected]>
perf trace: Refactor augmented_raw_syscalls using bpf_for
Viktor Malik <[email protected]>
perf trace: Factor out BPF loop body
Dapeng Mi <[email protected]>
perf/x86/intel: Remove anythread_deprecated bit from perf_capabilities
Dapeng Mi <[email protected]>
perf/x86/intel: Fix kernel address leakages in LBR stack
Lad Prabhakar <[email protected]>
rtc: rzn1: Disable alarm interrupt before reprogramming alarm registers
Lad Prabhakar <[email protected]>
rtc: rzn1: Handle unset alarm weekday in rzn1_rtc_read_alarm
Lad Prabhakar <[email protected]>
rtc: rzn1: Fix weekday underflow when alarm crosses month boundary
Lad Prabhakar <[email protected]>
rtc: rzn1: Handle EPROBE_DEFER for optional pps interrupt
Shakeel Butt <[email protected]>
memcg: make the v1 soft limit knob inert
Shakeel Butt <[email protected]>
memcg: bypass the reclaim and oom killer for dying tasks once oom_reaper is done
Shakeel Butt <[email protected]>
memcg: keep folio's objcg same as its node
Eric Dumazet <[email protected]>
mm/mempolicy: fix sleeping allocation in alloc_pages_bulk_weighted_interleave()
Usama Arif <[email protected]>
mm/huge_memory: transfer the pmd dirty bit to the folio on zap
Baineng Shou <[email protected]>
misc: fastrpc: don't publish fd before copy_to_user() succeeds
Masami Hiramatsu (Google) <[email protected]>
kprobes: Protect kprobe_blacklist with RCU
Ju Nan <[email protected]>
irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout
Bradley Morgan <[email protected]>
ima: Check for ERR_PTR from dentry_path() in validate_hash_algo()
Hajo Noerenberg <[email protected]>
ata: ahci: work around lost interrupts on Marvell 88SE61xx
Max Kellermann <[email protected]>
ceph: lock mutex in ceph_mds_check_access()
Hui Su <[email protected]>
bpf: Fix infinite loop in pcpu_freelist push with one possible CPU
Chen Pei <[email protected]>
bpf, riscv: Make arena support depend on ZACAS
Damien Le Moal <[email protected]>
block: flag zoned disks with GENHD_FL_NO_PART
Ulf Hansson <[email protected]>
cpuidle: psci: Fix support for probe deferral by dropping the faux device
Linkai Gong <[email protected]>
cpuidle: dt_idle_genpd: kfree() the original name allocation
Koichiro Den <[email protected]>
dmaengine: dw-edma: Mark emulated IRQ as level-triggered
Koichiro Den <[email protected]>
dmaengine: dw-edma: Initialize IRQ data before requesting IRQs
Koichiro Den <[email protected]>
dmaengine: dw-edma: Complete descriptors before pausing
Koichiro Den <[email protected]>
dmaengine: dw-edma: Fix HDMA channel status register access
Martin Kaiser <[email protected]>
dmaengine: fsl-edma: tracing: no ptr dereference during log output
Aneesh Kumar K.V (Arm) <[email protected]>
dma-direct: return struct page from dma_direct_alloc_from_pool()
Baineng Shou <[email protected]>
dma-buf: dma-heap: don't publish fd before copy_to_user() succeeds
Mikulas Patocka <[email protected]>
dm: fix resume-vs-remove race
Mikulas Patocka <[email protected]>
dm: fix race when loading and unloading a table
Ibrahim Hashimov <[email protected]>
HID: wacom: validate report length in wacom_intuos_pro2_bt_irq
Wei Jie Law <[email protected]>
HID: rmi: fix OOB access with undersized RMI reports
Shen Yongchao <[email protected]>
HID: bpf: serialize device reference release in struct_ops destroy path
Steven Rostedt <[email protected]>
ftrace: Synchronize the initialization of ftrace_ops
Steven Rostedt <[email protected]>
ftrace: Take trace_array reference before accessing its ftrace_ops
Sebastian Andrzej Siewior <[email protected]>
futex: Provide rt_mutex_.*_schedule() equivalents for futex scheduling
Yao Kai <[email protected]>
futex: Prevent rcuwait use-after-free during requeue PI
Lorenzo Stoakes (ARM) <[email protected]>
mm/secretmem: properly account locked pages
SJ Park <[email protected]>
mm/damon/core: initialize damos->last_applied
SJ Park <[email protected]>
mm/damon/core: handle region split failure in apply_min_nr_regions()
SJ Park <[email protected]>
mm/damon/core-kunit: skip wrong region walk in commit_target_regions()
SJ Park <[email protected]>
mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals()
SJ Park <[email protected]>
mm/damon/core-kunit: skip wrong dest walk in commit_dests_for()
SJ Park <[email protected]>
mm/damon/core-kunit: handle region split failure in filter_out()
SJ Park <[email protected]>
mm/damon/core-kunit: check region count before testing in split_at()
SJ Park <[email protected]>
mm/damon/sysfs: kobject_del() target (normal), context and kdamond dirs
SJ Park <[email protected]>
mm/damon/sysfs: kobject_del() region and target (error) dirs
SJ Park <[email protected]>
mm/damon/sysfs-schemes: kobject_del() scheme region dirs
SJ Park <[email protected]>
mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirs
SJ Park <[email protected]>
mm/damon/sysfs-schemes: kobject_del() scheme filter dirs
SJ Park <[email protected]>
mm/damon/sysfs-schemes: kobject_del() scheme dirs
SJ Park <[email protected]>
mm/damon/sysfs-schemes: kobject_del() scheme action destination dirs
SJ Park <[email protected]>
samples/damon/wsse: stop and free damon ctx when damon_call() fails
SJ Park <[email protected]>
samples/damon/wsse: handle damon_start() failure
SJ Park <[email protected]>
samples/damon/prcl: stop and free damon ctx when damon_call() fails
SJ Park <[email protected]>
samples/damon/prcl: handle damon_start() failure
SJ Park <[email protected]>
samples/damon/mtier: handle damon_stop() failure
SJ Park <[email protected]>
samples/damon/mtier: handle damon_start() failure
SJ Park <[email protected]>
mm/damon/vaddr-kunit: check region count in three_regions test
SJ Park <[email protected]>
mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of()
SJ Park <[email protected]>
mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
SJ Park <[email protected]>
mm/damon/sysfs: read addr_unit only once in damon_sysfs_apply_inputs()
Song Hu <[email protected]>
Docs/ABI/damon: fix typo in intervals_goal sysfs path
Runyu Xiao <[email protected]>
scsi: pm8001: Use rollback index when freeing MSI-X vectors
Thomas Lamprecht <[email protected]>
scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
Rahul Chandelkar <[email protected]>
scsi: bsg: Fix TOCTOU in io_uring passthrough command setup
Yang Xiuwei <[email protected]>
scsi: bsg: Cap io_uring sense copy to max_response_len
Sujal Tuladhar <[email protected]>
scsi: target: iscsi: Reserve a terminator byte for the login payload
Honghui Jiang <[email protected]>
spi: Fix DMA mapping ownership on partial map failure
Can Peng <[email protected]>
spi: bcmbca-hsspi: disable clocks on resume failure
Can Peng <[email protected]>
spi: bcm63xx: disable clock on resume failure
Can Peng <[email protected]>
spi: bcm63xx-hsspi: disable clocks on resume failure
Viken Dadhaniya <[email protected]>
soc: qcom: geni-se: Use HW PROG_RAM_DEPTH to validate firmware size
Paul Louvel <[email protected]>
soc: fsl: qe: Add chained_irq_{enter,exit}() calls in cascade handler
Kanishka De Silva <[email protected]>
ublk: clear VM_MAYWRITE on read-only ublk char device mmap
Bryan Lim <[email protected]>
userfaultfd: reset err to be 0 when move_pages_ptes succeeded
Steven Rostedt <[email protected]>
tracing: Take trace_array reference when opening options file
Steven Rostedt <[email protected]>
tracing: Have show_event_filters/triggers files take trace array ref
Masami Hiramatsu (Google) <[email protected]>
tracing/probes: Fix anon_stack check for unnamed bitfields in btf_find_struct_member
Can Peng <[email protected]>
thermal/drivers/qoriq: Disable clock on resume failure
Can Peng <[email protected]>
thermal/drivers/imx: Disable clock on runtime resume failure
Arthur Gautier <[email protected]>
xhci: fix lost bounce buffers on TDs spanning several ring segments
Muhammad Bilal <[email protected]>
staging: rtl8723bs: fix OOB read in rtw_restruct_wmm_ie()
Muhammad Bilal <[email protected]>
staging: rtl8723bs: fix OOB read in rtw_action_frame_parse()
Muhammad Bilal <[email protected]>
staging: rtl8723bs: fix OOB read / stack overflow in rtw_get_wps_attr()
Jeffin Philip <[email protected]>
usb: gadget: fix null pointer dereference in usb_put_function_instance()
Lovekesh Solanki <[email protected]>
USB: gadget: fix NULL pointer dereference in gadget_dev_ioctl()
Jeffin Philip <[email protected]>
usb: gadget: f_midi: initialize work in f_midi_alloc()
Ivy Lopez <[email protected]>
usb: gadget: f_midi2: fix use-after-free in string attribute show path
Jeffin Philip <[email protected]>
usb: gadget: f_mass_storage: fix null pointer dereference in fsg_common_set_num_buffers()
Aleksandr Nogikh <[email protected]>
usb: gadget: midi2: Fix null-pointer dereference in f_midi2_free_ep_reqs
Jameson Thies <[email protected]>
usb: typec: ucsi: displayport: Fix OOB altmode array index
Sven Peter <[email protected]>
usb: typec: tipd: Fix Thunderbolt altmode VDOs for cd321x
Amit Sunil Dhamne <[email protected]>
usb: typec: tcpm: constrain TCPM_SOURCING_VBUS event handling
Fan Wu <[email protected]>
usb: typec: qcom-pmic: cancel reset_work on stop
Fan Wu <[email protected]>
usb: typec: qcom-pmic-typec: drain cc_debounce_dwork if port_start() fails
Fan Wu <[email protected]>
usb: typec: qcom-pmic-typec: disable cc_debounce_dwork on stop
Marek Vasut <[email protected]>
usb: typec: mux: Fix typec_switch_match()
Marek Vasut <[email protected]>
usb: typec: mux: avoid duplicated mux switches
Chang Wu <[email protected]>
usb: typec: hd3ss3220: track VBUS enable state per consumer
Myeonghun Pak <[email protected]>
usb: storage: realtek_cr: fix use-after-free on disconnect
Elson Serrao <[email protected]>
usb: dwc3: clear forceRM when issuing EndTransfer
Radhey Shyam Pandey <[email protected]>
usb: dwc3: google: Initialise probe properties with DWC3_DEFAULT_PROPERTIES
Andy Shevchenko <[email protected]>
usb: f_mass_storage: Bump local buffer size in fsg_common_create_luns()
Pawel Laszczak <[email protected]>
usb: cdnsp: fix wakeup from S3 after controller context loss
Liu Qi <[email protected]>
usb-storage: ene_ub6250: fix race between scan work and probe
Shuangpeng Bai <[email protected]>
media: usbtv: keep device alive while ALSA card exists
Stephan Gerhold <[email protected]>
clk: qcom: gcc-mdm9607: Increase delay for USB PHY reset
HyeongJun An <[email protected]>
ALSA: usb-audio: fix OOB write in snd_usbmidi_us122l_output()
Griffin Kroah-Hartman <[email protected]>
usb: image: mdc800: change kmalloc() to kzalloc()
Hari Mishal <[email protected]>
drm/amd/display: fix division by zero in get_estimated_bw()
Chuck Lever <[email protected]>
NFSD: Prevent client use-after-free during blocked-lock reaping
Chuck Lever <[email protected]>
NFSD: Prevent client use-after-free during close_lru reaping
Chuck Lever <[email protected]>
NFSD: Consolidate the revocation-path client unpin
Chuck Lever <[email protected]>
NFSD: Prevent client use-after-free during export state revocation
Chuck Lever <[email protected]>
NFSD: Guard admin state-revocation walks with NFSD_NET_UP
Chuck Lever <[email protected]>
NFSD: Annotate caller preconditions for the state-table walkers
Sean Christopherson <[email protected]>
KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped
Sean Christopherson <[email protected]>
KVM: x86/mmu: Use split "zap all fast" helpers when invalidating memslot
Sean Christopherson <[email protected]>
KVM: x86/mmu: Split kvm_mmu_zap_all_fast() into "front" and "back" halves
Sean Christopherson <[email protected]>
KVM: x86/mmu: Fold kvm_mmu_zap_memslot() into kvm_arch_flush_shadow_memslot()
Rong Zhang <[email protected]>
ACPI: battery: Protect all properties with a separated mutex
Rong Zhang <[email protected]>
ACPI: battery: Use kstrtoul() over sscanf("%lu\n")
Doruk Tan Ozturk <[email protected]>
HID: sony: clean up device list on probe failure
Rosalie Wanders <[email protected]>
HID: sony: use guard() and scoped_guard()
Sam Edwards <[email protected]>
ceph: properly decrypt filenames in vmalloc() buffers
David Carlier <[email protected]>
zram: fix slot lock bit position on big-endian 64-bit
Sebastian Andrzej Siewior <[email protected]>
zram: move lockmap to be per-zram instead per table
Neill Kapron <[email protected]>
usb: gadget: f_fs: Fix Use-After-Free in AIO error path
Gabriel Prostitis <[email protected]>
USB: gadget: ffs: fix mm lifetime handling
Brendan Jackman <[email protected]>
mm/page_alloc: don't spin_trylock() in NMI on UP
Linus Torvalds <[email protected]>
drm/xe: Don't hand out the flat CCS storage as usable VRAM
HE WEI(ギカク) <[email protected]>
fs/ntfs3: fix slab-out-of-bounds write in ni_create_attr_list()
Norbert Szetei <[email protected]>
net: skbuff: don't skb_tx_error() the source skb in skb_zerocopy()
-------------
Diffstat:
Documentation/ABI/testing/sysfs-kernel-mm-damon | 8 +- Documentation/admin-guide/cgroup-v1/memory.rst | 49 +---- .../devicetree/bindings/media/nxp,imx8-isi.yaml | 4 +- Documentation/trace/hisi-ptt.rst | 28 +-- .../media/v4l/ext-ctrls-colorimetry.rst | 12 +- Makefile | 4 +- arch/arm64/include/asm/cpu.h | 1 + arch/arm64/include/asm/cpufeature.h | 7 - arch/arm64/include/asm/kvm_host.h | 3 - arch/arm64/include/asm/kvm_nested.h | 20 ++ arch/arm64/kernel/cpu_errata.c | 2 +- arch/arm64/kernel/cpufeature.c | 33 +++- arch/arm64/kernel/cpuinfo.c | 2 +- arch/arm64/kvm/at.c | 2 - arch/arm64/kvm/hyp/vhe/switch.c | 3 +- arch/arm64/kvm/nested.c | 139 +++++++++----- arch/arm64/kvm/sys_regs.c | 11 ++ arch/arm64/kvm/vgic/vgic-init.c | 1 + arch/arm64/kvm/vgic/vgic-its.c | 8 + arch/arm64/kvm/vgic/vgic-v3-nested.c | 2 +- arch/arm64/kvm/vgic/vgic-v3.c | 12 +- arch/arm64/mm/fault.c | 12 +- arch/loongarch/Kconfig | 2 +- arch/loongarch/include/asm/kvm_dmsintc.h | 1 + arch/loongarch/include/asm/kvm_eiointc.h | 1 + arch/loongarch/include/asm/kvm_host.h | 1 + arch/loongarch/include/asm/kvm_ipi.h | 1 + arch/loongarch/include/asm/kvm_pch_pic.h | 1 + arch/loongarch/include/asm/pgtable.h | 9 +- arch/loongarch/kernel/acpi.c | 3 +- arch/loongarch/kernel/kprobes.c | 3 + arch/loongarch/kernel/rethook_trampoline.S | 2 - arch/loongarch/kvm/exit.c | 1 - arch/loongarch/kvm/intc/dmsintc.c | 8 +- arch/loongarch/kvm/intc/eiointc.c | 5 + arch/loongarch/kvm/intc/ipi.c | 5 + arch/loongarch/kvm/intc/pch_pic.c | 8 + arch/loongarch/kvm/main.c | 39 +++- arch/loongarch/kvm/mmu.c | 10 + arch/loongarch/kvm/vcpu.c | 8 +- arch/loongarch/kvm/vm.c | 1 + arch/loongarch/mm/init.c | 17 +- arch/loongarch/net/bpf_jit.c | 40 ++-- arch/parisc/kernel/head.S | 1 + arch/powerpc/include/asm/papr-watchdog.h | 64 +++++++ arch/powerpc/include/asm/reg.h | 12 ++ arch/powerpc/kexec/file_load_64.c | 2 +- arch/powerpc/kexec/ranges.c | 12 +- arch/powerpc/kvm/book3s_hv.c | 15 +- arch/powerpc/kvm/powerpc.c | 6 + arch/powerpc/mm/book3s64/radix_pgtable.c | 7 +- arch/powerpc/platforms/pseries/setup.c | 28 ++- arch/riscv/net/bpf_jit_comp64.c | 10 +- arch/s390/include/asm/nmi.h | 3 + arch/s390/kernel/nmi.c | 5 +- arch/s390/kvm/guestdbg.c | 9 +- arch/s390/kvm/interrupt.c | 26 +-- arch/s390/kvm/kvm-s390.c | 22 ++- arch/x86/events/intel/core.c | 10 +- arch/x86/events/intel/lbr.c | 12 +- arch/x86/events/perf_event.h | 2 +- arch/x86/include/asm/kvm-x86-ops.h | 4 + arch/x86/include/asm/kvm_host.h | 6 + arch/x86/kvm/hyperv.c | 25 ++- arch/x86/kvm/mmu/mmu.c | 107 ++++++----- arch/x86/kvm/mmu/tdp_iter.h | 7 + arch/x86/kvm/mmu/tdp_mmu.c | 20 +- arch/x86/kvm/svm/sev.c | 80 ++++++-- arch/x86/kvm/svm/svm.c | 6 +- arch/x86/kvm/svm/svm.h | 2 + arch/x86/kvm/vmx/nested.c | 75 ++++---- arch/x86/kvm/x86.c | 17 +- arch/x86/kvm/x86.h | 2 +- block/genhd.c | 7 + drivers/accel/amdxdna/amdxdna_gem.c | 3 + drivers/accel/ethosu/ethosu_drv.c | 2 + drivers/accel/ethosu/ethosu_job.c | 10 +- drivers/acpi/battery.c | 155 +++++++++++----- drivers/ata/ahci.c | 49 +++++ drivers/block/ublk_drv.c | 6 + drivers/block/zram/zram_drv.c | 27 ++- drivers/block/zram/zram_drv.h | 16 +- drivers/clk/mediatek/Kconfig | 1 + drivers/clk/meson/gxbb.c | 2 +- drivers/clk/microchip/clk-mpfs.c | 2 +- drivers/clk/qcom/gcc-mdm9607.c | 182 +----------------- drivers/clk/qcom/gcc-msm8916.c | 5 +- drivers/clk/qcom/gcc-msm8939.c | 5 +- drivers/clk/rockchip/clk-rk3588.c | 2 +- drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 4 +- drivers/cpuidle/cpuidle-psci.c | 42 ++--- drivers/cpuidle/dt_idle_genpd.c | 3 +- drivers/dma-buf/dma-buf.c | 20 ++ drivers/dma-buf/dma-heap.c | 80 ++++---- drivers/dma/dw-edma/dw-edma-core.c | 24 ++- drivers/dma/dw-edma/dw-hdma-v0-core.c | 2 +- drivers/dma/fsl-edma-trace.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 7 + drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 59 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 +- drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 3 + drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 8 +- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 8 +- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 8 +- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 10 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 10 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 +- .../gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 23 ++- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 56 ++++-- .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 12 +- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 6 + .../drm/amd/display/amdgpu_dm/amdgpu_dm_color.c | 13 ++ .../dml21/src/dml2_core/dml2_core_shared_types.h | 4 +- .../display/dc/dml2_0/dml2_translation_helper.c | 1 + drivers/gpu/drm/amd/display/dc/link/link_factory.c | 2 +- .../display/dc/link/protocols/link_dp_dpia_bw.c | 5 + drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 3 +- drivers/gpu/drm/drm_atomic_uapi.c | 2 + drivers/gpu/drm/drm_drv.c | 34 +++- drivers/gpu/drm/drm_pagemap.c | 128 ++++++++++--- drivers/gpu/drm/gud/gud_connector.c | 12 +- drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 54 ++---- drivers/gpu/drm/i915/display/intel_cursor.c | 15 +- drivers/gpu/drm/i915/display/skl_universal_plane.c | 15 +- drivers/gpu/drm/i915/i915_pci.c | 3 + drivers/gpu/drm/msm/dsi/dsi_host.c | 12 ++ drivers/gpu/drm/nouveau/include/nvkm/engine/disp.h | 1 + drivers/gpu/drm/nouveau/nouveau_chan.c | 9 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 18 +- drivers/gpu/drm/nouveau/nouveau_sgdma.c | 4 +- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 6 +- drivers/gpu/drm/nouveau/nvkm/engine/device/base.c | 10 +- drivers/gpu/drm/nouveau/nvkm/engine/disp/Kbuild | 1 + drivers/gpu/drm/nouveau/nvkm/engine/disp/ga102.c | 13 +- drivers/gpu/drm/nouveau/nvkm/engine/disp/gb202.c | 191 +++++++++++++++++++ drivers/gpu/drm/nouveau/nvkm/engine/disp/gv100.c | 4 +- drivers/gpu/drm/nouveau/nvkm/engine/disp/head.h | 4 + drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h | 1 + drivers/gpu/drm/nouveau/nvkm/engine/disp/priv.h | 17 ++ drivers/gpu/drm/nouveau/nvkm/engine/disp/tu102.c | 86 ++++++++- .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/disp.c | 129 ++++++------- .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/disp.c | 64 +++++++ .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/gsp.c | 9 + .../nouveau/nvkm/subdev/gsp/rm/r570/nvrm/disp.h | 2 + drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 5 + drivers/gpu/drm/panel/panel-edp.c | 19 +- drivers/gpu/drm/panthor/panthor_fw.c | 22 ++- drivers/gpu/drm/solomon/ssd130x.c | 9 +- drivers/gpu/drm/sun4i/sun4i_backend.c | 2 +- drivers/gpu/drm/sysfb/ofdrm.c | 8 +- drivers/gpu/drm/sysfb/simpledrm.c | 74 ++++++-- drivers/gpu/drm/ttm/ttm_pool.c | 15 +- drivers/gpu/drm/xe/xe_vram.c | 26 ++- drivers/hid/bpf/hid_bpf_struct_ops.c | 17 +- drivers/hid/hid-rmi.c | 46 ++++- drivers/hid/hid-sony.c | 87 ++++----- drivers/hid/wacom_wac.c | 13 ++ drivers/i2c/busses/i2c-designware-platdrv.c | 2 +- drivers/i2c/busses/i2c-qcom-cci.c | 11 +- drivers/i2c/busses/i2c-qcom-geni.c | 4 +- drivers/i2c/i2c-core-base.c | 6 + drivers/i2c/i2c-mux.c | 1 + drivers/i2c/muxes/i2c-demux-pinctrl.c | 1 + drivers/iio/adc/Kconfig | 2 + drivers/iio/adc/ad4080.c | 5 + drivers/iio/adc/adi-axi-adc.c | 30 +++ drivers/iio/adc/pac1921.c | 2 +- drivers/iio/adc/ti-ads7138.c | 42 ++++- drivers/iio/chemical/atlas-sensor.c | 19 +- drivers/iio/chemical/sgp30.c | 3 + drivers/iio/dac/Kconfig | 1 + drivers/iio/dac/ad3552r-hs.c | 2 +- drivers/iio/dac/ad5446-i2c.c | 2 +- drivers/iio/dac/m62332.c | 17 +- drivers/iio/gyro/mpu3050-core.c | 2 +- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_fusion.c | 5 + drivers/iio/industrialio-buffer.c | 38 ++-- drivers/iio/light/apds9306.c | 8 +- drivers/iio/light/cm32181.c | 2 +- drivers/iio/light/gp2ap002.c | 10 +- drivers/iio/light/ltrf216a.c | 3 +- drivers/iio/light/opt4001.c | 37 ++-- drivers/iio/light/opt4060.c | 5 +- drivers/iio/pressure/dps310.c | 3 +- drivers/iio/pressure/mpl115.c | 11 +- drivers/iio/proximity/srf04.c | 1 + drivers/iio/temperature/hid-sensor-temperature.c | 3 +- drivers/irqchip/irq-mbigen.c | 20 +- drivers/irqchip/irq-stm32mp-exti.c | 4 +- drivers/md/dm.c | 14 +- drivers/media/cec/core/cec-adap.c | 10 +- drivers/media/cec/core/cec-core.c | 2 - drivers/media/cec/platform/meson/ao-cec-g12a.c | 1 + .../extron-da-hd-4k-plus/extron-da-hd-4k-plus.c | 3 +- drivers/media/dvb-frontends/rtl2832_sdr.c | 23 ++- drivers/media/i2c/alvium-csi2.c | 2 +- drivers/media/i2c/imx355.c | 3 +- drivers/media/i2c/imx415.c | 4 +- drivers/media/i2c/ov02a10.c | 12 +- drivers/media/i2c/ov7740.c | 4 +- drivers/media/i2c/ov9282.c | 3 +- drivers/media/i2c/vd55g1.c | 32 +++- drivers/media/i2c/video-i2c.c | 8 +- drivers/media/pci/cobalt/cobalt-alsa-main.c | 1 - drivers/media/pci/cx23885/cimax2.c | 1 + drivers/media/pci/intel/ipu-bridge.c | 8 +- drivers/media/pci/intel/ipu6/ipu6-isys.c | 1 + drivers/media/pci/saa7164/saa7164-core.c | 8 +- drivers/media/pci/zoran/zoran_card.c | 2 +- drivers/media/platform/amphion/venc.c | 2 - .../media/platform/arm/mali-c55/mali-c55-core.c | 2 + .../media/platform/arm/mali-c55/mali-c55-params.c | 1 + .../platform/arm/mali-c55/mali-c55-registers.h | 2 +- .../media/platform/arm/mali-c55/mali-c55-resizer.c | 2 +- drivers/media/platform/broadcom/bcm2835-unicam.c | 3 +- .../platform/chips-media/wave5/wave5-vpu-dec.c | 64 +++++-- .../platform/chips-media/wave5/wave5-vpu-enc.c | 6 +- .../platform/chips-media/wave5/wave5-vpuconfig.h | 2 +- .../media/platform/mediatek/mdp3/mtk-mdp3-core.c | 6 +- .../platform/nxp/imx8-isi/imx8-isi-crossbar.c | 6 +- .../media/platform/nxp/imx8-isi/imx8-isi-video.c | 2 +- drivers/media/platform/qcom/iris/iris_ctrls.c | 2 +- drivers/media/platform/qcom/iris/iris_hfi_gen1.c | 16 +- .../platform/qcom/iris/iris_platform_common.h | 1 - drivers/media/platform/qcom/iris/iris_state.c | 2 +- drivers/media/platform/qcom/iris/iris_vidc.c | 11 +- drivers/media/platform/qcom/iris/iris_vpu_common.c | 2 +- drivers/media/platform/qcom/venus/hfi_parser.c | 9 +- .../media/platform/renesas/rzg2l-cru/rzg2l-video.c | 5 + drivers/media/platform/rockchip/rga/rga3-hw.c | 12 +- .../platform/rockchip/rkvdec/rkvdec-hevc-common.c | 3 + drivers/media/platform/rockchip/rkvdec/rkvdec.c | 8 +- drivers/media/platform/ti/vpe/vip.c | 37 +++- drivers/media/rc/sunxi-cir.c | 9 +- drivers/media/test-drivers/vimc/vimc-capture.c | 4 +- drivers/media/tuners/tda18250.c | 4 +- drivers/media/usb/airspy/airspy.c | 19 +- drivers/media/usb/cx231xx/cx231xx-video.c | 4 +- drivers/media/usb/em28xx/em28xx-cards.c | 3 +- drivers/media/usb/em28xx/em28xx-core.c | 2 + drivers/media/usb/go7007/snd-go7007.c | 10 +- drivers/media/usb/s2255/s2255drv.c | 11 ++ drivers/media/usb/usbtv/usbtv-audio.c | 11 ++ drivers/media/v4l2-core/v4l2-async.c | 1 - drivers/media/v4l2-core/v4l2-ctrls-core.c | 64 +++++-- drivers/media/v4l2-core/v4l2-fwnode.c | 2 + drivers/misc/fastrpc.c | 16 +- drivers/mtd/mtdoops.c | 3 + drivers/mtd/nand/ecc-realtek.c | 1 + drivers/mtd/nand/raw/nand_onfi.c | 27 ++- drivers/mtd/nand/raw/pl35x-nand-controller.c | 5 +- drivers/mtd/nand/raw/sunxi_nand.c | 113 +++++++++--- drivers/mtd/parsers/afs.c | 7 + drivers/nvdimm/btt.c | 8 + drivers/nvme/host/core.c | 24 ++- drivers/nvme/host/fabrics.c | 2 + drivers/nvme/host/fc.c | 26 ++- drivers/nvme/host/tcp.c | 7 + drivers/nvme/target/auth.c | 6 + drivers/nvme/target/core.c | 2 +- drivers/nvme/target/nvmet.h | 2 + drivers/nvme/target/tcp.c | 10 + drivers/parisc/eisa.c | 5 + drivers/pci/hotplug/pnv_php.c | 2 +- drivers/pci/hotplug/rpaphp_slot.c | 2 +- drivers/pci/pci.c | 5 +- drivers/pci/slot.c | 50 +++-- drivers/pmdomain/mediatek/Kconfig | 5 +- drivers/pmdomain/qcom/rpmhpd.c | 4 - drivers/power/supply/ab8500_fg.c | 32 ++-- drivers/remoteproc/qcom_q6v5_pas.c | 13 +- drivers/rtc/rtc-rzn1.c | 30 ++- drivers/s390/crypto/vfio_ap_ops.c | 203 ++++++++++++++------- drivers/scsi/megaraid/megaraid_sas_base.c | 13 +- drivers/scsi/pm8001/pm8001_init.c | 4 +- drivers/scsi/qla2xxx/qla_attr.c | 6 +- drivers/scsi/qla2xxx/qla_bsg.c | 46 +++-- drivers/scsi/qla2xxx/qla_dbg.c | 2 +- drivers/scsi/qla2xxx/qla_dfs.c | 4 +- drivers/scsi/qla2xxx/qla_edif.c | 3 + drivers/scsi/qla2xxx/qla_gs.c | 4 +- drivers/scsi/qla2xxx/qla_init.c | 61 ++++++- drivers/scsi/qla2xxx/qla_inline.h | 13 ++ drivers/scsi/qla2xxx/qla_isr.c | 39 +++- drivers/scsi/qla2xxx/qla_mbx.c | 28 ++- drivers/scsi/qla2xxx/qla_nvme.c | 31 +++- drivers/scsi/qla2xxx/qla_os.c | 14 +- drivers/scsi/scsi_bsg.c | 47 +++-- drivers/soc/fsl/qe/qe_ports_ic.c | 7 + drivers/soc/qcom/qcom-geni-se.c | 24 +-- drivers/spi/spi-bcm63xx-hsspi.c | 8 +- drivers/spi/spi-bcm63xx.c | 6 +- drivers/spi/spi-bcmbca-hsspi.c | 8 +- drivers/spi/spi.c | 34 ++-- drivers/staging/media/meson/vdec/vdec.c | 4 +- drivers/staging/media/sunxi/cedrus/cedrus.c | 4 +- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 7 + drivers/staging/rtl8723bs/core/rtw_mlme.c | 3 + drivers/target/iscsi/iscsi_target_login.c | 2 +- drivers/thermal/imx_thermal.c | 9 +- drivers/thermal/qoriq_thermal.c | 13 +- drivers/usb/cdns3/cdnsp-gadget.c | 111 ++++++++++- drivers/usb/cdns3/cdnsp-gadget.h | 1 + drivers/usb/cdns3/cdnsp-mem.c | 98 ++++------ drivers/usb/dwc3/dwc3-google.c | 1 + drivers/usb/dwc3/ep0.c | 2 +- drivers/usb/dwc3/gadget.c | 21 ++- drivers/usb/gadget/function/f_fs.c | 31 +++- drivers/usb/gadget/function/f_mass_storage.c | 5 +- drivers/usb/gadget/function/f_midi.c | 2 +- drivers/usb/gadget/function/f_midi2.c | 17 +- drivers/usb/gadget/functions.c | 2 +- drivers/usb/gadget/legacy/inode.c | 3 +- drivers/usb/host/xhci-ring.c | 32 +++- drivers/usb/image/mdc800.c | 4 +- drivers/usb/storage/ene_ub6250.c | 2 + drivers/usb/storage/realtek_cr.c | 9 +- drivers/usb/typec/hd3ss3220.c | 9 +- drivers/usb/typec/mux.c | 21 ++- .../usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 2 + drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 5 + drivers/usb/typec/tcpm/tcpm.c | 28 ++- drivers/usb/typec/tipd/core.c | 17 +- drivers/usb/typec/tipd/tps6598x.h | 4 +- drivers/usb/typec/ucsi/displayport.c | 2 +- drivers/watchdog/pseries-wdt.c | 53 +----- fs/ceph/crypto.c | 50 +++-- fs/ceph/mds_client.c | 12 +- fs/ceph/mds_client.h | 1 + fs/f2fs/data.c | 8 +- fs/f2fs/debug.c | 4 - fs/f2fs/dir.c | 7 +- fs/f2fs/f2fs.h | 29 ++- fs/f2fs/file.c | 170 +++++++++++++---- fs/f2fs/gc.c | 38 ++-- fs/f2fs/gc.h | 27 +-- fs/f2fs/inline.c | 2 +- fs/f2fs/iostat.c | 6 + fs/f2fs/namei.c | 17 +- fs/f2fs/node.c | 10 +- fs/f2fs/recovery.c | 41 +++-- fs/f2fs/segment.c | 18 +- fs/f2fs/super.c | 4 +- fs/f2fs/sysfs.c | 30 +-- fs/f2fs/xattr.c | 2 +- fs/nfsd/nfs4proc.c | 5 + fs/nfsd/nfs4state.c | 118 ++++++++---- fs/nfsd/nfsctl.c | 6 +- fs/ntfs3/frecord.c | 20 +- fs/smb/server/oplock.c | 79 ++++++-- include/linux/dma-buf.h | 1 + include/linux/ftrace.h | 5 +- include/linux/kprobes.h | 1 + include/linux/kvm_host.h | 1 + include/linux/pci.h | 8 +- include/linux/sched/rt.h | 2 + include/linux/sched/user.h | 3 +- include/linux/soc/qcom/geni-se.h | 4 + include/trace/events/f2fs.h | 20 +- kernel/bpf/percpu_freelist.c | 35 +++- kernel/bpf/percpu_freelist.h | 1 + kernel/bpf/stackmap.c | 173 ++++++++++++------ kernel/dma/direct.c | 18 +- kernel/events/core.c | 20 +- kernel/futex/pi.c | 16 +- kernel/futex/requeue.c | 12 +- kernel/kprobes.c | 14 +- kernel/locking/rtmutex_api.c | 2 + kernel/sched/core.c | 16 ++ kernel/trace/ftrace.c | 70 ++++--- kernel/trace/ring_buffer.c | 11 +- kernel/trace/trace.c | 67 ++++++- kernel/trace/trace.h | 5 +- kernel/trace/trace_btf.c | 12 +- kernel/trace/trace_events.c | 28 ++- kernel/trace/trace_functions.c | 2 +- kernel/trace/trace_stack.c | 2 +- lib/once.c | 2 +- mm/damon/core.c | 27 ++- mm/damon/ops-common.c | 5 +- mm/damon/paddr.c | 20 +- mm/damon/sysfs-schemes.c | 18 +- mm/damon/sysfs.c | 29 ++- mm/damon/tests/core-kunit.h | 33 +++- mm/damon/tests/vaddr-kunit.h | 5 + mm/damon/vaddr.c | 34 +--- mm/huge_memory.c | 2 + mm/hugetlb.c | 20 +- mm/hugetlb_cgroup.c | 7 +- mm/hugetlb_cma.c | 21 ++- mm/khugepaged.c | 6 - mm/madvise.c | 8 + mm/memcontrol-v1.c | 43 +++-- mm/memcontrol.c | 113 ++++++++++-- mm/mempolicy.c | 2 +- mm/migrate_device.c | 18 ++ mm/page_alloc.c | 6 +- mm/secretmem.c | 116 +++++++++++- mm/userfaultfd.c | 4 +- net/batman-adv/bridge_loop_avoidance.c | 15 +- net/batman-adv/distributed-arp-table.c | 8 +- net/batman-adv/main.c | 4 + net/batman-adv/mesh-interface.c | 7 +- net/batman-adv/multicast_forw.c | 7 +- net/core/skbuff.c | 5 +- net/sunrpc/xprtrdma/ib_client.c | 26 ++- rust/kernel/drm/ioctl.rs | 6 + samples/damon/mtier.c | 14 +- samples/damon/prcl.c | 11 +- samples/damon/wsse.c | 11 +- security/integrity/ima/ima_appraise.c | 2 + sound/core/pcm_native.c | 2 + sound/core/rawmidi.c | 2 +- sound/parisc/harmony.c | 6 +- sound/soc/codecs/adau1761.c | 34 ++-- sound/soc/codecs/cs35l33.c | 14 +- sound/soc/codecs/cs35l34.c | 14 +- sound/soc/codecs/cx2072x.c | 134 +++++++------- sound/soc/codecs/hdac_hda.c | 4 +- sound/soc/codecs/max9860.c | 2 +- sound/soc/codecs/ml26124.c | 4 +- sound/soc/codecs/pcm512x.c | 40 ++-- sound/soc/codecs/pm4125-sdw.c | 2 +- sound/soc/codecs/rt1017-sdca-sdw.h | 10 +- sound/soc/codecs/rt1316-sdw.c | 2 +- sound/soc/codecs/rt1318-sdw.c | 2 +- sound/soc/codecs/rt1318.c | 4 +- sound/soc/codecs/rt274.c | 8 +- sound/soc/codecs/rt286.c | 14 +- sound/soc/codecs/rt298.c | 14 +- sound/soc/codecs/rt700-sdw.h | 11 +- sound/soc/codecs/rt711-sdca-sdw.h | 6 +- sound/soc/codecs/rt711-sdw.h | 10 +- sound/soc/codecs/rt712-sdca-dmic.h | 6 +- sound/soc/codecs/rt712-sdca-sdw.h | 11 +- sound/soc/codecs/rt715-sdca-sdw.h | 48 +++-- sound/soc/codecs/rt715-sdw.h | 32 ++-- sound/soc/codecs/rt721-sdca-sdw.h | 44 ++--- sound/soc/codecs/sgtl5000.c | 2 +- sound/soc/codecs/sti-sas.c | 2 +- sound/soc/codecs/tas2552.c | 14 +- sound/soc/codecs/tas2764.c | 2 +- sound/soc/codecs/tas2780.c | 2 +- sound/soc/codecs/tas2783-sdw.c | 177 +++++++++--------- sound/soc/fsl/fsl_easrc.c | 8 +- sound/soc/fsl/mpc5200_psc_i2s.c | 1 + sound/soc/intel/atom/sst/sst_pci.c | 4 +- sound/soc/loongson/loongson_card.c | 6 +- sound/soc/samsung/aries_wm8994.c | 1 + sound/usb/midi.c | 2 + tools/perf/Makefile.config | 2 + .../util/bpf_skel/augmented_raw_syscalls.bpf.c | 155 ++++++++++------ .../util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 47 ++--- .../util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 12 ++ tools/testing/selftests/mm/memfd_secret.c | 30 +-- virt/kvm/guest_memfd.c | 4 + 461 files changed, 5681 insertions(+), 2746 deletions(-)
Greg Kroah-Hartman
maintainerPATCH 1/556 net: skbuff: dont skb_tx_error() the source skb in skb_zerocopy()
7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Szetei <[email protected]>
[ Upstream commit 8ece906150128d5ec2462aabcc978c568433eca4 ]
skb_zerocopy() copies frags from @from into @to. On an skb_orphan_frags() failure it calls skb_tx_error(@from), a destructive operation on the source skb the copy helper does not own. That completes @from's zerocopy uarg and clears SKBFL_ALL_ZEROCOPY, including the SKBFL_SHARED_FRAG page-ownership marker.
Both callers already report the failure on their own drop path. nfnetlink_queue does it at nla_put_failure, and Open vSwitch does it in the flow-miss drop arm of ovs_dp_process_packet(), so nothing is lost by dropping it here.
On Open vSwitch's OVS_ACTION_ATTR_USERSPACE path the skb is not freed on this error: do_execute_actions() ignores output_userspace()'s return value and, unless the upcall was the last action, keeps forwarding the same skb through the flow's remaining actions. The uarg is completed while that skb is still in flight, telling the producer its buffers are free, and SKBFL_SHARED_FRAG is cleared on an skb the rest of the stack still handles. That flag is what makes esp_input() call skb_cow_data() instead of decrypting in place, so a later local ESP delivery can decrypt over frags the skb does not own privately.
Leave error reporting to the callers.
--- net/core/skbuff.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/core/skbuff.c +2 -3
@@ -3910,10 +3910,9 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)skb_len_add (to, len + plen); -if (unlikely (skb_orphan_frags (from,GFP_ATOMIC ))) { -skb_tx_error (from); +if (unlikely (skb_orphan_frags (from,GFP_ATOMIC )))return -ENOMEM ; - } +skb_zerocopy_clone (to, from,GFP_ATOMIC );for (i =0 ; i <skb_shinfo (from)->nr_frags; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2/556 fs/ntfs3: fix slab-out-of-bounds write in ni_create_attr_list()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: HE WEI(ギカク) <[email protected]>
commit 7c4841e2a62794a3bab7c1ff0540580f387e377f upstream.
ni_create_attr_list() allocates a fixed buffer of al_aligned(record_size) (== record_size) bytes and then walks every attribute of the primary MFT record, writing one ATTR_LIST_ENTRY per attribute and advancing the cursor by le_size(name_len), with no check against the end of the buffer; the total size is only computed after the loop.
A minimum-size resident attribute occupies SIZEOF_RESIDENT (0x18 = 24) bytes on disk, but an unnamed attribute expands to le_size(0) (0x20 = 32) bytes in the list. Because the number of attributes in a record is not bounded (mi_enum_attr() accepts arbitrarily many equal-type, nameless minimum-size attributes), a crafted record packed with such attributes produces a list larger than record_size and overflows the heap buffer.
This is reachable from a crafted, loop-mounted NTFS image: opening the file and adding an attribute (e.g. via setxattr) drives ntfs_set_ea() -> ni_insert_resident() -> ni_insert_attr() -> ni_ins_attr_ext() -> ni_create_attr_list().
BUG: KASAN: slab-out-of-bounds in ni_create_attr_list+0xc48/0x1058 Write of size 4 at addr ffff000008984c00 by task setfattr/345 ni_create_attr_list+0xc48/0x1058 ni_ins_attr_ext+0x510/0x7c0 ni_insert_attr+0x3f8/0x70c ni_insert_resident+0xc8/0x3b0 ntfs_set_ea+0x66c/0xd28 ntfs_setxattr+0x4d8/0x5b0 __arm64_sys_setxattr+0xa4/0x124 Allocated by task 345: ni_create_attr_list+0x188/0x1058 The buggy address belongs to the cache kmalloc-1k of size 1024 (the write lands at object+1024).
Size the buffer from the actual attributes instead of assuming a single record_size is always enough.
--- fs/ntfs3/frecord.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
fs/ntfs3/frecord.c +16 -4
@@ -768,10 +768,23 @@ int ni_create_attr_list(struct ntfs_inod rs = sbi->record_size;/* -* Skip estimating exact memory requirement. -* Looks like one record_size is always enough. +* Compute the exact size of the attribute list. Each attribute in the +* record yields one ATTR_LIST_ENTRY of le_size(name_len) bytes. The +* minimum on-disk attribute is SIZEOF_RESIDENT (0x18) bytes, but an +* unnamed one expands to le_size(0) (0x20) here, so a record crafted +* with many such attributes needs more than a single record_size; the +* previous fixed kzalloc(record_size) could therefore be overflowed by +* an attacker-controlled record. */ - le =kzalloc (al_aligned (rs),GFP_NOFS ); + lsize =0 ; + attr =NULL ; +while ((attr =mi_enum_attr (ni, &ni->mi, attr))) + lsize +=le_size (attr->name_len); + +if (!lsize) +return -EINVAL ; + + le =kzalloc (al_aligned (lsize),GFP_NOFS );if (!le)return -ENOMEM ;
@@ -781,7 +794,6 @@ int ni_create_attr_list(struct ntfs_inod attr =NULL ; nb =0 ; free_b =0 ; - attr =NULL ;for (; (attr =mi_enum_attr (ni, &ni->mi, attr)); le =Add2Ptr (le, sz)) { sz =le_size (attr->name_len);
Greg Kroah-Hartman
maintainerPATCH 3/556 drm/xe: Dont hand out the flat CCS storage as usable VRAM
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
commit 818bebeb63dd6bf5f4e07e145f6cdbace520a34c upstream.
get_flat_ccs_offset() reads the base of the flat CCS storage from the hardware, scales it by the number of enabled L3 nodes, and rounds the result up to 128K. Everything below that offset is then handed to the VRAM allocator as usable memory.
Rounding a limit that means "usable memory ends here" upwards publishes whatever lies between the real base and the rounded one as free memory, and that memory belongs to the compression hardware. The scaled value has no reason to be 128K aligned, and on a Battlemage G21 with 16 GiB it is not:
flat CCS base: raw 0x3fafff800, rounded 0x3fb000000
so the last 2 KiB of page 0x3fafff000 is CCS storage, in the allocator's pool. Whatever is allocated there gets that tail overwritten by the compression hardware, which needs no page-table entry, no buffer object and no GPU submission to do it, and does it before userspace exists.
On this machine a Mesa VM's level-3 page table landed on that page on every cold boot. It lost the entry covering the compositor's batch-buffer heap, so the compositor's first submission faulted fetching its batch and gdm restarted it forever: a black screen on an otherwise working machine. Restarting gdm cleared it because the next VM's page tables were allocated somewhere else.
Round down instead, to the page size the allocator works in. On this machine that excludes exactly one page.
Reading the reserved page afterwards shows what had been writing it:
[369] 0xcccc000000000000 [371] 0xcc77000000000000 [373] 0xcccc000000000000 [375] 0xcc77000000000000
compression metadata, two bytes per sixteen, sitting where the driver used to hand out memory.
The assertion that should have caught this compares the offset against GSMBASE - ccs_size for equality. That value is 128K aligned, so it agrees with the rounded-up offset precisely when the base is not aligned - the check cannot fail in the case it exists to catch, and is compiled out unless CONFIG_DRM_XE_DEBUG is set. Replace it with one that can fail: CCS storage must not run into GSM.
[ And this was a debug session from hell, enormously helped by an AI
doing much of the grunt-work.
I'd like to call it my tireless helper, but the AI several times stated flat out that this was impossible and unsolvable and that we should just write a report about it.
I suspect those things have been trained by people who may not be quite as stubborn as I am.
But while the AI was ready to give up several times, it did keep adding debug code and analyzing it faithfully when I pushed. So credit where credit is due and I let the AI write the commit message above.
This is basically a one-liner fixing a bogus "round_up()" to a "round_down()", but there were 24 patches adding more and more debug information to this, and 18 kernel boot to finally narrow it down to
this. - Linus ]
--- drivers/gpu/drm/xe/xe_vram.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_vram.c +18 -5
@@ -89,12 +89,25 @@ static int get_flat_ccs_offset(struct xe offset = offset_hi <<32 ;/* HW view bits 39:32 */ offset |= offset_lo <<6 ;/* HW view bits 31:6 */ offset *= num_enabled;/* convert to SW view */ - offset =round_up (offset,SZ_128K );/* SW must round up to nearest 128K */ -/* We don't expect any holes */ -xe_assert_msg (xe, offset == (xe_mmio_read64_2x32 (>_to_tile (gt)->mmio,GSMBASE ) - - ccs_size), -"Hole between CCS and GSM.\n" ); +/* +* Everything below this offset is handed to the VRAM +* allocator, so it has to be the *first* address the +* compression hardware owns, rounded down. Rounding it up +* publishes CCS storage as free memory. +*/ + offset =round_down (offset,SZ_4K ); + +/* +* CCS storage must not run into GSM. The old check compared +* the offset against GSMBASE - ccs_size for equality, which +* could not fail: that value is 128K aligned, so it agreed +* with the rounded-up offset even when the base was not 128K +* aligned - exactly the case this fixes. +*/ +xe_assert_msg (xe, offset + ccs_size <= +xe_mmio_read64_2x32 (>_to_tile (gt)->mmio,GSMBASE ), +"CCS overlaps GSM.\n" ); }else { reg =xe_gt_mcr_unicast_read_any (gt,XEHP_FLAT_CCS_BASE_ADDR ); offset = (u64 )REG_FIELD_GET (XEHP_FLAT_CCS_PTR , reg) *SZ_64K ;
Greg Kroah-Hartman
maintainerPATCH 4/556 mm/page_alloc: dont spin_trylock() in NMI on UP
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brendan Jackman <[email protected]>
[ Upstream commit 3105ae628fb785d48b49256468be4f21a7b3cfc0 ]
Patch series "mm/page_alloc: fixes for free_pages_nolock() on RT/UP".
Pre-existing bugs found by Sashiko during review of this other series:
https://lore.kernel.org/all/[email protected]/
I have not reproduced these bugs, and I suspect there is no real-world user that is affected by them.
This patch (of 2):
As noted in can_spin_trylock(), using this is unsafe in this context. commit 620b46ed6ae17 ("mm/page_alloc: return NULL early from alloc_frozen_pages_nolock() in NMI on UP") fixed this on the alloc side but missed the free side.
Impact: If BPF programs using these features in NMI (probably tracing) are present on non-SMP builds this might crash the kernel and is probably exploitable by local attackers for privilege escalation.
--- mm/page_alloc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/page_alloc.c +4 -2
@@ -2967,8 +2967,10 @@ static void __free_frozen_pages(struct p migratetype =MIGRATE_MOVABLE ; } -if (unlikely ((fpi_flags &FPI_TRYLOCK ) &&IS_ENABLED (CONFIG_PREEMPT_RT ) - && (in_nmi () ||in_hardirq ()))) { +if (unlikely ((fpi_flags &FPI_TRYLOCK ) && + ((IS_ENABLED (CONFIG_PREEMPT_RT ) && + (in_nmi () ||in_hardirq ())) || + (!IS_ENABLED (CONFIG_SMP ) &&in_nmi ())))) {add_page_to_zone_llist (zone, page, order);return ; }
Greg Kroah-Hartman
maintainerPATCH 5/556 USB: gadget: ffs: fix mm lifetime handling
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabriel Prostitis <[email protected]>
[ Upstream commit 5eb5c72c72fef76cb765ef1669b62b6a3ba1bfc8 ]
io_data stores a pointer to the submitting task's mm_struct, but does not currently hold a reference to it while async requests are pending.
This can result in a use-after-free if the task exits before completion handling finishes.
Take a reference with mmgrab() when queuing the read request and release it with mmdrop() on request completion.
Stable-dep-of: e78dcb1f7ec2 ("usb: gadget: f_fs: Fix Use-After-Free in AIO error path")
--- drivers/usb/gadget/function/f_fs.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-)
drivers/usb/gadget/function/f_fs.c +20 -7
@@ -873,9 +873,15 @@ static void ffs_user_copy_worker(structbool kiocb_has_eventfd = io_data->kiocb->ki_flags &IOCB_EVENTFD ;if (io_data->read && ret >0 ) { -kthread_use_mm (io_data->mm); - ret =ffs_copy_to_iter (io_data->buf, ret, &io_data->data); -kthread_unuse_mm (io_data->mm); +if (mmget_not_zero (io_data->mm)) { +kthread_use_mm (io_data->mm); + ret =ffs_copy_to_iter (io_data->buf, ret, &io_data->data); +kthread_unuse_mm (io_data->mm); +mmput (io_data->mm); + }else { + ret = -EFAULT ; + } +mmdrop (io_data->mm); } io_data->kiocb->ki_complete (io_data->kiocb, ret);
@@ -1270,16 +1276,20 @@ static ssize_t ffs_epfile_write_iter(str kiocb->private = p; -if (p->aio) +if (p->aio) { +mmgrab (p->mm);kiocb_set_cancel_fn (kiocb, ffs_aio_cancel); + } res =ffs_epfile_io (kiocb->ki_filp, p);if (res == -EIOCBQUEUED )return res; -if (p->aio) +if (p->aio) { +mmdrop (p->mm);kfree (p); -else + }else { *from = p->data; + }return res; }
@@ -1314,14 +1324,17 @@ static ssize_t ffs_epfile_read_iter(stru kiocb->private = p; -if (p->aio) +if (p->aio) { +mmgrab (p->mm);kiocb_set_cancel_fn (kiocb, ffs_aio_cancel); + } res =ffs_epfile_io (kiocb->ki_filp, p);if (res == -EIOCBQUEUED )return res;if (p->aio) { +mmdrop (p->mm);kfree (p->to_free);kfree (p); }else {
Greg Kroah-Hartman
maintainerPATCH 6/556 usb: gadget: f_fs: Fix Use-After-Free in AIO error path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Neill Kapron <[email protected]>
[ Upstream commit e78dcb1f7ec271449c54984dc90c62a5ba272de7 ]
In ffs_epfile_write_iter() and ffs_epfile_read_iter(), when ffs_epfile_io() fails with an error other than -EIOCBQUEUED, the io_data structure (p) is freed. However, for AIO operations, the kiocb cancel function was already armed and kiocb->private was set to p.
If a concurrent cancel operation (such as sys_io_cancel()) executes after ffs_epfile_io() fails but before the function frees p, a Use-After-Free can occur when the cancellation handler accesses the freed pointer.
To securely fix this race condition, we must properly un-arm the cancellation. Invoking kiocb->ki_complete() does exactly this by acquiring ctx->ctx_lock and safely removing the kiocb from the active sequence. In doing so, it ensures that a parallel io_cancel can no longer discover the kiocb, effectively closing the race window.
We then return -EIOCBQUEUED to notify the VFS layer that the kiocb has been consumed and it should avoid attempting to complete the request again or triggering subsequent completion handlers.
--- drivers/usb/gadget/function/f_fs.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/gadget/function/f_fs.c +4 -0
@@ -1285,8 +1285,10 @@ static ssize_t ffs_epfile_write_iter(strif (res == -EIOCBQUEUED )return res;if (p->aio) { + kiocb->ki_complete (kiocb, res);mmdrop (p->mm);kfree (p); +return -EIOCBQUEUED ; }else { *from = p->data; }
@@ -1334,9 +1336,11 @@ static ssize_t ffs_epfile_read_iter(strureturn res;if (p->aio) { + kiocb->ki_complete (kiocb, res);mmdrop (p->mm);kfree (p->to_free);kfree (p); +return -EIOCBQUEUED ; }else { *to = p->data; }
Greg Kroah-Hartman
maintainerPATCH 7/556 zram: move lockmap to be per-zram instead per table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit dbb7ba9c7fa81a48ed2a108ad684cf3655f3ae4b ]
Patch series "zram: lockmap tweaks".
This patch (of 2):
The zram object contains an array zram_table_entry. Each one has a `lock' variable and each has a matching struct lockdep_map. This mimics a struct mutex.
It uses always the same key for all lockdep_map instances. This makes it look like the same lock to lockdep. Therefore it could be reduced to have one lockdep_map per struct zram.
Use only one struct lockdep_map per struct zram.
Stable-dep-of: a8b5875741d4 ("zram: fix slot lock bit position on big-endian 64-bit")
--- drivers/block/zram/zram_drv.c | 21 +++++++++------------ drivers/block/zram/zram_drv.h | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-)
drivers/block/zram/zram_drv.c +9 -12
@@ -57,14 +57,12 @@ static size_t huge_class_size;static const struct block_device_operations zram_devops;static void slot_free (struct zram *zram,u32 index); -#define slot_dep_map (zram, index) (&(zram)->table[(index)].dep_map) -static void slot_lock_init (struct zram *zram,u32 index) +static void slot_lock_init (struct zram *zram) {static struct lock_class_key __key; -lockdep_init_map (slot_dep_map (zram, index),"zram->table[index].lock" , - &__key,0 ); +lockdep_init_map (&zram->table_lock_map,"zram->table[index].lock" , &__key,0 ); }/*
@@ -84,8 +82,8 @@ static __must_check bool slot_trylock(stunsigned long *lock = &zram->table[index].__lock;if (!test_and_set_bit_lock (ZRAM_ENTRY_LOCK , lock)) { -mutex_acquire (slot_dep_map (zram, index),0 ,1 , _RET_IP_); -lock_acquired (slot_dep_map (zram, index), _RET_IP_); +mutex_acquire (&zram->table_lock_map,0 ,1 , _RET_IP_); +lock_acquired (&zram->table_lock_map, _RET_IP_);return true; }
@@ -96,16 +94,16 @@ static void slot_lock(struct zram *zram, {unsigned long *lock = &zram->table[index].__lock; -mutex_acquire (slot_dep_map (zram, index),0 ,0 , _RET_IP_); +mutex_acquire (&zram->table_lock_map,0 ,0 , _RET_IP_);wait_on_bit_lock (lock,ZRAM_ENTRY_LOCK ,TASK_UNINTERRUPTIBLE ); -lock_acquired (slot_dep_map (zram, index), _RET_IP_); +lock_acquired (&zram->table_lock_map, _RET_IP_); }static void slot_unlock (struct zram *zram,u32 index) {unsigned long *lock = &zram->table[index].__lock; -mutex_release (slot_dep_map (zram, index), _RET_IP_); +mutex_release (&zram->table_lock_map, _RET_IP_);clear_and_wake_up_bit (ZRAM_ENTRY_LOCK , lock); }
@@ -1989,7 +1987,7 @@ static void zram_meta_free(struct zram *static bool zram_meta_alloc (struct zram *zram,u64 disksize) { -size_t num_pages, index; +size_t num_pages; num_pages = disksize >>PAGE_SHIFT ; zram->table =vzalloc (array_size (num_pages,sizeof (*zram->table)));
@@ -2006,8 +2004,7 @@ static bool zram_meta_alloc(struct zramif (!huge_class_size) huge_class_size =zs_huge_class_size (zram->mem_pool); -for (index =0 ; index < num_pages; index++) -slot_lock_init (zram, index); +slot_lock_init (zram);return true; }
drivers/block/zram/zram_drv.h +1 -1
@@ -74,7 +74,6 @@ struct zram_table_entry {#endif } attr; }; -struct lockdep_map dep_map; };struct zram_stats {
@@ -107,6 +106,7 @@ struct zram_stats {struct zram {struct zram_table_entry *table; +struct lockdep_map table_lock_map;struct zs_pool *mem_pool;struct zcomp *comps[ZRAM_MAX_COMPS ];struct zcomp_params params[ZRAM_MAX_COMPS ];
Greg Kroah-Hartman
maintainerPATCH 8/556 zram: fix slot lock bit position on big-endian 64-bit
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Carlier <[email protected]>
[ Upstream commit a8b5875741d416703e19ad8eeac6fce8a12bd6e4 ]
The slot lock is a bit operation on the whole __lock word, which flags and ac_time alias as two u32s. On little-endian the lock bit lands in the position ZRAM_ENTRY_LOCK reserves in flags, so the aliasing works out. On 64-bit big-endian it lands in ac_time instead: with ZRAM_TRACK_ENTRY_ACTIME enabled, storing the access time from mark_slot_accessed() or slot_free() wipes out the held lock bit, letting another CPU take the same slot lock; an access time value with that bit set makes the slot look locked forever.
Shift the lock bit into the flags half of the word on big-endian 64-bit.
--- drivers/block/zram/zram_drv.c | 6 +++--- drivers/block/zram/zram_drv.h | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/block/zram/zram_drv.c +3 -3
@@ -81,7 +81,7 @@ static __must_check bool slot_trylock(st {unsigned long *lock = &zram->table[index].__lock; -if (!test_and_set_bit_lock (ZRAM_ENTRY_LOCK , lock)) { +if (!test_and_set_bit_lock (ZRAM_ENTRY_LOCK_BIT , lock)) {mutex_acquire (&zram->table_lock_map,0 ,1 , _RET_IP_);lock_acquired (&zram->table_lock_map, _RET_IP_);return true;
@@ -95,7 +95,7 @@ static void slot_lock(struct zram *zram,unsigned long *lock = &zram->table[index].__lock;mutex_acquire (&zram->table_lock_map,0 ,0 , _RET_IP_); -wait_on_bit_lock (lock,ZRAM_ENTRY_LOCK ,TASK_UNINTERRUPTIBLE ); +wait_on_bit_lock (lock,ZRAM_ENTRY_LOCK_BIT ,TASK_UNINTERRUPTIBLE );lock_acquired (&zram->table_lock_map, _RET_IP_); }
@@ -104,7 +104,7 @@ static void slot_unlock(struct zram *zraunsigned long *lock = &zram->table[index].__lock;mutex_release (&zram->table_lock_map, _RET_IP_); -clear_and_wake_up_bit (ZRAM_ENTRY_LOCK , lock); +clear_and_wake_up_bit (ZRAM_ENTRY_LOCK_BIT , lock); }static inline bool init_done (struct zram *zram)
drivers/block/zram/zram_drv.h +14 -0
@@ -15,6 +15,7 @@#ifndef _ZRAM_DRV_H_#define _ZRAM_DRV_H_ +#include <asm/byteorder.h> #include <linux/rwsem.h> #include <linux/zsmalloc.h>
@@ -58,6 +59,19 @@ enum zram_pageflags { };/* +* The slot lock is a bit-wait lock on the whole __lock word, while +* flags and ac_time alias that word as two u32s. The lock bit must +* land in the slot that ZRAM_ENTRY_LOCK reserves in attr.flags; on +* 64-bit big-endian the flags word maps to the upper half of __lock, +* so the bit position has to be shifted up. +*/ +#if defined(CONFIG_64BIT ) && defined(__BIG_ENDIAN) +#define ZRAM_ENTRY_LOCK_BIT (ZRAM_ENTRY_LOCK + 32) +#else +#define ZRAM_ENTRY_LOCK_BIT ZRAM_ENTRY_LOCK +#endif + +/* * Allocated for each disk page. We use bit-lock (ZRAM_ENTRY_LOCK bit * of flags) to save memory. There can be plenty of entries and standard * locking primitives (e.g. mutex) will significantly increase sizeof()
Greg Kroah-Hartman
maintainerPATCH 9/556 ceph: properly decrypt filenames in vmalloc() buffers
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sam Edwards <[email protected]>
[ Upstream commit e939fc6a7bd969a58a150b7f188c1047138403e3 ]
The fscrypt subsystem uses the scatterlist crypto API, inheriting its requirement that any buffers are in the linear mapping region. However, the messenger client uses kvmalloc() to create buffers for messages, which will occasionally place those buffers in the vmalloc() region when physical memory fragmentation doesn't permit a large enough kmalloc(). The various callers of ceph_fname_to_usr() directly pass (slices of) raw messages from the MDS without considering that the messages may be in vmalloc() buffers, resulting in oopses especially on non-x86 platforms (see 'Closes:' for more details and a reproducer).
Make ceph_fname_to_usr() explicitly tolerant of vmalloc()-allocated fname->ctext, fname->name, and/or oname->name buffers, using tname (which, when non-null, must be a linear address; when null, is briefly allocated as necessary) as a bounce buffer to avoid passing any inappropriate addresses to fscrypt_fname_disk_to_usr().
Additionally change parse_reply_info_readdir() -- the only function to supply its own tname -- to follow the new "tname must never come from vmalloc()" rule by passing NULL when the message is not in the linear region. Though this causes a per-dentry kmalloc()+kfree(), this overhead exists only when processing the minority of messages that spill into vmalloc(). My (crude) testing puts this at only about 1 in 8,000 readdir messages. Still, if the overhead proves unreasonable in the future, it is easy enough to mitigate: a future change could allocate a bounce buffer in parse_reply_info_readdir() and use that as tname instead.
--- fs/ceph/crypto.c | 50 +++++++++++++++++++++++++++++++++++++++----------- fs/ceph/mds_client.c | 8 ++++++-- 2 files changed, 45 insertions(+), 13 deletions(-)
fs/ceph/crypto.c +39 -11
@@ -298,6 +298,11 @@ out:* Otherwise, base64 decode the string, and then ask fscrypt to format it * for userland presentation. * +* Though the fscrypt/crypto subsystems broadly expect all buffers to be in the +* linear-mapped region, this function slightly relaxes those requirements: +* fname->ctext, fname->name, and oname->name may be vmalloc(), but not +* tname->name. +* * Returns 0 on success or negative error code on error. */ int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname,
@@ -305,11 +310,15 @@ int ceph_fname_to_usr(const struct ceph_ {struct inode *dir = fname->dir;struct fscrypt_str _tname =FSTR_INIT (NULL ,0 ); +struct fscrypt_str _oname;struct fscrypt_str iname;char *name = fname->name;int name_len = fname->name_len;int ret; +if (WARN_ON_ONCE (tname &&is_vmalloc_addr (tname->name))) +return -EIO ; +/* Sanity check that the resulting name will fit in the buffer */ if (fname->name_len >NAME_MAX || fname->ctext_len >NAME_MAX )return -EIO ;
@@ -350,31 +359,50 @@ int ceph_fname_to_usr(const struct ceph_ goto out_inode; } +if ((!tname || !tname->name) && + (fname->ctext_len ==0 || +unlikely (is_vmalloc_addr (fname->ctext)) || +unlikely (is_vmalloc_addr (oname->name)))) { + ret =fscrypt_fname_alloc_buffer (NAME_MAX , &_tname); +if (ret) + goto out_inode; + tname = &_tname; + } +if (fname->ctext_len ==0 ) {int declen; -if (!tname) { - ret =fscrypt_fname_alloc_buffer (NAME_MAX , &_tname); -if (ret) - goto out_inode; - tname = &_tname; - } - - declen =base64_decode (name, name_len, - tname->name, false,BASE64_IMAP ); + declen =base64_decode (name, name_len, tname->name, false, +BASE64_IMAP );if (declen <=0 ) { ret = -EIO ; goto out; } iname.name = tname->name; iname.len = declen; + }else if (unlikely (is_vmalloc_addr (fname->ctext))) { +memcpy (tname->name, fname->ctext, fname->ctext_len); + + iname.name = tname->name; + iname.len = fname->ctext_len; }else { iname.name = fname->ctext; iname.len = fname->ctext_len; } - ret =fscrypt_fname_disk_to_usr (dir,0 ,0 , &iname, oname); -if (!ret && (dir != fname->dir)) { + _oname.name =unlikely (is_vmalloc_addr (oname->name)) ? + tname->name : oname->name; + _oname.len = oname->len; + + ret =fscrypt_fname_disk_to_usr (dir,0 ,0 , &iname, &_oname); +if (ret) + goto out; + +if (unlikely (is_vmalloc_addr (oname->name))) +memcpy (oname->name, _oname.name, _oname.len); + oname->len = _oname.len; + +if (dir != fname->dir) {char tmp_buf[BASE64_CHARS (NAME_MAX )]; name_len = snprintf(tmp_buf, sizeof(tmp_buf), "_%.*s_%llu",
fs/ceph/mds_client.c +6 -2
@@ -541,9 +541,13 @@ static int parse_reply_info_readdir(void* to do the base64_decode in-place. It's * safe because the decoded string should * always be shorter, which is 3/4 of origin -* string. +* string. If this message was allocated with +* vmalloc() (happens, but rarely), leave it +* NULL and let ceph_fname_to_usr() allocate +* suitable temporary working space instead. */ - tname.name = _name; +if (likely (!is_vmalloc_addr (_name))) + tname.name = _name;/* * Set oname to _name too, and this will be
Greg Kroah-Hartman
maintainerPATCH 10/556 HID: sony: use guard() and scoped_guard()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosalie Wanders <[email protected]>
[ Upstream commit da4f817ad273bca9aefd8636d347a8c101069111 ]
This replaces the spin_lock_irqsave() and spin_unlock_irqrestore() calls with the RAII guard() and scoped_guard().
Stable-dep-of: 7c65699a3a31 ("HID: sony: clean up device list on probe failure")
--- drivers/hid/hid-sony.c | 62 ++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 36 deletions(-)
drivers/hid/hid-sony.c +26 -36
@@ -29,6 +29,7 @@* There will be no PIN request from the device. */ +#include <linux/cleanup.h> #include <linux/device.h> #include <linux/hid.h> #include <linux/module.h>
@@ -569,14 +570,12 @@ static void sony_set_leds(struct sony_scstatic inline void sony_schedule_work (struct sony_sc *sc,enum sony_worker which) { -unsigned long flags; -switch (which) {case SONY_WORKER_STATE : -spin_lock_irqsave (&sc->lock, flags); -if (!sc->defer_initialization && sc->state_worker_initialized) -schedule_work (&sc->state_worker); -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { +if (!sc->defer_initialization && sc->state_worker_initialized) +schedule_work (&sc->state_worker); + }break ; } }
@@ -949,7 +948,6 @@ static const u8 *sony_report_fixup(strucstatic void sixaxis_parse_report (struct sony_sc *sc,u8 *rd,int size) {static const u8 sixaxis_battery_capacity[] = {0 ,1 ,25 ,50 ,75 ,100 }; -unsigned long flags;int offset;u8 index;u8 battery_capacity;
@@ -972,10 +970,10 @@ static void sixaxis_parse_report(struct battery_status =POWER_SUPPLY_STATUS_DISCHARGING ; } -spin_lock_irqsave (&sc->lock, flags); - sc->battery_capacity = battery_capacity; - sc->battery_status = battery_status; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->battery_capacity = battery_capacity; + sc->battery_status = battery_status; + }if (sc->quirks &SIXAXIS_CONTROLLER ) {int val;
@@ -1092,7 +1090,6 @@ static void rb4_ps5_guitar_parse_report(u8 battery_data;u8 battery_capacity;u8 battery_status; -unsigned long flags;/* * Rock Band 4 PS5 guitars have whammy and
@@ -1132,10 +1129,10 @@ static void rb4_ps5_guitar_parse_report(break ; } -spin_lock_irqsave (&sc->lock, flags); - sc->battery_capacity = battery_capacity; - sc->battery_status = battery_status; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->battery_capacity = battery_capacity; + sc->battery_status = battery_status; + }input_sync (sc->input_dev); }
@@ -1869,15 +1866,14 @@ static int sony_battery_get_property(str union power_supply_propval *val) {struct sony_sc *sc =power_supply_get_drvdata (psy); -unsigned long flags;int ret =0 ;u8 battery_capacity;int battery_status; -spin_lock_irqsave (&sc->lock, flags); - battery_capacity = sc->battery_capacity; - battery_status = sc->battery_status; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + battery_capacity = sc->battery_capacity; + battery_status = sc->battery_status; + }switch (psp) {case POWER_SUPPLY_PROP_PRESENT :
@@ -1959,10 +1955,9 @@ static inline int sony_compare_connectiostatic int sony_check_add_dev_list (struct sony_sc *sc) {struct sony_sc *entry; -unsigned long flags;int ret; -spin_lock_irqsave (&sony_dev_list_lock, flags); +guard (spinlock_irqsave)(&sony_dev_list_lock);list_for_each_entry (entry, &sony_device_list, list_node) { ret = memcmp(sc->mac_address, entry->mac_address,
@@ -1976,26 +1971,23 @@ static int sony_check_add_dev_list(struc"controller with MAC address %pMR already connected\n" , sc->mac_address); } - goto unlock; + goto out; } } ret =0 ;list_add (&(sc->list_node), &sony_device_list); -unlock: -spin_unlock_irqrestore (&sony_dev_list_lock, flags); +out:return ret; }static void sony_remove_dev_list (struct sony_sc *sc) { -unsigned long flags; -if (sc->list_node.next) { -spin_lock_irqsave (&sony_dev_list_lock, flags); -list_del (&(sc->list_node)); -spin_unlock_irqrestore (&sony_dev_list_lock, flags); + scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { +list_del (&(sc->list_node)); + } } }
@@ -2123,12 +2115,10 @@ static inline void sony_init_output_repostatic inline void sony_cancel_work_sync (struct sony_sc *sc) { -unsigned long flags; -if (sc->state_worker_initialized) { -spin_lock_irqsave (&sc->lock, flags); - sc->state_worker_initialized =0 ; -spin_unlock_irqrestore (&sc->lock, flags); + scoped_guard(spinlock_irqsave, &sc->lock) { + sc->state_worker_initialized =0 ; + }cancel_work_sync (&sc->state_worker); } }
Greg Kroah-Hartman
maintainerPATCH 11/556 HID: sony: clean up device list on probe failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
[ Upstream commit 7c65699a3a311198a07659a614fe64d45924839e ]
sony_input_configured() adds some controllers to sony_device_list before HID core registers their input devices. input_register_device() can fail after the callback returns successfully. sony_probe() then observes that HID_CLAIMED_INPUT is clear and unwinds, but only stops the HID hardware. The devres-managed sony_sc is freed while its list node remains linked, so the next matching controller traverses freed memory.
Initialize the list node and device ID to inactive states. Make list removal idempotent and run the driver-private cleanup on every probe failure path. This also makes a second cleanup safe when sony_input_configured() already unwound a partial initialization before sony_probe() handles the missing input claim.
Found by 0sec (https://0sec.ai) using automated source analysis; verified against the HID input registration and probe unwind paths.
--- drivers/hid/hid-sony.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/hid/hid-sony.c +17 -16
@@ -1984,11 +1984,10 @@ out:static void sony_remove_dev_list (struct sony_sc *sc) { -if (sc->list_node.next) { - scoped_guard(spinlock_irqsave, &sony_dev_list_lock) { -list_del (&(sc->list_node)); - } - } +guard (spinlock_irqsave)(&sony_dev_list_lock); + +if (!list_empty (&sc->list_node)) +list_del_init (&sc->list_node); }static int sony_get_bt_devaddr (struct sony_sc *sc)
@@ -2123,6 +2122,13 @@ static inline void sony_cancel_work_sync } } +static void sony_cleanup (struct sony_sc *sc) +{ +sony_cancel_work_sync (sc); +sony_remove_dev_list (sc); +sony_release_device_id (sc); +} +static int sony_input_configured (struct hid_device *hdev,struct hid_input *hidinput) {
@@ -2296,9 +2302,7 @@ static int sony_input_configured(struct err_close:hid_hw_close (hdev); err_stop: -sony_cancel_work_sync (sc); -sony_remove_dev_list (sc); -sony_release_device_id (sc); +sony_cleanup (sc);return ret; }
@@ -2322,6 +2326,8 @@ static int sony_probe(struct hid_devicereturn -ENOMEM ;spin_lock_init (&sc->lock); +INIT_LIST_HEAD (&sc->list_node); + sc->device_id =-1 ; sc->quirks = quirks;hid_set_drvdata (hdev, sc);
@@ -2350,6 +2356,7 @@ static int sony_probe(struct hid_device ret =hid_hw_start (hdev, connect_mask);if (ret) {hid_err (hdev,"hw start failed\n" ); +sony_cleanup (sc);return ret; }
@@ -2404,7 +2411,7 @@ static int sony_probe(struct hid_device err:usb_free_urb (sc->ghl_urb); - +sony_cleanup (sc);hid_hw_stop (hdev);return ret; }
@@ -2421,13 +2428,7 @@ static void sony_remove(struct hid_devic }hid_hw_close (hdev); - -sony_cancel_work_sync (sc); - -sony_remove_dev_list (sc); - -sony_release_device_id (sc); - +sony_cleanup (sc);hid_hw_stop (hdev); }
Greg Kroah-Hartman
maintainerPATCH 12/556 ACPI: battery: Use kstrtoul() over sscanf("%lu\n")
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rong Zhang <[email protected]>
[ Upstream commit 57346c4d78d38b357dbe9ef16d3f63bf4610c039 ]
It is more preferred to use kstrto*() to parse a single number. The function family properly returns an errno on error and is the correct mechanism to parse data from sysfs.
The number base is set to 10 in order not to break the ABI.
Stable-dep-of: 9e409f1dff78 ("ACPI: battery: Protect all properties with a separated mutex")
--- drivers/acpi/battery.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/acpi/battery.c +6 -2
@@ -668,9 +668,13 @@ static ssize_t acpi_battery_alarm_store( {unsigned long x;struct acpi_battery *battery =to_acpi_battery (dev_get_drvdata (dev)); +int err; -if (sscanf (buf,"%lu\n" , &x) ==1 ) - battery->alarm = x/1000 ; + err =kstrtoul (buf,10 , &x); +if (err) +return err; + + battery->alarm = x /1000 ;if (acpi_battery_present (battery))acpi_battery_set_alarm (battery);return count;
Greg Kroah-Hartman
maintainerPATCH 13/556 ACPI: battery: Protect all properties with a separated mutex
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rong Zhang <[email protected]>
[ Upstream commit 9e409f1dff7841634e4b101111d6427f979c0aac ]
The acpi_battery_get_property() callback calls acpi_battery_get_state() without any lock held. On some devices, it happens that the property cache has expired before a uevent reaches userspace, triggering simultaneous attempts to evaluate _BST. See [1] for an analysis to sysrq stacktraces on one of the these devices.
In a few cases, including when the AML is sleeping or acquiring a mutex, ACPICA drops the namespace and interpreter locks and allows the evaluation of _BST to start while another task is still evaluating it. This could somehow confuse the interpreter and lead to chaos in AML mutexes on some devices, see [2] for an example.
Not holding the lock is also prone to race conditions, for example:
CPU0 | CPU1
acpi_battery_get_property() |
acpi_battery_get_state() |
[update_time expired] |
extract_package() | acpi_battery_get_property()
battery->update_time = jiffies | acpi_battery_get_state()
kfree() | [up to date]
| [read capacity_now]
[fix capacity_now due to quirk] |where CPU1 gets raw capacity_now before CPU0 fixes it to a meaningful value.
The existing mutex update_lock is not applicapable for acpi_battery_get_property(), as some code path could call or wait for acpi_battery_get_property() while holding update_lock.
Therefore, introduce a mutex called property_lock to protect all accesses to battery properties, so that acpi_battery_get_property() can take the advantage of the mutex and synchronize itself. With the mutex, acpi_battery_get_state() are synchronized in all code paths calling it, and its cache mechanism can always clamp the frequency of _BST evaluations according to cache_time.
The helper function acpi_battery_handle_discharging() for quirky devices has to be inlined due to the change, as the mutex must be unlocked before calling the expensive power_supply_is_system_supplied() helper function.
--- drivers/acpi/battery.c | 147 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 101 insertions(+), 46 deletions(-)
drivers/acpi/battery.c +101 -46
@@ -15,6 +15,7 @@#include <linux/jiffies.h> #include <linux/kernel.h> #include <linux/list.h> +#include <linux/lockdep.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/platform_device.h>
@@ -97,6 +98,9 @@ struct acpi_battery {struct device *phys_dev;struct notifier_block pm_nb;struct list_head list; +unsigned long flags; + +struct mutex property_lock;/* Protects properties below. */ unsigned long update_time;int revision;int rate_now;
@@ -123,7 +127,6 @@ struct acpi_battery {char oem_info[MAX_STRING_LENGTH ];int state;int power_unit; -unsigned long flags; };#define to_acpi_battery (x) power_supply_get_drvdata(x)
@@ -180,20 +183,6 @@ static bool acpi_battery_is_degraded(str battery->full_charge_capacity < battery->design_capacity; } -static int acpi_battery_handle_discharging (struct acpi_battery *battery) -{ -/* -* Some devices wrongly report discharging if the battery's charge level -* was above the device's start charging threshold atm the AC adapter -* was plugged in and the device thus did not start a new charge cycle. -*/ -if ((battery_ac_is_broken ||power_supply_is_system_supplied ()) && - battery->rate_now ==0 ) -return POWER_SUPPLY_STATUS_NOT_CHARGING ; - -return POWER_SUPPLY_STATUS_DISCHARGING ; -} -static int acpi_battery_get_property (struct power_supply *psy,enum power_supply_property psp,union power_supply_propval *val)
@@ -201,15 +190,41 @@ static int acpi_battery_get_property(strint full_capacity =ACPI_BATTERY_VALUE_UNKNOWN , ret =0 ;struct acpi_battery *battery =to_acpi_battery (psy); -if (acpi_battery_present (battery)) { -/* run battery update only if it is present */ -acpi_battery_get_state (battery); - }else if (psp !=POWER_SUPPLY_PROP_PRESENT ) -return -ENODEV ; +/* run battery update only if it is present */ +if (!acpi_battery_present (battery)) { +switch (psp) { +case POWER_SUPPLY_PROP_PRESENT : + val->intval =0 ; +return 0 ; +default : +return -ENODEV ; + } + } + +mutex_lock (&battery->property_lock); + +acpi_battery_get_state (battery); +switch (psp) {case POWER_SUPPLY_PROP_STATUS : +/* +* Some devices wrongly report discharging if the battery's charge level +* was above the device's start charging threshold atm the AC adapter +* was plugged in and the device thus did not start a new charge cycle. +*/ if (battery->state &ACPI_BATTERY_STATE_DISCHARGING ) - val->intval =acpi_battery_handle_discharging (battery); +if (battery->rate_now !=0 ) { + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; + }else if (battery_ac_is_broken) { + val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ; + }else { +mutex_unlock (&battery->property_lock); + + val->intval =power_supply_is_system_supplied () + ?POWER_SUPPLY_STATUS_NOT_CHARGING + :POWER_SUPPLY_STATUS_DISCHARGING ; +return 0 ; + }else if (battery->state &ACPI_BATTERY_STATE_CHARGING )/* Validate the status by checking the current. */ if (battery->rate_now != ACPI_BATTERY_VALUE_UNKNOWN &&
@@ -311,6 +326,8 @@ static int acpi_battery_get_property(strdefault : ret = -EINVAL ; } + +mutex_unlock (&battery->property_lock);return ret; }
@@ -533,6 +550,8 @@ static int acpi_battery_get_info(structint use_bix;int result = -ENODEV ; +lockdep_assert_held (&battery->property_lock); +if (!acpi_battery_present (battery))return 0 ;
@@ -572,6 +591,8 @@ static int acpi_battery_get_state(structacpi_status status =0 ;struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +lockdep_assert_held (&battery->property_lock); +if (!acpi_battery_present (battery))return 0 ;
@@ -625,6 +646,8 @@ static int acpi_battery_set_alarm(struct {acpi_status status =0 ; +lockdep_assert_held (&battery->property_lock); +if (!acpi_battery_present (battery) || !test_bit (ACPI_BATTERY_ALARM_PRESENT , &battery->flags))return -ENODEV ;
@@ -642,6 +665,8 @@ static int acpi_battery_set_alarm(structstatic int acpi_battery_init_alarm (struct acpi_battery *battery) { +lockdep_assert_held (&battery->property_lock); +/* See if alarms are supported, and if so, set default */ if (!acpi_has_method (battery->device->handle,"_BTP" )) {clear_bit (ACPI_BATTERY_ALARM_PRESENT , &battery->flags);
@@ -659,6 +684,8 @@ static ssize_t acpi_battery_alarm_show(s {struct acpi_battery *battery =to_acpi_battery (dev_get_drvdata (dev)); +guard (mutex)(&battery->property_lock); +return sysfs_emit (buf,"%d\n" , battery->alarm *1000 ); }
@@ -674,6 +701,8 @@ static ssize_t acpi_battery_alarm_store(if (err)return err; +guard (mutex)(&battery->property_lock); + battery->alarm = x /1000 ;if (acpi_battery_present (battery))acpi_battery_set_alarm (battery);
@@ -858,12 +887,17 @@ static int sysfs_add_battery(struct acpi .no_wakeup_source = true, };bool full_cap_broken = false; +int power_unit; -if (!ACPI_BATTERY_CAPACITY_VALID (battery->full_charge_capacity) && - !ACPI_BATTERY_CAPACITY_VALID (battery->design_capacity)) - full_cap_broken = true; + scoped_guard(mutex, &battery->property_lock) { + power_unit = battery->power_unit; -if (battery->power_unit ==ACPI_BATTERY_POWER_UNIT_MA ) { +if (!ACPI_BATTERY_CAPACITY_VALID (battery->full_charge_capacity) && + !ACPI_BATTERY_CAPACITY_VALID (battery->design_capacity)) + full_cap_broken = true; + } + +if (power_unit ==ACPI_BATTERY_POWER_UNIT_MA ) {if (full_cap_broken) { battery->bat_desc.properties = charge_battery_full_cap_broken_props;
@@ -917,6 +951,9 @@ static void sysfs_remove_battery(structstatic void find_battery (const struct dmi_header *dm,void *private) {struct acpi_battery *battery = (struct acpi_battery *)private; + +lockdep_assert_held (&battery->property_lock); +/* Note: the hardcoded offsets below have been extracted from * the source code of dmidecode. */
@@ -948,6 +985,8 @@ static void find_battery(const struct dm*/ static void acpi_battery_quirks (struct acpi_battery *battery) { +lockdep_assert_held (&battery->property_lock); +if (test_bit (ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY , &battery->flags))return ;
@@ -1000,30 +1039,38 @@ static void acpi_battery_quirks(struct astatic int acpi_battery_update (struct acpi_battery *battery,bool resume) {int result =acpi_battery_get_status (battery); +bool wakeup;if (result)return result;if (!acpi_battery_present (battery)) {sysfs_remove_battery (battery); - battery->update_time =0 ; +scoped_guard (mutex, &battery->property_lock) + battery->update_time = 0;return 0 ; }if (resume)return 0 ; -if (!battery->update_time) { - result =acpi_battery_get_info (battery); + scoped_guard(mutex, &battery->property_lock) { +if (!battery->update_time) { + result =acpi_battery_get_info (battery); +if (result) +return result; +acpi_battery_init_alarm (battery); + } + + result =acpi_battery_get_state (battery);if (result)return result; -acpi_battery_init_alarm (battery); - } +acpi_battery_quirks (battery); - result =acpi_battery_get_state (battery); -if (result) -return result; -acpi_battery_quirks (battery); + wakeup = ((battery->state &ACPI_BATTERY_STATE_CRITICAL ) || + (test_bit (ACPI_BATTERY_ALARM_PRESENT , &battery->flags) && + (battery->capacity_now <= battery->alarm))); + }if (!battery->bat) { result =sysfs_add_battery (battery);
@@ -1035,9 +1082,7 @@ static int acpi_battery_update(struct ac* Wakeup the system if battery is critical low * or lower than the alarm level */ -if ((battery->state &ACPI_BATTERY_STATE_CRITICAL ) || - (test_bit (ACPI_BATTERY_ALARM_PRESENT , &battery->flags) && - (battery->capacity_now <= battery->alarm))) +if (wakeup)acpi_pm_wakeup_event (battery->phys_dev);return result;
@@ -1050,12 +1095,14 @@ static void acpi_battery_refresh(structif (!battery->bat)return ; - power_unit = battery->power_unit; + scoped_guard(mutex, &battery->property_lock) { + power_unit = battery->power_unit; -acpi_battery_get_info (battery); +acpi_battery_get_info (battery); -if (power_unit == battery->power_unit) -return ; +if (power_unit == battery->power_unit) +return ; + }/* The battery has changed its reporting units. */ sysfs_remove_battery (battery);
@@ -1110,17 +1157,21 @@ static int battery_notify(struct notifie }else {int result; - result =acpi_battery_get_info (battery); -if (result) -return result; + scoped_guard(mutex, &battery->property_lock) { + result =acpi_battery_get_info (battery); +if (result) +return result; + } result =sysfs_add_battery (battery);if (result)return result; } -acpi_battery_init_alarm (battery); -acpi_battery_get_state (battery); + scoped_guard(mutex, &battery->property_lock) { +acpi_battery_init_alarm (battery); +acpi_battery_get_state (battery); + } }return 0 ;
@@ -1262,6 +1313,10 @@ static int acpi_battery_probe(struct plaif (result)return result; + result =devm_mutex_init (&pdev->dev, &battery->property_lock); +if (result) +return result; +if (acpi_has_method (battery->device->handle,"_BIX" ))set_bit (ACPI_BATTERY_XINFO_PRESENT , &battery->flags);
Greg Kroah-Hartman
maintainerPATCH 14/556 KVM: x86/mmu: Fold kvm_mmu_zap_memslot() into kvm_arch_flush_shadow_memslot()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 06d38eaa78fdac1cc889f261fa420eba8e9caa1a ]
Fold kvm_mmu_zap_memslot() into its sole caller so that its GFN range structure can be used to trigger guest_memfd invalidations regardless of whether KVM will do a partial or full zap of the MMU.
No functional change intended.
Stable-dep-of: d1a3c2162334 ("KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped")
--- arch/x86/kvm/mmu/mmu.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
arch/x86/kvm/mmu/mmu.c +15 -20
@@ -7535,8 +7535,14 @@ out_flush:kvm_mmu_remote_flush_or_zap (kvm, &invalid_list, flush); } -static void kvm_mmu_zap_memslot (struct kvm *kvm, -struct kvm_memory_slot *slot) +static inline bool kvm_memslot_flush_zap_all (struct kvm *kvm) +{ +return kvm->arch.vm_type ==KVM_X86_DEFAULT_VM && +kvm_check_has_quirk (kvm,KVM_X86_QUIRK_SLOT_ZAP_ALL ); +} + +void kvm_arch_flush_shadow_memslot (struct kvm *kvm, +struct kvm_memory_slot *slot) {struct kvm_gfn_range range = { .slot = slot,
@@ -7547,25 +7553,14 @@ static void kvm_mmu_zap_memslot(struct k };bool flush; -write_lock (&kvm->mmu_lock); - flush =kvm_unmap_gfn_range (kvm, &range); -kvm_mmu_zap_memslot_pages_and_flush (kvm, slot, flush); -write_unlock (&kvm->mmu_lock); -} - -static inline bool kvm_memslot_flush_zap_all (struct kvm *kvm) -{ -return kvm->arch.vm_type ==KVM_X86_DEFAULT_VM && -kvm_check_has_quirk (kvm,KVM_X86_QUIRK_SLOT_ZAP_ALL ); -} - -void kvm_arch_flush_shadow_memslot (struct kvm *kvm, -struct kvm_memory_slot *slot) -{ -if (kvm_memslot_flush_zap_all (kvm)) +if (kvm_memslot_flush_zap_all (kvm)) {kvm_mmu_zap_all_fast (kvm); -else -kvm_mmu_zap_memslot (kvm, slot); + }else { +write_lock (&kvm->mmu_lock); + flush =kvm_unmap_gfn_range (kvm, &range); +kvm_mmu_zap_memslot_pages_and_flush (kvm, slot, flush); +write_unlock (&kvm->mmu_lock); + } }void kvm_mmu_invalidate_mmio_sptes (struct kvm *kvm,u64 gen)
Greg Kroah-Hartman
maintainerPATCH 15/556 KVM: x86/mmu: Split kvm_mmu_zap_all_fast() into "front" and "back" halves
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit b27622c4eeb125814081baaefe9175191be5b94d ]
Split kvm_mmu_zap_all_fast() into a "front half" and a "back half", where the front half is everything that runs with mmu_lock held for write, and the back half is the code that runs outside of mmu_lock. This will allow putting more code inside kvm_arch_flush_shadow_memslot()'s critical section without having to take mmu_lock twice in quick succession.
No functional change intended.
Stable-dep-of: d1a3c2162334 ("KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped")
--- arch/x86/kvm/mmu/mmu.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
arch/x86/kvm/mmu/mmu.c +25 -12
@@ -6896,20 +6896,11 @@ restart:kvm_mmu_commit_zap_page (kvm, &invalid_list); } -/* -* Fast invalidate all shadow pages and use lock-break technique -* to zap obsolete pages. -* -* It's required when memslot is being deleted or VM is being -* destroyed, in these cases, we should ensure that KVM MMU does -* not use any resource of the being-deleted slot or all slots -* after calling the function. -*/ -static void kvm_mmu_zap_all_fast (struct kvm *kvm) +static void __kvm_mmu_zap_all_fast_front_half (struct kvm *kvm) {lockdep_assert_held (&kvm->slots_lock); +lockdep_assert_held_write (&kvm->mmu_lock); -write_lock (&kvm->mmu_lock);trace_kvm_mmu_zap_all_fast (kvm);/*
@@ -6946,8 +6937,12 @@ static void kvm_mmu_zap_all_fast(structkvm_make_all_cpus_request (kvm,KVM_REQ_MMU_FREE_OBSOLETE_ROOTS );kvm_zap_obsolete_pages (kvm); +} -write_unlock (&kvm->mmu_lock); +static void __kvm_mmu_zap_all_fast_back_half (struct kvm *kvm) +{ +lockdep_assert_held (&kvm->slots_lock); +lockdep_assert_not_held (&kvm->mmu_lock);/* * Zap the invalidated TDP MMU roots, all SPTEs must be dropped before
@@ -6961,6 +6956,24 @@ static void kvm_mmu_zap_all_fast(structkvm_tdp_mmu_zap_invalidated_roots (kvm, true); } +/* +* Fast invalidate all shadow pages and use lock-break technique +* to zap obsolete pages. +* +* It's required when memslot is being deleted or VM is being +* destroyed, in these cases, we should ensure that KVM MMU does +* not use any resource of the being-deleted slot or all slots +* after calling the function. +*/ +static void kvm_mmu_zap_all_fast (struct kvm *kvm) +{ +write_lock (&kvm->mmu_lock); +__kvm_mmu_zap_all_fast_front_half (kvm); +write_unlock (&kvm->mmu_lock); + +__kvm_mmu_zap_all_fast_back_half (kvm); +} +int kvm_mmu_init_vm (struct kvm *kvm) {int r, i;
Greg Kroah-Hartman
maintainerPATCH 16/556 KVM: x86/mmu: Use split "zap all fast" helpers when invalidating memslot
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit db095727ff5739f4f46ee641ee6ef450032886db ]
Manually invoke the front half and back half of the "zap all fast" flow when invalidating a memslot so that mmu_lock is acquired at function scope
in kvm_arch_flush_shadow_memslot(). This will allow putting more code
inside the critical section without having to take mmu_lock twice in quick succession.
Opportunistically open code checking whether or not to do the fast zap, to discourage removing the local "zap_all" in a future cleanup, i.e. to ensure the SLOT_ZAP_ALL quirk is queried exactly once. Processing the front half but not the back half of the fast zap (if SLOT_ZAP_ALL were disabled concurrently) would result in KVM unnecessarily keeping invalid TDP MMU roots until the VM is destroyed.
No functional change intended.
Stable-dep-of: d1a3c2162334 ("KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped")
--- arch/x86/kvm/mmu/mmu.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
arch/x86/kvm/mmu/mmu.c +11 -10
@@ -7548,12 +7548,6 @@ out_flush:kvm_mmu_remote_flush_or_zap (kvm, &invalid_list, flush); } -static inline bool kvm_memslot_flush_zap_all (struct kvm *kvm) -{ -return kvm->arch.vm_type ==KVM_X86_DEFAULT_VM && -kvm_check_has_quirk (kvm,KVM_X86_QUIRK_SLOT_ZAP_ALL ); -} -void kvm_arch_flush_shadow_memslot (struct kvm *kvm,struct kvm_memory_slot *slot) {
@@ -7564,16 +7558,23 @@ void kvm_arch_flush_shadow_memslot(struc .may_block = true, .attr_filter = KVM_FILTER_PRIVATE | KVM_FILTER_SHARED, }; +bool zap_all = kvm->arch.vm_type ==KVM_X86_DEFAULT_VM && +kvm_check_has_quirk (kvm,KVM_X86_QUIRK_SLOT_ZAP_ALL );bool flush; -if (kvm_memslot_flush_zap_all (kvm)) { -kvm_mmu_zap_all_fast (kvm); +write_lock (&kvm->mmu_lock); + +if (zap_all) { +__kvm_mmu_zap_all_fast_front_half (kvm); }else { -write_lock (&kvm->mmu_lock); flush =kvm_unmap_gfn_range (kvm, &range);kvm_mmu_zap_memslot_pages_and_flush (kvm, slot, flush); -write_unlock (&kvm->mmu_lock); } + +write_unlock (&kvm->mmu_lock); + +if (zap_all) +__kvm_mmu_zap_all_fast_back_half (kvm); }void kvm_mmu_invalidate_mmio_sptes (struct kvm *kvm,u64 gen)
Greg Kroah-Hartman
maintainerPATCH 17/556 KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit d1a3c216233413f57f5341a9b878b7e2dde7e785 ]
Wire up a gmem_invalidate_range() call for SNP VMs, and use it to force vCPUs to reload/recheck their guest-provided VMSA if the backing gmem page is being invalidated, e.g. is being PUNCH_HOLE'd. Use the same core logic to handle invalidations as VMX does for the APIC-access page, as the two concepts are nearly identical: shove the physical address of a page into the vCPU's control structure:
1. Snapshot the invalidation sequence counter
2. Grab the pfn (from guest_memfd in this case)
3. Acquire mmu_lock for read
4. Re-request reload if retry is needed, otherwise commit the change.
Note, the re-request action in #4 is necessary as KVM's retry logic is fuzzy, i.e. can get false positives. If the guest_memfd page has been dropped, at some point a subsequent reload will fail to get a PFN from guest_memfd, and KVM will fail KVM_RUN. If the retry was due to a false positive, KVM will retry until there are no relevant MMU notifier events (and will retry in the "outer" loop, i.e. will drop locks and resched as needed).
Note #2! Take care to invalidate the VMSA when a relevant memslot is DELETED or MOVED, as invalidations in response to PUNCH_HOLE are predicated on memslot bindings (KVM doesn't know what GFN range(s) to invalidate without a binding). And more importantly, the VMSA mapping requires a memslot, i.e. must be invalidated if its memslots disappears, regardless of the state of the underlying guest_memfd inode.
Failure to invalidate the vCPU's control.vmsa_pa (which is checked by pre_sev_run()) can prevent KVM from properly freeing the page as firmware will reject the RMPUPDATE to reclaim the page with FAIL_INUSE if the vCPU is actively running, i.e. if VMSA page is in-use. That in turn leads to an RMP #PF on the next use, as the page will still be assigned to the SNP VM.
SEV-SNP: RMPUPDATE failed for PFN 78d198, pg_level: 1, ret: 3
SEV-SNP: PFN 0x78d198, RMP entry: [0xfff0000000144001 - 0x000000000000000f]
CPU: 3 UID: 0 PID: 31345 Comm: sev_snp_vmsa_pu Tainted: G U O Tainted: [U]=USER, [O]=OOT_MODULE Hardware name: Google, Inc. Arcadia_IT_80/Arcadia_IT_80, BIOS 34.86.0-102 01/25/2026 Call Trace: <TASK> dump_stack_lvl+0x54/0x70 rmpupdate+0x12c/0x140 rmp_make_shared+0x3b/0x60 sev_gmem_invalidate+0xe0/0x170 [kvm_amd] delete_from_page_cache_batch+0x1d8/0x220 truncate_inode_pages_range+0x120/0x3d0 kvm_gmem_fallocate+0x19a/0x270 [kvm] vfs_fallocate+0x1bc/0x1f0 __x64_sys_fallocate+0x48/0x70 do_syscall_64+0x10a/0x480 entry_SYSCALL_64_after_hwframe+0x4b/0x53 RIP: 0033:0x496c7e </TASK> ------------[ cut here ]------------ SEV: Failed to update RMP entry for PFN 0x78d198 error -14 WARNING: arch/x86/kvm/svm/sev.c:5160 at sev_gmem_invalidate+0x126/0x170 [kvm_amd], CPU#3: sev_snp_vmsa_pu/31345 CPU: 3 UID: 0 PID: 31345 Comm: sev_snp_vmsa_pu Tainted: G U O Tainted: [U]=USER, [O]=OOT_MODULE Hardware name: Google, Inc. Arcadia_IT_80/Arcadia_IT_80, BIOS 34.86.0-102 01/25/2026 RIP: 0010:sev_gmem_invalidate+0x12b/0x170 [kvm_amd] Call Trace: <TASK> delete_from_page_cache_batch+0x1d8/0x220 truncate_inode_pages_range+0x120/0x3d0 kvm_gmem_fallocate+0x19a/0x270 [kvm] vfs_fallocate+0x1bc/0x1f0 __x64_sys_fallocate+0x48/0x70 do_syscall_64+0x10a/0x480 entry_SYSCALL_64_after_hwframe+0x4b/0x53 RIP: 0033:0x496c7e </TASK> irq event stamp: 20689 hardirqs last enabled at (20699): [<ffffffff8e76092c>] __console_unlock+0x5c/0x60 hardirqs last disabled at (20708): [<ffffffff8e760911>] __console_unlock+0x41/0x60 softirqs last enabled at (20722): [<ffffffff8e6cd74e>] __irq_exit_rcu+0x7e/0x140 softirqs last disabled at (20717): [<ffffffff8e6cd74e>] __irq_exit_rcu+0x7e/0x140 ---[ end trace 0000000000000000 ]--- BUG: unable to handle page fault for address: ffff99a64d198000 #PF: supervisor write access in kernel mode #PF: error_code(0x80000003) - RMP violation PGD 13eb001067 P4D 13eb001067 PUD 78d1d1063 PMD 1184e0063 PTE 800000078d198163 SEV-SNP: PFN 0x78d198, RMP entry: [0x6030000000144001 - 0x000000000000000f] Oops: Oops: 0003 [#1] SMP CPU: 3 UID: 0 PID: 31407 Comm: highlanderd_hea Tainted: G U W O Tainted: [U]=USER, [W]=WARN, [O]=OOT_MODULE Hardware name: Google, Inc. Arcadia_IT_80/Arcadia_IT_80, BIOS 34.86.0-102 01/25/2026 RIP: 0010:prep_new_page+0x67/0x220 Call Trace: <TASK> get_page_from_freelist+0x1c40/0x1c70 __alloc_frozen_pages_noprof+0xca/0x1f0 alloc_pages_mpol+0x10b/0x1b0 alloc_pages_noprof+0x81/0x90 pte_alloc_one+0x1b/0xd0 do_pte_missing+0xdf/0x1020 handle_mm_fault+0x7c7/0xb20 do_user_addr_fault+0x268/0x6b0 exc_page_fault+0x67/0xa0 asm_exc_page_fault+0x26/0x30 RIP: 0033:0x4a6b1e </TASK> gsmi: Log Shutdown Reason 0x03 CR2: ffff99a64d198000 ---[ end trace 0000000000000000 ]--- RIP: 0010:prep_new_page+0x67/0x220
Drop the pseudo-TODO comment about needing to pin the page if guest_memfd every supports migration, as integrating with invalidations events means KVM will Just Work if/when page migration is ever supported (assuming SNP hardware supports migrating VMSA pages).
Note #3, invalidate() and invalidate_range() have _completely_ different semantics; the new invalidate_range() is a true invalidation, whereas the existing invalidate() is really a "make shared" operation. Ignore the confusing naming and poor Kconfig bundling for the moment to minimize the delta for LTS kernels, the mess will be cleaned up shortly.
--- arch/x86/include/asm/kvm-x86-ops.h | 4 + arch/x86/include/asm/kvm_host.h | 6 ++ arch/x86/kvm/mmu/mmu.c | 5 ++ arch/x86/kvm/svm/sev.c | 80 +++++++++++++++++++++++++++++++------ arch/x86/kvm/svm/svm.c | 2 arch/x86/kvm/svm/svm.h | 2 arch/x86/kvm/x86.c | 6 ++ include/linux/kvm_host.h | 1 virt/kvm/guest_memfd.c | 4 + 9 files changed, 99 insertions(+), 11 deletions(-)
arch/x86/include/asm/kvm-x86-ops.h +4 -0
@@ -134,6 +134,7 @@ KVM_X86_OP_OPTIONAL(mem_enc_unregister_r KVM_X86_OP_OPTIONAL(vm_copy_enc_context_from) KVM_X86_OP_OPTIONAL(vm_move_enc_context_from) KVM_X86_OP_OPTIONAL(guest_memory_reclaimed) +KVM_X86_OP_OPTIONAL(reload_vmsa) KVM_X86_OP(get_feature_msr) KVM_X86_OP(check_emulate_instruction) KVM_X86_OP(apic_init_signal_blocked)
@@ -148,6 +149,9 @@ KVM_X86_OP_OPTIONAL(alloc_apic_backing_p KVM_X86_OP_OPTIONAL_RET0(gmem_prepare) KVM_X86_OP_OPTIONAL_RET0(gmem_max_mapping_level) KVM_X86_OP_OPTIONAL(gmem_invalidate) +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE +KVM_X86_OP_OPTIONAL(gmem_invalidate_range) +#endif #endif #undef KVM_X86_OP
arch/x86/include/asm/kvm_host.h +6 -0
@@ -128,6 +128,8 @@ KVM_ARCH_REQ_FLAGS(31, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_HV_TLB_FLUSH \ KVM_ARCH_REQ_FLAGS(32, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP) +#define KVM_REQ_VMSA_PAGE_RELOAD \ + KVM_ARCH_REQ_FLAGS(33, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)#define KVM_REQ_UPDATE_PROTECTED_GUEST_STATE \ KVM_ARCH_REQ_FLAGS(34, KVM_REQUEST_WAIT)
@@ -1985,6 +1987,7 @@ struct kvm_x86_ops {int (*vm_copy_enc_context_from)(struct kvm *kvm,unsigned int source_fd);int (*vm_move_enc_context_from)(struct kvm *kvm,unsigned int source_fd);void (*guest_memory_reclaimed)(struct kvm *kvm); +void (*reload_vmsa)(struct kvm_vcpu *vcpu);int (*get_feature_msr)(u32 msr,u64 *data);
@@ -2009,6 +2012,9 @@ struct kvm_x86_ops {void *(*alloc_apic_backing_page)(struct kvm_vcpu *vcpu);int (*gmem_prepare)(struct kvm *kvm,kvm_pfn_t pfn,gfn_t gfn,int max_order);void (*gmem_invalidate)(kvm_pfn_t start,kvm_pfn_t end); +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE +void (*gmem_invalidate_range)(struct kvm *kvm,struct kvm_gfn_range *range); +#endif int (*gmem_max_mapping_level)(struct kvm *kvm,kvm_pfn_t pfn,bool is_private); };
arch/x86/kvm/mmu/mmu.c +5 -0
@@ -7564,6 +7564,11 @@ void kvm_arch_flush_shadow_memslot(strucwrite_lock (&kvm->mmu_lock); +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE +if (slot->gmem.file) +kvm_arch_gmem_invalidate_range (kvm, &range); +#endif +if (zap_all) {__kvm_mmu_zap_all_fast_front_half (kvm); }else {
arch/x86/kvm/svm/sev.c +69 -11
128 lines not on this page · raw message
arch/x86/kvm/svm/svm.c +2 -0
@@ -5463,12 +5463,14 @@ struct kvm_x86_ops svm_x86_ops __initdat .mem_enc_register_region = sev_mem_enc_register_region, .mem_enc_unregister_region = sev_mem_enc_unregister_region, .guest_memory_reclaimed = sev_guest_memory_reclaimed, + .reload_vmsa = sev_snp_reload_vmsa, .vm_copy_enc_context_from = sev_vm_copy_enc_context_from, .vm_move_enc_context_from = sev_vm_move_enc_context_from, .gmem_prepare = sev_gmem_prepare, .gmem_invalidate = sev_gmem_invalidate, + .gmem_invalidate_range = sev_gmem_invalidate_range, .gmem_max_mapping_level = sev_gmem_max_mapping_level, #endif .check_emulate_instruction = svm_check_emulate_instruction,
arch/x86/kvm/svm/svm.h +2 -0
@@ -997,6 +997,7 @@ static inline struct page *snp_safe_allo {return snp_safe_alloc_page_node (numa_node_id (),GFP_KERNEL_ACCOUNT ); } +void sev_snp_reload_vmsa (struct kvm_vcpu *vcpu);int sev_vcpu_create (struct kvm_vcpu *vcpu);void sev_free_vcpu (struct kvm_vcpu *vcpu);
@@ -1011,6 +1012,7 @@ extern unsigned int max_sev_asid;void sev_handle_rmp_fault (struct kvm_vcpu *vcpu,gpa_t gpa,u64 error_code);int sev_gmem_prepare (struct kvm *kvm,kvm_pfn_t pfn,gfn_t gfn,int max_order);void sev_gmem_invalidate (kvm_pfn_t start,kvm_pfn_t end); +void sev_gmem_invalidate_range (struct kvm *kvm,struct kvm_gfn_range *range);int sev_gmem_max_mapping_level (struct kvm *kvm,kvm_pfn_t pfn,bool is_private);struct vmcb_save_area *sev_decrypt_vmsa (struct kvm_vcpu *vcpu);void sev_free_decrypted_vmsa (struct kvm_vcpu *vcpu,struct vmcb_save_area *vmsa);
arch/x86/kvm/x86.c +6 -0
@@ -11278,6 +11278,8 @@ static int vcpu_enter_guest(struct kvm_v goto out; } } +if (kvm_check_request (KVM_REQ_VMSA_PAGE_RELOAD , vcpu)) +kvm_x86_call (reload_vmsa)(vcpu); } if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win ||
@@ -14142,6 +14144,10 @@ void kvm_arch_gmem_invalidate(kvm_pfn_t {kvm_x86_call (gmem_invalidate)(start, end); } +void kvm_arch_gmem_invalidate_range (struct kvm *kvm,struct kvm_gfn_range *range) +{ +kvm_x86_call (gmem_invalidate_range)(kvm, range); +}#endif #endif
include/linux/kvm_host.h +1 -0
@@ -2608,6 +2608,7 @@ long kvm_gmem_populate(struct kvm *kvm,#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE void kvm_arch_gmem_invalidate (kvm_pfn_t start,kvm_pfn_t end); +void kvm_arch_gmem_invalidate_range (struct kvm *kvm,struct kvm_gfn_range *range);#endif #ifdef CONFIG_KVM_GENERIC_PRE_FAULT_MEMORY
virt/kvm/guest_memfd.c +4 -0
@@ -185,6 +185,10 @@ static void __kvm_gmem_invalidate_start( } flush |=kvm_mmu_unmap_gfn_range (kvm, &gfn_range); + +#ifdef CONFIG_HAVE_KVM_ARCH_GMEM_INVALIDATE +kvm_arch_gmem_invalidate_range (kvm, &gfn_range); +#endif }if (flush)
Greg Kroah-Hartman
maintainerPATCH 18/556 NFSD: Annotate caller preconditions for the state-table walkers
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 5f367f05481d56be90f8c13eee4cb421cd7af2d8 ]
The state-table walkers now assert nfsd_mutex with lockdep_assert_held() and document the nfsd_mutex / nn->nfsd_serv precondition in a Context: kdoc section, so the next caller added to this path cannot silently reintroduce the same use-after-free.
Stable-dep-of: 2f3e6638aebc ("NFSD: Guard admin state-revocation walks with NFSD_NET_UP")
--- fs/nfsd/nfs4proc.c | 6 ++++++ fs/nfsd/nfs4state.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-)
fs/nfsd/nfs4proc.c +6 -0
@@ -1597,6 +1597,11 @@ static bool nfsd4_copy_on_sb(const struc* nfsd4_cancel_copy_by_sb - cancel async copy operations on @sb * @net: net namespace containing the copy operations * @sb: targeted superblock +* +* Context: Caller must hold nfsd_mutex with nn->nfsd_serv confirmed +* non-NULL. nfs4_state_destroy_net() frees conf_id_hashtbl +* at server shutdown without clearing the pointer, so a +* walk without these guarantees iterates freed slab memory. */ void nfsd4_cancel_copy_by_sb (struct net *net,struct super_block *sb) {
@@ -1606,6 +1611,7 @@ void nfsd4_cancel_copy_by_sb(struct netunsigned int idhashval;LIST_HEAD (to_cancel); +lockdep_assert_held (&nfsd_mutex);spin_lock (&nn->client_lock);for (idhashval =0 ; idhashval <CLIENT_HASH_SIZE ; idhashval++) {struct list_head *head = &nn->conf_id_hashtbl[idhashval];
fs/nfsd/nfs4state.c +15 -1
@@ -1944,14 +1944,21 @@ static void revoke_one_stid(struct nfsd_* being released. Thus nfsd will no longer prevent the filesystem from being * unmounted. * -* The clients which own the states will subsequently being notified that the +* The clients which own the states will subsequently be notified that the * states have been "admin-revoked". +* +* Context: Caller must hold nfsd_mutex with nn->nfsd_serv confirmed +* non-NULL. nfs4_state_destroy_net() frees conf_id_hashtbl +* at server shutdown without clearing the pointer, so a +* walk without these guarantees iterates freed slab memory. */ void nfsd4_revoke_states (struct nfsd_net *nn,struct super_block *sb) {unsigned int idhashval;unsigned int sc_types; +lockdep_assert_held (&nfsd_mutex); + sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock);
@@ -2030,12 +2037,19 @@ static struct nfs4_stid *find_one_export* * Userspace (exportfs -u) sends this after removing the last client * for a path, enabling the underlying filesystem to be unmounted. +* +* Context: Caller must hold nfsd_mutex with nn->nfsd_serv confirmed +* non-NULL. nfs4_state_destroy_net() frees conf_id_hashtbl +* at server shutdown without clearing the pointer, so a +* walk without these guarantees iterates freed slab memory. */ void nfsd4_revoke_export_states (struct nfsd_net *nn,const struct path *path) {unsigned int idhashval;unsigned int sc_types; +lockdep_assert_held (&nfsd_mutex); + sc_types =SC_TYPE_OPEN |SC_TYPE_LOCK |SC_TYPE_DELEG |SC_TYPE_LAYOUT ;spin_lock (&nn->client_lock);
Greg Kroah-Hartman
maintainerPATCH 19/556 NFSD: Guard admin state-revocation walks with NFSD_NET_UP
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 2f3e6638aebc0ab8afb8b4e9816ea9a1cad85378 ]
Writing to /proc/fs/nfsd/unlock_filesystem, or sending the NFSD_CMD_UNLOCK_FILESYSTEM or NFSD_CMD_UNLOCK_EXPORT netlink command, walks the NFSv4 client hash tables to revoke open state and cancel async COPY operations. All three handlers gate that walk on nn->nfsd_serv, but a listener added via portlist or netlink listener_set sets nn->nfsd_serv before any nfsd thread starts. nfsd_startup_net() has not yet allocated nn->conf_id_hashtbl, so the walkers dereference a NULL table. A local administrator with CAP_SYS_ADMIN can crash the kernel this way without ever starting the server.
nn->nfsd_serv is set when the service is created, which precedes table allocation. NFSD_NET_UP instead brackets the window where the tables are live: set at the end of nfsd_startup_net() and cleared in nfsd_shutdown_net() after they are freed, both under nfsd_mutex. Gating the three unlock paths on NFSD_NET_UP fixes the startup-time NULL dereference while preserving the earlier post-shutdown use-after-free fix.
--- fs/nfsd/nfs4proc.c | 7 +++---- fs/nfsd/nfs4state.c | 14 ++++++-------- fs/nfsd/nfsctl.c | 6 +++--- 3 files changed, 12 insertions(+), 15 deletions(-)
fs/nfsd/nfs4proc.c +3 -4
@@ -1598,10 +1598,9 @@ static bool nfsd4_copy_on_sb(const struc* @net: net namespace containing the copy operations * @sb: targeted superblock * -* Context: Caller must hold nfsd_mutex with nn->nfsd_serv confirmed -* non-NULL. nfs4_state_destroy_net() frees conf_id_hashtbl -* at server shutdown without clearing the pointer, so a -* walk without these guarantees iterates freed slab memory. +* Context: Caller must hold nfsd_mutex with NFSD_NET_UP set. Outside +* that window nn->conf_id_hashtbl is unallocated or freed, +* so the walk would dereference a NULL or dangling pointer. */ void nfsd4_cancel_copy_by_sb (struct net *net,struct super_block *sb) {
fs/nfsd/nfs4state.c +6 -8
@@ -1947,10 +1947,9 @@ static void revoke_one_stid(struct nfsd_* The clients which own the states will subsequently be notified that the * states have been "admin-revoked". * -* Context: Caller must hold nfsd_mutex with nn->nfsd_serv confirmed -* non-NULL. nfs4_state_destroy_net() frees conf_id_hashtbl -* at server shutdown without clearing the pointer, so a -* walk without these guarantees iterates freed slab memory. +* Context: Caller must hold nfsd_mutex with NFSD_NET_UP set. Outside +* that window nn->conf_id_hashtbl is unallocated or freed, +* so the walk would dereference a NULL or dangling pointer. */ void nfsd4_revoke_states (struct nfsd_net *nn,struct super_block *sb) {
@@ -2038,10 +2037,9 @@ static struct nfs4_stid *find_one_export* Userspace (exportfs -u) sends this after removing the last client * for a path, enabling the underlying filesystem to be unmounted. * -* Context: Caller must hold nfsd_mutex with nn->nfsd_serv confirmed -* non-NULL. nfs4_state_destroy_net() frees conf_id_hashtbl -* at server shutdown without clearing the pointer, so a -* walk without these guarantees iterates freed slab memory. +* Context: Caller must hold nfsd_mutex with NFSD_NET_UP set. Outside +* that window nn->conf_id_hashtbl is unallocated or freed, +* so the walk would dereference a NULL or dangling pointer. */ void nfsd4_revoke_export_states (struct nfsd_net *nn,const struct path *path) {
fs/nfsd/nfsctl.c +3 -3
@@ -299,7 +299,7 @@ static ssize_t write_unlock_fs(struct fi error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb);mutex_lock (&nfsd_mutex); nn =net_generic (netns (file), nfsd_net_id); -if (nn->nfsd_serv) { +if (test_bit (NFSD_NET_UP , &nn->flags)) {nfsd4_cancel_copy_by_sb (netns (file), path.dentry->d_sb);nfsd4_revoke_states (nn, path.dentry->d_sb); }else {
@@ -2424,7 +2424,7 @@ int nfsd_nl_unlock_filesystem_doit(struc error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb);mutex_lock (&nfsd_mutex); -if (nn->nfsd_serv) { +if (test_bit (NFSD_NET_UP , &nn->flags)) {nfsd4_cancel_copy_by_sb (net, path.dentry->d_sb);nfsd4_revoke_states (nn, path.dentry->d_sb); }else {
@@ -2471,7 +2471,7 @@ int nfsd_nl_unlock_export_doit(struct skreturn error;mutex_lock (&nfsd_mutex); -if (nn->nfsd_serv) { +if (test_bit (NFSD_NET_UP , &nn->flags)) {nfsd_file_close_export (net, &path);nfsd4_revoke_export_states (nn, &path); }else
Greg Kroah-Hartman
maintainerPATCH 20/556 NFSD: Prevent client use-after-free during export state revocation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 2108de53568a64936a0da3e04d85c35df98d3fb6 ]
nfsd4_revoke_export_states() has the same use-after-free as nfsd4_revoke_states(): it drops nn->client_lock across revoke_one_stid() and the following read of clp->cl_minorversion, but the stateid reference it holds does not pin the client. A teardown racing the dropped lock can free the client while revoke_one_stid() still dereferences it.
exportfs -u drives this path through NFSD_CMD_UNLOCK_EXPORT, so an administrator removing an export can race a client expiry.
Skip a client that is already expiring and otherwise pin it with cl_rpc_users under client_lock before dropping the lock, matching nfsd4_revoke_states().
Stable-dep-of: 2330b788d732 ("NFSD: Prevent client use-after-free during close_lru reaping")
--- fs/nfsd/nfs4state.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +10 -3
@@ -2056,10 +2056,14 @@ void nfsd4_revoke_export_states(struct nstruct nfs4_client *clp; retry:list_for_each_entry (clp, head, cl_idhash) { -struct nfs4_stid *stid =find_one_export_stid ( - clp, path, - sc_types); +struct nfs4_stid *stid; + +/* Skip or pin clp as in nfsd4_revoke_states(). */ +if (is_client_expired (clp)) +continue ; + stid =find_one_export_stid (clp, path, sc_types);if (stid) { +atomic_inc (&clp->cl_rpc_users);spin_unlock (&nn->client_lock);revoke_one_stid (nn, clp, stid);nfs4_put_stid (stid);
@@ -2067,6 +2071,9 @@ void nfsd4_revoke_export_states(struct nif (clp->cl_minorversion ==0 ) nn->nfs40_last_revoke =ktime_get_boottime_seconds (); +if (atomic_dec_and_test (&clp->cl_rpc_users) && +is_client_expired (clp)) +wake_up_all (&expiry_wq); goto retry; } }
Greg Kroah-Hartman
maintainerPATCH 21/556 NFSD: Consolidate the revocation-path client unpin
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 3308cf3f11ed23c79f9f3f90b34bbbad3e3a6ea9 ]
The client use-after-free fixes in the state-revocation paths left four open-coded copies of one idiom: drop a cl_rpc_users pin without renewing the client's lease, waking force_expire_client() when the last pin drops on a client it is tearing down. The accompanying "do not renew" rationale was documented at only one of the four sites.
put_client_renew_locked() and put_client_renew() already carry the same pin-drop logic, but they renew a non-expired client's lease and so would resurrect the client whose state is being revoked. Factor the common pin-drop into __put_client_locked(), parameterized by whether to renew. The renew helpers pass true; the new put_client_no_renew_locked() and put_client_no_renew() pass false and carry the revocation paths, which must not revive the client they are tearing down. No change in behavior.
Stable-dep-of: 2330b788d732 ("NFSD: Prevent client use-after-free during close_lru reaping")
--- fs/nfsd/nfs4state.c | 69 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 28 deletions(-)
fs/nfsd/nfs4state.c +41 -28
@@ -202,18 +202,28 @@ renew_client_locked(struct nfs4_client * clp->cl_state =NFSD4_ACTIVE ; } +/* +* Finish a cl_rpc_users unpin with the client_lock held. A +* revocation walk clears @renew so the client whose state it is +* revoking is not revived; every other caller renews the lease of +* a still-active client. +*/ +static void __put_client_locked (struct nfs4_client *clp,bool renew) +{ +if (is_client_expired (clp)) +wake_up_all (&expiry_wq); +else if (renew) +renew_client_locked (clp); +} +static void put_client_renew_locked (struct nfs4_client *clp) {struct nfsd_net *nn =net_generic (clp->net, nfsd_net_id);lockdep_assert_held (&nn->client_lock); -if (!atomic_dec_and_test (&clp->cl_rpc_users)) -return ; -if (!is_client_expired (clp)) -renew_client_locked (clp); -else -wake_up_all (&expiry_wq); +if (atomic_dec_and_test (&clp->cl_rpc_users)) +__put_client_locked (clp, true); }static void put_client_renew (struct nfs4_client *clp)
@@ -222,10 +232,27 @@ static void put_client_renew(struct nfs4if (!atomic_dec_and_lock (&clp->cl_rpc_users, &nn->client_lock))return ; -if (!is_client_expired (clp)) -renew_client_locked (clp); -else -wake_up_all (&expiry_wq); +__put_client_locked (clp, true); +spin_unlock (&nn->client_lock); +} + +static void put_client_no_renew_locked (struct nfs4_client *clp) +{ +struct nfsd_net *nn =net_generic (clp->net, nfsd_net_id); + +lockdep_assert_held (&nn->client_lock); + +if (atomic_dec_and_test (&clp->cl_rpc_users)) +__put_client_locked (clp, false); +} + +static void put_client_no_renew (struct nfs4_client *clp) +{ +struct nfsd_net *nn =net_generic (clp->net, nfsd_net_id); + +if (!atomic_dec_and_lock (&clp->cl_rpc_users, &nn->client_lock)) +return ; +__put_client_locked (clp, false);spin_unlock (&nn->client_lock); }
@@ -1991,9 +2018,7 @@ void nfsd4_revoke_states(struct nfsd_net*/ nn->nfs40_last_revoke =ktime_get_boottime_seconds (); -if (atomic_dec_and_test (&clp->cl_rpc_users) && -is_client_expired (clp)) -wake_up_all (&expiry_wq); +put_client_no_renew_locked (clp); goto retry; } }
@@ -2071,9 +2096,7 @@ void nfsd4_revoke_export_states(struct nif (clp->cl_minorversion ==0 ) nn->nfs40_last_revoke =ktime_get_boottime_seconds (); -if (atomic_dec_and_test (&clp->cl_rpc_users) && -is_client_expired (clp)) -wake_up_all (&expiry_wq); +put_client_no_renew_locked (clp); goto retry; } }
@@ -7205,9 +7228,7 @@ retry:nfsd4_drop_revoked_stid (stid);nfs4_put_stid (stid);spin_lock (&nn->client_lock); -if (atomic_dec_and_test (&clp->cl_rpc_users) && -is_client_expired (clp)) -wake_up_all (&expiry_wq); +put_client_no_renew_locked (clp); goto retry; }spin_unlock (&clp->cl_lock);
@@ -7280,15 +7301,7 @@ nfs4_laundromat(struct nfsd_net *nn) clp = dp->dl_stid.sc_client;list_del_init (&dp->dl_recall_lru);revoke_delegation (dp); -/* -* Unpin without renewing: put_client_renew() would -* renew the reaped client's lease. -*/ -if (atomic_dec_and_lock (&clp->cl_rpc_users, &nn->client_lock)) { -if (is_client_expired (clp)) -wake_up_all (&expiry_wq); -spin_unlock (&nn->client_lock); - } +put_client_no_renew (clp); }spin_lock (&nn->client_lock);
Greg Kroah-Hartman
maintainerPATCH 22/556 NFSD: Prevent client use-after-free during close_lru reaping
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 2330b788d732f43668b965b3105b37ceb276dfea ]
An nfs4_openowner left on nn->close_lru after its final CLOSE keeps its last closed stateid in oo_last_closed_stid, holding only a raw pointer to its nfs4_client. The laundromat reaps timed-out entries, drops nn->client_lock, and calls nfs4_put_stid(), which dereferences the client through cl_lock. Nothing pins the client across that window, so a concurrent force_expire_client() can free it and nfs4_put_stid() reads freed memory. __destroy_client() hits the same race, walking clp->cl_openowners without cl_lock.
Pin the client with cl_rpc_users before dropping client_lock, and skip clients already expiring. __destroy_client() then cleans up its own close_lru entries through release_last_closed_stateid(), so teardown no longer races the laundromat.
--- fs/nfsd/nfs4state.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/nfsd/nfs4state.c +5 -0
@@ -7311,11 +7311,16 @@ nfs4_laundromat(struct nfsd_net *nn)if (!state_expired (<, oo->oo_time))break ;list_del_init (&oo->oo_close_lru); + clp = oo->oo_owner.so_client; +if (is_client_expired (clp)) +continue ; stp = oo->oo_last_closed_stid; oo->oo_last_closed_stid =NULL ; +atomic_inc (&clp->cl_rpc_users);spin_unlock (&nn->client_lock);nfs4_put_stid (&stp->st_stid);spin_lock (&nn->client_lock); +put_client_no_renew_locked (clp); }spin_unlock (&nn->client_lock);
Greg Kroah-Hartman
maintainerPATCH 23/556 NFSD: Prevent client use-after-free during blocked-lock reaping
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 9026932ac8be4d0ae01db47f23619a98cc57b671 ]
A bare lock owner -- its only remaining reference a blocked lock on nn->blocked_locks_lru -- holds a raw pointer to its nfs4_client but no reference keeping the client alive. When the per-net laundromat reaps such a lock, freeing the nbl drops the owner reference held through flc_owner, and the final nfs4_put_stateowner() takes the client's cl_lock. Because the laundromat detaches the nbl first, __destroy_client() no longer finds it, so a concurrent force_expire_client() can free the client before nfs4_put_stateowner() runs, dereferencing cl_lock in freed memory.
Pin the client with cl_rpc_users before dropping nn->blocked_locks_lock, and skip clients already expiring, whose blocked locks __destroy_client() frees while holding an owner reference. Take nn->client_lock outside nn->blocked_locks_lock. Every other site holds nn->blocked_locks_lock as a leaf, acquiring no further lock, so placing nn->client_lock outside it cannot form a lock-order cycle.
--- fs/nfsd/nfs4state.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +20 -3
@@ -353,6 +353,16 @@ free_blocked_lock(struct nfsd4_blocked_lkref_put (&nbl->nbl_kref, free_nbl); } +/* A blocked lock's flc_owner is its nfs4_lockowner. */ +static struct nfs4_client * +nbl_client (struct nfsd4_blocked_lock *nbl) +{ +struct nfs4_lockowner *lo; + + lo = (struct nfs4_lockowner *)nbl->nbl_lock.c.flc_owner; +return lo->lo_owner.so_client; +} +static void remove_blocked_locks (struct nfs4_lockowner *lo) {
@@ -7336,22 +7346,29 @@ nfs4_laundromat(struct nfsd_net *nn)* indefinitely once the lock does become free. */ BUG_ON (!list_empty (&reaplist)); +spin_lock (&nn->client_lock);spin_lock (&nn->blocked_locks_lock); -while (!list_empty (&nn->blocked_locks_lru)) { - nbl =list_first_entry (&nn->blocked_locks_lru, - struct nfsd4_blocked_lock, nbl_lru); +list_for_each_safe (pos, next, &nn->blocked_locks_lru) { + nbl = list_entry(pos, struct nfsd4_blocked_lock, nbl_lru);if (!state_expired (<, nbl->nbl_time))break ; + clp =nbl_client (nbl); +if (is_client_expired (clp)) +continue ; +atomic_inc (&clp->cl_rpc_users);list_move (&nbl->nbl_lru, &reaplist);list_del_init (&nbl->nbl_list); }spin_unlock (&nn->blocked_locks_lock); +spin_unlock (&nn->client_lock);while (!list_empty (&reaplist)) { nbl =list_first_entry (&reaplist, struct nfsd4_blocked_lock, nbl_lru); + clp =nbl_client (nbl);list_del_init (&nbl->nbl_lru);free_blocked_lock (nbl); +put_client_no_renew (clp); }#ifdef CONFIG_NFSD_V4_2_INTER_SSC /* service the server-to-server copy delayed unmount list */
Greg Kroah-Hartman
maintainerPATCH 24/556 drm/amd/display: fix division by zero in get_estimated_bw()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hari Mishal <[email protected]>
commit f63de9054da858d57054474c32464106f8375e0d upstream.
get_estimated_bw() divides by link->dpia_bw_alloc_config.bw_granularity, which is zeroed by reset_bw_alloc_struct() and only populated once DP_TUNNELING_BW_ALLOC_CAP_CHANGED has been handled.
link_dp_dpia_handle_bw_alloc_status(), the DPCD interrupt handler, calls get_estimated_bw() whenever DP_TUNNELING_ESTIMATED_BW_CHANGED is set, independently of whether DP_TUNNELING_BW_ALLOC_CAP_CHANGED has ever fired for that link. A connected USB4/DPIA tunneling device that reports an estimated-bandwidth change before ever reporting a capability change drives a division by zero in this IRQ path.
link_dpia_send_bw_alloc_request() already guards the same bw_granularity division; add the identical guard here rather than introducing a new pattern.
--- drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/display/dc/link/protocols/link_dp_dpia_bw.c +5 -0
@@ -103,6 +103,11 @@ static int get_estimated_bw(struct dc_li {uint8_t bw_estimated_bw =0 ; +if (link->dpia_bw_alloc_config.bw_granularity ==0 ) { +DC_LOG_ERROR ("%s: BW granularity is zero!\n" , __func__); +return 0 ; + } + core_link_read_dpcd( link, ESTIMATED_BW,
Greg Kroah-Hartman
maintainerPATCH 25/556 usb: image: mdc800: change kmalloc() to kzalloc()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Griffin Kroah-Hartman <[email protected]>
commit 2430eb81e44111b30eeb5273bbcf8b24ca517ef9 upstream.
Change the kmalloc() calls in usb_mdc800_init() for irq_urb_buffer and download_urb_buffer to kzalloc(), avoiding potential stack leaks if a shorter message is received in mdc800_usb_irq() and mdc800_usb_download_notify()
--- drivers/usb/image/mdc800.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/image/mdc800.c +2 -2
@@ -1000,13 +1000,13 @@ static int __init usb_mdc800_init (void) mdc800->downloaded =0 ; mdc800->written =0 ; - mdc800->irq_urb_buffer=kmalloc (8 ,GFP_KERNEL ); + mdc800->irq_urb_buffer=kzalloc (8 ,GFP_KERNEL );if (!mdc800->irq_urb_buffer) goto cleanup_on_fail; mdc800->write_urb_buffer=kmalloc (8 ,GFP_KERNEL );if (!mdc800->write_urb_buffer) goto cleanup_on_fail; - mdc800->download_urb_buffer=kmalloc (64 ,GFP_KERNEL ); + mdc800->download_urb_buffer=kzalloc (64 ,GFP_KERNEL );if (!mdc800->download_urb_buffer) goto cleanup_on_fail;
Greg Kroah-Hartman
maintainerPATCH 26/556 ALSA: usb-audio: fix OOB write in snd_usbmidi_us122l_output()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
commit e4637ce34607f1733a34a57294966d26b263e626 upstream.
The snd_usbmidi_us122l_output() picks a count of 2 on anything slower than high speed and never relates it to ep->max_transfer. The URB buffer holds exactly max_transfer bytes, so a device declaring a one byte bulk endpoint takes two bytes from snd_rawmidi_transmit(), and the memset that pads the rest computes 1 - 2 in int and wraps to SIZE_MAX.
Only 0x800e and 0x800f are pinned to nine bytes. The US-122MKII at 0x0644:0x8021 falls to the default and takes usb_maxpacket(), which the USB core only clamps downward.
The akai and novation output ops in this file were given the same guard recently. Do the same here.
--- sound/usb/midi.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/midi.c +2 -0
@@ -971,6 +971,8 @@ static void snd_usbmidi_us122l_output(stdefault : count =2 ; } +if (ep->max_transfer < count) +return ; count =snd_rawmidi_transmit (ep->ports[0 ].substream, urb->transfer_buffer, count);
Greg Kroah-Hartman
maintainerPATCH 27/556 clk: qcom: gcc-mdm9607: Increase delay for USB PHY reset
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit c99bc8e83848358bd4a0436e4bdae5b7919babb2 upstream.
To conform to the specifications of the USB PHY, the reset signal should be asserted for at least 10us. Guarantee that by increasing the delay for the USB2_HS_PHY_ONLY_BCR reset control similar to commit dcc6c9fb7128 ("clk:
qcom: gcc-msm8909: Increase delay for USB PHY reset").
--- drivers/clk/qcom/gcc-mdm9607.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/gcc-mdm9607.c +1 -1
@@ -1567,7 +1567,7 @@ static const struct qcom_reset_map gcc_m [USB_HS_HSIC_BCR] = { 0x3d05c }, [GCC_MSS_RESTART] = { 0x3e000 }, [USB_HS_BCR] = { 0x41000 }, - [USB2_HS_PHY_ONLY_BCR] = { 0x41034 }, + [USB2_HS_PHY_ONLY_BCR] = { .reg = 0x41034, .udelay = 15 }, [QUSB2_PHY_BCR] = { 0x4103c }, };
Greg Kroah-Hartman
maintainerPATCH 28/556 media: usbtv: keep device alive while ALSA card exists
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
commit fc530fe168bb2b745a93f553ad21fc25fd9cba3d upstream.
The ALSA PCM callbacks store the driver state in pcm->private_data. An open PCM file can outlive USB disconnect because usbtv_audio_free() uses snd_card_free_when_closed(). The disconnect path can then drop the V4L2 device reference and free struct usbtv before ALSA releases the substream, so a later close dereferences freed memory in snd_usbtv_pcm_close().
Take a V4L2 device reference for the ALSA card and drop it from the card private_free callback. This keeps struct usbtv valid until ALSA has closed the remaining files and freed the card.
--- drivers/media/usb/usbtv/usbtv-audio.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/media/usb/usbtv/usbtv-audio.c +11 -0
@@ -317,6 +317,13 @@ static const struct snd_pcm_ops snd_usbt .pointer = snd_usbtv_pointer, }; +static void usbtv_audio_card_free (struct snd_card *card) +{ +struct usbtv *usbtv = card->private_data; + +v4l2_device_put (&usbtv->v4l2_dev); +} +int usbtv_audio_init (struct usbtv *usbtv) {int rv;
@@ -331,6 +338,10 @@ int usbtv_audio_init(struct usbtv *usbtvif (rv <0 )return rv; +v4l2_device_get (&usbtv->v4l2_dev); + card->private_data = usbtv; + card->private_free = usbtv_audio_card_free; +strscpy (card->driver, usbtv->dev->driver->name,sizeof (card->driver));strscpy (card->shortname,"usbtv" ,sizeof (card->shortname)); snprintf(card->longname, sizeof(card->longname),
Greg Kroah-Hartman
maintainerPATCH 29/556 usb-storage: ene_ub6250: fix race between scan work and probe
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Qi <[email protected]>
commit 445fc368c6bc73eff0aeb3818cf5f355facfbb16 upstream.
ene_ub6250_probe() calls usb_stor_probe2(), which starts the usb-storage infrastructure and schedules the delayed scan work. The driver then calls ene_get_card_type(), which sends an ENE command through ene_send_scsi_cmd() and the usb-storage bulk transfer helpers.
Both the delayed scan work, through usb_stor_Bulk_max_lun(), and ene_get_card_type() use us->current_urb. The scan work serializes this access with us->dev_mutex, but the ENE card-type probe does not. If the scan work runs while ene_get_card_type() is still using us->current_urb, usb_submit_urb() warns that the URB is already active.
Serialize ene_get_card_type() with us->dev_mutex, matching the locking used by the scan path.
--- drivers/usb/storage/ene_ub6250.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/storage/ene_ub6250.c +2 -0
@@ -2357,7 +2357,9 @@ static int ene_ub6250_probe(struct usb_ireturn result;/* probe card type */ +mutex_lock (&us->dev_mutex); result =ene_get_card_type (us,REG_CARD_STATUS , info->bbuf); +mutex_unlock (&us->dev_mutex);if (result !=USB_STOR_XFER_GOOD ) {usb_stor_disconnect (intf);return USB_STOR_TRANSPORT_ERROR ;
Greg Kroah-Hartman
maintainerPATCH 30/556 usb: cdnsp: fix wakeup from S3 after controller context loss
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pawel Laszczak <[email protected]>
commit eae6460f617382044c5afe5ef202f4d8b2c099b5 upstream.
CDNSP controller may lose its runtime register programming across S3 suspend/resume, depending on SoC power domain configuration. After resume the operational and interrupter registers may contain reset values, which prevents the gadget side from recovering correctly and breaks wakeup from S3.
Fix this by detecting whether the controller lost its register context after resume and handling both cases:
- If context was lost (CFG_3XPORT_U1_PIPE_CLK_GATE_EN set or power lost): reset the controller and reprogram the state required for normal operation, including the command ring, DCBAA pointer, doorbell base, event ring, ERST base/size and event ring dequeue pointer.
- If context was retained: restart the controller directly without reprogramming registers. Issue a wakeup if the link was in U3 before suspend.
Move the basic controller register programming out of the one-time memory initialization path and make it reusable from the resume path. Also separate ring allocation from ring initialization so that rings can be reinitialized without reallocating DMA memory.
Always perform the full suspend sequence regardless of the current link state. Previously, if the device was already in U3, the suspend callback returned early without stopping the controller, which could lead to commands being issued on a disabled slot during resume.
--- drivers/usb/cdns3/cdnsp-gadget.c | 111 +++++++++++++++++++++++++++++++++++++-- drivers/usb/cdns3/cdnsp-gadget.h | 1 drivers/usb/cdns3/cdnsp-mem.c | 98 ++++++++++++---------------------- 3 files changed, 142 insertions(+), 68 deletions(-)
drivers/usb/cdns3/cdnsp-gadget.c +106 -5
@@ -1338,7 +1338,6 @@ static int cdnsp_run(struct cdnsp_device cdnsp_gadget_ep0_desc.wMaxPacketSize =cpu_to_le16 (512 ); - ret =cdnsp_start (pdev);if (ret) { ret = -ENODEV ;
@@ -1837,6 +1836,82 @@ static void cdnsp_get_rev_cap(struct cdn readl(&pdev->rev_cap->tx_buff_size)); } +static void cdnsp_set_event_deq (struct cdnsp_device *pdev) +{ +dma_addr_t deq; +u64 temp; + + deq =cdnsp_trb_virt_to_dma (pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + +/* Update controller event ring dequeue pointer */ + temp =cdnsp_read_64 (&pdev->ir_set->erst_dequeue); + temp &=ERST_PTR_MASK ; + +/* +* Don't clear the EHB bit (which is RW1C) because +* there might be more events to service. +*/ + temp &= ~ERST_EHB ; + +cdnsp_write_64 (((u64 )deq & (u64 )~ERST_PTR_MASK ) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_interrupter (struct cdnsp_device *pdev) +{ +u64 erst_base; +u32 erst_size; + +/* Set ERST count with the number of entries in the segment table. */ + erst_size =readl (&pdev->ir_set->erst_size); + erst_size &=ERST_SIZE_MASK ; + erst_size |=ERST_NUM_SEGS ; +writel (erst_size, &pdev->ir_set->erst_size); + +/* Set the segment table base address. */ + erst_base =cdnsp_read_64 (&pdev->ir_set->erst_base); + erst_base &=ERST_PTR_MASK ; + erst_base |= (pdev->erst.erst_dma_addr & (u64 )~ERST_PTR_MASK ); +cdnsp_write_64 (erst_base, &pdev->ir_set->erst_base); + +/* Set the event ring dequeue address. */ +cdnsp_set_event_deq (pdev); +} + +/* Set up basic CDNSP registers */ +static void cdnsp_init (struct cdnsp_device *pdev) +{ +unsigned int val; +u64 val_64; + + val =readl (&pdev->op_regs->config_reg); + val |= ((val & ~MAX_DEVS ) |CDNSP_DEV_MAX_SLOTS ) |CONFIG_U3E ; +writel (val, &pdev->op_regs->config_reg); + +/* Initialize the Command ring */ +cdnsp_ring_init (pdev, pdev->cmd_ring); + +/* Set the address in the Command Ring Control register */ + val_64 =cdnsp_read_64 (&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64 )CMD_RING_RSVD_BITS ) | + (pdev->cmd_ring->first_seg->dma & (u64 )~CMD_RING_RSVD_BITS ) | + pdev->cmd_ring->cycle_state; +cdnsp_write_64 (val_64, &pdev->op_regs->cmd_ring); + +/* Set Device Context Base Address Array pointer */ +cdnsp_write_64 (pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr); + +/* Set Doorbell array pointer */ + val =readl (&pdev->cap_regs->db_off); + val &=DBOFF_MASK ; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + +/* Initialize the Primary interrupter */ +cdnsp_ring_init (pdev, pdev->event_ring); +cdnsp_add_interrupter (pdev); +} +static int cdnsp_gen_setup (struct cdnsp_device *pdev) {int ret;
@@ -1902,6 +1977,8 @@ static int cdnsp_gen_setup(struct cdnsp_if (ret)return ret; +cdnsp_init (pdev); +/* * Software workaround for U1: after transition * to U1 the controller starts gating clock, and in some cases,
@@ -2031,9 +2108,6 @@ static int cdnsp_gadget_suspend(struct cstruct cdnsp_device *pdev = cdns->gadget_dev;unsigned long flags; -if (pdev->link_state ==XDEV_U3 ) -return 0 ; -spin_lock_irqsave (&pdev->lock, flags);cdnsp_disconnect_gadget (pdev);cdnsp_stop (pdev);
@@ -2047,12 +2121,38 @@ static int cdnsp_gadget_resume(struct cdstruct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;unsigned long flags; +bool context_lost; +u32 val;int ret;if (!pdev->gadget_driver)return 0 ;spin_lock_irqsave (&pdev->lock, flags); + val =readl (&pdev->port3x_regs->mode_2); + context_lost = !!(val &CFG_3XPORT_U1_PIPE_CLK_GATE_EN ) || lost_power; + +if (context_lost) { +cdnsp_halt (pdev); +cdnsp_set_apb_timeout_value (pdev); + +/* Reset the internal controller memory state and registers. */ + ret =cdnsp_reset (pdev); +if (ret) + goto unlock; + + val =readl (&pdev->port3x_regs->mode_2); + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN ; +writel (val, &pdev->port3x_regs->mode_2); + +cdnsp_clear_cmd_ring (pdev); + +memset (pdev->event_ring->first_seg->trbs,0 , +sizeof (union cdnsp_trb ) * (TRBS_PER_SEGMENT )); + +cdnsp_init (pdev); + } + max_speed = pdev->gadget_driver->max_speed;/* Limit speed if necessary. */
@@ -2060,9 +2160,10 @@ static int cdnsp_gadget_resume(struct cd ret =cdnsp_run (pdev, max_speed); -if (pdev->link_state ==XDEV_U3 ) +if (!context_lost && pdev->link_state ==XDEV_U3 )__cdnsp_gadget_wakeup (pdev); +unlock:spin_unlock_irqrestore (&pdev->lock, flags);return ret;
drivers/usb/cdns3/cdnsp-gadget.h +1 -0
@@ -1510,6 +1510,7 @@ int cdnsp_endpoint_init(struct cdnsp_devint cdnsp_ring_expansion (struct cdnsp_device *pdev,struct cdnsp_ring *ring,unsigned int num_trbs,gfp_t flags); +void cdnsp_ring_init (struct cdnsp_device *pdev,struct cdnsp_ring *ring);struct cdnsp_ring *cdnsp_dma_to_transfer_ring (struct cdnsp_ep *ep,u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep,
drivers/usb/cdns3/cdnsp-mem.c +35 -63
166 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 31/556 usb: f_mass_storage: Bump local buffer size in fsg_common_create_luns()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
commit 9f6f095beec82a80daa666a3b2186a5b95841e9a upstream.
GCC (Debian 14.2.0-19) is not happy about the buffer size:
drivers/usb/gadget/function/f_mass_storage.c:2970:48: error: ‘%d’ directive output may be truncated writing between 1 and 9 bytes into a region of size 5 [-Werror=format-truncation=]
Bump the size to get it enough for all possible values.
Note, although cfg->nluns is limited to FSG_MAX_LUNS (16), the compiler doesn't realize this and complains about the buffer size.
Also note, the existing comment is wrong as size 8 for the whole buffer doesn't cover 100 mil numbers, hence drop it altogether.
--- drivers/usb/gadget/function/f_mass_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_mass_storage.c +1 -1
@@ -2961,7 +2961,7 @@ EXPORT_SYMBOL_GPL(fsg_common_create_lun)int fsg_common_create_luns (struct fsg_common *common,struct fsg_config *cfg) { -char buf[8 ];/* enough for 100000000 different numbers, decimal */ +char buf[14 ];int i, rc;fsg_common_remove_luns (common);
Greg Kroah-Hartman
maintainerPATCH 32/556 usb: dwc3: google: Initialise probe properties with DWC3_DEFAULT_PROPERTIES
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Radhey Shyam Pandey <[email protected]>
commit 6b2a674fcc953378e5e750d47a888bbe51229de5 upstream.
dwc3_google_probe() zero initialises struct dwc3_probe_data and never assigns its properties member. The unspecified state of gsbuscfg0_reqinfo is encoded as DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED (0xffffffff), not as zero, so dwc3_get_software_properties() reads the zeroed field as a value the glue explicitly requested:
if (properties->gsbuscfg0_reqinfo !=
DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED) {
dwc->gsbuscfg0_reqinfo = properties->gsbuscfg0_reqinfo;
return;
}Two things follow. dwc3_config_soc_bus() programs GSBUSCFG0.REQINFO with zero on hardware that never asked for it, and the early return skips the walk over the parent devices, so a swnode or device tree supplied snps,gsbuscfg0-reqinfo would be ignored.
Assign DWC3_DEFAULT_PROPERTIES so the unset fields carry their unspecified sentinels and the controller is left alone.
--- drivers/usb/dwc3/dwc3-google.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/dwc3/dwc3-google.c +1 -0
@@ -442,6 +442,7 @@ static int dwc3_google_probe(struct plat probe_data.dwc = &google->dwc; probe_data.res = res; probe_data.ignore_clocks_and_resets = true; + probe_data.properties =DWC3_DEFAULT_PROPERTIES ; ret =dwc3_core_probe (&probe_data);if (ret) { ret =dev_err_probe (dev, ret,"failed to register DWC3 Core\n" );
Greg Kroah-Hartman
maintainerPATCH 33/556 usb: dwc3: clear forceRM when issuing EndTransfer
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Elson Serrao <[email protected]>
commit b58e6200450d350314db0ecda7d6d1bde3281e80 upstream.
The forceRM bit of the DEPCMD register controls the behavior of the EndTransfer command used to stop an active transfer. Older DWC3 programming guide revisions recommended setting forceRM=1 when issuing EndTransfer. Newer programming guide revisions recommend issuing EndTransfer with forceRM cleared.
With forceRM=1 on DWC_usb31 v2.00a and v2.10a controllers, a transfer aborted through the ep_dequeue path was observed to remain active after EndTransfer completion. A subsequent StartTransfer issued on the same endpoint triggered writes associated with the aborted transfer. This resulted in an SMMU fault because the transfer buffer had already been unmapped during EndTransfer command-completion cleanup.
Using forceRM=0 eliminates the issue. Although older DWC3 programming guide revisions recommended setting forceRM=1, no issues are known from using forceRM=0. Clear forceRM when issuing EndTransfer to provide consistent EndTransfer behavior and align with newer programming guide recommendations.
--- drivers/usb/dwc3/ep0.c | 2 +- drivers/usb/dwc3/gadget.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-)
drivers/usb/dwc3/ep0.c +1 -1
@@ -304,7 +304,7 @@ void dwc3_ep0_out_start(struct dwc3 *dwc dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP ;if (dwc->connected) -dwc3_stop_active_transfer (dwc3_ep, true, true); +dwc3_stop_active_transfer (dwc3_ep, false, true);else dwc3_remove_requests (dwc, dwc3_ep, -ESHUTDOWN ); }
drivers/usb/dwc3/gadget.c +13 -8
@@ -1004,7 +1004,7 @@ static int __dwc3_gadget_ep_enable(struc* controller to generate an ERDY to initiate the * stream. */ -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);/* * All stream eps will reinitiate stream on NoStream
@@ -1032,7 +1032,7 @@ void dwc3_remove_requests(struct dwc3 *d {struct dwc3_request *req; -dwc3_stop_active_transfer (dep, true, false); +dwc3_stop_active_transfer (dep, false, false);/* If endxfer is delayed, avoid unmapping requests */ if (dep->flags &DWC3_EP_DELAY_STOP )
@@ -1720,7 +1720,7 @@ static int __dwc3_gadget_kick_transfer(sif (ret == -EAGAIN )return ret; -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list)dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_DEQUEUED );
@@ -1757,6 +1757,11 @@ static int __dwc3_gadget_get_frame(struc* the controller won't update the TRB progress on command * completion. It also won't clear the HWO bit in the TRB. * The command will also not complete immediately in that case. +* +* Older programming guide revisions recommended setting ForceRM to 1 +* when ending a transfer. Newer programming guide revisions now +* recommend keeping ForceRM cleared, and TRBs are properly updated +* on command completion. */ static int __dwc3_stop_active_transfer (struct dwc3_ep *dep,bool force,bool interrupt) {
@@ -1882,7 +1887,7 @@ static int dwc3_gadget_start_isoc_quirk(* to wait for the next XferNotReady to test the command again */ if (cmd_status ==0 ) { -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);return 0 ; } }
@@ -2165,7 +2170,7 @@ static int dwc3_gadget_ep_dequeue(structstruct dwc3_request *t;/* wait until it is processed */ -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);/* * Remove any started request if the transfer is
@@ -2242,7 +2247,7 @@ int __dwc3_gadget_ep_set_halt(struct dwcreturn 0 ; } -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);list_for_each_entry_safe (req, tmp, &dep->started_list, list)dwc3_gadget_move_cancelled_request (req,DWC3_REQUEST_STATUS_STALLED );
@@ -3357,7 +3362,7 @@ static void dwc3_nostream_work(struct wodwc3_send_gadget_generic_command (dwc, cmd, dep->number); }else { dep->flags |=DWC3_EP_DELAY_START ; -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);spin_unlock_irqrestore (&dwc->lock, flags);return ; }
@@ -3715,7 +3720,7 @@ static bool dwc3_gadget_endpoint_trbs_coif (usb_endpoint_xfer_isoc (dep->endpoint.desc) &&list_empty (&dep->started_list) && (list_empty (&dep->pending_list) || status == -EXDEV )) -dwc3_stop_active_transfer (dep, true, true); +dwc3_stop_active_transfer (dep, false, true);else if (dwc3_gadget_ep_should_continue (dep))if (__dwc3_gadget_kick_transfer (dep) ==0 ) no_started_trb = false;
Greg Kroah-Hartman
maintainerPATCH 34/556 usb: storage: realtek_cr: fix use-after-free on disconnect
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 4ffee1aebb0c0ffcda9faffd17834ea9b00d42cc upstream.
realtek_cr_destructor() calls timer_delete() before the chip containing the timer is freed. The timer callback may still be running and can rearm itself, resulting in a use-after-free.
Use timer_shutdown_sync() to wait for the callback and prevent further rearming. Do this unconditionally because ss_en may be changed after the timer is armed.
Move timer_setup() into init_realtek_cr() so the timer is initialized before any failure path can invoke the destructor.
Found by static analysis.
--- drivers/usb/storage/realtek_cr.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/storage/realtek_cr.c +4 -5
@@ -916,7 +916,6 @@ static int realtek_cr_autosuspend_setup( us->proto_handler = rts51x_invoke_transport; chip->timer_expires =0 ; -timer_setup (&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn,0 );fw5895_init (us);/* enable autosuspend function of the usb device */
@@ -934,10 +933,7 @@ static void realtek_cr_destructor(void *return ;#ifdef CONFIG_REALTEK_AUTOPM -if (ss_en) { -timer_delete (&chip->rts51x_suspend_timer); - chip->timer_expires =0 ; - } +timer_shutdown_sync (&chip->rts51x_suspend_timer);#endif kfree (chip->status); }
@@ -982,6 +978,9 @@ static int init_realtek_cr(struct us_dat us->extra = chip; us->extra_destructor = realtek_cr_destructor; +#ifdef CONFIG_REALTEK_AUTOPM +timer_setup (&chip->rts51x_suspend_timer, rts51x_suspend_timer_fn,0 ); +#endif us->max_lun = chip->max_lun =rts51x_get_max_lun (us); chip->us = us;
Greg Kroah-Hartman
maintainerPATCH 35/556 usb: typec: hd3ss3220: track VBUS enable state per consumer
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chang Wu <[email protected]>
commit c9a48db776d7184981630ecc01a3ad30a8f7dc24 upstream.
regulator_is_enabled() reports the aggregate regulator state, not whether this consumer holds an enable reference. If another consumer enables VBUS first, the driver can skip its own regulator_enable() call and later attempt to drop a reference it never acquired, triggering an unbalanced regulator disable warning.
Track successful enable and disable calls locally. Keep the state unchanged when an operation fails so a later role or ID notification retries the operation while this consumer keeps balanced references.
--- drivers/usb/typec/hd3ss3220.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/usb/typec/hd3ss3220.c +7 -2
@@ -62,6 +62,7 @@ struct hd3ss3220 {int id_irq;struct regulator *vbus; +bool vbus_enabled; };static int hd3ss3220_set_power_opmode (struct hd3ss3220 *hd3ss3220,int power_opmode)
@@ -208,7 +209,7 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on) {int ret; -if (regulator_is_enabled (hd3ss3220->vbus) == on) +if (hd3ss3220->vbus_enabled == on)return ;if (on)
@@ -216,9 +217,13 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)else ret =regulator_disable (hd3ss3220->vbus); -if (ret) +if (ret) {dev_err (hd3ss3220->dev,"vbus regulator %s failed: %d\n" , on ?"enable" :"disable" , ret); +return ; + } + + hd3ss3220->vbus_enabled = on; }static void hd3ss3220_set_role (struct hd3ss3220 *hd3ss3220)
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 36/556 usb: typec: mux: avoid duplicated mux switches
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
commit d50b6442bef66abbe4694f918f8ad013f81d75cf upstream.
Some devices use combo PHYs (i.e. USB3 + DisplayPort), which also handle the lane muxing. These PHYs are referenced twice from the USB-C connector (USB super-speed lines and SBU/AUX lines) resulting in the mux being configured twice. Avoid this by dropping duplicates.
This is a re-application of b145c3f29d62 ("usb: typec: mux: avoid duplicated mux switches"), with fix derived from usb: typec: mux:
Fix typec_switch_match() .
--- drivers/usb/typec/mux.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/usb/typec/mux.c +15 -2
@@ -275,7 +275,9 @@ static int mux_fwnode_match(struct devicstatic void *typec_mux_match (const struct fwnode_handle *fwnode,const char *id,void *data) { +struct typec_mux_dev **mux_devs = data;struct device *dev; +int i;/* * Device graph (OF graph) does not give any means to identify the
@@ -290,8 +292,18 @@ static void *typec_mux_match(const struc dev =class_find_device (&typec_mux_class,NULL , fwnode, mux_fwnode_match); +if (!dev) +return ERR_PTR (-EPROBE_DEFER ); + +/* Skip duplicates */ +for (i =0 ; i <TYPEC_MUX_MAX_DEVS ; i++) +if (to_typec_mux_dev (dev) == mux_devs[i]) { +put_device (dev); +return NULL ; + } -return dev ?to_typec_mux_dev (dev) :ERR_PTR (-EPROBE_DEFER ); + +return to_typec_mux_dev (dev); }/**
@@ -316,7 +328,8 @@ struct typec_mux *fwnode_typec_mux_get(sreturn ERR_PTR (-ENOMEM ); count =fwnode_connection_find_matches (fwnode,"mode-switch" , -NULL , typec_mux_match, + (void **)mux_devs, + typec_mux_match, (void **)mux_devs,ARRAY_SIZE (mux_devs));if (count <=0 ) {
Greg Kroah-Hartman
maintainerPATCH 37/556 usb: typec: mux: Fix typec_switch_match()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Vasut <[email protected]>
commit dea99705bc8fcda12590cfeeae6d2ba47a7ef572 upstream.
The fwnode_typec_switch_get() sporadically returns NULL instead of an -EPROBE_DEFER for orientation-switch described in DT. This makes it impossible to discern whether the DT does describe an orientation-switch which did not probe yet, or whether the DT does not describe the switch. This happens with gpio-sbu-mux connected to an I2C GPIO expander.
The class_find_device() on typec_switch_match() may return NULL in case the mux did not probe just yet early on boot. The sw_devs[] array can be empty on boot as well. If these two conditions occur, then the conditional if (to_typec_switch_dev(dev) == sw_devs[i]) evaluates to true and the match function returns NULL, which propagates to fwnode_typec_switch_get() which makes it look as if the orientation-switch was not described in DT.
This is incorrect, because the mux driver will probe a bit later on, but at that point, the caller of fwnode_typec_switch_get() already got the NULL return value. The NULL return value also does not trigger IS_ERR(), therefore the caller driver interprets this as if the orientation-switch is not described in DT, and does not return -EPROBE_DEFER to try again, even if it should.
Fix this by checking the class_find_device() return value, and return -EPROBE_DEFER if it is NULL right away. If the return value is not NULL, perform the deduplication test, and if that test passes, consider the return value to be already non-NULL.
--- drivers/usb/typec/mux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/typec/mux.c +3 -1
@@ -57,6 +57,8 @@ static void *typec_switch_match(const st*/ dev =class_find_device (&typec_mux_class,NULL , fwnode, switch_fwnode_match); +if (!dev) +return ERR_PTR (-EPROBE_DEFER );/* Skip duplicates */ for (i =0 ; i <TYPEC_MUX_MAX_DEVS ; i++)
@@ -65,7 +67,7 @@ static void *typec_switch_match(const streturn NULL ; } -return dev ?to_typec_switch_dev (dev) :ERR_PTR (-EPROBE_DEFER ); +return to_typec_switch_dev (dev); }/**
Greg Kroah-Hartman
maintainerPATCH 38/556 usb: typec: qcom-pmic-typec: disable cc_debounce_dwork on stop
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 263f7d61a4201cde16849b2d016251806e7418be upstream.
cc_debounce_dwork is queued from the set_cc() and start_toggling() callbacks, which run from TCPM's kthread worker. port_stop() returns before tcpm_unregister_port() destroys that worker. Flushing the worker during unregister may therefore run a callback which queues the delayed work after port_stop() has returned.
The delayed work can then run after devres has freed pmic_typec_port.
Use disable_delayed_work_sync() in port_stop() to cancel a pending instance and prevent the TCPM callbacks from queueing another one.
This issue was found by an in-house static analysis tool.
--- drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +2 -0
@@ -693,6 +693,8 @@ static void qcom_pmic_typec_port_stop(stfor (i =0 ; i < pmic_typec_port->nr_irqs; i++)disable_irq (pmic_typec_port->irq_data[i].irq); + +disable_delayed_work_sync (&pmic_typec_port->cc_debounce_dwork); } int qcom_pmic_typec_port_probe(struct platform_device *pdev,
Greg Kroah-Hartman
maintainerPATCH 39/556 usb: typec: qcom-pmic-typec: drain cc_debounce_dwork if port_start() fails
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit c9273c83885835dbd1e8835d5665dfb8503d65e0 upstream.
cc_debounce_dwork can be queued before port_start() fails:tcpm_register_port() runs first, and its state machine may invoke set_cc() or start_toggling() from the TCPM worker. The error path then calls tcpm_unregister_port(), whose worker flush may queue the delayed work before devres frees pmic_typec_port.
Disable and drain the delayed work directly at port_start()'s error exit. Do not use port_stop() for this path: its IRQs use IRQF_NO_AUTOEN and are enabled only after a successful port_start().
This issue was found by an in-house static analysis tool.
--- drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c +3 -0
@@ -683,6 +683,9 @@ static int qcom_pmic_typec_port_start(stenable_irq (pmic_typec_port->irq_data[i].irq); done: +if (ret) +disable_delayed_work_sync (&pmic_typec_port->cc_debounce_dwork); +return ret; }
Greg Kroah-Hartman
maintainerPATCH 40/556 usb: typec: qcom-pmic: cancel reset_work on stop
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 7b0df6efd143f8085bdb68778a013a46f1349913 upstream.
pdphy_stop() disables IRQs but leaves reset_work pending. If the IRQ handler schedules it just before disable_irq(), the work runs after remove() frees the struct via devm.
Call cancel_work_sync() after disabling IRQs to close the window.
This issue was found by an in-house static analysis tool.
--- drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c +2 -0
@@ -543,6 +543,8 @@ static void qcom_pmic_typec_pdphy_stop(sfor (i =0 ; i < pmic_typec_pdphy->nr_irqs; i++)disable_irq (pmic_typec_pdphy->irq_data[i].irq); +cancel_work_sync (&pmic_typec_pdphy->reset_work); +qcom_pmic_typec_pdphy_reset_on (pmic_typec_pdphy);regulator_disable (pmic_typec_pdphy->vdd_pdphy);
Greg Kroah-Hartman
maintainerPATCH 41/556 usb: typec: tcpm: constrain TCPM_SOURCING_VBUS event handling
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amit Sunil Dhamne <[email protected]>
commit cd3b9cea675bbfebc223f007dc2f4e79524fa54c upstream.
When a sink detach occurs while waiting for TX send status, the old TCPM_SOURCING_VBUS event along with TCPM_VBUS_EVENT and TCPM_CC_EVENT can be queued in port->pd_events. Because TCPM_SOURCING_VBUS is evaluated after TCPM_VBUS_EVENT and TCPM_CC_EVENT in tcpm_pd_event_handler(), a stale TCPM_SOURCING_VBUS event can override the detach handling and incorrectly set port->vbus_source and port->vbus_present to true.
Add a state guard to check that the port is either operating as a Source (tcpm_port_is_source(port)) or in a Fast Role Swap (FRS) state up to FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED before processing TCPM_SOURCING_VBUS. Otherwise, discard and log the event.
Log snippet for error condition before fix:
[72792.204955] state change SRC_ATTACHED -> SRC_STARTUP [rev3 NONE_AMS] [72792.204960] sourcing vbus [72792.204962] VBUS on [72792.204970] AMS POWER_NEGOTIATION start [72792.204974] cc:=4 [72792.205319] state change SRC_STARTUP -> AMS_START [rev3 POWER_NEGOTIATION] [72792.205325] state change AMS_START -> SRC_SEND_CAPABILITIES [rev3 POWER_NEGOTIATION] [72792.205332] PD TX, header: 0x11a1 [72792.216911] PD TX complete, status: 2 [72792.216957] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION] [72792.218005] VBUS off [72792.218013] pending state change SRC_SEND_CAPABILITIES -> SNK_UNATTACHED @ 650 ms [rev3 POWER_NEGOTIATION] [72792.218020] VBUS VSAFE0V [72792.218024] state change SRC_SEND_CAPABILITIES -> SNK_UNATTACHED [rev3 POWER_NEGOTIATION] [72792.218458] CC1: 2 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected] [72792.218467] VBUS on --> VBUS left on [72792.218980] disable vbus discharge ret:0 [72792.235193] Start toggling
After fix:
[ 1195.291691] state change SRC_ATTACHED -> SRC_STARTUP [rev3 NONE_AMS] [ 1195.291698] sourcing vbus [ 1195.291700] VBUS on [ 1195.291707] AMS POWER_NEGOTIATION start [ 1195.291710] cc:=4 [ 1195.291758] state change SRC_STARTUP -> AMS_START [rev3 POWER_NEGOTIATION] [ 1195.291794] state change AMS_START -> SRC_SEND_CAPABILITIES [rev3 POWER_NEGOTIATION] [ 1195.291798] PD TX, header: 0x11a1 [ 1195.297056] PD TX complete, status: 2 [ 1195.297092] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION] [ 1195.297177] VBUS off [ 1195.297184] pending state change SRC_SEND_CAPABILITIES -> SNK_UNATTACHED @ 650 ms [rev3 POWER_NEGOTIATION] [ 1195.297227] CC1: 2 -> 0, CC2: 0 -> 0 [state SRC_SEND_CAPABILITIES, polarity 0, disconnected] [ 1195.307469] cc:=2 [ 1195.307544] pending state change SRC_SEND_CAPABILITIES -> SNK_UNATTACHED @ 650 ms [rev3 POWER_NEGOTIATION] [ 1195.307555] Discarding sourcing vbus! Invalid state SRC_SEND_CAPABILITIES [ 1195.957636] state change SRC_SEND_CAPABILITIES -> SNK_UNATTACHED [delayed 650 ms] [ 1195.957732] disable vbus discharge ret:0 [ 1195.970196] Start toggling [ 1195.970468] VBUS off [ 1196.051637] VBUS off [ 1196.051642] VBUS VSAFE0V
--- drivers/usb/typec/tcpm/tcpm.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +22 -6
@@ -6921,16 +6921,32 @@ static void tcpm_pd_event_handler(struct } }if (events &TCPM_SOURCING_VBUS ) { -tcpm_log (port,"sourcing vbus" );/* * In fast role swap case TCPC autonomously sources vbus. Set vbus_source -* true as TCPM wouldn't have called tcpm_set_vbus. +* true conditionally as TCPM wouldn't have called tcpm_set_vbus. +* If TCPM calls tcpm_set_vbus to source vbus, vbus_source would already +* be true. * -* When vbus is sourced on the command on TCPM i.e. TCPM called -* tcpm_set_vbus to source vbus, vbus_source would already be true. +* When TCPM_FRS_EVENT and TCPM_SOURCING_VBUS arrive simultaneously, +* handling TCPM_FRS_EVENT above transitions the state to AMS_START +* with upcoming_state FR_SWAP_SEND. */ - port->vbus_source = true; -_tcpm_pd_vbus_on (port); + +if (tcpm_port_is_source (port) || +tcpm_port_is_debug_source (port) || + (port->state ==AMS_START && port->upcoming_state ==FR_SWAP_SEND ) || + port->state ==FR_SWAP_SEND || + port->state ==FR_SWAP_SEND_TIMEOUT || + port->state ==FR_SWAP_SNK_SRC_TRANSITION_TO_OFF || + port->state ==FR_SWAP_SNK_SRC_NEW_SINK_READY || + port->state ==FR_SWAP_SNK_SRC_SOURCE_VBUS_APPLIED ) { +tcpm_log (port,"sourcing vbus" ); + port->vbus_source = true; +_tcpm_pd_vbus_on (port); + }else { +tcpm_log (port,"Discarding sourcing vbus! Invalid state %s" , + tcpm_states[port->state]); + } }if (events &TCPM_PORT_CLEAN ) {tcpm_log (port,"port clean" );
Greg Kroah-Hartman
maintainerPATCH 42/556 usb: typec: tipd: Fix Thunderbolt altmode VDOs for cd321x
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Peter <[email protected]>
commit e24e3370356bddb65d667985a332b5f8aeeb5f97 upstream.
The Intel VID status register is actually 9 bytes long and doesn't contain the raw VDOs but only the upper 16bits for device mode and enter mode. Shift those two fields into place and reconstruct the cable discover mode VDO from the data status register instead since it's not directly accessible. With this fixed now the correct VDOs are forwarded to the PHY and the to-be-submitted Thunderbolt/USB4 native host interface so that the right mode can be negotiated and the link actually comes up.
--- drivers/usb/typec/tipd/core.c | 17 +++++++++++++---- drivers/usb/typec/tipd/tps6598x.h | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-)
drivers/usb/typec/tipd/core.c +13 -4
@@ -114,7 +114,6 @@ struct tps6598x_intel_vid_status_reg {__le32 attention_vdo;__le16 enter_vdo;__le16 device_mode; -__le16 cable_mode; } __packed;/* Standard Task return codes */
@@ -700,9 +699,19 @@ static void cd321x_typec_update_mode(str cd321x->state.mode == TYPEC_TBT_MODE)return ; - tbt_data.cable_mode =le16_to_cpu (st->intel_vid_status.cable_mode); - tbt_data.device_mode =le16_to_cpu (st->intel_vid_status.device_mode); - tbt_data.enter_vdo =le16_to_cpu (st->intel_vid_status.enter_vdo); + tbt_data.cable_mode =TBT_MODE | +TBT_SET_CABLE_SPEED (TPS_DATA_STATUS_TBT_CABLE_SPEED (st->data_status)) | +TBT_SET_CABLE_ROUNDED (TPS_DATA_STATUS_TBT_CABLE_GEN (st->data_status)); +if (st->data_status &TPS_DATA_STATUS_OPTICAL_CABLE ) + tbt_data.cable_mode |=TBT_CABLE_OPTICAL ; +if (st->data_status &TPS_DATA_STATUS_ACTIVE_LINK_TRAIN ) + tbt_data.cable_mode |=TBT_CABLE_LINK_TRAINING ; +if (st->data_status &TPS_DATA_STATUS_ACTIVE_CABLE ) + tbt_data.cable_mode |=TBT_CABLE_ACTIVE_PASSIVE ; + tbt_data.device_mode =TBT_MODE | + (u32 )le16_to_cpu (st->intel_vid_status.device_mode) <<16 ; + tbt_data.enter_vdo = + (u32 )le16_to_cpu (st->intel_vid_status.enter_vdo) <<16 ; cd321x->state.alt = cd321x->port_altmode_tbt; cd321x->state.mode =TYPEC_TBT_MODE ; cd321x->state.data = &tbt_data;
drivers/usb/typec/tipd/tps6598x.h +2 -2
@@ -206,10 +206,10 @@#define TPS_DATA_STATUS_DP_PIN_ASSIGNMENT (x) \ TPS_FIELD_GET(TPS_DATA_STATUS_DP_PIN_ASSIGNMENT_MASK, (x))#define TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK GENMASK(27, 25) -#define TPS_DATA_STATUS_TBT_CABLE_SPEED \ +#define TPS_DATA_STATUS_TBT_CABLE_SPEED (x) \ TPS_FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_SPEED_MASK, (x))#define TPS_DATA_STATUS_TBT_CABLE_GEN_MASK GENMASK(29, 28) -#define TPS_DATA_STATUS_TBT_CABLE_GEN \ +#define TPS_DATA_STATUS_TBT_CABLE_GEN (x) \ TPS_FIELD_GET(TPS_DATA_STATUS_TBT_CABLE_GEN_MASK, (x))/* Map data status to DP spec assignments */
Greg Kroah-Hartman
maintainerPATCH 43/556 usb: typec: ucsi: displayport: Fix OOB altmode array index
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jameson Thies <[email protected]>
commit 04cec690b1fd9d1c4c314b91a10d8c68a3acfe18 upstream.
The UCSI displayport driver indexes the connector's port altmode array with the GET_CURRENT_CAM response after checking it is not 0xff. The port altmode array is UCSI_MAX_ALTMODES elements long. If the PPM returns an invalid GET_CURRENT_CAM response above UCSI_MAX_ALTMODES and not equal to 0xff, the kernel may crash with an array index OOB error.
Update the UCSI displayport driver to verify the current cam is less than UCSI_MAX_ALTMODES before accessing the port altmode array.
--- drivers/usb/typec/ucsi/displayport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/ucsi/displayport.c +1 -1
@@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct cur =0xff ; } -if (cur !=0xff ) { +if (cur <UCSI_MAX_ALTMODES ) { ret = dp->con->port_altmode[cur] == alt ?0 : -EBUSY ; goto err_unlock; }
Greg Kroah-Hartman
maintainerPATCH 44/556 usb: gadget: midi2: Fix null-pointer dereference in f_midi2_free_ep_reqs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandr Nogikh <[email protected]>
commit f0efaf1872949e96d213c8e910fd9517f7d7c406 upstream.
A null-pointer dereference occurs in f_midi2_free_ep_reqs() when attempting to clean up an endpoint that was never initialized.
When configuring the MIDI 2.0 gadget via configfs and setting the block direction to SNDRV_UMP_DIR_INPUT, the initialization of the midi1_ep_out endpoint is explicitly skipped during the gadget bind phase (f_midi2_bind()). As a result, the usb_ep->card field remains NULL.
Later, when the host sets the alternate setting, f_midi2_set_alt() unconditionally stops both the IN and OUT endpoints by calling f_midi2_stop_eps(), which in turn calls f_midi2_free_ep_reqs() for both endpoints. When f_midi2_free_ep_reqs() is called for the uninitialized midi1_ep_out, it attempts to dereference usb_ep->card to determine the number of requests to free, leading to a crash.
Fix this by using usb_ep->num_reqs instead of usb_ep->card->info.num_reqs in f_midi2_free_ep_reqs(). usb_ep->num_reqs is correctly set during f_midi2_init_ep() and remains 0 if the endpoint was never initialized, safely avoiding the loop. For consistency, apply the same change to f_midi2_alloc_ep_reqs().
Oops: general protection fault, probably for non-canonical address 0xdffffc00000000ee: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000770-0x0000000000000777] ... RIP: 0010:f_midi2_free_ep_reqs drivers/usb/gadget/function/f_midi2.c:1166 [inline] RIP: 0010:f_midi2_stop_eps+0x28e/0x4d0 drivers/usb/gadget/function/f_midi2.c:1246 ... Call Trace: <TASK> f_midi2_set_alt+0x11c/0xf00 drivers/usb/gadget/function/f_midi2.c:1296 composite_setup+0x1ffd/0x3480 drivers/usb/gadget/composite.c:1933 configfs_composite_setup+0xbd/0x100 drivers/usb/gadget/configfs.c:1877
--- drivers/usb/gadget/function/f_midi2.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/usb/gadget/function/f_midi2.c +2 -3
@@ -1145,7 +1145,7 @@ static int f_midi2_alloc_ep_reqs(structif (!usb_ep->reqs)return -EINVAL ; -for (i =0 ; i < midi2->info.num_reqs; i++) { +for (i =0 ; i < usb_ep->num_reqs; i++) {if (usb_ep->reqs[i].req)continue ; usb_ep->reqs[i].req = alloc_ep_req(usb_ep->usb_ep,
@@ -1160,10 +1160,9 @@ static int f_midi2_alloc_ep_reqs(struct/* Free allocated requests */ static void f_midi2_free_ep_reqs (struct f_midi2_usb_ep *usb_ep) { -struct f_midi2 *midi2 = usb_ep->card;int i; -for (i =0 ; i < midi2->info.num_reqs; i++) { +for (i =0 ; i < usb_ep->num_reqs; i++) {if (!usb_ep->reqs[i].req)continue ;free_ep_req (usb_ep->usb_ep, usb_ep->reqs[i].req);
Greg Kroah-Hartman
maintainerPATCH 45/556 usb: gadget: f_mass_storage: fix null pointer dereference in fsg_common_set_num_buffers()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
commit 2c0f5ca48674a5b5f9fa4a9c3325aa48053af0bc upstream.
Previously fsg_num_buffers_validate() was removed as it was not necessary due to Kconfig setting the limits for n from 2 to 256 with default as 2. However, setting the page content in such a way that kstrtou8() reflects n value as either 0 or 1 bypasses these restrictions leading to a null pointer dereference if n is 0. Fix this by adding a check for n < 2 and returning -EINVAL if n is either 0 or 1 consistent with Kconfig logic.
--- drivers/usb/gadget/function/f_mass_storage.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/gadget/function/f_mass_storage.c +3 -0
@@ -2748,6 +2748,9 @@ int fsg_common_set_num_buffers(struct fsstruct fsg_buffhd *bh, *buffhds;int i; +if (n <2 ) +return -EINVAL ; + buffhds =kzalloc_objs (*buffhds, n);if (!buffhds)return -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 46/556 usb: gadget: f_midi2: fix use-after-free in string attribute show path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ivy Lopez <[email protected]>
commit fed0aa7c6eaedc6c0d4e362fc91724aa47be4a7b upstream.
f_midi2_opts_str_show() takes the string lock internally, but its callers dereference the opts->info.<field> pointer before calling it, outside the lock. This races with f_midi2_opts_str_store(), which frees the old string under opts->lock when the attribute is written concurrently, the show path can read a pointer that gets freed before the lock inside str_show() is even taken.
Change f_midi2_opts_str_show() to take a pointer to the string field, matching the existing pattern in f_midi2_opts_str_store(), and dereference it only after the lock is held. Update all three callers (iface_name, block name, and the EP string option macro) accordingly.
--- drivers/usb/gadget/function/f_midi2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/gadget/function/f_midi2.c +6 -6
@@ -2177,13 +2177,13 @@ end:/* generic show/store for string */ static ssize_t f_midi2_opts_str_show (struct f_midi2_opts *opts, -const char *str,char *page) +const char **strp,char *page) {int result =0 ;mutex_lock (&opts->lock); -if (str) - result =scnprintf (page,PAGE_SIZE ,"%s\n" , str); +if (*strp) + result =scnprintf (page,PAGE_SIZE ,"%s\n" , *strp);mutex_unlock (&opts->lock);return result; }
@@ -2277,7 +2277,7 @@ static ssize_t f_midi2_block_opts_name_s {struct f_midi2_block_opts *opts =to_f_midi2_block_opts (item); -return f_midi2_opts_str_show (opts->ep->opts, opts->info.name, page); +return f_midi2_opts_str_show (opts->ep->opts, &opts->info.name, page); } static ssize_t f_midi2_block_opts_name_store(struct config_item *item,
@@ -2434,7 +2434,7 @@ static ssize_t f_midi2_ep_opts_##name##_ char *page) \ { \struct f_midi2_ep_opts *opts =to_f_midi2_ep_opts (item); \ -return f_midi2_opts_str_show (opts->opts, opts->info.name, page);\ +return f_midi2_opts_str_show (opts->opts, &opts->info.name, page);\ } \ \ static ssize_t f_midi2_ep_opts_##name##_store(struct config_item *item, \
@@ -2589,7 +2589,7 @@ static ssize_t f_midi2_opts_iface_name_s {struct f_midi2_opts *opts =to_f_midi2_opts (item); -return f_midi2_opts_str_show (opts, opts->info.iface_name, page); +return f_midi2_opts_str_show (opts, &opts->info.iface_name, page); } static ssize_t f_midi2_opts_iface_name_store(struct config_item *item,
Greg Kroah-Hartman
maintainerPATCH 47/556 usb: gadget: f_midi: initialize work in f_midi_alloc()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
commit 7e07d3e4c389217d7d7171d80edf2e23ac70f1ea upstream.
f_midi_alloc initializes free_ref to 1 and it can only be incremented when a sound card is registered via f_midi_register_card(). f_midi_register_card() is only called in f_midi_bind() which actually performs INIT_WORK. If f_midi_bind() is never run, work is not initialized and the if condition in f_midi_free becomes true, this results in a warning later in __flush_work as work->func = 0. Fix this by moving INIT_WORK from f_midi_bind() to f_midi_alloc().
--- drivers/usb/gadget/function/f_midi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_midi.c +1 -1
@@ -879,7 +879,6 @@ static int f_midi_bind(struct usb_configint status, n, jack =1 , i =0 , endpoint_descriptor_index =0 ; midi->gadget = cdev->gadget; -INIT_WORK (&midi->work, f_midi_in_work); status =f_midi_register_card (midi);if (status <0 ) goto fail_register;
@@ -1377,6 +1376,7 @@ static struct usb_function *f_midi_alloc status = -ENOMEM ; goto midi_free; } +INIT_WORK (&midi->work, f_midi_in_work); midi->out_ports = opts->out_ports; midi->index = opts->index; midi->buflen = opts->buflen;
Greg Kroah-Hartman
maintainerPATCH 48/556 USB: gadget: fix NULL pointer dereference in gadget_dev_ioctl()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lovekesh Solanki <[email protected]>
commit dd0eed9e165b1a6292f49e622e3dd0b7d99b106d upstream.
gadget_dev_ioctl() reads dev->gadget before acquiring dev->lock, but dev->state is checked after acquiring the lock. Therefore a concurrent bind can change the device state between these operations, which can leave ioctl with a stale NULL gadget pointer and causing a NULL pointer dereference at gadget->ops->ioctl.
Read dev->gadget while holding dev->lock so that the gadget pointer and device state are sampled consistently.
--- drivers/usb/gadget/legacy/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/legacy/inode.c +2 -1
@@ -1251,10 +1251,11 @@ out:static long gadget_dev_ioctl (struct file *fd,unsigned code,unsigned long value) {struct dev_data *dev = fd->private_data; -struct usb_gadget *gadget = dev->gadget; +struct usb_gadget *gadget;long ret = -ENOTTY ;spin_lock_irq (&dev->lock); + gadget = dev->gadget;if (dev->state ==STATE_DEV_OPENED || dev->state ==STATE_DEV_UNBOUND ) {/* Not bound to a UDC */
Greg Kroah-Hartman
maintainerPATCH 49/556 usb: gadget: fix null pointer dereference in usb_put_function_instance()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
commit 6e74ac5c596fd246e37eadfc354567179ccbe9aa upstream.
usb_put_function_instance() attempts to dereference fd inside fi struct to get mod in uvc_alloc_inst() error path. However, fd is not allocated until later in try_get_usb_function_instance() after allocating fi in uvc_alloc_inst() and thus guranteed to be null in error path. Fix this by adding a null check for fi->fd that returns if fd is null.
--- drivers/usb/gadget/functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/functions.c +1 -1
@@ -70,7 +70,7 @@ void usb_put_function_instance(struct us {struct module *mod; -if (!fi) +if (!fi || !fi->fd)return ; mod = fi->fd->mod;
Greg Kroah-Hartman
maintainerPATCH 50/556 staging: rtl8723bs: fix OOB read / stack overflow in rtw_get_wps_attr()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 99aa998dec83ba180822f70e6d48a514fc81c20d upstream.
rtw_get_wps_attr() walks WPS attributes inside a WPS IE taken from a wireless management frame. For each candidate attribute it only checks that the fixed 4-byte attribute header (2-byte ID + 2-byte length) fits inside the IE:
if (attr_ptr + 4 > wps_ie + wps_ielen) break; u16 attr_id = get_unaligned_be16(attr_ptr); u16 attr_data_len = get_unaligned_be16(attr_ptr + 2); u16 attr_len = attr_data_len + 4;
attr_data_len (and therefore attr_len) is read directly from the wire and is never checked against the remaining bytes in the IE before being used as the size of:
memcpy(buf_attr, attr_ptr, attr_len);
Since attr_len is fully attacker controlled (0 to 65535+4), this is both a heap OOB read of wps_ie, and, more seriously, a stack buffer overflow at several call sites where buf_attr is a single-byte stack variable, e.g. rtw_get_wps_attr_content()'s callers passing WPS_ATTR_SELECTED_REGISTRAR into a stack "u8 sr"/"u8 selected_registrar" (drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c, drivers/staging/rtl8723bs/core/rtw_mlme_ext.c). A crafted WPS IE in a beacon or probe response processed during scanning can therefore smash the stack of the parsing thread.
rtw_get_wps_attr_content() itself has no independent length check and simply trusts the attr_len it gets back from rtw_get_wps_attr(), so fixing the bound here also fixes that caller.
The "attr_ptr + 4 > wps_ie + wps_ielen" header check above was added by commit 1463ca3ec6601 ("staging: rtl8723bs: fix OOB reads in rtw_get_sec_ie(), rtw_get_wapi_ie(), and rtw_get_wps_attr()"), which bounded the fixed header but never extended the check to cover the variable-length attribute data that follows it. Add that missing check before attr_len is used as a memcpy() length or accepted as a match.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +4 -0
@@ -737,6 +737,10 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wpu16 attr_data_len =get_unaligned_be16 (attr_ptr +2 );u16 attr_len = attr_data_len +4 ; +/* Reject attributes whose claimed length runs past the IE */ +if (attr_ptr + attr_len > wps_ie + wps_ielen) +break ; +if (attr_id == target_attr_id) { target_attr_ptr = attr_ptr;
Greg Kroah-Hartman
maintainerPATCH 51/556 staging: rtl8723bs: fix OOB read in rtw_action_frame_parse()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit ff917923f4fb9c83717ba135ee47d7e4c1567bb7 upstream.
rtw_action_frame_parse() takes a frame_len parameter but never actually checks it before indexing into the frame body:
const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr); ... c = frame_body[0]; ... a = frame_body[1];
frame_body already points 24 bytes (sizeof(struct ieee80211_hdr_3addr)) into frame, so reading frame_body[0] and frame_body[1] requires frame_len >= 26. A management action frame shorter than that (e.g. exactly 24 bytes, the minimum a malicious peer can send) causes a 1-2 byte out-of-bounds read.
This is reachable from rtw_cfg80211_monitor_if_xmit_entry() and cfg80211_rtw_mgmt_tx() in ioctl_cfg80211.c, both of which pass attacker/user-influenced frame buffers and lengths straight through.
Add the missing length check before frame_body is dereferenced.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +3 -0
@@ -1149,6 +1149,9 @@ int rtw_action_frame_parse(const u8 *frau8 c;u8 a =ACT_PUBLIC_MAX ; +if (frame_len <sizeof (struct ieee80211_hdr_3addr ) +2 ) +return false; + fc =le16_to_cpu (((struct ieee80211_hdr_3addr *)frame)->frame_control); if ((fc & (IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) !=
Greg Kroah-Hartman
maintainerPATCH 52/556 staging: rtl8723bs: fix OOB read in rtw_restruct_wmm_ie()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 28a289beaf226b30b1e6e7d7b1a2946fe2d6e852 upstream.
rtw_restruct_wmm_ie() scans in_ie for a WMM IE with:
while (i < in_len) {
...
if (i + 5 < in_len && in_ie[i] == 0xDD && ...) {
...
break;
}
i += (in_ie[i + 1] + 2); /* to the next IE element */
}When the "i + 5 < in_len" match check fails simply because i is within 5 bytes of the end of the buffer (i.e. no WMM IE was found near the tail of in_ie), execution falls through to
"i += (in_ie[i + 1] + 2)", which reads in_ie[i + 1]. If i == in_len
- 1 at that point, this is a 1-byte out-of-bounds read of an attacker-influenced IE buffer built from association/scan data.
Commit a75281626fc8f ("staging: rtl8723bs: fix potential out-of-bounds read in rtw_restruct_wmm_ie") added the "i + 5 < in_len" guard to the match condition itself, but did not add an equivalent guard before the fallthrough advance, so the same class of OOB read remained reachable through the non-matching path.
Add an explicit bounds check before advancing to the next IE.
--- drivers/staging/rtl8723bs/core/rtw_mlme.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/rtl8723bs/core/rtw_mlme.c +3 -0
@@ -1980,6 +1980,9 @@ int rtw_restruct_wmm_ie(struct adapter *break ; } +if (i +1 >= in_len) +break ; + i += (in_ie[i +1 ] +2 );/* to the next IE element */ }
Greg Kroah-Hartman
maintainerPATCH 53/556 xhci: fix lost bounce buffers on TDs spanning several ring segments
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arthur Gautier <[email protected]>
commit ff44dfb03a293bf30e31f98772a1dd316a6071d1 upstream.
When a TD reaches a link TRB with data that is not aligned to the endpoint's wMaxPacketSize, xhci_align_td() stages the unalignable tail through the bounce buffer of the ring segment holding that link TRB. xhci_unmap_td_bounce_buffer() later unmaps it and, for IN transfers, copies the data back into the URB's buffer.
The enqueue path records the segment that was bounced in td->bounce_seg, under the assumption that a TD never spans more than two ring segments. That assumption does not hold: a TD large enough to span three or more segments crosses several link TRBs and can be bounced at each of them. Only the last one survives in td->bounce_seg, so every earlier bounce buffer is neither copied back nor DMA unmapped.
The URB still completes with actual_length equal to the requested length and no error, so the transfer looks successful while a wMaxPacketSize sized hole in the destination buffer silently keeps its previous contents. It also leaks a DMA mapping per dropped bounce.
Any sufficiently large and fragmented bulk transfer can hit this. It was found with a USB mass storage device behind xHCI backing a dm-verity target with 512 byte hash blocks, where the stale data is detected rather than silently consumed. The device enumerates as SuperSpeed, so wMaxPacketSize is 1024, while dm-bufio issues one 512 byte bio per hash block. verity_prefetch_io() makes the block layer merge hundreds of them into a single request of up to 512 scatterlist entries of 512 bytes each. At 256 TRBs per ring segment such a TD spans three segments, and every segment boundary falls on an odd multiple of 512, i.e. unaligned to wMaxPacketSize. dm-bufio then caches a hash block holding stale data and dm-verity declares the metadata block corrupted:
device-mapper: verity: 8:2: metadata block 10850 is corrupted
A reproducer running this under qemu is available at
https://github.com/baloo/xhci-verity
The bounce state (bounce_buf, bounce_dma, bounce_len, bounce_offs) already lives on the ring segment, so there is nothing extra to track. Keep recording the last bounced segment in td->bounce_seg and, on completion, walk the segments from td->start_seg up to it, unmapping every segment that still has a pending bounce.
Stopping at td->bounce_seg rather than td->end_seg matters: a bounce implies the TD continues past that segment's link TRB, so bounce_seg is always strictly before end_seg, and a later TD may already have started in end_seg and been bounced there. Walking that far would copy a foreign bounce buffer into this URB and unmap it twice. It also keeps the walk correct if a TD ever wraps the whole ring so that end_seg == start_seg.
[mn: Add ring->num_segs check to prevent unlikely infinite for loop.]
--- drivers/usb/host/xhci-ring.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-)
drivers/usb/host/xhci-ring.c +24 -8
@@ -842,21 +842,18 @@ static void xhci_giveback_urb_in_irq(strusb_hcd_giveback_urb (hcd, urb, status); } -static void xhci_unmap_td_bounce_buffer (struct xhci_hcd *xhci, -struct xhci_ring *ring,struct xhci_td *td) +static void xhci_unmap_one_bounce_buffer (struct xhci_hcd *xhci, +struct xhci_ring *ring,struct xhci_td *td, +struct xhci_segment *seg) {struct device *dev =xhci_to_hcd (xhci)->self.sysdev; -struct xhci_segment *seg = td->bounce_seg;struct urb *urb = td->urb;size_t len; -if (!ring || !seg || !urb) -return ; -if (usb_urb_dir_out (urb)) {dma_unmap_single (dev, seg->bounce_dma, ring->bounce_buf_len,DMA_TO_DEVICE ); -return ; + goto done; } dma_unmap_single(dev, seg->bounce_dma, ring->bounce_buf_len,
@@ -872,10 +869,29 @@ static void xhci_unmap_td_bounce_buffer(memcpy (urb->transfer_buffer + seg->bounce_offs, seg->bounce_buf, seg->bounce_len); } +done: seg->bounce_len =0 ; seg->bounce_offs =0 ; } +static void xhci_unmap_td_bounce_buffer (struct xhci_hcd *xhci, +struct xhci_ring *ring,struct xhci_td *td) +{ +struct xhci_segment *seg; +int i =0 ; + +if (!td->bounce_seg || !ring || !td->urb) +return ; + +/* td->bounce_seg is the last one bounced, unmap them all */ +for (seg = td->start_seg; i++ < ring->num_segs; seg = seg->next) { +if (seg->bounce_len) +xhci_unmap_one_bounce_buffer (xhci, ring, td, seg); +if (seg == td->bounce_seg) +break ; + } +} +static void xhci_td_cleanup (struct xhci_hcd *xhci,struct xhci_td *td,struct xhci_ring *ep_ring,int status) {
@@ -3688,7 +3704,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd * &trb_buff_len, ring->enq_seg)) { send_addr = ring->enq_seg->bounce_dma; -/* assuming TD won't span 2 segs */ +/* TD bounced at least, and last on this seg */ td->bounce_seg = ring->enq_seg; } }
Greg Kroah-Hartman
maintainerPATCH 54/556 thermal/drivers/imx: Disable clock on runtime resume failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit bcc6d886e5006a4656901d2d7fb6a215c96068a0 upstream.
imx_thermal_runtime_resume() enables the thermal clock before powering up the sensor and enabling measurements.
If either regmap_write() fails, the function returns with the clock still enabled. This leaves the clock enable count unbalanced after a failed runtime resume.
Disable the clock on those failure paths before returning the error.
--- drivers/thermal/imx_thermal.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/thermal/imx_thermal.c +7 -2
@@ -832,12 +832,12 @@ static int imx_thermal_runtime_resume(st ret =regmap_write (map, socdata->sensor_ctrl +REG_CLR , socdata->power_down_mask);if (ret) -return ret; + goto disable_clk; ret =regmap_write (map, socdata->sensor_ctrl +REG_SET , socdata->measure_temp_mask);if (ret) -return ret; + goto disable_clk;/* * According to the temp sensor designers, it may require up to ~17us
@@ -846,6 +846,11 @@ static int imx_thermal_runtime_resume(stusleep_range (20 ,50 );return 0 ; + +disable_clk: +clk_disable_unprepare (data->thermal_clk); + +return ret; }static const struct dev_pm_ops imx_thermal_pm_ops = {
Greg Kroah-Hartman
maintainerPATCH 55/556 thermal/drivers/qoriq: Disable clock on resume failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit fcbf9964b67a6d6704c50ed28daa24c3b164f01c upstream.
qoriq_tmu_resume() enables the TMU clock before clearing the power-down bit and enabling monitoring.
If either register update fails, the function returns with the clock still enabled. This leaves the clock enable count unbalanced after a failed resume.
Disable the clock on those failure paths before returning the error.
--- drivers/thermal/qoriq_thermal.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/thermal/qoriq_thermal.c +11 -2
@@ -415,11 +415,20 @@ static int qoriq_tmu_resume(struct devicif (data->ver >TMU_VER1 ) { ret =regmap_clear_bits (data->regmap,REGS_TMR ,TMR_CMD );if (ret) -return ret; + goto disable_clk; }/* Enable monitoring */ -return regmap_update_bits (data->regmap,REGS_TMR ,TMR_ME ,TMR_ME ); + ret =regmap_update_bits (data->regmap,REGS_TMR ,TMR_ME ,TMR_ME ); +if (ret) + goto disable_clk; + +return 0 ; + +disable_clk: +clk_disable_unprepare (data->clk); + +return ret; } static DEFINE_SIMPLE_DEV_PM_OPS(qoriq_tmu_pm_ops,
Greg Kroah-Hartman
maintainerPATCH 56/556 tracing/probes: Fix anon_stack check for unnamed bitfields in btf_find_struct_member
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit f36d94a20ca185bcadef3a10b980cd2cfd72d53a upstream.
btf_find_struct_member() traverses into nested anonymous structures and unions by pushing members with !member->name_off onto anon_stack. However, it does not consider the unnamed bitfields (e.g. int : 5 or unsigned int : 0) which also have member->name_off == 0.
If such an unnamed bitfield is pushed to anon_stack, the btf_find_struct_member() return an error even if there are other valid entries in anon_stack.
To fix this, only push unnamed struct/union members to anon_stack. Also move the btf_type_is_struct() check to the entry of this function because now it is sure only struct/union are pushed to anon_stack.
--- kernel/trace/trace_btf.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
kernel/trace/trace_btf.c +6 -6
@@ -74,24 +74,24 @@ const struct btf_member *btf_find_struct {struct btf_anon_stack *anon_stack;const struct btf_member *member; +const struct btf_type *mtype;u32 tid, cur_offset =0 ;const char *name;int i, top =0 ; +if (!btf_type_is_struct (type)) +return ERR_PTR (-EINVAL ); + anon_stack =kzalloc_objs (*anon_stack,BTF_ANON_STACK_MAX );if (!anon_stack)return ERR_PTR (-ENOMEM ); retry: -if (!btf_type_is_struct (type)) { - member =ERR_PTR (-EINVAL ); - goto out; - } -for_each_member (i, type, member) {if (!member->name_off) {/* Anonymous union/struct: push it for later use */ -if (btf_type_skip_modifiers (btf, member->type, &tid) && + mtype =btf_type_skip_modifiers (btf, member->type, &tid); +if (mtype &&btf_type_is_struct (mtype) && top <BTF_ANON_STACK_MAX ) { anon_stack[top].tid = tid; anon_stack[top++].offset =
Greg Kroah-Hartman
maintainerPATCH 57/556 tracing: Have show_event_filters/triggers files take trace array ref
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit f4a771cc684c7354b6200147f7252c58d17408ff upstream.
The newly added files show_event_filters and show_event_triggers that show all filters or triggers that are set within the trace array do not take a reference for the trace array it is showing. Without taking a reference, the trace_array may be freed via "rmdir" while a task is reading one of theses files. Those files iterate all the events within an instance (trace_array) and nothing prevents that instance from being freed while its data is being read. This causes a use-after-free crash.
Have the open of both those files take the trace_array reference via the trace_array_get() that prevents the trace_array from being freed while the files are opened.
--- kernel/trace/trace_events.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-)
kernel/trace/trace_events.c +24 -4
@@ -2654,14 +2654,14 @@ static const struct file_operations ftra .open = ftrace_event_show_filters_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release, + .release = ftrace_event_release, };static const struct file_operations ftrace_show_event_triggers_fops = { .open = ftrace_event_show_triggers_open, .read = seq_read, .llseek = seq_lseek, - .release = seq_release, + .release = ftrace_event_release, };static const struct file_operations ftrace_set_event_pid_fops = {
@@ -2819,7 +2819,17 @@ ftrace_event_set_open(struct inode *inodstatic int ftrace_event_show_filters_open (struct inode *inode,struct file *file) { -return ftrace_event_open (inode, file, &show_show_event_filters_seq_ops); +struct trace_array *tr = inode->i_private; +int ret; + + ret =tracing_check_open_get_tr (tr); +if (ret) +return ret; + + ret =ftrace_event_open (inode, file, &show_show_event_filters_seq_ops); +if (ret <0 ) +trace_array_put (tr); +return ret; }/**
@@ -2833,7 +2843,17 @@ ftrace_event_show_filters_open(struct instatic int ftrace_event_show_triggers_open (struct inode *inode,struct file *file) { -return ftrace_event_open (inode, file, &show_show_event_triggers_seq_ops); +struct trace_array *tr = inode->i_private; +int ret; + + ret =tracing_check_open_get_tr (tr); +if (ret) +return ret; + + ret =ftrace_event_open (inode, file, &show_show_event_triggers_seq_ops); +if (ret <0 ) +trace_array_put (tr); +return ret; } static int
Greg Kroah-Hartman
maintainerPATCH 58/556 tracing: Take trace_array reference when opening options file
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit f2951ebd15c36a1ea4820a7f0cbb0b5f1c028b73 upstream.
The options files do not take the trace_array reference for the options they represent. This could cause a use-after-free kernel crash if one of these files is opened by one task and another task removes the instance that the option is for. Because it doesn't take a reference upon opening, it will not stop the removal which will free the options descriptor that is being used.
As the options are somewhat dynamic in their creation at boot up, each file represents a flag in the trace_array. The trace_array has an array of indexes to represent each of these flags that is stored in the trace_flags_index array. The address of the index array element is used to pass to the inode->i_private pointer. Then that element is read which holds the index (which represents the flag) and then the index is used to calculate the trace_array descriptor from its trace_flags_index array.
One issue is that the index element can not be referenced until the trace_array's reference is taken. To handle this, create a new helper function called: trace_array_options_get() that will iterate all the existing trace_arrays in the ftrace_trace_arrays list (under the trace_types_lock), and compare the passed in address of the index element with the entire array of the trace_array's trace_flags_index array. If it matches, then up the corresponding trace_array's reference and return.
--- kernel/trace/trace.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 4 deletions(-)
kernel/trace/trace.c +63 -4
@@ -7840,11 +7840,70 @@ trace_options_core_write(struct file *fireturn cnt; } +/* +* The tr_index is the address of a trace_array->trace_flags_index[] +* element that holds the index of the trace flag. But since the +* trace_array reference has not been taken yet, it cannot be referenced +* as it could have been freed by a rmdir of the instance the trace_array +* represents. +* +* Search the list of trace_arrays and compare the tr_index to the +* address of the entire trace_array trace_flags_index array for each +* trace_array in the list. If one is matched, then take the reference +* and return it. If not, the trace_array no longer exits. +*/ +static int trace_array_options_get (void *tr_index) +{ +struct trace_array *tr; +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + +if (tracing_disabled) +return -ENODEV ; + +guard (mutex)(&trace_types_lock); +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (tr_index >= (void *)&tr->trace_flags_index[0 ] && + tr_index < (void *)&tr->trace_flags_index[TRACE_FLAGS_MAX_SIZE ]) +return __trace_array_get (tr); + } +return -ENODEV ; +} + +static int trace_options_open (struct inode *inode,struct file *filp) +{ +void *tr_index = inode->i_private; + +if (trace_array_options_get (tr_index) <0 ) +return -ENODEV ; + + filp->private_data = tr_index; + +return 0 ; +} + +static int trace_options_release (struct inode *inode,struct file *filp) +{ +void *tr_index = filp->private_data; +struct trace_array *tr; +unsigned int index; + +get_tr_index (tr_index, &tr, &index); + +trace_array_put (tr); + +return 0 ; +} +static const struct file_operations trace_options_core_fops = { - .open = tracing_open_generic, - .read = trace_options_core_read, - .write = trace_options_core_write, - .llseek = generic_file_llseek, + .open = trace_options_open, + .read = trace_options_core_read, + .write = trace_options_core_write, + .llseek = generic_file_llseek, + .release = trace_options_release, }; struct dentry *trace_create_file(const char *name,
Greg Kroah-Hartman
maintainerPATCH 59/556 userfaultfd: reset err to be 0 when move_pages_ptes succeeded
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan Lim <[email protected]>
commit f025ca73decda1f895a4b80b961d3bc88825298a upstream.
During move_pages() operation, when move_pages_ptes() returns EAGAIN, the error code is not cleared even after we processed it. This leads to a successful retry but then the same pages are retried again due to the stale error code. This time move fails because pages are already moved, loop is terminated and move_pages() reports a failure. Clear the error code once we processes EAGAIN.
--- mm/userfaultfd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/userfaultfd.c +3 -1
@@ -2085,8 +2085,10 @@ static ssize_t move_pages(struct userfau }if (err) { -if (err == -EAGAIN ) +if (err == -EAGAIN ) { + err =0 ;continue ; + }break ; }
Greg Kroah-Hartman
maintainerPATCH 60/556 ublk: clear VM_MAYWRITE on read-only ublk char device mmap
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kanishka De Silva <[email protected]>
commit 6e2b571b0a54755b06e092501913e1dfefe75d6c upstream.
ublk_ch_mmap() rejects mmap requests with VM_WRITE set, but never clears VM_MAYWRITE on the resulting read-only mapping. This allows a userspace daemon to mmap the per-queue command buffer PROT_READ, then upgrade it to PROT_WRITE via mprotect(), since VM_MAYWRITE was never cleared.
The command buffer holds struct ublksrv_io_desc entries that are kernel-written ABI; a writable mapping lets an unprivileged daemon process corrupt fields such as addr, op_flags, nr_sectors, and start_sector.
Same bug class as the drm/panthor and drm/vc4 VM_MAYWRITE fixes, and the 2026-08-13 ptp/vmclock fix (a5edadbae57e).
Verified via mprotect() PoC: before the fix, a PROT_READ mapping can be upgraded to PROT_READ|PROT_WRITE and a write into the command buffer corrupts io_desc fields (confirmed under KASAN). After the fix, mprotect() returns -EACCES.
--- drivers/block/ublk_drv.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/block/ublk_drv.c +6 -0
@@ -2651,6 +2651,12 @@ static int ublk_ch_mmap(struct file *filif (vma->vm_flags &VM_WRITE )return -EPERM ; +/* +* The per-queue command buffer is kernel-written ABI; prevent +* the daemon from upgrading to writable via mprotect(). +*/ +vm_flags_clear (vma,VM_MAYWRITE ); + end =UBLKSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;if (phys_off <UBLKSRV_CMD_BUF_OFFSET || phys_off >= end)return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 61/556 soc: fsl: qe: Add chained_irq_{enter,exit}() calls in cascade handler
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Louvel <[email protected]>
commit 7e47fe56415847732419ca8cef9307bf111dd368 upstream.
Wrap the cascade handler body with chained_irq_{enter,exit}() to properly inform the parent IRQ chip that a chained interrupt is being serviced.
--- drivers/soc/fsl/qe/qe_ports_ic.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/soc/fsl/qe/qe_ports_ic.c +7 -0
@@ -6,6 +6,7 @@*/ #include <linux/irq.h> +#include <linux/irqchip/chained_irq.h> #include <linux/irqdomain.h> #include <linux/platform_device.h>
@@ -79,7 +80,13 @@ static int qepic_get_irq(struct irq_descstatic void qepic_cascade (struct irq_desc *desc) { +struct irq_chip *chip =irq_desc_get_chip (desc); + +chained_irq_enter (chip, desc); +generic_handle_irq (qepic_get_irq (desc)); + +chained_irq_exit (chip, desc); }static int qepic_host_map (struct irq_domain *h,unsigned int virq,irq_hw_number_t hw)
Greg Kroah-Hartman
maintainerPATCH 62/556 soc: qcom: geni-se: Use HW PROG_RAM_DEPTH to validate firmware size
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viken Dadhaniya <[email protected]>
commit 522bfb4f33c0930b3d14d5c5ee80bc93a883b544 upstream.
The hardcoded MAX_GENI_CFG_RAMn_CNT limit is not accurate for all SoCs:
some targets have less CFG RAM than the constant implies, while others like QCS615 need more entries than the old limit of 455 allowed, causing valid firmware to be rejected at load time.
Rather than hardcoding a constant, read PROG_RAM_DEPTH from SE_HW_PARAM_2 at runtime to get the actual CFG RAM depth of the hardware instance and use that as the upper bound for firmware size validation.
--- drivers/soc/qcom/qcom-geni-se.c | 24 +++++++++++++----------- include/linux/soc/qcom/geni-se.h | 4 ++++ 2 files changed, 17 insertions(+), 11 deletions(-)
drivers/soc/qcom/qcom-geni-se.c +13 -11
@@ -154,8 +154,6 @@ struct se_fw_hdr {/*Magic numbers*/ #define SE_MAGIC_NUM 0x57464553 -#define MAX_GENI_CFG_RAMn_CNT 455 -#define MI_PBT_NON_PAGED_SEGMENT 0x0#define MI_PBT_HASH_SEGMENT 0x2#define MI_PBT_NOTUSED_SEGMENT 0x3
@@ -1224,24 +1222,27 @@ EXPORT_SYMBOL_GPL(geni_se_resources_init/** * geni_find_protocol_fw() - Locate and validate SE firmware for a protocol. -* @dev: Pointer to the device structure. +* @se: Pointer to the serial engine structure. * @fw: Pointer to the firmware image. * @protocol: Expected serial engine protocol type. * * Identifies the appropriate firmware image or configuration required for a -* specific communication protocol instance running on a Qualcomm GENI -* controller. +* specific communication protocol instance running on a Qualcomm GENI +* controller. Validates the firmware size against the hardware PROG_RAM_DEPTH +* read from SE_HW_PARAM_2. * * Return: pointer to a valid 'struct se_fw_hdr' if found, or NULL otherwise. */ -static struct se_fw_hdr *geni_find_protocol_fw (struct device *dev,const struct firmware *fw, +static struct se_fw_hdr *geni_find_protocol_fw (struct geni_se *se,const struct firmware *fw,enum geni_se_protocol_type protocol) { +struct device *dev = se->dev;const struct elf32_hdr *ehdr;const struct elf32_phdr *phdrs;const struct elf32_phdr *phdr;struct se_fw_hdr *sefw;u32 fw_end, cfg_idx_end, cfg_val_end; +u32 prog_ram_depth;u16 fw_size;int i;
@@ -1300,10 +1301,11 @@ static struct se_fw_hdr *geni_find_proto sefw->fw_size_in_items =cpu_to_le16 (fw_size); } -if (fw_size >= MAX_GENI_CFG_RAMn_CNT) { -dev_err (dev, -"Firmware size (%u) exceeds max allowed RAMn count (%u)\n" , - fw_size, MAX_GENI_CFG_RAMn_CNT); + prog_ram_depth =FIELD_GET (PROG_RAM_DEPTH_MSK , +readl_relaxed (se->base +SE_HW_PARAM_2 )); +if (fw_size >= prog_ram_depth) { +dev_err (dev,"Firmware size (%u) exceeds RAM size (%u)\n" , + fw_size, prog_ram_depth);continue ; }
@@ -1427,7 +1429,7 @@ static int geni_load_se_fw(struct geni_sint ret;struct se_fw_hdr *hdr; - hdr =geni_find_protocol_fw (se->dev, fw, protocol); + hdr =geni_find_protocol_fw (se, fw, protocol);if (!hdr)return -EINVAL ;
include/linux/soc/qcom/geni-se.h +4 -0
@@ -124,6 +124,7 @@ struct geni_se {#define SE_DMA_RX_FSM_RST 0xd58#define SE_HW_PARAM_0 0xe24#define SE_HW_PARAM_1 0xe28 +#define SE_HW_PARAM_2 0xe2c/* GENI_FORCE_DEFAULT_REG fields */ #define FORCE_DEFAULT BIT(0)
@@ -291,6 +292,9 @@ struct geni_se {#define RX_FIFO_DEPTH_MSK GENMASK(21, 16)#define RX_FIFO_DEPTH_SHFT 16 +/* SE_HW_PARAM_2 fields */ +#define PROG_RAM_DEPTH_MSK GENMASK(10, 0) +#define HW_VER_MAJOR_MASK GENMASK(31, 28)#define HW_VER_MAJOR_SHFT 28#define HW_VER_MINOR_MASK GENMASK(27, 16)
Greg Kroah-Hartman
maintainerPATCH 63/556 spi: bcm63xx-hsspi: disable clocks on resume failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit 3b0cee02664041aea7e4f787c66cb86c82eb4e97 upstream.
bcm63xx_hsspi_resume() enables the HSSPI clock, and optionally the PLL clock, before restarting the SPI controller queue.
If spi_controller_resume() fails, the function currently reports success and leaves those clocks enabled. Propagate the error and disable the clocks before returning.
--- drivers/spi/spi-bcm63xx-hsspi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-bcm63xx-hsspi.c +7 -1
@@ -915,7 +915,13 @@ static int bcm63xx_hsspi_resume(struct d } } -spi_controller_resume (host); + ret =spi_controller_resume (host); +if (ret) { +if (bs->pll_clk) +clk_disable_unprepare (bs->pll_clk); +clk_disable_unprepare (bs->clk); +return ret; + }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 64/556 spi: bcm63xx: disable clock on resume failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit 2b62c2c134fa32d9d3a9e7323c8ac74518eeb4ac upstream.
bcm63xx_spi_resume() enables the controller clock before restarting the SPI controller queue.
If spi_controller_resume() fails, the function currently reports success and leaves the clock enabled. Propagate the error and disable the clock before returning.
--- drivers/spi/spi-bcm63xx.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/spi/spi-bcm63xx.c +5 -1
@@ -650,7 +650,11 @@ static int bcm63xx_spi_resume(struct devif (ret)return ret; -spi_controller_resume (host); + ret =spi_controller_resume (host); +if (ret) { +clk_disable_unprepare (bs->clk); +return ret; + }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 65/556 spi: bcmbca-hsspi: disable clocks on resume failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit d2f5a606710ad70c341dc609430a20a5645618d5 upstream.
bcmbca_hsspi_resume() enables the HSSPI clock, and optionally the PLL clock, before restarting the SPI controller queue.
If spi_controller_resume() fails, the function currently reports success and leaves those clocks enabled. Propagate the error and disable the clocks before returning.
--- drivers/spi/spi-bcmbca-hsspi.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/spi/spi-bcmbca-hsspi.c +7 -1
@@ -594,7 +594,13 @@ static int bcmbca_hsspi_resume(struct de } } -spi_controller_resume (host); + ret =spi_controller_resume (host); +if (ret) { +if (bs->pll_clk) +clk_disable_unprepare (bs->pll_clk); +clk_disable_unprepare (bs->clk); +return ret; + }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 66/556 spi: Fix DMA mapping ownership on partial map failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Honghui Jiang <[email protected]>
commit 367cea239fc93094e5c16a72724800e0358f5c46 upstream.
If RX mapping fails after TX mapping succeeds, __spi_map_msg() unmaps TX but leaves tx_sg_mapped set. If TX mapping fails on a later transfer, mappings created for earlier transfers remain active.
In both cases, cur_{tx,rx}_dma_dev have not yet been updated because they are assigned only after every transfer has been mapped. The subsequent spi_unmap_msg() may therefore unmap the TX mapping again or release earlier mappings using a NULL or stale device. Using a NULL device can trigger an oops. An empty SG table does not prevent the NULL dereference because dma_unmap_sg_attrs() accesses the device before checking the entry count.
Publish both mapping devices before mapping starts and unwind all failures through __spi_unmap_msg(). This clears the mapping flags and releases each mapping once with the device that created it.
Publishing the devices before the loop also refreshes them when no transfer needs mapping. No mapping flag is set in that case, so current users do not use the pointers as mapping owners.
--- drivers/spi/spi.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
drivers/spi/spi.c +18 -16
@@ -1231,6 +1231,8 @@ void spi_unmap_buf(struct spi_controllerspi_unmap_buf_attrs (ctlr, dev, sgt, dir,0 ); } +static int __spi_unmap_msg (struct spi_controller *ctlr,struct spi_message *msg); +static int __spi_map_msg (struct spi_controller *ctlr,struct spi_message *msg) {struct device *tx_dev, *rx_dev;
@@ -1254,7 +1256,13 @@ static int __spi_map_msg(struct spi_contelse rx_dev = ctlr->dev.parent; - ret = -ENOMSG ; +/* +* Store the devices before mapping so partial failures can be unwound +* with the device that created each mapping. +*/ + ctlr->cur_tx_dma_dev = tx_dev; + ctlr->cur_rx_dma_dev = rx_dev; +list_for_each_entry (xfer, &msg->transfers, transfer_list) {/* The sync is done before each transfer. */ unsigned long attrs =DMA_ATTR_SKIP_CPU_SYNC ;
@@ -1267,8 +1275,8 @@ static int __spi_map_msg(struct spi_cont (void *)xfer->tx_buf, xfer->len,DMA_TO_DEVICE , attrs); -if (ret !=0 ) -return ret; +if (ret) + goto unwind; xfer->tx_sg_mapped = true; }
@@ -1277,25 +1285,19 @@ static int __spi_map_msg(struct spi_cont ret =spi_map_buf_attrs (ctlr, rx_dev, &xfer->rx_sg, xfer->rx_buf, xfer->len,DMA_FROM_DEVICE , attrs); -if (ret !=0 ) { -spi_unmap_buf_attrs (ctlr, tx_dev, - &xfer->tx_sg,DMA_TO_DEVICE , - attrs); - -return ret; - } +if (ret) + goto unwind; xfer->rx_sg_mapped = true; } } -/* No transfer has been mapped, bail out with success */ -if (ret) -return 0 ; - - ctlr->cur_rx_dma_dev = rx_dev; - ctlr->cur_tx_dma_dev = tx_dev;return 0 ; + +unwind: +__spi_unmap_msg (ctlr, msg); + +return ret; }static int __spi_unmap_msg (struct spi_controller *ctlr,struct spi_message *msg)
Greg Kroah-Hartman
maintainerPATCH 67/556 scsi: target: iscsi: Reserve a terminator byte for the login payload
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sujal Tuladhar <[email protected]>
commit f4825922d2fb371e2b969697d792077f1b62b62c upstream.
iscsi_target_check_login_request() rejects a login PDU whose DataSegmentLength exceeds MAX_KEY_VALUE_PAIRS, but the test is '>' and login->req_buf is allocated with exactly MAX_KEY_VALUE_PAIRS bytes. Since iscsit_get_login_rx() receives payload_length + padding bytes, where
padding = ((-payload_length) & 3);
any payload_length from 8189 to 8192 fills the whole 8192 byte buffer. The write stays in bounds, but no byte is left for a NUL terminator.
The buffer is subsequently consumed as a C string. In the CHAP path chap_check_algorithm() calls kstrdup(a_str), and extract_param() calls strstr(in_buf, pattern) followed by strlen_semi(), none of which take a length. convert_null_to_semi() additionally rewrites every embedded NUL to ';', so even a payload made of well formed NUL separated key=value records is left without a terminator. These walk past the end of the object into adjacent slab memory. It is reachable by an unauthenticated initiator against a portal configured for CHAP; when authentication is not required iscsi_login_zero_tsih_s2() rewrites AuthMethod to None and the CHAP path is never entered.
Allocate one extra byte. kzalloc() zeroes it and nothing ever writes to it, as every writer copies to offset 0 for at most MAX_KEY_VALUE_PAIRS bytes, so the buffer is always terminated.
--- drivers/target/iscsi/iscsi_target_login.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target_login.c +1 -1
@@ -47,7 +47,7 @@ static struct iscsi_login *iscsi_login_i login->conn = conn; login->first_request =1 ; - login->req_buf =kzalloc (MAX_KEY_VALUE_PAIRS ,GFP_KERNEL ); + login->req_buf =kzalloc (MAX_KEY_VALUE_PAIRS +1 ,GFP_KERNEL );if (!login->req_buf) {pr_err ("Unable to allocate memory for response buffer.\n" ); goto out_login;
Greg Kroah-Hartman
maintainerPATCH 68/556 scsi: bsg: Cap io_uring sense copy to max_response_len
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
commit ece06de726737e887dc0225c8283477624f8ae21 upstream.
Completion copied scmd->sense_len to the user response buffer without honoring max_response_len. After a valid sense, the midlayer sets sense_len to the real length (up to SCSI_SENSE_BUFFERSIZE), so a smaller user buffer was overrun.
--- drivers/scsi/scsi_bsg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/scsi_bsg.c +4 -4
@@ -18,6 +18,7 @@ struct scsi_bsg_uring_cmd_pdu {struct bio *bio;/* mapped user buffer, unmap in task work */ struct request *req;/* block request, freed in task work */ u64 response_addr;/* user space response buffer address */ +u32 max_response_len;/* user response buffer size */ }; static_assert(sizeof(struct scsi_bsg_uring_cmd_pdu) <= sizeof_field(struct io_uring_cmd, pdu));
@@ -45,8 +46,8 @@ static void scsi_bsg_uring_task_cb(strucif (scsi_status_is_check_condition (scmd->result)) { driver_status =DRIVER_SENSE ;if (pdu->response_addr) - sense_len_wr =min_t (u8, scmd->sense_len, -SCSI_SENSE_BUFFERSIZE ); + sense_len_wr = min_t(unsigned int, pdu->max_response_len, + scmd->sense_len); }if (sense_len_wr) {
@@ -155,8 +156,7 @@ static int scsi_bsg_uring_cmd(struct req } pdu->response_addr = cmd->response; - scmd->sense_len = cmd->max_response_len ? -min (cmd->max_response_len,SCSI_SENSE_BUFFERSIZE ) :SCSI_SENSE_BUFFERSIZE ; + pdu->max_response_len = cmd->max_response_len;if (cmd->dout_xfer_len || cmd->din_xfer_len) { ret =scsi_bsg_map_user_buffer (req, ioucmd, issue_flags, gfp_mask);
Greg Kroah-Hartman
maintainerPATCH 69/556 scsi: bsg: Fix TOCTOU in io_uring passthrough command setup
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rahul Chandelkar <[email protected]>
commit 4b3c5965fca99f62d31c963294bd5b23cc488e97 upstream.
scsi_bsg_uring_cmd() reads bsg_uring_cmd from the shared mmap'd SQE. Userspace can change a field after we check it and before we use it. request_len is the sharp case: it can grow past sizeof(scmd->cmnd) after the bound check and overflow scmd->cmnd in copy_from_user().
READ_ONCE() the SQE fields we check or use into locals before use.
--- drivers/scsi/scsi_bsg.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-)
drivers/scsi/scsi_bsg.c +25 -14
@@ -77,12 +77,10 @@ static enum rq_end_io_ret scsi_bsg_uring_cmd_done(struct request *req,static int scsi_bsg_map_user_buffer (struct request *req,struct io_uring_cmd *ioucmd, -unsigned int issue_flags,gfp_t gfp_mask) +unsigned int issue_flags,gfp_t gfp_mask, +bool is_write,u64 buf_addr, +unsigned long buf_len) { - const struct bsg_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd); -bool is_write = cmd->dout_xfer_len >0 ; -u64 buf_addr = is_write ? cmd->dout_xferp : cmd->din_xferp; -unsigned long buf_len = is_write ? cmd->dout_xfer_len : cmd->din_xfer_len;struct iov_iter iter;int ret;
@@ -105,21 +103,28 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc unsigned int issue_flags, bool open_for_write) {struct scsi_bsg_uring_cmd_pdu *pdu =scsi_bsg_uring_cmd_pdu (ioucmd); - const struct bsg_uring_cmd *cmd = io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd); +const struct bsg_uring_cmd *cmd = + io_uring_sqe128_cmd(ioucmd->sqe, struct bsg_uring_cmd);struct scsi_cmnd *scmd;struct request *req;blk_mq_req_flags_t blk_flags =0 ;gfp_t gfp_mask =GFP_KERNEL ; +u64 request =READ_ONCE (cmd->request); +u32 request_len =READ_ONCE (cmd->request_len); +u64 dout_xferp =READ_ONCE (cmd->dout_xferp); +u32 dout_xfer_len =READ_ONCE (cmd->dout_xfer_len); +u64 din_xferp =READ_ONCE (cmd->din_xferp); +u32 din_xfer_len =READ_ONCE (cmd->din_xfer_len);int ret;if (cmd->protocol !=BSG_PROTOCOL_SCSI || cmd->subprotocol !=BSG_SUB_PROTOCOL_SCSI_CMD )return -EINVAL ; -if (!cmd->request || cmd->request_len ==0 ) +if (!request || request_len ==0 )return -EINVAL ; -if (cmd->dout_xfer_len && cmd->din_xfer_len) { +if (dout_xfer_len && din_xfer_len) {pr_warn_once ("BIDI support in bsg has been removed.\n" );return -EOPNOTSUPP ; }
@@ -132,20 +137,20 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc gfp_mask =GFP_NOWAIT ; } - req =scsi_alloc_request (q, cmd->dout_xfer_len ? + req =scsi_alloc_request (q, dout_xfer_len ?REQ_OP_DRV_OUT :REQ_OP_DRV_IN , blk_flags);if (IS_ERR (req))return PTR_ERR (req); scmd =blk_mq_rq_to_pdu (req); -if (cmd->request_len >sizeof (scmd->cmnd)) { +if (request_len >sizeof (scmd->cmnd)) { ret = -EINVAL ; goto out_free_req; } - scmd->cmd_len = cmd->request_len; + scmd->cmd_len = request_len; scmd->allowed =SG_DEFAULT_RETRIES ; -if (copy_from_user (scmd->cmnd,uptr64 (cmd->request), cmd->request_len)) { +if (copy_from_user (scmd->cmnd,uptr64 (request), request_len)) { ret = -EFAULT ; goto out_free_req; }
@@ -158,8 +163,14 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *iouc pdu->response_addr = cmd->response; pdu->max_response_len = cmd->max_response_len; -if (cmd->dout_xfer_len || cmd->din_xfer_len) { - ret =scsi_bsg_map_user_buffer (req, ioucmd, issue_flags, gfp_mask); +if (dout_xfer_len || din_xfer_len) { +bool is_write = dout_xfer_len >0 ; +u64 buf_addr = is_write ? dout_xferp : din_xferp; +unsigned long buf_len = is_write ? dout_xfer_len : din_xfer_len; + + ret =scsi_bsg_map_user_buffer (req, ioucmd, issue_flags, + gfp_mask, is_write, buf_addr, + buf_len);if (ret) goto out_free_req; pdu->bio = req->bio;
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 70/556 scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Lamprecht <[email protected]>
commit af8c27375733fb6a6df9fa484cda77cc3dd0cb80 upstream.
megasas_make_prp_nvme() builds a command's PRP list in cmd->sg_frame, a DMA pool buffer of instance->max_chain_frame_sz bytes, spending one entry per NVMe page of the transfer plus one per page of the buffer for the chain pointer. The loop runs until the transfer is described and never checks the buffer bound.
max_hw_sectors comes straight from the MDTS the firmware reports for the drive. On drives with a large MDTS the only thing keeping the list inside the buffer was the block layer default of 1280 KiB, which needs 320 entries, which fit into a 4 KiB frame as that holds 512. But since commit 9b8b84879d4a ("block: Increase BLK_DEF_MAX_SECTORS_CAP") that default is 4 MiB, and such a transfer needs 1025 entries, so the list runs a full page past the end of the frame:
sd 1:0:1:0: [sdb] tag#630 page boundary ptr_sgl: 0x00000000ba62d13f
BUG: unable to handle page fault for address: ff663bcb81e7c000 #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page RIP: 0010:megasas_build_and_issue_cmd_fusion+0xeaa/0x1870 [megaraid_sas]
If the page after the frame happens to be mapped, the overrun does not fault but silently corrupts the neighbouring pool entry, which is another in-flight command's PRP list.
Cap max_hw_sectors at what the chain frame can describe, less one page for transfers that do not start on a page boundary and so need one entry more. This is the megaraid_sas counterpart of commit 04631f55afc5 ("scsi: mpt3sas: Limit NVMe request size to 2 MiB"), but derives the limit from max_chain_frame_sz rather than hardcoding it.
--- drivers/scsi/megaraid/megaraid_sas_base.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/scsi/megaraid/megaraid_sas_base.c +12 -1
@@ -1973,12 +1973,23 @@ megasas_set_nvme_device_properties(struc {struct megasas_instance *instance;u32 mr_nvme_pg_size; +u64 max_prp_io; instance = (struct megasas_instance *)sdev->host->hostdata; mr_nvme_pg_size =max_t (u32, instance->nvme_page_size,MR_DEFAULT_NVME_PAGE_SIZE ); - lim->max_hw_sectors = max_io_size /512 ; +/* +* megasas_make_prp_nvme() builds the PRP list in cmd->sg_frame without +* bounding it against that buffer, and spends one entry per page of +* it on the chain pointer. Cap the transfer at what the buffer holds, +* less one page for lists that start off a page boundary. +*/ + max_prp_io = (u64)((instance->max_chain_frame_sz /sizeof (u64)) - + (instance->max_chain_frame_sz / mr_nvme_pg_size) -1 ) * + mr_nvme_pg_size; + + lim->max_hw_sectors =min_t (u64, max_io_size, max_prp_io) >>SECTOR_SHIFT ; lim->virt_boundary_mask = mr_nvme_pg_size -1 ; }
Greg Kroah-Hartman
maintainerPATCH 71/556 scsi: pm8001: Use rollback index when freeing MSI-X vectors
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 3f92a64545165bdbb36dee8fa35626b295463313 upstream.
pm8001_request_msix() unwinds previously registered handlers with free_irq() when request_irq() fails. The rollback loop uses the failing index i for every iteration instead of the already registered vector index j.
That passes the wrong IRQ/dev_id pair to free_irq() and leaves the earlier handlers installed. Use j for both pci_irq_vector() and the matching irq_vector entry in the rollback loop.
--- drivers/scsi/pm8001/pm8001_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/pm8001/pm8001_init.c +2 -2
@@ -1029,8 +1029,8 @@ static u32 pm8001_request_msix(struct pm &(pm8001_ha->irq_vector[i]));if (rc) {for (j =0 ; j < i; j++) { -free_irq (pci_irq_vector (pm8001_ha->pdev, i), - &(pm8001_ha->irq_vector[i])); +free_irq (pci_irq_vector (pm8001_ha->pdev, j), + &pm8001_ha->irq_vector[j]); }pci_free_irq_vectors (pm8001_ha->pdev);break ;
Greg Kroah-Hartman
maintainerPATCH 72/556 Docs/ABI/damon: fix typo in intervals_goal sysfs path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Song Hu <[email protected]>
commit 1b492fc82368399123413c937f13da6ed312ee4d upstream.
Patch series "Docs/ABI/damon: sysfs ABI document fixes and additions", v2.
This series fixes typos and fills in missing entries in the DAMON sysfs ABI document (Documentation/ABI/testing/sysfs-kernel-mm-damon).
Patch 1 fixes a path typo, "intrvals_goal" -> "intervals_goal", in four
What: entries; the documented path points to a non-existent directory, so it is Cc'ed to stable.
Patch 2 fixes two further typos ("WDate:", "manimum").
Patches 3 and 4 add ABI entries that exist in the kernel and are already described in usage.rst but are missing from the canonical ABI document:
the 'update_tuned_intervals' state command (patch 3) and the 'tried_regions/<R>/probes/<P>/hits' file (patch 4).
This patch (of 4):
The ABI document spells the DAMON sysfs directory as "intrvals_goal" (missing 'e') in four What: entries, but the kernel creates it as "intervals_goal" (mm/damon/sysfs.c). Following the documented path therefore yields a non-existent directory.
--- Documentation/ABI/testing/sysfs-kernel-mm-damon | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Documentation/ABI/testing/sysfs-kernel-mm-damon +4 -4
@@ -112,7 +112,7 @@ Description: Writing a value to this fil DAMON context in microseconds as the value. Reading this file returns the value. -What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intrvals_goal/access_bp +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intervals_goal/access_bp Date: Feb 2025 Contact: SJ Park <[email protected]> Description: Writing a value to this file sets the monitoring intervals
@@ -120,7 +120,7 @@ Description: Writing a value to this fil the given time interval (aggrs in same directory), in bp (1/10,000). Reading this file returns the value. -What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intrvals_goal/aggrs +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intervals_goal/aggrs Date: Feb 2025 Contact: SJ Park <[email protected]> Description: Writing a value to this file sets the time interval to achieve
@@ -128,14 +128,14 @@ Description: Writing a value to this fil access events ratio (access_bp in same directory) within. Reading this file returns the value. -What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intrvals_goal/min_sample_us +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intervals_goal/min_sample_us Date: Feb 2025 Contact: SJ Park <[email protected]> Description: Writing a value to this file sets the minimum value of auto-tuned sampling interval in microseconds. Reading this file returns the value. -What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intrvals_goal/max_sample_us +What: /sys/kernel/mm/damon/admin/kdamonds/<K>/contexts/<C>/monitoring_attrs/intervals/intervals_goal/max_sample_us Date: Feb 2025 Contact: SJ Park <[email protected]> Description: Writing a value to this file sets the maximum value of
Greg Kroah-Hartman
maintainerPATCH 73/556 mm/damon/sysfs: read addr_unit only once in damon_sysfs_apply_inputs()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit ab4d9358e32316fa39b5f1f5360292135978c3d9 upstream.
damon_sysfs_apply_inputs() reads addr_unit twice. It could race with addr_unit_store(). As a result, the min_region_sz could wrongly be set up. Read it once.
The user impact is trivial. Sane users ain't update the parameter in parallel. Even if it happens, the DAMON core layer handles the wrong min_region_sz (!is_power_of_2()). Even if somehow the race ended up making a min_region_sz that is different from the user's intention but still valid, only monitoring itself runs differently than expected. No critical consequences like kernel panic or memory corruption happen.
The issue was discovered [1] by Sashiko.
--- mm/damon/sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +2 -2
@@ -2047,11 +2047,11 @@ static int damon_sysfs_apply_inputs(stru err =damon_select_ops (ctx, sys_ctx->ops_id);if (err)return err; - ctx->addr_unit = sys_ctx->addr_unit; + ctx->addr_unit =READ_ONCE (sys_ctx->addr_unit);/* addr_unit is respected by only DAMON_OPS_PADDR */ if (sys_ctx->ops_id ==DAMON_OPS_PADDR ) ctx->min_region_sz =max ( -DAMON_MIN_REGION_SZ / sys_ctx->addr_unit,1 ); +DAMON_MIN_REGION_SZ / ctx->addr_unit,1 ); ctx->pause = sys_ctx->pause; err =damon_sysfs_set_attrs (ctx, sys_ctx->attrs);if (err)
Greg Kroah-Hartman
maintainerPATCH 74/556 mm/damon/sysfs: read ops_id only once in damon_sysfs_apply_inputs()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 5adaaa28be8a79ddd7e103b171f9d6e14e7fc26e upstream.
damon_sysfs_apply_inputs() reads ops_id twice. It could race with ops_id_store(). As a result, the min_region_sz could wrongly be set up. Read it once.
The user impact is trivial. Sane users ain't update the parameter in parallel. Even if it happens, the DAMON core layer handles the wrong min_region_sz (!is_power_of_2()). Even if somehow the race ended up making a min_region_sz that is different from the user's intention but still valid, only monitoring itself runs differently than expected. No critical consequences like kernel panic or memory corruption happen
The issue was discovered [1] by Sashiko.
--- mm/damon/sysfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +4 -2
@@ -2042,14 +2042,16 @@ static inline bool damon_sysfs_kdamond_rstatic int damon_sysfs_apply_inputs (struct damon_ctx *ctx,struct damon_sysfs_context *sys_ctx) { +enum damon_ops_id ops_id;int err; - err =damon_select_ops (ctx, sys_ctx->ops_id); + ops_id =READ_ONCE (sys_ctx->ops_id); + err =damon_select_ops (ctx, ops_id);if (err)return err; ctx->addr_unit =READ_ONCE (sys_ctx->addr_unit);/* addr_unit is respected by only DAMON_OPS_PADDR */ -if (sys_ctx->ops_id ==DAMON_OPS_PADDR ) +if (ops_id ==DAMON_OPS_PADDR ) ctx->min_region_sz =max (DAMON_MIN_REGION_SZ / ctx->addr_unit,1 ); ctx->pause = sys_ctx->pause;
Greg Kroah-Hartman
maintainerPATCH 75/556 mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit b640708929aa956235866bf7717d89018c661083 upstream.
KUNIT_EXPECT_EQ() does not abort the execution of test code when the expectation is not met. But damon_test_merge_regions_of() code after its initial KUNIT_EXPECT_EQ() call assumes the expectation is met. It does a per-region test with a hard-coded number of regions that is correct only if the expectation was met. As a result, __nth_region_of() could return NULL, and the test code can dereference NULL pointers. Fix the issue by catching the expectation failure and skip the per-region tests.
The user impact on realistic setups should be negligible, as it is a unit test.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/core-kunit.h | 3 +++ 1 file changed, 3 insertions(+)
mm/damon/tests/core-kunit.h +3 -0
@@ -259,11 +259,14 @@ static void damon_test_merge_regions_of(damon_merge_regions_of (t,9 ,9999 );/* 0-112, 114-130, 130-156, 156-170, 170-230, 230-10170 */ KUNIT_EXPECT_EQ (test,damon_nr_regions (t),6u ); +if (damon_nr_regions (t) !=6 ) + goto out;for (i =0 ; i <6 ; i++) { r =__nth_region_of (t, i);KUNIT_EXPECT_EQ (test, r->ar.start, saddrs[i]);KUNIT_EXPECT_EQ (test, r->ar.end, eaddrs[i]); } +out:damon_free_target (t); }
Greg Kroah-Hartman
maintainerPATCH 76/556 mm/damon/vaddr-kunit: check region count in three_regions test
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 5fea07e460874c8c7cf00f728efbe22abc62c8d8 upstream.
damon_do_test_apply_three_regions() iterates regions after damon_set_regions() call assuming the function would succeed at setting the number of regions the same to the expected one. It might have failed. In this case, __nth_region_of() in the iteration could return NULL and NULL dereference can happen in the test.
The consequent user impact (NULL dereference) is quite bad. The realistic user impact would be limited, though. It would affect only test run setups.
Fix it by testing if the number of regions was also changed as expected and exit early for the failure.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/vaddr-kunit.h | 5 +++++ 1 file changed, 5 insertions(+)
mm/damon/tests/vaddr-kunit.h +5 -0
@@ -158,12 +158,17 @@ static void damon_do_test_apply_three_rekunit_skip (test,"second damon_set_regions() fail" ); } +KUNIT_EXPECT_EQ (test,damon_nr_regions (t), nr_expected /2 ); +if (damon_nr_regions (t) != nr_expected /2 ) + goto out; +for (i =0 ; i < nr_expected /2 ; i++) { r =__nth_region_of (t, i);KUNIT_EXPECT_EQ (test, r->ar.start, expected[i *2 ]);KUNIT_EXPECT_EQ (test, r->ar.end, expected[i *2 +1 ]); } +out:damon_destroy_target (t,NULL ); }
Greg Kroah-Hartman
maintainerPATCH 77/556 samples/damon/mtier: handle damon_start() failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit c7230d08ee79b13127bd2b45a3648d361ac912fc upstream.
damon_sample_mtier_start() callers assume it will clean up resources when it fails. And the function does the cleanup for context buildup failures. However, it is not doing the cleanup for damon_start() failure.
As a result, when damon_start() fails, it could leak the memory for DAMON context. Also, if damon_start() fails for only the second context, the first context will indefinitely run, and avoid starting other DAMON contexts since it is running in the exclusive mode. Stop possibly started DAMON context and free the contexts in case of the failure to fix the issues.
Note that the issue can reliably be reproduced because the module calls damon_start() in the exclusive mode. For example,
$ sudo damo start
$ echo Y | sudo tee /sys/module/damon_sample_mtier/parameters/enabled
$ sudo cat /proc/allocinfo | grep damon_new_ctxBecause the first command is running another DAMON instance, the second command fails the damon_start() call because the new DAMON instance cannot exclusively run. And without this fix, by repeating the second and the third commands above, we can show the memory consumption is only increasing due to the leaks. It requires the sudo permission though.
The issue was discovered [1] by Sashiko.
--- samples/damon/mtier.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
samples/damon/mtier.c +10 -1
@@ -180,6 +180,7 @@ free_out:static int damon_sample_mtier_start (void ) {struct damon_ctx *ctx; +int err; ctx =damon_sample_mtier_build_ctx (true);if (!ctx)
@@ -191,7 +192,15 @@ static int damon_sample_mtier_start(voidreturn -ENOMEM ; } ctxs[1 ] = ctx; -return damon_start (ctxs,2 , true); + err =damon_start (ctxs,2 , true); +if (!err) +return 0 ; + +if (damon_is_running (ctxs[0 ])) +damon_stop (ctxs,1 ); +damon_destroy_ctx (ctxs[0 ]); +damon_destroy_ctx (ctxs[1 ]); +return err; }static void damon_sample_mtier_stop (void )
Greg Kroah-Hartman
maintainerPATCH 78/556 samples/damon/mtier: handle damon_stop() failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 9dc5b6d66fd51b103eff21ed0df3e292f489ebc0 upstream.
damon_sample_mtier_stop() assumes its damon_stop() call will always successfully stops the two DAMON contexts. Hence it deallocates the two DAMON contexts after the damon_stop() call. However, if a given context is already stopped, damon_stop() fails and returns an error while letting the DAMON contexts that have not yet stopped keep running. This kind of unexpected early DAMON context stops could happen due to memory allocation failures in kdamond_fn(). Because damon_sample_mtier_stop() just deallocates all DAMON contexts with damon_target and damon_region objects that are linked to the contexts, the execution of the unstopped DAMON context (kdamond) ends up using the memory that freed (use-after-free). Fix the issue by separating the damon_stop() to be invoked per context.
Note that DAMON_SYSFS also allows multiple DAMON contexts execution. But, it calls damon_stop() for each context one by one. Hence this issue is only in mtier.
For the long term, it would be better to refactor damon_stop() to always ensure stopping all contexts regardless of the failures in the middle. Make this fix in the current way, though, to keep it simple and easy to backport. I will do the refactoring later.
The issue was discovered [1] by Sashiko.
--- samples/damon/mtier.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
samples/damon/mtier.c +2 -1
@@ -205,7 +205,8 @@ static int damon_sample_mtier_start(voidstatic void damon_sample_mtier_stop (void ) { -damon_stop (ctxs,2 ); +damon_stop (ctxs,1 ); +damon_stop (&ctxs[1 ],1 );damon_destroy_ctx (ctxs[0 ]);damon_destroy_ctx (ctxs[1 ]); }
Greg Kroah-Hartman
maintainerPATCH 79/556 samples/damon/prcl: handle damon_start() failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 8b724349229bb6ebbf781178be011ba9bc2cca57 upstream.
damon_sample_prcl_start() callers assume it will clean up resources when it fails. And the function does the cleanup for context buildup failures. However, it is not doing the cleanup for damon_start() failure. As a result, when damon_start() fails, it leaks the memory for DAMON context. Free the context in case of the failure to fix the issues.
Note that the issue can reliably be reproduced because the module calls damon_start() in the exclusive mode. For example,
$ sudo damo start
$ echo $$ | sudo tee /sys/module/damon_sample_prcl/parameters/target_pid
$ echo Y | sudo tee /sys/module/damon_sample_prcl/parameters/enabled
$ sudo cat /proc/allocinfo | grep damon_new_ctxBecause the first command is running another DAMON instance, the third command fails the damon_start() call because the new DAMON instance cannot exclusively run. And without this fix, by repeating the third and the fourth commands above, we can show the memory consumption is only increasing due to the leaks. It requires the sudo permission though.
The issue was discovered [1] by Sashiko.
--- samples/damon/prcl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
samples/damon/prcl.c +3 -1
@@ -106,8 +106,10 @@ static int damon_sample_prcl_start(void)damon_set_schemes (ctx, &scheme,1 ); err =damon_start (&ctx,1 , true); -if (err) +if (err) { +damon_destroy_ctx (ctx);return err; + } repeat_call_control.data = ctx;return damon_call (ctx, &repeat_call_control);
Greg Kroah-Hartman
maintainerPATCH 80/556 samples/damon/prcl: stop and free damon ctx when damon_call() fails
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit a73fa45d3f0f42c446ae55c5799e3d5ef044cd5d upstream.
damon_sample_prcl_start() calls damon_call() right after damon_start() is succeeded. The kdamond that has started by the damon_start() could be terminated by itself before or in the middle of the damon_call() execution. There could be multiple reasons for such a stop including monitoring target process termination and kdamond_fn() internal memory allocation failures. In the case, damon_call() will fail and return an error without cleaning up the DAMON context object. The damon_sample_prcl_start() caller assumes it would clean up the object, though. When the user requests to start DAMON again, damon_sample_prcl_start() is called again, allocates a new DAMON context object and overwrites the pointer for the previous object. As a result, the previous context object is leaked.
Safely stop the kdamond and deallocate the context object when the failure is returned. Note that the kdamond should be stopped first, because damon_call() failure means not complete termination of the kdamond but only the fact that the termination process has started.
The user impact shouldn't be that significant because the race is not easy to happen, and only up to one DAMON context object can be leaked per race.
The issue was discovered [1] by Sashiko.
--- samples/damon/prcl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
samples/damon/prcl.c +6 -1
@@ -112,7 +112,12 @@ static int damon_sample_prcl_start(void) } repeat_call_control.data = ctx; -return damon_call (ctx, &repeat_call_control); + err =damon_call (ctx, &repeat_call_control); +if (err) { +damon_stop (&ctx,1 ); +damon_destroy_ctx (ctx); + } +return err; }static void damon_sample_prcl_stop (void )
Greg Kroah-Hartman
maintainerPATCH 81/556 samples/damon/wsse: handle damon_start() failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit e4742be45ea45bf554399ce89a09f71e525d7981 upstream.
Patch series "samples/damon: handle damon_{start,stop}() failures".
All DAMON sample modules are not correctly handling failures from damon_start(). Among those, mtier also has an additional problem for handling of damon_stop() failures. wsse and prcl also have a problem in their damon_call() failure handling. As a result, memory leaks, next DAMON operation disruptions, and use-after-free can happen. Fix those.
Note that only the damon_start() failure caused issues can reliably be reproduced. Reproducing those issues require the admin permission, though.
This patch (of 6):
damon_sample_wsse_start() callers assume it will clean up resources when it fails. And the function does the cleanup for context buildup failures. However, it is not doing the cleanup for damon_start() failure. As a result, when damon_start() fails, it leaks the memory for DAMON context. Free the context in case of the failure to fix the issues.
Note that the issue can reliably be reproduced because the module calls damon_start() in the exclusive mode. For example,
$ sudo damo start
$ echo $$ | sudo tee /sys/module/damon_sample_wsse/parameters/target_pid
$ echo Y | sudo tee /sys/module/damon_sample_wsse/parameters/enabled
$ sudo cat /proc/allocinfo | grep damon_new_ctxBecause the first command is running another DAMON instance, the third command fails the damon_start() call because the new DAMON instance cannot exclusively run. And without this fix, by repeating the third and the fourth commands above, we can show the memory consumption is only increasing due to the leaks. It requires the sudo permission though.
The issue was discovered [1] by Sashiko.
--- samples/damon/wsse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
samples/damon/wsse.c +3 -1
@@ -87,8 +87,10 @@ static int damon_sample_wsse_start(void) target->pid = target_pidp; err =damon_start (&ctx,1 , true); -if (err) +if (err) { +damon_destroy_ctx (ctx);return err; + } repeat_call_control.data = ctx;return damon_call (ctx, &repeat_call_control); }
Greg Kroah-Hartman
maintainerPATCH 82/556 samples/damon/wsse: stop and free damon ctx when damon_call() fails
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit a2c6fa6c23ad87c61e1379b05dc05cf5fed4bf8d upstream.
damon_sample_wsse_start() calls damon_call() right after damon_start() is succeeded. The kdamond that has started by the damon_start() could be terminated by itself before or in the middle of the damon_call() execution. There could be multiple reasons for such a stop including monitoring target process termination and kdamond_fn() internal memory allocation failures. In the case, damon_call() will fail and return an error without cleaning up the DAMON context object. The damon_sample_wsse_start() caller assumes it would clean up the object, though. When the user requests to start DAMON again, damon_sample_wsse_start() is called again, allocates a new DAMON context object and overwrites the pointer for the previous object. As a result, the previous context object is leaked.
Safely stop the kdamond and deallocate the context object when the failure is returned. Note that the kdamond should be stopped first, because damon_call() failure means not complete termination of the kdamond but only the fact that the termination process has started.
The user impact shouldn't be that significant because the race is not easy to happen, and only up to one DAMON context object can be leaked per race.
The issue was discovered [1] by Sashiko.
--- samples/damon/wsse.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
samples/damon/wsse.c +6 -1
@@ -92,7 +92,12 @@ static int damon_sample_wsse_start(void)return err; } repeat_call_control.data = ctx; -return damon_call (ctx, &repeat_call_control); + err =damon_call (ctx, &repeat_call_control); +if (err) { +damon_stop (&ctx,1 ); +damon_destroy_ctx (ctx); + } +return err; }static void damon_sample_wsse_stop (void )
Greg Kroah-Hartman
maintainerPATCH 83/556 mm/damon/sysfs-schemes: kobject_del() scheme action destination dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 286380c78bc51e6c578621b9ae660bf9e5ad2563 upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme action destination directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -2138,8 +2138,10 @@ static void damos_sysfs_dests_rm_dirs(struct damos_sysfs_dest **dests_arr = dests->dests_arr;int i; -for (i =0 ; i < dests->nr; i++) +for (i =0 ; i < dests->nr; i++) { +kobject_del (&dests_arr[i]->kobj);kobject_put (&dests_arr[i]->kobj); + } dests->nr =0 ;kfree (dests_arr); dests->dests_arr =NULL ;
Greg Kroah-Hartman
maintainerPATCH 84/556 mm/damon/sysfs-schemes: kobject_del() scheme dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 05fb6ac98c49be870c5f9ccdfdf95f0107e564ae upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +4 -1
@@ -2683,6 +2683,7 @@ void damon_sysfs_schemes_rm_dirs(structfor (i =0 ; i < schemes->nr; i++) {damon_sysfs_scheme_rm_dirs (schemes_arr[i]); +kobject_del (&schemes_arr[i]->kobj);kobject_put (&schemes_arr[i]->kobj); } schemes->nr =0 ;
@@ -2724,13 +2725,15 @@ static int damon_sysfs_schemes_add_dirs( goto out; err =damon_sysfs_scheme_add_dirs (scheme);if (err) - goto out; + goto del_out; schemes_arr[i] = scheme; schemes->nr++; }return 0 ; +del_out: +kobject_del (&scheme->kobj); out:damon_sysfs_schemes_rm_dirs (schemes);kobject_put (&scheme->kobj);
Greg Kroah-Hartman
maintainerPATCH 85/556 mm/damon/sysfs-schemes: kobject_del() scheme filter dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 3c453bddacd4c04ecb38cf79dbfa41e7dfe0531b upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme filter directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -911,8 +911,10 @@ static void damon_sysfs_scheme_filters_rstruct damon_sysfs_scheme_filter **filters_arr = filters->filters_arr;int i; -for (i =0 ; i < filters->nr; i++) +for (i =0 ; i < filters->nr; i++) { +kobject_del (&filters_arr[i]->kobj);kobject_put (&filters_arr[i]->kobj); + } filters->nr =0 ;kfree (filters_arr); filters->filters_arr =NULL ;
Greg Kroah-Hartman
maintainerPATCH 86/556 mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 0d4397ca921ceaf80fc3eca4c8194812ff79a979 upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme quota goal directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -1462,8 +1462,10 @@ static void damos_sysfs_quota_goals_rm_dstruct damos_sysfs_quota_goal **goals_arr = goals->goals_arr;int i; -for (i =0 ; i < goals->nr; i++) +for (i =0 ; i < goals->nr; i++) { +kobject_del (&goals_arr[i]->kobj);kobject_put (&goals_arr[i]->kobj); + } goals->nr =0 ;kfree (goals_arr); goals->goals_arr =NULL ;
Greg Kroah-Hartman
maintainerPATCH 87/556 mm/damon/sysfs-schemes: kobject_del() scheme region dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit f3ec3271210781c255e737498b84d5790e8176b4 upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme region directories by adding kobject_del() calls.
This issue was discovered [1] by Sashiko, though its analysis was partially incorrect.
--- mm/damon/sysfs-schemes.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/sysfs-schemes.c +1 -0
@@ -332,6 +332,7 @@ static void damon_sysfs_scheme_regions_rlist_for_each_entry_safe (r, next, ®ions->regions_list, list) {damos_sysfs_region_rm_dirs (r);list_del (&r->list); +kobject_del (&r->kobj);kobject_put (&r->kobj); regions->nr_regions--; }
Greg Kroah-Hartman
maintainerPATCH 88/556 mm/damon/sysfs: kobject_del() region and target (error) dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 2603ef6f6ec3d3f7de2d6a07e7c9a683cebac419 upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for the normal creation path of region directories and the error path of target directories, by adding kobject_del() calls.
--- mm/damon/sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +6 -2
@@ -105,8 +105,10 @@ static void damon_sysfs_regions_rm_dirs(struct damon_sysfs_region **regions_arr = regions->regions_arr;int i; -for (i =0 ; i < regions->nr; i++) +for (i =0 ; i < regions->nr; i++) { +kobject_del (®ions_arr[i]->kobj);kobject_put (®ions_arr[i]->kobj); + } regions->nr =0 ;kfree (regions_arr); regions->regions_arr =NULL ;
@@ -369,13 +371,15 @@ static int damon_sysfs_targets_add_dirs( err =damon_sysfs_target_add_dirs (target);if (err) - goto out; + goto del_out; targets_arr[i] = target; targets->nr++; }return 0 ; +del_out: +kobject_del (&target->kobj); out:damon_sysfs_targets_rm_dirs (targets);kobject_put (&target->kobj);
Greg Kroah-Hartman
maintainerPATCH 89/556 mm/damon/sysfs: kobject_del() target (normal), context and kdamond dirs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 263af33a72d1995ae6cdc22b08d527e2bda17259 upstream.
Patch series "mm/damon/sysfs: kobject_del() directories that users can create/remove".
DAMON sysfs interface allows users to create and remove arbitrary number of directories on sysfs, using a few files having 'nr_' prefix. For example, 'nr_kdamonds'. When the user writes a number 'N' to the files, directories having name starting from '0' to 'N - 1' are created in the same directory. The pre-existing number-named directories are removed before creating the new directories.
For the removal of the existing directories, DAMON sysfs interface use only kobject_put(). Because DAMON sysfs interface is the only kernel component that manages the directories, there is no problem in normal situations. However, if CONFIG_DEBUG_KOBJECT_RELEASE is enabled, the removal of dirs are delayed. Let's suppose a user writes a non-zero number to the 'nr_*' files while there are pre-existing number-named directories, on the config enabled kernel. DAMON sysfs interface decreases the reference counts of the existing directories and immediately creates new directories. Because the removal of the sysfs directories is delayed, it shows some pre-existing directories of the same names when it tries to create the new directories, and fails.
For example, the issue can be triggered like below:
# grep DEBUG_KOBJECT_RELEASE /boot/config-$(uname -r)
CONFIG_DEBUG_KOBJECT_RELEASE=y
# ls
nr_kdamonds
# echo 1 > nr_kdamonds
# echo 1 > nr_kdamonds
bash: echo: write error: File exists
# dmesg
[...]
[ 300.880458] kobject: kobject_add_internal failed for 0 with -EEXIST, don't try to register things with the same name in the same directory.
[...]Some of the error handling paths of the directories also lack the kobject_del() call. If the user uses nr_* file right after the errors, similar issues can happen.
This doesn't cause catastrophic issues like kernel panics or memory corruptions. Users can work around by removing all directories first (write 0 to the nr_* files) and then create new directories after confirming the old directories are gone. But, this is definitely a bug that causes a bad user experience.
Fix the issues by calling kobject_del() before creating new directories.
This patch (of 11)
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for normal creation paths of target, context and kdamond directories, and error paths of context and kdamond directories by adding kobject_del() calls.
Note that this fix for target directories is not complete since it has a similar issue in the damon_sysfs_targets_add_dirs() error path. Because the normal path issue and the error path issue are introduced by different commits, this commit is fixing only the normal path issue. A commit for the error path will be added next.
--- mm/damon/sysfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +9 -2
@@ -333,6 +333,7 @@ static void damon_sysfs_targets_rm_dirs(for (i =0 ; i < targets->nr; i++) {damon_sysfs_target_rm_dirs (targets_arr[i]); +kobject_del (&targets_arr[i]->kobj);kobject_put (&targets_arr[i]->kobj); } targets->nr =0 ;
@@ -1644,6 +1645,7 @@ static void damon_sysfs_contexts_rm_dirsfor (i =0 ; i < contexts->nr; i++) {damon_sysfs_context_rm_dirs (contexts_arr[i]); +kobject_del (&contexts_arr[i]->kobj);kobject_put (&contexts_arr[i]->kobj); } contexts->nr =0 ;
@@ -1682,13 +1684,15 @@ static int damon_sysfs_contexts_add_dirs err =damon_sysfs_context_add_dirs (context);if (err) - goto out; + goto del_out; contexts_arr[i] = context; contexts->nr++; }return 0 ; +del_out: +kobject_del (&context->kobj); out:damon_sysfs_contexts_rm_dirs (contexts);kobject_put (&context->kobj);
@@ -2505,6 +2509,7 @@ static void damon_sysfs_kdamonds_rm_dirsfor (i =0 ; i < kdamonds->nr; i++) {damon_sysfs_kdamond_rm_dirs (kdamonds_arr[i]); +kobject_del (&kdamonds_arr[i]->kobj);kobject_put (&kdamonds_arr[i]->kobj); } kdamonds->nr =0 ;
@@ -2559,13 +2564,15 @@ static int damon_sysfs_kdamonds_add_dirs err =damon_sysfs_kdamond_add_dirs (kdamond);if (err) - goto out; + goto del_out; kdamonds_arr[i] = kdamond; kdamonds->nr++; }return 0 ; +del_out: +kobject_del (&kdamond->kobj); out:damon_sysfs_kdamonds_rm_dirs (kdamonds);kobject_put (&kdamond->kobj);
Greg Kroah-Hartman
maintainerPATCH 90/556 mm/damon/core-kunit: check region count before testing in split_at()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 9b18ef3c3aa1ce24176e340061caf15fa2742564 upstream.
damon_test_split_at() test next region that is assumed to be created by damon_split_region_at() invocation. But the split might fail. In this case, the succeeding test may dereference invalid pointers returned by damon_next_region().
The invalid pointer may not cause a really bad user impact, because of the implementation detail. It would only read wrong contents in the belonging damon_target struct. Depending on the future change of the offset from the link header to the accessing field, this could also be really dangerous, though. Still, the realistic user impact would be limited. It would affect only test run setups.
Fix it by testing if the number of regions was also changed as expected and exit early for the failure.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/core-kunit.h | 5 +++++ 1 file changed, 5 insertions(+)
mm/damon/tests/core-kunit.h +5 -0
@@ -157,6 +157,10 @@ static void damon_test_split_at(struct k r->age =10 ;damon_add_region (r, t);damon_split_region_at (t, r,25 ); +KUNIT_EXPECT_EQ (test,damon_nr_regions (t),2 ); +if (damon_nr_regions (t) !=2 ) + goto out; +KUNIT_EXPECT_EQ (test, r->ar.start,0ul );KUNIT_EXPECT_EQ (test, r->ar.end,25ul );
@@ -169,6 +173,7 @@ static void damon_test_split_at(struct kKUNIT_EXPECT_EQ (test, r->last_nr_accesses, r_new->last_nr_accesses);KUNIT_EXPECT_EQ (test, r->age, r_new->age); +out:damon_free_target (t); }
Greg Kroah-Hartman
maintainerPATCH 91/556 mm/damon/core-kunit: handle region split failure in filter_out()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 3423fe70395210e2f0cd795270292f6a27cd57b5 upstream.
damos_test_filter_out() test checks if damos_filter_match() of an address filter splits the region as expected under a given condition. But, the test continued regardless of the split successes. As a result, the later part of the test could dereference invalid pointers that returned from damon_next_region(). Further, it could corrupt memory from damon_destroy_region().
The consequent user impact (memory corruption) is quite bad. The realistic user impact would be limited, though. It would affect only test run setups.
Fix it by exiting early for the number of regions test failure.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/core-kunit.h | 5 +++++ 1 file changed, 5 insertions(+)
mm/damon/tests/core-kunit.h +5 -0
@@ -1259,6 +1259,8 @@ static void damos_test_filter_out(structKUNIT_EXPECT_EQ (test, r->ar.start,1 );KUNIT_EXPECT_EQ (test, r->ar.end,2 );KUNIT_EXPECT_EQ (test,damon_nr_regions (t),2 ); +if (damon_nr_regions (t) !=2 ) + goto out; r2 =damon_next_region (r);KUNIT_EXPECT_EQ (test, r2->ar.start,2 );KUNIT_EXPECT_EQ (test, r2->ar.end,4 );
@@ -1273,11 +1275,14 @@ static void damos_test_filter_out(structKUNIT_EXPECT_EQ (test, r->ar.start,2 );KUNIT_EXPECT_EQ (test, r->ar.end,6 );KUNIT_EXPECT_EQ (test,damon_nr_regions (t),2 ); +if (damon_nr_regions (t) !=2 ) + goto out; r2 =damon_next_region (r);KUNIT_EXPECT_EQ (test, r2->ar.start,6 );KUNIT_EXPECT_EQ (test, r2->ar.end,8 );damon_destroy_region (r2, t); +out:damon_free_target (t);damos_free_filter (f); }
Greg Kroah-Hartman
maintainerPATCH 92/556 mm/damon/core-kunit: skip wrong dest walk in commit_dests_for()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 7e2f2c41b27f64caad6599073aaa0ccdd08745e1 upstream.
damos_test_commit_dests_for() traverse damos action destinations after damos_commit_dests(). It assumes damos_commit_dests() made expected numbers of destinations for source and destination structures. It might not. Because the traversal is made based on destination struct length, it could do out of bounds access for source value expectation.
The consequent user impact (out-of-bound access ) is quite bad. The realistic user impact would be limited, though. It would affect only test run setups.
Fix it by exiting early for the number of regions test failure.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/core-kunit.h | 2 ++ 1 file changed, 2 insertions(+)
mm/damon/tests/core-kunit.h +2 -0
@@ -902,6 +902,8 @@ static void damos_test_commit_dests_for( skip = false;KUNIT_EXPECT_EQ (test, dst.nr_dests, src_nr_dests); +if (dst.nr_dests != src_nr_dests) + goto out;for (i =0 ; i < dst.nr_dests; i++) {KUNIT_EXPECT_EQ (test, dst.node_id_arr[i], src_node_id_arr[i]);KUNIT_EXPECT_EQ (test, dst.weight_arr[i], src_weight_arr[i]);
Greg Kroah-Hartman
maintainerPATCH 93/556 mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 867bbe6dbd5a68eb58e79cc7f068a6cf184c40d8 upstream.
damos_test_commit_quota_goals_for() traverses damos quota goals after damos_commit_quota_goals() call. It assumes damos_commit_quota_goals() made expected numbers of goals. It might not. Because the traversal is made based on destination struct length, it could do out of bounds access for source expectation value array.
The consequent user impact (out-of-bound access ) is quite bad. The realistic user impact would be limited though. It would affect only test run setups.
Fix it by testing if the number of goals was also changed as expected and exit early for the failure.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/core-kunit.h | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/damon/tests/core-kunit.h +9 -0
@@ -733,6 +733,7 @@ static void damos_test_commit_quota_goalstruct damos_quota_goal *goal, *next;bool skip = true;int i; +int nr_dst =0 , nr_src =0 ;INIT_LIST_HEAD (&dst.goals);INIT_LIST_HEAD (&src.goals);
@@ -755,6 +756,14 @@ static void damos_test_commit_quota_goaldamos_commit_quota_goals (&dst, &src); +damos_for_each_quota_goal (goal, &dst) + nr_dst++; +damos_for_each_quota_goal (goal, &src) + nr_src++; +KUNIT_EXPECT_EQ (test, nr_dst, nr_src); +if (nr_dst != nr_src) + goto out; + i =0 ;damos_for_each_quota_goal (goal, (&dst)) {KUNIT_EXPECT_EQ (test, goal->metric, src_goals[i].metric);
Greg Kroah-Hartman
maintainerPATCH 94/556 mm/damon/core-kunit: skip wrong region walk in commit_target_regions()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 488cf81c49955f83b7682dda880e9920c173e617 upstream.
damon_test_commit_target_regions_for() traverses expected values array after damon_commit_target_regions() call. It assumes damon_commit_target_regions() made expected number of regions. It might not. Because the traversal is made based on the region count, it could do out of bounds access to the expectation value array.
The consequent user impact (out-of-bound access) is quite bad. The realistic user impact would be limited, though. It would affect only test run setups.
Fix it by testing if the number of regions was also changed as expected and exit early for the failure.
The issue was discovered [1] by Sashiko.
--- mm/damon/tests/core-kunit.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
mm/damon/tests/core-kunit.h +7 -2
@@ -1171,14 +1171,19 @@ static void damon_test_commit_target_regkunit_skip (test,"src target setup fail" ); }damon_commit_target_regions (dst_target, src_target,1 ); + +KUNIT_EXPECT_EQ (test,damon_nr_regions (dst_target), nr_expect_regions); +if (damon_nr_regions (dst_target) != nr_expect_regions) + goto out; + i =0 ;damon_for_each_region (r, dst_target) {KUNIT_EXPECT_EQ (test, r->ar.start, expect_start_end[i][0 ]);KUNIT_EXPECT_EQ (test, r->ar.end, expect_start_end[i][1 ]); i++; } -KUNIT_EXPECT_EQ (test,damon_nr_regions (dst_target), nr_expect_regions); -KUNIT_EXPECT_EQ (test, i, nr_expect_regions); + +out:damon_free_target (dst_target);damon_free_target (src_target); }
Greg Kroah-Hartman
maintainerPATCH 95/556 mm/damon/core: handle region split failure in apply_min_nr_regions()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit c608748607620f331196ed0ba9fe4017892c1457 upstream.
damon_apply_min_nr_regions() repeatedly split each region until its size becomes small enough to meet the user-defined low limit of the number of regions. The loop assumes the split operation (damon_split_region_at()) will always succeed and create the new region. But the operation could silently fail for memory allocation failures, for example.
If such failure happens and the region was the last region, the linked list-based next region fetching returns invalid pointer. As a result, invalid memory dereference and corruption could happen. Even if the corner case is handled, it imposes stress to the allocator by trying split regions for other targets. Fix the issue by breaking all the loops for any region split failure.
This means there could be a min_nr_regions violation. It will only rarely happen since the allocation is arguably too small to fail. Even if it happens, it is only temporal. damon_apply_min_nr_regions() will be called again after the aggregation interval.
The user impact of the issue should be minor, since the allocation is arguably too small to fail. But, it could still theoretically happen, and the consequence is very bad.
This issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
mm/damon/core.c +9 -4
@@ -1670,7 +1670,7 @@ static unsigned long damon_region_sz_limreturn sz; } -static void damon_split_region_at (struct damon_target *t, +static int damon_split_region_at (struct damon_target *t,struct damon_region *r,unsigned long sz_r);/*
@@ -1696,11 +1696,13 @@ static unsigned long damon_apply_min_nr_damon_for_each_target (t, ctx) {damon_for_each_region_safe (r, next, t) {while (damon_sz_region (r) > max_region_sz) { -damon_split_region_at (t, r, max_region_sz); +if (damon_split_region_at (t, r, max_region_sz)) + goto out; r =damon_next_region (r); } } } +out:return max_region_sz; }
@@ -3194,8 +3196,10 @@ static void damon_verify_split_region_at* * r the region to be split * sz_r size of the first sub-region that will be made +* +* Return: 0 on success, negative error code otherwise. */ -static void damon_split_region_at (struct damon_target *t, +static int damon_split_region_at (struct damon_target *t,struct damon_region *r,unsigned long sz_r) {struct damon_region *new;
@@ -3203,7 +3207,7 @@ static void damon_split_region_at(structdamon_verify_split_region_at (r, sz_r); new =damon_new_region (r->ar.start + sz_r, r->ar.end);if (!new) -return ; +return -ENOMEM ; r->ar.end = new->ar.start;
@@ -3215,6 +3219,7 @@ static void damon_split_region_at(structmemcpy (new->probe_hits, r->probe_hits,sizeof (r->probe_hits));damon_insert_region (new, r,damon_next_region (r), t); +return 0 ; }/* Split every region in the given target into 'nr_subs' regions */
Greg Kroah-Hartman
maintainerPATCH 96/556 mm/damon/core: initialize damos->last_applied
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit af5f76aeb9c9aa9c77d5e1d94e0ee4618c805239 upstream.
Patch series "mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs".
Fix a few Sashiko-found unurgent bugs. Patch 1 fixes use of uninitialized damos->last_applied field. Patches 2-7 fix DAMON kunit tests that do invalid memory access under test failures.
The bugs are better to be fixed and eventually merged into stable@ kernel. That said, the fixes are arguably not urgent. Patch 1 only introduces negligible DAMOS efficiency degradation in occasional cases. Kunit fixes could introduce quite bad consequences but those are test code that affect only test run setups.
This patch (of 7):
Multiple DAMON regions could exist across a folio. If they fulfill the condition to apply a DAMOS scheme, the scheme could be applied multiple times to the folio. To avoid this, each DAMOS scheme stores the folio that the scheme was applied to last time in the damos->last_applied field and skips repeatedly applying the same scheme to the same folio.
The field is being used without initialization, though. Hence, the mechanism could wrongly skip applying a scheme to a folio at the very first time of DAMOS run.
The user impact is trivial. DAMON might unexpectedly skip applying DAMOS action for one folio for the first time per scheme. In the DAMON's best-effort world, this is never a real problem. No critical consequences such as kernel panic or memory corruption happen.
It is a clear bug, though, and the fix is straightforward. Fix the issue by initializing the field in DAMOS scheme creation function, damon_new_scheme().
The issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/core.c +1 -0
@@ -579,6 +579,7 @@ struct damos *damon_new_scheme(struct daINIT_LIST_HEAD (&scheme->ops_filters); scheme->stat = (struct damos_stat ){}; scheme->max_nr_snapshots =0 ; + scheme->last_applied =NULL ;INIT_LIST_HEAD (&scheme->list); scheme->quota = *(damos_quota_init (quota));
Greg Kroah-Hartman
maintainerPATCH 97/556 mm/secretmem: properly account locked pages
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
commit 97d34aa65c29cca85e3e9050f4c936389b38a054 upstream.
secretmem accounts folios by treating memory as if it were mlock()'d and thus limited by the RLIMIT_MEMLOCK limit.
However the folios are unevictable and remain so until the inode is evicted, eliminating usual mlock() semantics - mapping folios then unmapping them does not clear their unevictable state, since it depends on AS_UNEVICTABLE, not PG_mlocked.
A user can therefore easily work around the RLIMIT_MEMLOCK limit - simply map then unmap and VmLck no longer counts the secretmem range. Worse, folios are not accounted in the process's RSS, meaning the OOM killer won't know to kill the process.
Repeatedly mapping/unmapping (or forking) can then result in the consumption of all available system memory with unevictable folios and cause system instability.
A secretmem fd can be passed between processes and over fork so a per-process limit simply does not make sense, so follow the precedent set by io_uring, perf, skbuff, iommufd and xdp by tracking the number of locked pages in user_struct->locked_vm.
Since the scope tracked is actually inode lifetime, the RLIMIT_MEMLOCK applies per-user not per-process, so it doesn't make sense to bypass for users with CAP_IPC_LOCK, therefore remove this bypass.
There is simply no reason to carry on marking the mapping as mlock()'d since it's misleading and the lifecycle is now correctly handled, so remove this too.
Note that secretmem does not support any form of truncation (including hole punching) and the folios are unreclaimable, so the folios need only be accounted on fault and unaccounted on inode destruction.
__secretmem_account_pages() is more or less a duplicate of the code that io_uring etc. use, but since this is a bug fix that needs backporting, defer any de-duplication efforts to a follow-up.
test_mlock_limit() asserts mlock_future_ok() on mmap(), however this has been removed, so remove the test altogether for the fix. A new test will be sent separately for upstream.
--- include/linux/sched/user.h | 3 mm/secretmem.c | 116 +++++++++++++++++++++++++++--- tools/testing/selftests/mm/memfd_secret.c | 30 ------- 3 files changed, 110 insertions(+), 39 deletions(-)
include/linux/sched/user.h +2 -1
@@ -25,7 +25,8 @@ struct user_struct {#if defined(CONFIG_PERF_EVENTS ) || defined(CONFIG_BPF_SYSCALL ) || \ defined(CONFIG_NET ) || defined(CONFIG_IO_URING ) || \ - defined(CONFIG_VFIO_PCI_ZDEV_KVM ) ||IS_ENABLED (CONFIG_IOMMUFD ) + defined(CONFIG_VFIO_PCI_ZDEV_KVM ) ||IS_ENABLED (CONFIG_IOMMUFD ) || \ + defined(CONFIG_SECRETMEM )atomic_long_t locked_vm;#endif #ifdef CONFIG_WATCH_QUEUE
mm/secretmem.c +107 -9
189 lines not on this page · raw message
tools/testing/selftests/mm/memfd_secret.c +1 -29
@@ -57,33 +57,6 @@ static void test_file_apis(int fd)pass ("file IO is blocked as expected\n" ); } -static void test_mlock_limit (int fd) -{ -size_t len; -char *mem; - - len = mlock_limit_cur; -if (len % page_size !=0 ) - len = (len/page_size) * page_size; - - mem =mmap (NULL , len, prot, mode, fd,0 ); -if (mem ==MAP_FAILED ) { -fail ("unable to mmap secret memory\n" ); -return ; - } -munmap (mem, len); - - len = mlock_limit_max *2 ; - mem =mmap (NULL , len, prot, mode, fd,0 ); -if (mem !=MAP_FAILED ) { -fail ("unexpected mlock limit violation\n" ); -munmap (mem, len); -return ; - } - -pass ("mlock limit is respected\n" ); -} -static void test_vmsplice (int fd,const char *desc) {ssize_t transferred;
@@ -297,7 +270,7 @@ static void prepare(void) strerror(errno)); } -#define NUM_TESTS 6 +#define NUM_TESTS 5int main (int argc,char *argv[]) {
@@ -319,7 +292,6 @@ int main(int argc, char *argv[])if (ftruncate (fd, page_size))ksft_exit_fail_msg ("ftruncate failed: %s\n" ,strerror (errno)); -test_mlock_limit (fd);test_file_apis (fd);/* * We have to run the first vmsplice test before any secretmem page was
Greg Kroah-Hartman
maintainerPATCH 98/556 futex: Prevent rcuwait use-after-free during requeue PI
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Kai <[email protected]>
commit a3b8d46fe401cba3a5c46dea610e6eb3dc15370e upstream.
On PREEMPT_RT, FUTEX_CMP_REQUEUE_PI can trigger a KASAN report (slab-out-of-bounds) in futex_requeue_pi_complete() invocation of rcuwait_wake_up().
The futex_q used by futex_wait_requeue_pi() is allocated on the waiter's stack. An early wakeup can race with a PI requeue as follows:
waiter requeue task
------ ------------futex_wait_requeue_pi()
futex_do_wait()
schedule()
futex_requeue
futex_proxy_trylock_atomic()
futex_requeue_pi_prepare()
Q_REQUEUE_PI_NONE -> Q_REQUEUE_PI_IN_PROGRESS
* timeout/ signal wakes waiter *
futex_requeue_pi_wakeup_sync()
Q_REQUEUE_PI_IN_PROGRESS -> Q_REQUEUE_PI_WAIT
requeue_pi_wake_futex
futex_requeue_pi_complete()
cmpxchg Q_REQUEUE_PI_WAIT -> Q_REQUEUE_PI_LOCKED
rcuwait_wait_event()
if (atomic_read(&q->requeue_state) != Q_REQUEUE_PI_WAIT)
break /* no schedule() */ /* q.pi_state->owner == current */
futex_private_hash_put()
/* return from syscall */
rcuwait_wake_up(&q->requeue_wait)
/* q is gone */futex_requeue_pi_complete() publishes Q_REQUEUE_PI_LOCKED before calling rcuwait_wake_up(). The waiter observes this state in rcuwait_wait_event() before invoking schedule() in rcuwait_wait_event(). Here, the waiter is free leave the syscall before requeue task can complete the wake.
To address this race skip rcuwait_wake_up() in the Q_REQUEUE_PI_LOCKED case.
This state is only published by requeue_pi_wake_futex(), which saves q->task before futex_requeue_pi_complete() and wakes the waiter via wake_up_state().
This wake is intended to wake the waiter from its futex_do_wait() sleep. If the waiter is still sleeping there, it can not get into the Q_REQUEUE_PI_WAIT state (and require this removed wake). Should the waiter be woken up from futex_do_wait() by other means (as in this example) and sleep in futex_requeue_pi_wakeup_sync() then the wake_up_state() from requeue_pi_wake_futex() will wake it, too. Should the waiter task terminate before wake_up_state() had a chance to wake the task then the task pointer does not become invalid because the futex_hash_bucket::lock is held and the task pointer is RCU protected.
[bigeasy: Updated comment and commit message]
--- kernel/futex/requeue.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/futex/requeue.c +10 -2
@@ -154,8 +154,16 @@ static inline void futex_requeue_pi_comp }while (!atomic_try_cmpxchg (&q->requeue_state, &old, new));#ifdef CONFIG_PREEMPT_RT -/* If the waiter interleaved with the requeue let it know */ -if (unlikely (old ==Q_REQUEUE_PI_WAIT )) +/* +* The waiter in futex_requeue_pi_wakeup_sync() can interleave with the +* wake below: It will assign Q_REQUEUE_PI_IN_PROGRESS and here it will +* be updated to Q_REQUEUE_PI_LOCKED (locked = 1). The rcuwait_wait_event() +* will already read Q_REQUEUE_PI_LOCKED and skip the schedule() invocation, +* leading to an access of futex_q::requeue_wait after the waiter returned. +* In this case only we skip the wake here and rely on following wake in +* requeue_pi_wake_futex() to perform the wake if needed. +*/ +if (unlikely (old ==Q_REQUEUE_PI_WAIT ) && new !=Q_REQUEUE_PI_LOCKED )rcuwait_wake_up (&q->requeue_wait);#endif }
Greg Kroah-Hartman
maintainerPATCH 99/556 futex: Provide rt_mutex_.*_schedule() equivalents for futex scheduling
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
commit 912edebe8501a36c6bedcef03bd238ab90a7e060 upstream.
There is rt_mutex_{pre|post}_schedule() around rt_mutex_wait_proxy_lock() to ensure that sched_submit_work()/ sched_update_worker() is invoked before we schedule out and block on rt_mutex while waiting for it become available.
The reason is that blocking on rt_mutex assigns a pi_waiter for the PI chain and sched_submit_work() will also assign a pi_waiter if it blocks on lock but a this point we already have a waiter assigned. We can't skip sched_submit_work() entirely because I/O relies on the fact that I/O queue is flushed while it blocks on a sleeping lock. Therefore sched_submit_work() is moved before we block on the lock.
Sleeping lock in this context means mutex or rw_semaphore not spinlock_t on PREEMPT_RT. Because the mutex abstraction on PREEMPT_RT uses the same abstraction as the futex proxy lock, the futex code ended up using rt_mutex_{pre|post}_schedule(), too.
Using it is/ was just to keep the task_struct::sched_rt_mutex assertion happy. Futex proxy lock is used only in the syscall context of a task. At this point it never got any I/O that needs to be flushed and it can't be a workqueue that needs to notify that it will be scheduled out. Therefore sched_submit_work() does nothing here.
By mistake futex_wait_requeue_pi() -> rt_mutex_wait_proxy_lock() did not get the rt_mutex_{pre|post}_schedule() annotation. This was not noticed because in this callchain the lock is (usually) not contended and so rt_mutex_slowlock_block() does not schedule, triggering the assert.
Adding rt_mutex_pre_schedule() here looks wrong (as noted by PeterZ) because at this point there is a pi_waiter recorded and invoking sched_submit_work() with a possible lock contention would be wrong.
Add rt_mutex_futex_{pre|post}_schedule() which toggles the sched_rt_mutex assert and does not involve sched_submit_work(). Add asserts here to ensure that sched_submit_work() would do nothing. Use it only in futex proxy lock case which is rt_mutex_wait_proxy_lock(). Remove it from futex_lock_pi().
--- include/linux/sched/rt.h | 2 ++ kernel/futex/pi.c | 16 +++------------- kernel/locking/rtmutex_api.c | 2 ++ kernel/sched/core.c | 16 ++++++++++++++++ 4 files changed, 23 insertions(+), 13 deletions(-)
include/linux/sched/rt.h +2 -0
@@ -52,8 +52,10 @@ static inline bool rt_or_dl_task_policy(#ifdef CONFIG_RT_MUTEXES extern void rt_mutex_pre_schedule (void ); +extern void rt_mutex_futex_pre_schedule (void );extern void rt_mutex_schedule (void );extern void rt_mutex_post_schedule (void ); +extern void rt_mutex_futex_post_schedule (void );/* * Must hold either p->pi_lock or task_rq(p)->lock.
kernel/futex/pi.c +3 -13
@@ -1070,17 +1070,11 @@ retry_private:* Caution; releasing @hb in-scope. The hb->lock is still locked * while the reference is dropped. The reference can not be dropped * after the unlock because if a user initiated resize is in progress -* then we might need to wake him. This can not be done after the -* rt_mutex_pre_schedule() invocation. The hb will remain valid because -* the thread, performing resize, will block on hb->lock during -* the requeue. +* then we might need to wake him. The hb will remain valid +* because the thread, performing resize, will block on +* hb->lock during the requeue. */ futex_private_hash_put (no_free_ptr (hbr.fph)); -/* -* Must be done before we enqueue the waiter, here is unfortunately -* under the hb lock, but that *should* work because it does nothing. -*/ -rt_mutex_pre_schedule ();rt_mutex_init_waiter (&rt_waiter);
@@ -1146,10 +1140,6 @@ cleanup:* the */ futex_q_lockptr_lock (&q); -/* -* Waiter is unqueued. -*/ -rt_mutex_post_schedule (); no_block:/* * Fixup the pi_state owner and possibly acquire the lock if we
kernel/locking/rtmutex_api.c +2 -0
@@ -423,6 +423,7 @@ int __sched rt_mutex_wait_proxy_lock(str {int ret; +rt_mutex_futex_pre_schedule ();raw_spin_lock_irq (&lock->wait_lock);/* sleep on the mutex */ set_current_state (TASK_INTERRUPTIBLE );
@@ -433,6 +434,7 @@ int __sched rt_mutex_wait_proxy_lock(str*/ fixup_rt_mutex_waiters (lock, true);raw_spin_unlock_irq (&lock->wait_lock); +rt_mutex_futex_post_schedule ();return ret; }
kernel/sched/core.c +16 -0
@@ -7633,6 +7633,17 @@ void rt_mutex_pre_schedule(void)sched_submit_work (current); } +/* +* Used within the futex syscall context, skips sched_submit_work() because none +* its work will be done. Asserts ensure that it is indeed the case. +*/ +void rt_mutex_futex_pre_schedule (void ) +{ +lockdep_assert (!(current->flags & (PF_WQ_WORKER |PF_IO_WORKER ))); +lockdep_assert (!current->plug); +lockdep_assert (!fetch_and_set (current->sched_rt_mutex,1 )); +} +void rt_mutex_schedule (void ) {lockdep_assert (current->sched_rt_mutex);
@@ -7645,6 +7656,11 @@ void rt_mutex_post_schedule(void)lockdep_assert (fetch_and_set (current->sched_rt_mutex,0 )); } +void rt_mutex_futex_post_schedule (void ) +{ +lockdep_assert (fetch_and_set (current->sched_rt_mutex,0 )); +} +/* * rt_mutex_setprio - set the current priority of a task * @p: task to boost
Greg Kroah-Hartman
maintainerPATCH 100/556 ftrace: Take trace_array reference before accessing its ftrace_ops
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit 9100191e5acb2e5ea2313f436667bb5fce129f47 upstream.
The trace instance files set_ftrace_filter and set_ftrace_notrace was updated to work with specific trace instances (trace_arrays). The issue is that when these files are opened, there is a small race window where it will use the ftrace_ops from the inode->private pointer to get a reference to the trace_array and then take its reference. The problem is that the ftrace_ops itself could be freed. If the rmdir on the instance happens at the same time the set_ftrace_filter file is opened, the rmdir could have also freed the ftrace_ops and referencing it will cause a use-after-free bug and crash the kernel.
Instead, pass in the trace_array as the file private data (NULL for the top level instance), and then pass both the trace_array and the ftrace_ops to the ftrace_regex_open() function. If the trace_array is NULL, then it just uses the ftrace_ops without the need to take its reference (like normal). If the ftrace_ops is NULL, that is only the case for the top level instance and the global_ops can be used.
This allows the trace_array to have its reference incremented before touching the ftrace_ops that could also be freed when the instance is.
--- include/linux/ftrace.h | 5 ++- kernel/trace/ftrace.c | 57 ++++++++++++++++++++++++++--------------- kernel/trace/trace.h | 5 ++- kernel/trace/trace_functions.c | 2 - kernel/trace/trace_stack.c | 2 - 5 files changed, 45 insertions(+), 26 deletions(-)
include/linux/ftrace.h +3 -2
@@ -866,8 +866,9 @@ unsigned long ftrace_get_addr_new(structunsigned long ftrace_get_addr_curr (struct dyn_ftrace *rec);extern ftrace_func_t ftrace_trace_function; +struct trace_array ; -int ftrace_regex_open (struct ftrace_ops *ops,int flag, +int ftrace_regex_open (struct trace_array *tr,struct ftrace_ops *ops,int flag,struct inode *inode,struct file *file);ssize_t ftrace_filter_write (struct file *file,const char __user *ubuf,size_t cnt,loff_t *ppos);
@@ -1077,7 +1078,7 @@ static inline unsigned long ftrace_locat* have them defined when ftrace is not enabled, but these * functions may still be called. Use a macro instead of inline. */ -#define ftrace_regex_open (ops, flag, inod, file) ({ -ENODEV; }) +#define ftrace_regex_open (tr, ops, flag, inode, file) ({ -ENODEV; })#define ftrace_set_early_filter (ops, buf, enable) do { } while (0)#define ftrace_set_filter_ip (ops, ip, remove, reset) ({ -ENODEV; })#define ftrace_set_filter_ips (ops, ips, cnt, remove, reset) ({ -ENODEV; })
kernel/trace/ftrace.c +37 -20
120 lines not on this page · raw message
kernel/trace/trace.h +3 -2
@@ -1340,7 +1340,7 @@ extern void clear_ftrace_function_probesint register_ftrace_command (struct ftrace_func_command *cmd);int unregister_ftrace_command (struct ftrace_func_command *cmd); -void ftrace_create_filter_files (struct ftrace_ops *ops, +void ftrace_create_filter_files (struct trace_array *tr,struct dentry *parent);void ftrace_destroy_filter_files (struct ftrace_ops *ops);
@@ -1363,11 +1363,12 @@ static inline void clear_ftrace_function { } +static inline void ftrace_create_filter_files (struct trace_array *tr, +struct dentry *parent) { }/* * The ops parameter passed in is usually undefined. * This must be a macro. */ -#define ftrace_create_filter_files (ops, parent) do { } while (0)#define ftrace_destroy_filter_files (ops) do { } while (0)#endif /* CONFIG_FUNCTION_TRACER && CONFIG_DYNAMIC_FTRACE */
kernel/trace/trace_functions.c +1 -1
@@ -101,7 +101,7 @@ int ftrace_create_function_files(structreturn ret; } -ftrace_create_filter_files (tr->ops, parent); +ftrace_create_filter_files (tr, parent);return 0 ; }
kernel/trace/trace_stack.c +1 -1
@@ -499,7 +499,7 @@ stack_trace_filter_open(struct inode *instruct ftrace_ops *ops = inode->i_private;/* Checks for tracefs lockdown */ -return ftrace_regex_open (ops,FTRACE_ITER_FILTER , +return ftrace_regex_open (NULL , ops,FTRACE_ITER_FILTER , inode, file); }
Greg Kroah-Hartman
maintainerPATCH 101/556 ftrace: Synchronize the initialization of ftrace_ops
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit 4617721c502b2ddaa4e324e86da4997edf738fa5 upstream.
There's some internal state that ftrace_ops needs to have set, but since it can be declared outside of the ftrace.c code, it calls ftrace_ops_init() on the ops in every global function. The issue is that if two tasks call it on the same ops at the same time it is possible to have the initialization of one corrupt the initialization of the other call.
Create a ops_mutex to use to synchronize every initialization of the ftrace_ops. The mutex is taken within checking the ftrace_ops flag that states it was initializied but the flag is checked again after the mutex has been taken. Checking first outside the mutex allows it to shortcut having to take the mutex. But then the check needs to be done again after the mute is taken in case of races.
Close: https://lore.kernel.org/all/[email protected]/
--- kernel/trace/ftrace.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
kernel/trace/ftrace.c +11 -2
@@ -75,6 +75,8 @@ .func_hash = &opsname.local_hash, \ .local_hash.regex_lock = __MUTEX_INITIALIZER(opsname.local_hash.regex_lock), \ .subop_list = LIST_HEAD_INIT(opsname.subop_list), +/* Used only to synchronize the initialization of ftrace_ops */ +static DEFINE_MUTEX(ops_mutex);#else #define INIT_OPS_HASH (opsname)#endif
@@ -159,11 +161,18 @@ const struct ftrace_ops ftrace_nop_ops =static inline void ftrace_ops_init (struct ftrace_ops *ops) {#ifdef CONFIG_DYNAMIC_FTRACE -if (!(ops->flags &FTRACE_OPS_FL_INITIALIZED )) { +unsigned long flags =smp_load_acquire (&ops->flags); + +if (!(flags &FTRACE_OPS_FL_INITIALIZED )) { +guard (mutex)(&ops_mutex); +/* Could have been initialized before lock taken */ +if (unlikely (ops->flags &FTRACE_OPS_FL_INITIALIZED )) +return ;mutex_init (&ops->local_hash.regex_lock);INIT_LIST_HEAD (&ops->subop_list); ops->func_hash = &ops->local_hash; - ops->flags |=FTRACE_OPS_FL_INITIALIZED ; + flags = ops->flags |FTRACE_OPS_FL_INITIALIZED ; +smp_store_release (&ops->flags, flags); }#endif }
Greg Kroah-Hartman
maintainerPATCH 102/556 HID: bpf: serialize device reference release in struct_ops destroy path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shen Yongchao <[email protected]>
commit 9cdc7e6dc7a99ad7311ad5e7c145f2b9ce4e24b0 upstream.
__hid_bpf_ops_destroy_device() and hid_bpf_unreg() can race on the same registration reference, double-putting struct hid_device and freeing it while hid_destroy_device() still uses it. Serialize the remove/NULL decision under hdev->bpf.prog_list_lock so exactly one path releases each registration reference: unreg re-checks ops->hdev under the lock and returns without putting when the destroy path already cleared it; all put_device() calls happen after the lock is dropped, which is safe because a concurrent unreg then observes ops->hdev == NULL under the lock.
Background: each successful attach (hid_bpf_ops_reg) acquires one device reference (hid_get_device()). Two paths can release it:
- device destruction: hid_destroy_device() -> hid_bpf_destroy_device() -> __hid_bpf_ops_destroy_device(), which walks hdev->bpf.prog_list under rcu_read_lock() and drops one reference per attached program;
- BPF link release: bpf map delete (no BPF_F_LINK) synchronously calls st_ops->unreg() -> hid_bpf_unreg(), which drops the reference for its own registration.
The coordination handshake (e->hdev = NULL on the destroy side vs "if (!hdev) return" on the unreg side) is a TOCTOU check: the two paths run under different lock domains (rcu_read_lock vs prog_list_lock), so a concurrent unreg can read ops->hdev as non-NULL, block on prog_list_lock, and then proceed while the destroy traversal executes - both paths then drop the same reference. The refcount reaches zero legitimately (each decrement is individually valid), so no refcount_t saturation fires: the device is simply freed while the transport is still inside hid_destroy_device(), and subsequent teardown touches freed memory.
The fix serializes the remove/NULL decision under prog_list_lock on both sides and moves the destroy-side puts outside the lock. With the lock held, plain reads/writes of ops->hdev are sufficient; no READ_ONCE/WRITE_ONCE are added, keeping the patch minimal.
Unlocked-read safety: the unlocked read of ops->hdev at the top of hid_bpf_unreg() cannot touch a freed device, because the unreg path itself still holds this registration's reference (released only by its own hid_put_device() after the lock is dropped), and a destroy traversal that already cleared ops->hdev makes the lock-internal re-check return early without any put. At most one of the two paths releases each registration reference.
--- drivers/hid/bpf/hid_bpf_struct_ops.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/hid/bpf/hid_bpf_struct_ops.c +13 -4
@@ -250,6 +250,11 @@ static void hid_bpf_unreg(void *kdata, smutex_lock (&hdev->bpf.prog_list_lock); +if (!ops->hdev) { +mutex_unlock (&hdev->bpf.prog_list_lock); +return ; + } +list_del_rcu (&ops->list);synchronize_srcu (&hdev->bpf.srcu); ops->hdev =NULL ;
@@ -310,13 +315,17 @@ static struct bpf_struct_ops bpf_hid_bpfvoid __hid_bpf_ops_destroy_device (struct hid_device *hdev) {struct hid_bpf_ops *e; +int count =0 ; -rcu_read_lock (); -list_for_each_entry_rcu (e, &hdev->bpf.prog_list, list) { -hid_put_device (hdev); +mutex_lock (&hdev->bpf.prog_list_lock); +list_for_each_entry (e, &hdev->bpf.prog_list, list) { e->hdev =NULL ; + count++; } -rcu_read_unlock (); +mutex_unlock (&hdev->bpf.prog_list_lock); + +while (count--) +hid_put_device (hdev); }static int __init hid_bpf_struct_ops_init (void )
Greg Kroah-Hartman
maintainerPATCH 103/556 HID: rmi: fix OOB access with undersized RMI reports
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Jie Law <[email protected]>
commit 4956993bb3befdf791d71a4952d8d13bcfd44c7b upstream.
The hid-rmi driver sizes its writeReport/readReport buffer purely from the report descriptor supplied by the device, with no minimum bound:
data->input_report_size = hid_report_len(input_report); data->output_report_size = hid_report_len(output_report); alloc_size = data->output_report_size + data->input_report_size; data->writeReport = devm_kzalloc(&hdev->dev, alloc_size, GFP_KERNEL); data->readReport = data->writeReport + data->output_report_size;
but then reads and writes fixed offsets into it. A device declaring a 1-byte output and a 1-byte input report makes hid_report_len() return 2 for each, so alloc_size is 4, while rmi_set_page() -- reached unconditionally at probe time through rmi_input_configured() -- stores writeReport[4] and rmi_hid_read_block() stores writeReport[0..5]. Since readReport lives at writeReport + output_report_size, those stores also corrupt the window the next reply is parsed out of.
The read path is worse: the copy length comes from readReport[1], which the device fills in and can be up to 255, and the copy starts at &readReport[2] with no regard for input_report_size, so it runs past the end of the allocation into adjacent slab objects. This does not even need a lying device -- rmi_f01_probe() issues a fixed 21-byte register read, so any device declaring an input report smaller than 23 bytes reads out of bounds even when it answers truthfully. Those bytes become the register values the RMI core acts on: rmi_f01_probe() prints them to the kernel log as the product id and exports them through the mode 0444 sysfs attribute of the same name, and rmi_driver_set_irq_bits() sends them back to the device as the interrupt mask, so an undersized report descriptor leaks heap contents both to unprivileged userspace and to the device itself.
The write path has no bound either: rmi_hid_write_block() copies an unbounded len to &writeReport[4], and the largest caller a device can drive at probe time is rmi_driver_set_irq_bits(), whose length is derived from the interrupt source counts the device declares in its Page Description Table.
Finally, the read loop cannot terminate on a zero-length reply: such a reply copies nothing and advances neither bytes_read nor bytes_needed, and because a reply did arrive the one second wait_event_timeout() does not fire either, so a device answering 0 forever keeps the loop running inside the probe worker with page_mutex held. khungtaskd does not notice, because every reply wakes the task.
Reject reports too small for what the driver builds -- 6 output bytes for the write reports and 3 input bytes for the read handshake -- at probe time, clamp the write and the read copy to the report sizes the device declared, and treat a zero-length reply as an error. A device refused this way is started as an ordinary HID device, like one that does not carry the RMI report ids at all.
RMI_DEVICE must not be left set in device_flags on that path, because rmi_input_configured() would then run the RMI setup and reach rmi_set_page(), which writes the writeReport buffer the refusal just skipped allocating. The bit can arrive set: rmi_probe() copies id->driver_data into device_flags before the report checks, and a bind through the new_id sysfs attribute can supply driver_data with RMI_DEVICE (BIT(0)) set. Strip the bit where driver_data is copied, so RMI_DEVICE keeps meaning exactly "this probe validated the reports"; the three jumps to start that predate this patch are covered as well.
The error path also clears RMI_READ_DATA_PENDING on its way out, because that flag is what the wait at the top of the loop tests: leaving it set would make every later wait_event_timeout() return immediately on the stale reply and kill the read path for the rest of the device's life.
Clamping does not regress working hardware: the read loop already handles a reply carrying fewer bytes than requested, and a write longer than the output report was overrunning the buffer already.
Verified on v6.12.69 and on v6.12.105 built with CONFIG_KASAN=y and booted kasan_multi_shot, whose hid-rmi.c is identical to mainline here. An emulated RMI4 device driven over /dev/uhid, and the same device again over dummy_hcd plus raw-gadget, give identical results:
BUG: KASAN: slab-out-of-bounds in rmi_hid_read_block+0x409/0x750 [hid_rmi] Read of size 21 at addr ffff88800bf33bba by task kworker/0:3/285 __asan_memcpy+0x23/0x60 rmi_hid_read_block+0x409/0x750 [hid_rmi] rmi_f01_probe+0x5dd/0x1dc0 [rmi_core] BUG: KASAN: slab-out-of-bounds in rmi_hid_write_block+0x1a9/0x350 [hid_rmi] Write of size 35 at addr ffff88810a2b24ac by task kworker/1:10/666 __asan_memcpy+0x3c/0x60 rmi_hid_write_block+0x1a9/0x350 [hid_rmi] rmi_driver_set_irq_bits+0x1f6/0x4d0 [rmi_core] rmi_driver_probe+0x636/0xbf0 [rmi_core] rmi_input_configured+0x184/0x2e0 [hid_rmi] rmi_probe+0x952/0xcf0 [hid_rmi]
and, for the zero-length reply, a probe worker left in D state in rmi_hid_read_block() after 225 replies at 200 ms intervals.
After this change the undersized descriptor is refused at probe with "rmi reports too small (out=2 in=2)", the oversized read and write are both rejected, the zero-length reply fails the read with -EIO while later reads on the same device keep working, and a device declaring reports large enough for a 21-byte register read still probes normally and reports its real product id. A device bound through new_id with RMI_DEVICE in its driver_data no longer reaches rmi_set_page() with an unallocated writeReport either.
--- drivers/hid/hid-rmi.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)
drivers/hid/hid-rmi.c +43 -3
@@ -235,7 +235,23 @@ static int rmi_hid_read_block(struct rmibreak ; } - read_input_count = data->readReport[1 ]; + read_input_count =min_t (int, data->readReport[1 ], + data->input_report_size -2 ); +if (!read_input_count) { +/* +* A zero length reply advances neither +* bytes_read nor bytes_needed, and because a +* reply did arrive the wait above does not +* time out either, so a device answering 0 +* forever would spin here indefinitely with +* page_mutex held. +*/ +hid_warn (hdev,"%s: zero-length read reply\n" , + __func__); +clear_bit (RMI_READ_DATA_PENDING , &data->flags); + ret = -EIO ; +break ; + }memcpy (buf + bytes_read, &data->readReport[2 ],min (read_input_count, bytes_needed));
@@ -271,6 +287,11 @@ static int rmi_hid_write_block(struct rm goto exit; } +if (len +4 > data->output_report_size) { + ret = -EINVAL ; + goto exit; + } + data->writeReport[0 ] =RMI_WRITE_REPORT_ID ; data->writeReport[1 ] = len; data->writeReport[2 ] = addr &0xFF ;
@@ -666,8 +687,16 @@ static int rmi_probe(struct hid_device *return ret; } -if (id->driver_data) - data->device_flags = id->driver_data; +/* +* RMI_DEVICE can only mean "this probe validated the RMI reports and +* allocated writeReport": every bail-out to start below skips that +* allocation, and device_flags left carrying RMI_DEVICE from +* driver_data would send rmi_input_configured() into rmi_set_page() +* with writeReport still NULL. A bind through the new_id sysfs +* attribute can supply driver_data with the bit set, so do not let +* driver_data grant it. +*/ + data->device_flags = id->driver_data & ~RMI_DEVICE ;/* * Check for the RMI specific report ids. If they are misisng
@@ -696,6 +725,17 @@ static int rmi_probe(struct hid_device * data->output_report_size =hid_report_len (output_report); +/* +* The write reports built by this driver occupy 6 bytes and the read +* handshake looks at the first 3 bytes of an input report, so refuse +* to drive a device whose reports cannot hold them. +*/ +if (data->output_report_size <6 || data->input_report_size <3 ) { +hid_err (hdev,"rmi reports too small (out=%u in=%u)\n" , + data->output_report_size, data->input_report_size); + goto start; + } + data->device_flags |=RMI_DEVICE ; alloc_size = data->output_report_size + data->input_report_size;
Greg Kroah-Hartman
maintainerPATCH 104/556 HID: wacom: validate report length in wacom_intuos_pro2_bt_irq
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
commit a8e04f3f894ccb52cfcd7e60125a9f35da4a616d upstream.
wacom_intuos_pro2_bt_irq() receives the wire report length in len but never consults it before parsing. After the report-id gate it unconditionally calls wacom_intuos_pro2_bt_pen() and then, selected by features.type, a fixed chain of sub-parsers, none of which receive len:
wacom_intuos_pro2_bt_pen(wacom);
if (type == INTUOSP2_BT || type == INTUOSP2S_BT) {
wacom_intuos_pro2_bt_touch(wacom);
wacom_intuos_pro2_bt_pad(wacom);
wacom_intuos_pro2_bt_battery(wacom);
} else {
wacom_intuos_gen3_bt_pad(wacom);
wacom_intuos_gen3_bt_battery(wacom);
}Each sub-parser dereferences wacom->data at fixed offsets. The furthest byte touched on each branch is:
INTUOSP2_BT / INTUOSP2S_BT: wacom_intuos_pro2_bt_pad() reads data[285]
(the touchring byte), so the report must be at least 286 bytes;
INTUOSHT3_BT ("gen3"): wacom_intuos_gen3_bt_battery() reads data[45],
so the report must be at least 46 bytes.
features.type is selected from the VID/PID id_table entry and wacom_setup_device_quirks() force-registers the pen/pad/touch inputs for that type independent of the report descriptor, so a malicious or malfunctioning paired/spoofed Bluetooth peripheral can advertise that VID/PID and send an undersized report that still satisfies the data[0] == 0x80/0x81 gate. The driver then reads past the received report and forwards the bytes to userspace via evdev (MSC_SERIAL / ABS_MISC / ABS_WHEEL on the pen and pad input nodes), an out-of-bounds read with a concrete userspace read-back channel, and a true out-of-bounds read on transports whose backing buffer is sized to the (small) report descriptor rather than a fixed-size staging buffer.
This is the same class of bug commit 2f1763f62909 ("HID: wacom: fix out-of-bounds read in wacom_intuos_bt_irq") already hardened in the sibling wacom_intuos_bt_irq(), which guards each report id against its minimum length before parsing.
Guard wacom_intuos_pro2_bt_irq() the same way: before parsing, reject reports shorter than the furthest offset the selected branch actually dereferences, warn, and bail out. Because the whole pen/touch/pad/ battery chain runs unconditionally per branch, a single up-front check against the maximum offset (286 bytes for INTUOSP2_BT/INTUOSP2S_BT, 46 bytes for the gen3 branch) bounds every sub-parser. Returning 0 on a short report also skips those calls for the same malformed report, which is the safe, conservative behavior.
--- drivers/hid/wacom_wac.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/hid/wacom_wac.c +13 -0
@@ -1548,6 +1548,19 @@ static int wacom_intuos_pro2_bt_irq(strureturn 0 ; } +if (wacom->features.type ==INTUOSP2_BT || + wacom->features.type ==INTUOSP2S_BT ) { +if (len <286 ) { +dev_warn (wacom->pen_input->dev.parent, +"Pro2 BT report too short: %zu bytes\n" , len); +return 0 ; + } + }else if (len <46 ) { +dev_warn (wacom->pen_input->dev.parent, +"Pro2 BT report too short: %zu bytes\n" , len); +return 0 ; + } +wacom_intuos_pro2_bt_pen (wacom);if (wacom->features.type ==INTUOSP2_BT || wacom->features.type ==INTUOSP2S_BT ) {
Greg Kroah-Hartman
maintainerPATCH 105/556 dm: fix race when loading and unloading a table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 5380c7f6335cc6d77eb77d065105e81155c4d9d3 upstream.
If the userspace calls two concurrent table load ioctls and one of them succeeds and the other fails, there is a race condition because dm_setup_md_queue walks &md->table_devices without any lock. If the walk races with dm_table_destroy -> free_devices -> dm_put_table_device, there is access to invalid memory.
Fix this race by extending the lock over the list walk.
--- drivers/md/dm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/md/dm.c +8 -4
@@ -2630,9 +2630,10 @@ int dm_setup_md_queue(struct mapped_devi*/ mutex_lock (&md->table_devices_lock); r =add_disk (md->disk); -mutex_unlock (&md->table_devices_lock); -if (r) +if (r) { +mutex_unlock (&md->table_devices_lock);return r; + }/* * Register the holder relationship for devices added before the disk
@@ -2643,18 +2644,21 @@ int dm_setup_md_queue(struct mapped_deviif (r) goto out_undo_holders; } +mutex_unlock (&md->table_devices_lock); r =dm_sysfs_init (md);if (r) - goto out_undo_holders; + goto lock_out_undo_holders; md->type = type; +return 0 ; +lock_out_undo_holders: +mutex_lock (&md->table_devices_lock); out_undo_holders:list_for_each_entry_continue_reverse (td, &md->table_devices, list)bd_unlink_disk_holder (td->dm_dev.bdev, md->disk); -mutex_lock (&md->table_devices_lock);del_gendisk (md->disk);mutex_unlock (&md->table_devices_lock);return r;
Greg Kroah-Hartman
maintainerPATCH 106/556 dm: fix resume-vs-remove race
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 44b43ec132f1cf3275ecc182d0c82f50c3c4c3d5 upstream.
If the user issues the resume ioctl and the remove ioctl at the same time, it may be possible that the device is resumed after it is suspended in __dm_destroy. The result is that the table is destroyed without calling the postsuspend method.
Dm targets expect that they may be removed only after the postsuspend method method was called. If we break this expectation, it can cause misbehavior in various targets. For example - in the dm-integrity target, the reboot notifier is not unregistered, leading to use-after-free.
Fix this bug by refusing to resume if the device is being destroyed.
--- drivers/md/dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm.c +1 -1
@@ -3144,7 +3144,7 @@ retry: r = -EINVAL ;mutex_lock_nested (&md->suspend_lock,SINGLE_DEPTH_NESTING ); -if (!dm_suspended_md (md)) +if (!dm_suspended_md (md) ||test_bit (DMF_FREEING , &md->flags)) goto out;if (dm_suspended_internally_md (md)) {
Greg Kroah-Hartman
maintainerPATCH 107/556 dma-buf: dma-heap: dont publish fd before copy_to_user() succeeds
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baineng Shou <[email protected]>
commit 30d0aff2c65a277135cfd8ea28fa1ee75e0ea4e0 upstream.
DMA_HEAP_IOCTL_ALLOC allocates a dma-buf and installs an fd into the caller's fd table via dma_buf_fd() -> fd_install() before dma_heap_ioctl() copies the result back to userspace. If the trailing copy_to_user() fails, userspace never learns the fd number, but the fd (and the underlying dma-buf reference) are already visible to other threads in the same process and are leaked for the lifetime of the process.
The obvious "close it on the failure path" fix is unsafe: once fd_install() has run, another thread can already dup() the fd, send it via SCM_RIGHTS, or close() it and let its number be reused, so a subsequent close_fd() from the ioctl path can operate on an unrelated file. This was pointed out by Christian König on v1 [1].
Restructure the allocation path so that fd_install() is the last, unfailable step of a successful ioctl:
1. heap->ops->allocate() creates the dma_buf.
2. get_unused_fd_flags() reserves an fd number in the caller's
fd table without publishing it, so no other thread can observe it.
3. copy_to_user() delivers the fd number to userspace;
on failure the fd is returned with put_unused_fd() and the dma_buf reference is dropped with dma_buf_put(), leaving no user- visible state behind.
4. dma_buf_fd_install() publishes the fd and emits the
trace_dma_buf_fd tracepoint -- from here on the ioctl cannot fail.
A new dma_buf_fd_install() helper is introduced in dma-buf.c to wrap fd_install() together with the DMA_BUF_TRACE() call, preserving the export tracing that dma_buf_fd() provides. dma_heap_ioctl_allocate() is refactored to return the struct dma_buf * directly (returning ERR_PTR on failure) so the caller holds the dmabuf reference across steps 3 and 4.
The failure at step 3 is easily reachable from userspace: pass a struct dma_heap_allocation_data that lives in a page whose protection is flipped to PROT_READ between copy_from_user() and copy_to_user() (e.g. via mprotect()). Before this change each such ioctl leaks one dmabuf fd; after it, the fd table is unchanged on failure and only /dev/dma_heap/<name> remains open.
No UAPI or heap-driver interface change.
[1] https://lore.kernel.org/dri-devel/[email protected]/
--- drivers/dma-buf/dma-buf.c | 20 +++++++++++ drivers/dma-buf/dma-heap.c | 80 ++++++++++++++++++++++----------------------- include/linux/dma-buf.h | 1 3 files changed, 61 insertions(+), 40 deletions(-)
drivers/dma-buf/dma-buf.c +20 -0
@@ -804,6 +804,26 @@ int dma_buf_fd(struct dma_buf *dmabuf, iEXPORT_SYMBOL_NS_GPL (dma_buf_fd,"DMA_BUF" );/** +* dma_buf_fd_install - install a reserved fd for a dma-buf +* @dmabuf: [in] pointer to dma_buf +* @fd: [in] fd reserved with get_unused_fd_flags() +* +* Publishes a previously reserved fd into the caller's fd table. +* Must only be called after all fallible work (e.g. copy_to_user) +* has succeeded, as it cannot be undone safely once called. +* +* The caller is responsible for having emitted the trace event +* (via dma_buf_fd() or get_unused_fd_flags() + this function) +* before calling this. +*/ +void dma_buf_fd_install (struct dma_buf *dmabuf,int fd) +{ +DMA_BUF_TRACE (trace_dma_buf_fd, dmabuf, fd); +fd_install (fd, dmabuf->file); +} +EXPORT_SYMBOL_NS_GPL (dma_buf_fd_install,"DMA_BUF" ); + +/** * dma_buf_get - returns the struct dma_buf related to an fd * @fd: [in] fd associated with the struct dma_buf to be returned *
drivers/dma-buf/dma-heap.c +40 -40
124 lines not on this page · raw message
include/linux/dma-buf.h +1 -0
@@ -567,6 +567,7 @@ void dma_buf_unpin(struct dma_buf_attachstruct dma_buf *dma_buf_export (const struct dma_buf_export_info *exp_info);int dma_buf_fd (struct dma_buf *dmabuf,int flags); +void dma_buf_fd_install (struct dma_buf *dmabuf,int fd);struct dma_buf *dma_buf_get (int fd);void dma_buf_put (struct dma_buf *dmabuf);
Greg Kroah-Hartman
maintainerPATCH 108/556 dma-direct: return struct page from dma_direct_alloc_from_pool()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aneesh Kumar K.V (Arm) <[email protected]>
commit 94a04ad732c9f8b9554270fc4038a06737de5c22 upstream.
Commit 5b138c534fda ("dma-direct: factor out a dma_direct_alloc_from_pool helper") changed dma_direct_alloc_from_pool() to return the CPU address from dma_alloc_from_pool(). That fits dma_direct_alloc(), but dma_direct_alloc_pages() also uses the helper and expects a struct page *.
Fix this by making dma_direct_alloc_from_pool() return the struct page * again, and pass the CPU address back through an out-parameter for the dma_direct_alloc() caller.
--- kernel/dma/direct.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
kernel/dma/direct.c +10 -8
@@ -164,22 +164,21 @@ static bool dma_direct_use_pool(struct dreturn !gfpflags_allow_blocking (gfp) && !is_swiotlb_for_alloc (dev); } -static void *dma_direct_alloc_from_pool (struct device *dev,size_t size, -dma_addr_t *dma_handle,gfp_t gfp) +static struct page *dma_direct_alloc_from_pool (struct device *dev,size_t size, +dma_addr_t *dma_handle,void **cpu_addr,gfp_t gfp) {struct page *page;u64 phys_limit; -void *ret;if (WARN_ON_ONCE (!IS_ENABLED (CONFIG_DMA_COHERENT_POOL )))return NULL ; gfp |=dma_direct_optimal_gfp_mask (dev, &phys_limit); - page =dma_alloc_from_pool (dev, size, &ret, gfp, dma_coherent_ok); + page =dma_alloc_from_pool (dev, size, cpu_addr, gfp, dma_coherent_ok);if (!page)return NULL ; *dma_handle =phys_to_dma_direct (dev,page_to_phys (page)); -return ret; +return page; } static void *dma_direct_alloc_no_mapping(struct device *dev, size_t size,
@@ -247,8 +246,11 @@ void *dma_direct_alloc(struct device *de* the atomic pools instead if we aren't allowed block. */ if ((remap ||force_dma_unencrypted (dev)) && -dma_direct_use_pool (dev, gfp)) -return dma_direct_alloc_from_pool (dev, size, dma_handle, gfp); +dma_direct_use_pool (dev, gfp)) { + page =dma_direct_alloc_from_pool (dev, size, dma_handle, + &ret, gfp); +return page ? ret :NULL ; + }/* we always manually zero the memory once we are done */ page =__dma_direct_alloc_pages (dev, size, gfp & ~__GFP_ZERO, true);
@@ -357,7 +359,7 @@ struct page *dma_direct_alloc_pages(struvoid *ret;if (force_dma_unencrypted (dev) &&dma_direct_use_pool (dev, gfp)) -return dma_direct_alloc_from_pool (dev, size, dma_handle, gfp); +return dma_direct_alloc_from_pool (dev, size, dma_handle, &ret, gfp); page =__dma_direct_alloc_pages (dev, size, gfp, false);if (!page)
Greg Kroah-Hartman
maintainerPATCH 109/556 dmaengine: fsl-edma: tracing: no ptr dereference during log output
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Kaiser <[email protected]>
commit 2ea04dca8e627f722caa7a2037cfbae0257f3501 upstream.
The fsl edma events store a pointer to a struct fsl_edma_engine in the ringbuffer and dereference it when a log entry is printed. At this time, the pointer may no longer be valid.
Event injection can be used to trigger a crash:
$ cd /sys/kernel/tracing $ echo 'value = 0' > events/fsl_edma/edma_writeb/inject $ cat trace
The log output needs only edma->membase. Add a membase field at the end of the event and use the new field for log output. Keep the existing fields for backward compatibility.
--- drivers/dma/fsl-edma-trace.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/dma/fsl-edma-trace.h +3 -1
@@ -19,14 +19,16 @@ DECLARE_EVENT_CLASS(edma_log_io, __field(struct fsl_edma_engine *, edma) __field(void __iomem *, addr) __field(u32, value) + __field(void __iomem *, membase) ),TP_fast_assign ( __entry->edma = edma; __entry->addr = addr; __entry->value = value; + __entry->membase = edma->membase; ),TP_printk ("offset %08x: value %08x" , - (u32)(__entry->addr - __entry->edma->membase), __entry->value) + (u32)(__entry->addr - __entry->membase), __entry->value) ); DEFINE_EVENT(edma_log_io, edma_readl,
Greg Kroah-Hartman
maintainerPATCH 110/556 dmaengine: dw-edma: Fix HDMA channel status register access
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit ef1b080e03acc83d5bde841da67036985acd50dc upstream.
GET_CH_32() takes the direction before the channel ID, but dw_hdma_v0_core_ch_status() passed them in the opposite order. This can make the status callback read another HDMA channel status register.
Use the same argument order as the other HDMA register accesses.
--- drivers/dma/dw-edma/dw-hdma-v0-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/dw-edma/dw-hdma-v0-core.c +1 -1
@@ -79,7 +79,7 @@ static enum dma_status dw_hdma_v0_core_cu32 tmp; tmp =FIELD_GET (HDMA_V0_CH_STATUS_MASK , -GET_CH_32 (dw, chan->id, chan->dir, ch_stat)); +GET_CH_32 (dw, chan->dir, chan->id, ch_stat));if (tmp ==1 )return DMA_IN_PROGRESS ;
Greg Kroah-Hartman
maintainerPATCH 111/556 dmaengine: dw-edma: Complete descriptors before pausing
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit c154060016a9db2ac889bfdb0a3c1322f9be8ded upstream.
If PAUSE is requested while the final burst of a descriptor is in flight, the DONE interrupt takes the PAUSE path without checking whether the descriptor has been depleted. The depleted descriptor remains on the issued list and the channel enters EDMA_ST_PAUSE.
On resume, dw_edma_start_transfer() can select that depleted descriptor again even though no burst remains, leaving the channel in an invalid busy state.
Check for descriptor completion before acknowledging PAUSE. If there is no work to start on resume, leave the channel idle. Also ignore DONE interrupts while the channel is paused so a stale or repeated interrupt cannot change its state or start queued work.
--- drivers/dma/dw-edma/dw-edma-core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +14 -6
@@ -297,7 +297,8 @@ static int dw_edma_device_resume(struct err = -EPERM ; }else { chan->status =EDMA_ST_BUSY ; -dw_edma_start_transfer (chan); +if (!dw_edma_start_transfer (chan)) + chan->status =EDMA_ST_IDLE ; }return err;
@@ -655,10 +656,16 @@ static void dw_edma_done_interrupt(strucunsigned long flags;spin_lock_irqsave (&chan->vc.lock, flags); +if (chan->status ==EDMA_ST_PAUSE ) { +spin_unlock_irqrestore (&chan->vc.lock, flags); +return ; + } + vd =vchan_next_desc (&chan->vc);if (vd) {switch (chan->request) {case EDMA_REQ_NONE : +case EDMA_REQ_PAUSE : desc =vd2dw_edma_desc (vd);if (!desc->chunks_alloc) { dw_hdma_set_callback_result(vd,
@@ -667,6 +674,12 @@ static void dw_edma_done_interrupt(strucvchan_cookie_complete (vd); } +if (chan->request ==EDMA_REQ_PAUSE ) { + chan->request =EDMA_REQ_NONE ; + chan->status =EDMA_ST_PAUSE ; +break ; + } +/* Continue transferring if there are remaining chunks or issued requests. */ chan->status =dw_edma_start_transfer (chan) ?EDMA_ST_BUSY :EDMA_ST_IDLE ;
@@ -679,11 +692,6 @@ static void dw_edma_done_interrupt(struc chan->status =EDMA_ST_IDLE ;break ; -case EDMA_REQ_PAUSE : - chan->request =EDMA_REQ_NONE ; - chan->status =EDMA_ST_PAUSE ; -break ; -default :break ; }
Greg Kroah-Hartman
maintainerPATCH 112/556 dmaengine: dw-edma: Initialize IRQ data before requesting IRQs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit 647217abea849d3d45f8cb0b8ee5b78d50f26985 upstream.
dw_edma_irq_request() passes struct dw_edma_irq to request_irq() before dw_edma_channel_setup() fills the back pointer. A shared interrupt can therefore enter the handler with dw_irq->dw still NULL, leading to a NULL pointer dereference.
Set the back pointer before installing each handler.
--- drivers/dma/dw-edma/dw-edma-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/dw-edma/dw-edma-core.c +2 -1
@@ -937,7 +937,6 @@ static int dw_edma_channel_setup(structelse irq->rd_mask |=BIT (chan->id); - irq->dw = dw;memcpy (&chan->msi, &irq->msi,sizeof (chan->msi)); dev_vdbg(dev, "MSI:\t\tChannel %s[%u] addr=0x%.8x%.8x, data=0x%.8x\n",
@@ -1018,6 +1017,7 @@ static int dw_edma_irq_request(struct dwif (chip->nr_irqs ==1 ) {/* Common IRQ shared among all channels */ irq = chip->ops->irq_vector (dev,0 ); + dw->irq[0 ].dw = dw; err =request_irq (irq, dw_edma_interrupt_common,IRQF_SHARED , dw->name, &dw->irq[0 ]);if (err) {
@@ -1040,6 +1040,7 @@ static int dw_edma_irq_request(struct dwfor (i =0 ; i < (*wr_alloc + *rd_alloc); i++) { irq = chip->ops->irq_vector (dev, i); + dw->irq[i].dw = dw; err = request_irq(irq, i < *wr_alloc ? dw_edma_interrupt_write :
Greg Kroah-Hartman
maintainerPATCH 113/556 dmaengine: dw-edma: Mark emulated IRQ as level-triggered
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit 0d995da5fb97e8c312834575604d4423eb6225b7 upstream.
The interrupt-emulation virtual IRQ uses handle_level_irq(), but the IRQ descriptor has not been marked with IRQ_LEVEL.
The interrupt emulation is somewhat unusual: the eDMA interrupt handlers dispatch the virtual IRQ for every edma_int[] interrupt because software cannot reliably tell an interrupt-emulation event from one caused solely by DONE/ABORT status. If an interrupt arrives before the doorbell handler is registered for the virtual IRQ, the IRQ core marks it pending. When the IRQ is later started, check_irq_resend() treats it as non-level and replays the pending interrupt, causing the newly registered handler to run for a stale event.
Mark the virtual IRQ with IRQ_LEVEL so the stale pending state is cleared without being replayed. This was observed in pci_endpoint_test as two doorbell handler calls when the DMA-variant test ran before DOORBELL_TEST.
--- drivers/dma/dw-edma/dw-edma-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/dw-edma/dw-edma-core.c +1 -0
@@ -763,6 +763,7 @@ static int dw_edma_emul_irq_alloc(structreturn virq;irq_set_chip_and_handler (virq, &dw_edma_emul_irqchip, handle_level_irq); +irq_set_status_flags (virq,IRQ_LEVEL );irq_set_chip_data (virq, dw);irq_set_noprobe (virq);
Greg Kroah-Hartman
maintainerPATCH 114/556 cpuidle: dt_idle_genpd: kfree() the original name allocation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 2b0ac85512b7f67479127b2713254490662eb13d upstream.
dt_idle_pd_alloc() kasprintf()s the full node path, then points pd->name at kbasename() of that string. dt_idle_pd_free() kfree()s pd->name, which is no longer the start of the allocation.
Copy the basename instead.
--- drivers/cpuidle/dt_idle_genpd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cpuidle/dt_idle_genpd.c +1 -2
@@ -99,7 +99,7 @@ struct generic_pm_domain *dt_idle_pd_allif (!pd) goto out; - pd->name =kasprintf (GFP_KERNEL ,"%pOF" , np); + pd->name =kstrdup (kbasename (of_node_full_name (np)),GFP_KERNEL );if (!pd->name) goto free_pd;
@@ -112,7 +112,6 @@ struct generic_pm_domain *dt_idle_pd_all goto free_name; pd->free_states = pd_free_states; - pd->name =kbasename (pd->name); pd->states = states; pd->state_count = state_count;
Greg Kroah-Hartman
maintainerPATCH 115/556 cpuidle: psci: Fix support for probe deferral by dropping the faux device
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ulf Hansson <[email protected]>
commit 0606f2114e2dc88fe293858fd991cda2688b8c3a upstream.
At the conversion to the faux driver/device we broke the support for probe deferral. In hindsight, the move to the faux device seems questionable, as it simply makes the code more complicated and for no good reason.
To fix the support for the probe deferral let's therefore restore the old code and drop the faux device.
--- drivers/cpuidle/cpuidle-psci.c | 42 +++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-)
drivers/cpuidle/cpuidle-psci.c +16 -26
@@ -16,7 +16,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/of.h> -#include <linux/device/faux.h> +#include <linux/platform_device.h> #include <linux/psci.h> #include <linux/pm_domain.h> #include <linux/pm_runtime.h>
@@ -428,14 +428,14 @@ deinit:* to register cpuidle driver then rollback to cancel all CPUs * registration. */ -static int psci_cpuidle_probe (struct faux_device *fdev) +static int psci_cpuidle_probe (struct platform_device *pdev) {int cpu, ret;struct cpuidle_driver *drv;struct cpuidle_device *dev;for_each_present_cpu (cpu) { - ret =psci_idle_init_cpu (&fdev->dev, cpu); + ret =psci_idle_init_cpu (&pdev->dev, cpu);if (ret) goto out_fail; }
@@ -455,36 +455,26 @@ out_fail:return ret; } -static struct faux_device_ops psci_cpuidle_ops = { +static struct platform_driver psci_cpuidle_driver = { .probe = psci_cpuidle_probe, + .driver = { + .name ="psci-cpuidle" , + }, }; -static bool __init dt_idle_state_present (void ) -{ - struct device_node *cpu_node __free(device_node) = -of_cpu_device_node_get (cpumask_first (cpu_possible_mask)); -if (!cpu_node) -return false; - - struct device_node *state_node __free(device_node) = -of_get_cpu_state_node (cpu_node,0 ); -if (!state_node) -return false; - -return !!of_match_node (psci_idle_state_match, state_node); -} -static int __init psci_idle_init (void ) { -struct faux_device *fdev; +struct platform_device *pdev; +int ret; -if (!dt_idle_state_present ()) -return 0 ; + ret =platform_driver_register (&psci_cpuidle_driver); +if (ret) +return ret; - fdev =faux_device_create ("psci-cpuidle" ,NULL , &psci_cpuidle_ops); -if (!fdev) { -pr_err ("Failed to create psci-cpuidle device\n" ); -return -ENODEV ; + pdev =platform_device_register_simple ("psci-cpuidle" ,-1 ,NULL ,0 ); +if (IS_ERR (pdev)) { +platform_driver_unregister (&psci_cpuidle_driver); +return PTR_ERR (pdev); }return 0 ;
Greg Kroah-Hartman
maintainerPATCH 116/556 block: flag zoned disks with GENHD_FL_NO_PART
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
commit 3f9c7a108c0e8f14425384912017071b71341e3b upstream.
Zoned block devices do not support partitions. However, the partition table is nevertheless still inspected, and any partition found ignored with a warning in add_partition(). While this is generally not a problem, and in fact beneficial to the user as it indicates an invalid use of a zoned block device, scanning for a partition table on the device may result in issuing read operations to offline zones (e.g. after a disk head is depopulated for disks that support head management operations).
Since partitions are ignored anyway, completely disable partition scanning for zoned gendisks by setting the flag GENHD_FL_NO_PART in __add_disk(). The existing check in add_partition() is left as-is to ensure that we still get a warning if for whatever reason, despite GENHD_FL_NO_PART, we still endup trying to add partitions.
Flagging zoned disks with GENHD_FL_NO_PART also has the benefit to expose through sysfs the ext_range attribute with the value of 1 instead of the default DISK_MAX_PARTS, thus correctly advertizing the fact that zoned disks do not support partitions.
--- block/genhd.c | 7 +++++++ 1 file changed, 7 insertions(+)
block/genhd.c +7 -0
@@ -448,6 +448,13 @@ static int __add_disk(struct device *par }/* +* We do not support partitions with zoned block devices, so do not try +* to scan the partitions table. +*/ +if (blk_queue_is_zoned (disk->queue)) + disk->flags |=GENHD_FL_NO_PART ; + +/* * If the driver provides an explicit major number it also must provide * the number of minors numbers supported, and those will be used to * setup the gendisk.
Greg Kroah-Hartman
maintainerPATCH 117/556 bpf, riscv: Make arena support depend on ZACAS
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Pei <[email protected]>
commit 536b523b407397c8d3967c020ce7aad70a0ea030 upstream.
The arena range tree allocates its nodes with kmalloc_nolock() since commit f8c67d8550ee ("bpf: Use kmalloc_nolock() in range tree"). kmalloc_nolock() requires slab caches with cmpxchg128 support (__CMPXCHG_DOUBLE); on riscv cmpxchg128 is provided by the ZACAS extension. On systems without ZACAS every arena map creation fails with a misleading -ENOMEM.
Report the missing support instead: make bpf_jit_supports_arena() return system_has_cmpxchg128() where it is defined, so arena map creation fails with -EOPNOTSUPP on systems without ZACAS. The macro is only defined when both CONFIG_RISCV_ISA_ZACAS and CONFIG_TOOLCHAIN_HAS_ZACAS are enabled, so guard it with #ifdef the same way mm/slab.h consumes it, and reject arena otherwise. This matches how arena BPF_CMPXCHG instructions are already gated on ZACAS in bpf_jit_supports_insn().
--- arch/riscv/net/bpf_jit_comp64.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
arch/riscv/net/bpf_jit_comp64.c +9 -1
@@ -2114,7 +2114,15 @@ bool bpf_jit_supports_ptr_xchg(void)bool bpf_jit_supports_arena (void ) { -return true; +/* +* The arena range tree uses kmalloc_nolock(), which needs +* cmpxchg128, provided by ZACAS on riscv. +*/ +#ifdef system_has_cmpxchg128 +return system_has_cmpxchg128 (); +#else +return false; +#endif }bool bpf_jit_supports_insn (struct bpf_insn *insn,bool in_arena)
Greg Kroah-Hartman
maintainerPATCH 118/556 bpf: Fix infinite loop in pcpu_freelist push with one possible CPU
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
commit efebf6496685c93150df5bb0794363ae70c5f58a upstream.
__pcpu_freelist_push() can loop forever when only one CPU is possible and an NMI re-enters pcpu_freelist_push() while the interrupted context holds that CPU's freelist lock.
After the current-CPU fast path fails, the fallback loop walks cpu_possible_mask while skipping the current CPU. With CONFIG_SMP=n, or when an SMP kernel is limited to one possible CPU with nr_cpus=1 or possible_cpus=1, there are no other possible CPUs to examine. The loop therefore makes no lock acquisition attempt and can never make progress.
The following stack was observed on a UP system:
NMI context:
pcpu_freelist_push
free_htab_elem
htab_map_delete_elem
[perf-event BPF program]
__perf_event_overflow
perf_event_nmi_handler
exc_nmi
Interrupted context:
__pcpu_freelist_push
pcpu_freelist_push
free_htab_elem
htab_map_delete_elem
[raw_tp/sys_enter BPF program]
__bpf_trace_sys_enter
do_syscall_64
raw_res_spin_lock() detects the same-CPU recursive acquisition and returns -EDEADLK, but the subsequent fallback loop has no candidate head on a system with one possible CPU.
Restore the extra fallback head that existed before the rqspinlock conversion. Keep the current-CPU fast path, then try the other possible CPUs and finally the extra head. The additional head lets a push, which cannot fail without losing a preallocated element, make progress when the only per-CPU head is held by the interrupted context.
Also check the extra head from the pop path so that nodes placed there can be reused.
--- kernel/bpf/percpu_freelist.c | 35 +++++++++++++++++++++++++++-------- kernel/bpf/percpu_freelist.h | 1 + 2 files changed, 28 insertions(+), 8 deletions(-)
kernel/bpf/percpu_freelist.c +27 -8
@@ -17,6 +17,8 @@ int pcpu_freelist_init(struct pcpu_freelraw_res_spin_lock_init (&head->lock); head->first =NULL ; } +raw_res_spin_lock_init (&s->extralist.lock); + s->extralist.first =NULL ;return 0 ; }
@@ -46,22 +48,28 @@ void __pcpu_freelist_push(struct pcpu_fr struct pcpu_freelist_node *node) {struct pcpu_freelist_head *head; -int cpu; +int cpu, this_cpu;if (___pcpu_freelist_push (this_cpu_ptr (s->freelist), node))return ; + this_cpu =raw_smp_processor_id ();while (true) { -for_each_cpu_wrap (cpu, cpu_possible_mask,raw_smp_processor_id ()) { -if (cpu ==raw_smp_processor_id ()) +for_each_cpu_wrap (cpu, cpu_possible_mask, this_cpu) { +if (cpu == this_cpu)continue ; + head =per_cpu_ptr (s->freelist, cpu); -if (raw_res_spin_lock (&head->lock)) -continue ; -pcpu_freelist_push_node (head, node); -raw_res_spin_unlock (&head->lock); -return ; +if (___pcpu_freelist_push (head, node)) +return ; } + +/* +* Push cannot fail. Use the extra list when none of the +* per-CPU freelists can accept the node. +*/ +if (___pcpu_freelist_push (&s->extralist, node)) +return ; } }
@@ -117,6 +125,17 @@ static struct pcpu_freelist_node *___pcp }raw_res_spin_unlock (&head->lock); } + +/* Per-CPU lists are empty or unavailable, try the extra list. */ + head = &s->extralist; +if (!READ_ONCE (head->first)) +return NULL ; +if (raw_res_spin_lock (&head->lock)) +return NULL ; + node = head->first; +if (node) +WRITE_ONCE (head->first, node->next); +raw_res_spin_unlock (&head->lock);return node; }
kernel/bpf/percpu_freelist.h +1 -0
@@ -14,6 +14,7 @@ struct pcpu_freelist_head {struct pcpu_freelist {struct pcpu_freelist_head __percpu *freelist; +struct pcpu_freelist_head extralist; };struct pcpu_freelist_node {
Greg Kroah-Hartman
maintainerPATCH 119/556 ceph: lock mutex in ceph_mds_check_access()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Max Kellermann <[email protected]>
commit a61c6ae1dae2611082b831b4aaa780878099c012 upstream.
MDS session OPEN handling replaces mdsc->s_cap_auths under mdsc->mutex, freeing the previous array and its strings.
ceph_mds_check_access() traverses this array without holding the mutex. A concurrent session reopen can therefore free the array while it is being inspected, resulting in a use-after-free like this:
Unable to handle kernel paging request at virtual address 003aaad64b2c8bb9 [...] Internal error: Oops: 0000000096000004 [#1] SMP Modules linked in: CPU: 56 UID: 2953037534 PID: 1253231 Comm: php-cgi8.4 Not tainted 6.18.45-i2-ampere #1146 NONE [..] pc : ceph_mds_check_access+0xd4/0x550 lr : ceph_mds_check_access+0xc8/0x550 [...] Call trace: ceph_mds_check_access+0xd4/0x550 (P) ceph_atomic_open+0x138/0xbe8 path_openat+0xa24/0xfa8 do_filp_open+0x94/0x158 do_sys_openat2+0x88/0xf8
--- fs/ceph/mds_client.c | 4 ++++ fs/ceph/mds_client.h | 1 + 2 files changed, 5 insertions(+)
fs/ceph/mds_client.c +4 -0
@@ -6593,11 +6593,13 @@ int ceph_mds_check_access(struct ceph_mddoutc (cl,"tpath '%s', mask %d, caller_uid %d, caller_gid %d\n" , tpath, mask, caller_uid, caller_gid); +mutex_lock (&mdsc->mutex);for (i =0 ; i < mdsc->s_cap_auths_num; i++) {struct ceph_mds_cap_auth *s = &mdsc->s_cap_auths[i]; err =ceph_mds_auth_match (mdsc, s, cred, tpath);if (err <0 ) { +mutex_unlock (&mdsc->mutex);put_cred (cred);return err; }else if (err >0 ) {
@@ -6619,6 +6621,7 @@ int ceph_mds_check_access(struct ceph_mddoutc (cl,"root_squash_perms %d, rw_perms_s %p\n" , root_squash_perms, rw_perms_s);if (root_squash_perms && rw_perms_s ==NULL ) { +mutex_unlock (&mdsc->mutex);doutc (cl,"access allowed\n" );return 0 ; }
@@ -6633,6 +6636,7 @@ int ceph_mds_check_access(struct ceph_md !!(mask & MAY_READ), !!(mask & MAY_WRITE)); }doutc (cl,"access denied\n" ); +mutex_unlock (&mdsc->mutex);return -EACCES ; }
fs/ceph/mds_client.h +1 -0
@@ -604,6 +604,7 @@ struct ceph_mds_client {struct rw_semaphore pool_perm_rwsem;struct rb_root pool_perm_tree; +/* protected by mutex */ u32 s_cap_auths_num;struct ceph_mds_cap_auth *s_cap_auths;
Greg Kroah-Hartman
maintainerPATCH 120/556 ata: ahci: work around lost interrupts on Marvell 88SE61xx
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hajo Noerenberg <[email protected]>
commit dc3565a4ae538e584e5e63b3b3cd1eaf502593c1 upstream.
ahci_single_level_irq_intr() services the ports first and clears the global HOST_IRQ_STAT afterwards, as recommended by AHCI 1.1 section 10.6.2. The Marvell 88SE6111/6121/6145 family stops reporting interrupts for a port when HOST_IRQ_STAT is cleared while PxIS still holds bits:
PxIS keeps its content, HOST_IRQ_STAT reads back as 0, the port is never looked at again, and the command in flight only ends in a timeout.
Measured on a Seagate Blackarmor NAS440 (Marvell 88F6281 Kirkwood, 88SE6121 rev B2 behind PCIe) by polling the AHCI registers from userspace while an IDENTIFY was outstanding:
t=303.046 irqs 127 PxIS 0x00000000 PxCI 0x00000001
IDENTIFY issued
t=303.057 irqs 128 PxIS 0x00000020 PxCI 0x00000000
CI cleared, DPS set, one interrupt taken ... PxIS stays 0x00000020, HOST_IRQ_STAT stays 0 ...
t~308.05 qc timeout after 5000 msecs
The command had completed - PxCI was clear and PxIS had DPS set - so ahci_qc_complete() would have completed it. It never got the chance because the handler read HOST_IRQ_STAT as 0 and returned IRQ_NONE.
Marvell's own driver for these chips clears the two registers in the opposite order and says so ("clear global before channel"), and ahci_xgene handles its broken edge latch the same way. Since the reordering costs at most one spurious interrupt per valid one on conforming controllers, do it in a private interrupt handler selected for board_ahci_mv instead of changing libahci for everyone.
With this applied, SATA-2 and SATA-3 disks work at 3.0 Gbps on the 88SE6121 without the drive-side 1.5 Gbps jumper that was needed before. Time from link up to a successful IDENTIFY:
WDC WD5000AADS-00S9B0 port 0 7 ms (never identified before) WDC WD3202ABYS-01B7A0 port 1 28 ms WDC WD30EFRX-68EUZN0 port 1 200 ms (3 TB, HPA detection ok)
Only the 88SE6121 was tested; board_ahci_mv also covers the 88SE6145, which Marvell's driver treats identically.
--- drivers/ata/ahci.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/ata/ahci.c +49 -0
@@ -2614,6 +2614,51 @@ static irqreturn_t ahci_thunderx_irq_han }#endif +/* +* The Marvell 88SE6111/6121/6145 ("Thor") family stops reporting interrupts +* for a port when HOST_IRQ_STAT is cleared while PxIS still holds bits: PxIS +* keeps its content, HOST_IRQ_STAT reads back as 0, the port is never looked +* at again and the command in flight only ends in a timeout. On a 88SE6121 +* this makes every SATA-2 or SATA-3 disk fail to IDENTIFY, while SATA-1 disks +* happen to win the race often enough to work. +* +* Clearing the host status before servicing the ports avoids it. Marvell's +* own driver for these chips does the same and says so ("clear global before +* channel"), and ahci_xgene handles its broken edge latch the same way. The +* price is at most one spurious interrupt per valid one, which is why this is +* not the generic behaviour - see AHCI 1.1 section 10.6.2. +* +* Link: https://bugzilla.kernel.org/show_bug.cgi?id=216094 +*/ +static irqreturn_t ahci_mv_irq_handler (int irq,void *dev_instance) +{ +struct ata_host *host = dev_instance; +struct ahci_host_priv *hpriv = host->private_data; +void __iomem *mmio = hpriv->mmio; +unsigned int rc; +u32 irq_stat, irq_masked; + + irq_stat =readl (mmio +HOST_IRQ_STAT ); +if (!irq_stat) +return IRQ_NONE ; + + irq_masked = irq_stat & hpriv->port_map; + +spin_lock (&host->lock); + +/* +* Use the unmasked value to clear the interrupt, as a spurious pending +* event on a dummy port might cause a screaming IRQ. +*/ +writel (irq_stat, mmio +HOST_IRQ_STAT ); + + rc =ahci_handle_port_intr (host, irq_masked); + +spin_unlock (&host->lock); + +return IRQ_RETVAL (rc); +} +static void ahci_remap_check (struct pci_dev *pdev,int bar,struct ahci_host_priv *hpriv) {
@@ -2917,6 +2962,10 @@ static int ahci_init_one(struct pci_devreturn -ENOMEM ; hpriv->flags |= (unsigned long )pi.private_data; +/* the Marvell "Thor" family needs HOST_IRQ_STAT cleared first */ +if (board_id == board_ahci_mv) + hpriv->irq_handler = ahci_mv_irq_handler; +/* MCP65 revision A1 and A2 can't do MSI */ if (board_id == board_ahci_mcp65 && (pdev->revision ==0xa1 || pdev->revision ==0xa2 ))
Greg Kroah-Hartman
maintainerPATCH 121/556 ima: Check for ERR_PTR from dentry_path() in validate_hash_algo()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit 8861f6d5c0678a7c5089c7b272509fc5931b8437 upstream.
dentry_path() returns ERR_PTR(-ENAMETOOLONG) when the path exceeds the buffer. validate_hash_algo() passes the result straight to integrity_audit_msg() without checking. ERR_PTR is not NULL, so integrity_audit_message() sees a valid pointer and calls strlen() on it, which faults:
BUG: unable to handle page fault for address: ffffffffffffffdc
RIP: 0010:strlen+0x30/0xa0
Call Trace:
audit_log_untrustedstring+0x19/0x30
integrity_audit_message+0x366/0x4f0
ima_inode_setxattr+0x512/0x5f0Check for IS_ERR() and use NULL instead, which makes the audit message skip the name= field instead of crashing.
--- security/integrity/ima/ima_appraise.c | 2 ++ 1 file changed, 2 insertions(+)
security/integrity/ima/ima_appraise.c +2 -0
@@ -748,6 +748,8 @@ static int validate_hash_algo(struct denreturn -EACCES ; path =dentry_path (dentry, pathbuf,PATH_MAX ); +if (IS_ERR (path)) + path =NULL ;integrity_audit_msg (AUDIT_INTEGRITY_DATA ,d_inode (dentry), path,"set_data" , errmsg, -EACCES ,0 );