6.12.112-rc1 review
Greg Kroah-Hartman
maintainerPATCH 487/877 drm/nouveau/uvmm: fix UAF in nouveau_uvmm_sm when BO is in TTM_PL_SYSTEM
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 3359a372efb6d585c97019ee1b7f1874442bcebe upstream.
nouveau_uvmm_sm() calls op_map(), which passes bo->resource through nouveau_mem() to nouveau_uvma_map(). nouveau_uvmm_vmm_map() then reads mem->mem.type.
But this is only valid when bo->resource is backed by struct nouveau_mem, as is the case for VRAM and TT resources. If the BO is left in TTM_PL_SYSTEM, bo->resource is only a struct ttm_resource. Treating it as struct nouveau_mem makes the mem->mem.type read past the end of the resource, causing a KASAN: slab-use-after-free Read in nouveau_uvmm_sm report:
BUG: KASAN: slab-use-after-free in nouveau_uvmm_vmm_map drivers/gpu/drm/nouveau/nouveau_uvmm.c:152 [inline] BUG: KASAN: slab-use-after-free in nouveau_uvma_map drivers/gpu/drm/nouveau/nouveau_uvmm.c:199 [inline] BUG: KASAN: slab-use-after-free in op_map drivers/gpu/drm/nouveau/nouveau_uvmm.c:849 [inline] BUG: KASAN: slab-use-after-free in nouveau_uvmm_sm.constprop.0+0x6ab/0x900 drivers/gpu/drm/nouveau/nouveau_uvmm.c:903 Read of size 1 at addr ffff888127d3e3a0 by task kworker/0:1/11 CPU: 0 UID: 0 PID: 11 Comm: kworker/0:1 Not tainted 7.2.0 #5 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Workqueue: nouveau_sched_wq_2224 drm_sched_run_job_work Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x95/0xe0 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xcb/0x5a0 mm/kasan/report.c:482 kasan_report+0xca/0x100 mm/kasan/report.c:595 nouveau_uvmm_vmm_map drivers/gpu/drm/nouveau/nouveau_uvmm.c:152 [inline] nouveau_uvma_map drivers/gpu/drm/nouveau/nouveau_uvmm.c:199 [inline] op_map drivers/gpu/drm/nouveau/nouveau_uvmm.c:849 [inline] nouveau_uvmm_sm.constprop.0+0x6ab/0x900 drivers/gpu/drm/nouveau/nouveau_uvmm.c:903 nouveau_uvmm_sm_unmap drivers/gpu/drm/nouveau/nouveau_uvmm.c:932 [inline] nouveau_uvmm_bind_job_run+0xd6/0x250 drivers/gpu/drm/nouveau/nouveau_uvmm.c:1532 nouveau_job_run drivers/gpu/drm/nouveau/nouveau_sched.c:350 [inline] nouveau_sched_run_job+0x62/0xd0 drivers/gpu/drm/nouveau/nouveau_sched.c:364 drm_sched_run_job_work+0x356/0xa10 drivers/gpu/drm/scheduler/sched_main.c:1061 process_one_work+0x8a5/0x1900 kernel/workqueue.c:3322 process_scheduled_works kernel/workqueue.c:3405 [inline] worker_thread+0x5dd/0xd80 kernel/workqueue.c:3486 kthread+0x31d/0x420 kernel/kthread.c:436 ret_from_fork+0x662/0x940 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 </TASK> Allocated by task 2224 on cpu 0 at 66.550027s: kasan_save_stack+0x24/0x50 mm/kasan/common.c:57 kasan_save_track+0x17/0x60 mm/kasan/common.c:78 poison_kmalloc_redzone mm/kasan/common.c:398 [inline] __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415 kasan_kmalloc include/linux/kasan.h:263 [inline] __do_kmalloc_node mm/slub.c:5334 [inline] __kmalloc_noprof+0x304/0x7c0 mm/slub.c:5359 _kmalloc_noprof include/linux/slab.h:992 [inline] dma_resv_list_alloc+0x27/0x90 drivers/dma-buf/dma-resv.c:106 dma_resv_reserve_fences+0x60e/0xa30 drivers/dma-buf/dma-resv.c:205 ttm_bo_alloc_resource+0x12c/0xbd0 drivers/gpu/drm/ttm/ttm_bo.c:721 ttm_bo_validate+0x1bc/0x4a0 drivers/gpu/drm/ttm/ttm_bo.c:856 ttm_bo_init_reserved+0x2c3/0x570 drivers/gpu/drm/ttm/ttm_bo.c:970 nouveau_bo_init+0x159/0x2c0 drivers/gpu/drm/nouveau/nouveau_bo.c:359 nouveau_gem_new+0x234/0x5f0 drivers/gpu/drm/nouveau/nouveau_gem.c:272 nouveau_gem_ioctl_new+0x1eb/0x420 drivers/gpu/drm/nouveau/nouveau_gem.c:352 drm_ioctl_kernel+0x192/0x350 drivers/gpu/drm/drm_ioctl.c:817 drm_ioctl+0x4f8/0xb40 drivers/gpu/drm/drm_ioctl.c:914 nouveau_drm_ioctl+0xea/0x2c0 drivers/gpu/drm/nouveau/nouveau_drm.c:1338 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl fs/ioctl.c:583 [inline] __x64_sys_ioctl+0x180/0x1d0 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 2223 on cpu 0 at 66.554063s: kasan_save_stack+0x24/0x50 mm/kasan/common.c:57 kasan_save_track+0x17/0x60 mm/kasan/common.c:78 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:584 poison_slab_object mm/kasan/common.c:253 [inline] __kasan_slab_free+0x61/0x80 mm/kasan/common.c:285 kasan_slab_free include/linux/kasan.h:235 [inline] slab_free_hook mm/slub.c:2677 [inline] __rcu_free_sheaf_prepare+0xb6/0x2e0 mm/slub.c:2928 rcu_free_sheaf+0x1b/0x120 mm/slub.c:5978 rcu_do_batch kernel/rcu/tree.c:2645 [inline] rcu_core+0x521/0x1490 kernel/rcu/tree.c:2897 handle_softirqs+0x1b1/0x8a0 kernel/softirq.c:622 __do_softirq kernel/softirq.c:656 [inline] invoke_softirq kernel/softirq.c:496 [inline] __irq_exit_rcu+0x137/0x1c0 kernel/softirq.c:735 irq_exit_rcu+0x9/0x20 kernel/softirq.c:752 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline] sysvec_apic_timer_interrupt+0x70/0x80 arch/x86/kernel/apic/apic.c:1062 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674 The buggy address belongs to the object at ffff888127d3e380 which belongs to the cache kmalloc-96 of size 96
The buggy address is located 32 bytes inside of
freed 96-byte region [ffff888127d3e380, ffff888127d3e3e0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x127d3e
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff888100041280 dead000000000122 0000000000000000
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888127d3e280: 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc
ffff888127d3e300: 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc
>ffff888127d3e380: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
^
ffff888127d3e400: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
ffff888127d3e480: 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fcFix by resetting the placement to the BO's valid domains before calling nouveau_bo_validate(), matching the handling in nouveau_uvmm_bo_validate(), so map jobs do not run for SYSTEM resources; Reject BO that cannot reside in VRAM or GART;
Also skip op_map() when the GPUVA has been invalidated, matching the handling in the unmap and remap paths.
Found when fuzzing the nouveau driver with a modified Syzkaller.
--- drivers/gpu/drm/nouveau/nouveau_uvmm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/gpu/drm/nouveau/nouveau_uvmm.c +11 -2
@@ -780,6 +780,9 @@ op_map(struct nouveau_uvma *uvma) {struct nouveau_bo *nvbo =nouveau_gem_object (uvma->va.gem.obj); +if (drm_gpuva_invalidated (&uvma->va)) +return ; +nouveau_uvma_map (uvma,nouveau_mem (nvbo->bo.resource)); }
@@ -1164,6 +1167,7 @@ bind_lock_validate(struct nouveau_job *jdrm_gpuva_for_each_op (va_op, op->ops) {struct drm_gem_object *obj =op_gem_obj (va_op); +struct nouveau_bo *nvbo;if (unlikely (!obj))continue ;
@@ -1178,8 +1182,13 @@ bind_lock_validate(struct nouveau_job *jif (va_op->op ==DRM_GPUVA_OP_UNMAP )continue ; - ret =nouveau_bo_validate (nouveau_gem_object (obj), - true, false); + nvbo =nouveau_gem_object (obj); +if (!(nvbo->valid_domains & + (NOUVEAU_GEM_DOMAIN_VRAM |NOUVEAU_GEM_DOMAIN_GART ))) +return -EINVAL ; + +nouveau_bo_placement_set (nvbo, nvbo->valid_domains,0 ); + ret =nouveau_bo_validate (nvbo, true, false);if (ret)return ret; }
Greg Kroah-Hartman
maintainerPATCH 488/877 drm/nouveau: fix autosuspend cleanup during teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit fefd9480ec361969f1a836df46326a1801062c26 upstream.
nouveau_drm_device_init() calls pm_runtime_use_autosuspend(), but nouveau_drm_device_fini() does not call the matching pm_runtime_dont_use_autosuspend().
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during teardown, this reference is not dropped and usage_count remains unbalanced.
The documentation for pm_runtime_use_autosuspend() also notes that it is important to undo it with pm_runtime_dont_use_autosuspend() at driver exit time, unless runtime PM was initially enabled with devm_pm_runtime_enable().
Add the missing pm_runtime_dont_use_autosuspend() call to the common device teardown path.
This issue was found by manual code inspection.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -0
@@ -563,6 +563,7 @@ nouveau_drm_device_fini(struct nouveau_dif (nouveau_pmops_runtime ()) {pm_runtime_get_sync (dev->dev);pm_runtime_forbid (dev->dev); +pm_runtime_dont_use_autosuspend (dev->dev); }nouveau_led_fini (dev);
Greg Kroah-Hartman
maintainerPATCH 489/877 drm/nouveau: Fix bridge reference leak in nv1a_ram_new()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 67b4411538c8341692548429d43256f25be99f7a upstream.
pci_get_domain_bus_and_slot() takes a reference to the PCI device, which is never released once the memory size has been read from its config space. Drop the reference before returning.
--- drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramnv1a.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramnv1a.c +2 -0
@@ -51,6 +51,8 @@ nv1a_ram_new(struct nvkm_fb *fb, struct mib = ((mem >>4 ) &127 ) +1 ; } +pci_dev_put (bridge); +return nvkm_ram_new_ (&nv04_ram_func, fb,NVKM_RAM_TYPE_STOLEN , mib *1024 *1024 , pram); }
Greg Kroah-Hartman
maintainerPATCH 490/877 drm/nouveau: fix double-free in nvif_vmm_dtor
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 97077ac87afe9e91ec074ef0be64454e7ccbf344 upstream.
On failure, nouveau_cli_init() calls nouveau_cli_fini() to tear the client down. Then, nouveau_drm_open() also enters into its cleanup path and calls nouveau_cli_fini() AGAIN. nouveau_cli_fini() calls nouveau_vmm_fini():
void
nouveau_vmm_fini(struct nouveau_vmm *vmm)
{
nouveau_svmm_fini(&vmm->svmm);
nvif_vmm_dtor(&vmm->vmm);
vmm->cli = NULL;
}Inside nvif_vmm_dtor(), vmm->page is freed unconditionally:
void
nvif_vmm_dtor(struct nvif_vmm *vmm)
{
kfree(vmm->page);
nvif_object_dtor(&vmm->object);
}vmm->page is never cleared after being freed, so the second call of nvif_vmm_dtor() will cause a double-free.
Found by fuzzing the nouveau driver with a modified Syzkaller:
BUG: KASAN: double-free in nvif_vmm_dtor+0x31/0x50 drivers/gpu/drm/nouveau/nvif/vmm.c:194 Free of addr ffff888010fcdc30 by task syz.0.173/2567 CPU: 1 UID: 0 PID: 2567 Comm: syz.0.173 Not tainted 7.2.0 #24 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x95/0xe0 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xcb/0x5a0 mm/kasan/report.c:482 kasan_report_invalid_free+0xaa/0xd0 mm/kasan/report.c:557 check_slab_allocation+0xe4/0x110 mm/kasan/common.c:235 kasan_slab_pre_free include/linux/kasan.h:199 [inline] slab_free_hook mm/slub.c:2622 [inline] slab_free mm/slub.c:6377 [inline] kfree+0x192/0x590 mm/slub.c:6692 nvif_vmm_dtor+0x31/0x50 drivers/gpu/drm/nouveau/nvif/vmm.c:194 nouveau_vmm_fini+0x16/0x50 drivers/gpu/drm/nouveau/nouveau_vmm.c:127 nouveau_cli_fini+0x10e/0x210 drivers/gpu/drm/nouveau/nouveau_drm.c:225 nouveau_drm_open+0x24e/0x740 drivers/gpu/drm/nouveau/nouveau_drm.c:1255 drm_file_alloc+0x5f2/0xad0 drivers/gpu/drm/drm_file.c:176 drm_open_helper+0x1d7/0x4a0 drivers/gpu/drm/drm_file.c:335 drm_open+0x190/0x3d0 drivers/gpu/drm/drm_file.c:388 drm_stub_open+0x1f2/0x460 drivers/gpu/drm/drm_drv.c:1211 chrdev_open+0x21c/0x660 fs/char_dev.c:411 do_dentry_open+0x59d/0x12b0 fs/open.c:947 vfs_open+0x82/0x390 fs/open.c:1052 do_open fs/namei.c:4700 [inline] path_openat+0x2345/0x3420 fs/namei.c:4863 do_file_open+0x207/0x460 fs/namei.c:4892 do_sys_openat2+0xd1/0x1d0 fs/open.c:1368 do_sys_open fs/open.c:1374 [inline] __do_sys_openat fs/open.c:1390 [inline] __se_sys_openat fs/open.c:1385 [inline] __x64_sys_openat+0x144/0x200 fs/open.c:1385 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fc6d687594d Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fc6d5295008 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 00007fc6d6b06180 RCX: 00007fc6d687594d RDX: 0000000000022501 RSI: 0000200000000000 RDI: ffffffffffffff9c RBP: 00007fc6d691c303 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fc6d6b06218 R14: 00007fc6d6b06180 R15: 00007ffd9451d760 </TASK> Allocated by task 2567 on cpu 1 at 163.593900s: kasan_save_stack+0x24/0x50 mm/kasan/common.c:57 kasan_save_track+0x17/0x60 mm/kasan/common.c:78 poison_kmalloc_redzone mm/kasan/common.c:398 [inline] __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415 kasan_kmalloc include/linux/kasan.h:263 [inline] __do_kmalloc_node mm/slub.c:5334 [inline] __kmalloc_noprof+0x304/0x7c0 mm/slub.c:5359 _kmalloc_noprof include/linux/slab.h:992 [inline] nvif_vmm_ctor+0x3c0/0x7e0 drivers/gpu/drm/nouveau/nvif/vmm.c:237 nouveau_vmm_init+0x40/0x90 drivers/gpu/drm/nouveau/nouveau_vmm.c:134 nouveau_cli_init+0x7b9/0xe10 drivers/gpu/drm/nouveau/nouveau_drm.c:293 nouveau_drm_open+0x236/0x740 drivers/gpu/drm/nouveau/nouveau_drm.c:1243 drm_file_alloc+0x5f2/0xad0 drivers/gpu/drm/drm_file.c:176 drm_open_helper+0x1d7/0x4a0 drivers/gpu/drm/drm_file.c:335 drm_open+0x190/0x3d0 drivers/gpu/drm/drm_file.c:388 drm_stub_open+0x1f2/0x460 drivers/gpu/drm/drm_drv.c:1211 chrdev_open+0x21c/0x660 fs/char_dev.c:411 do_dentry_open+0x59d/0x12b0 fs/open.c:947 vfs_open+0x82/0x390 fs/open.c:1052 do_open fs/namei.c:4700 [inline] path_openat+0x2345/0x3420 fs/namei.c:4863 do_file_open+0x207/0x460 fs/namei.c:4892 do_sys_openat2+0xd1/0x1d0 fs/open.c:1368 do_sys_open fs/open.c:1374 [inline] __do_sys_openat fs/open.c:1390 [inline] __se_sys_openat fs/open.c:1385 [inline] __x64_sys_openat+0x144/0x200 fs/open.c:1385 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 2567 on cpu 1 at 163.601355s: kasan_save_stack+0x24/0x50 mm/kasan/common.c:57 kasan_save_track+0x17/0x60 mm/kasan/common.c:78 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:584 poison_slab_object mm/kasan/common.c:253 [inline] __kasan_slab_free+0x61/0x80 mm/kasan/common.c:285 kasan_slab_free include/linux/kasan.h:235 [inline] slab_free_hook mm/slub.c:2677 [inline] slab_free mm/slub.c:6377 [inline] kfree+0x383/0x590 mm/slub.c:6692 nvif_vmm_dtor+0x31/0x50 drivers/gpu/drm/nouveau/nvif/vmm.c:194 nouveau_vmm_fini+0x16/0x50 drivers/gpu/drm/nouveau/nouveau_vmm.c:127 nouveau_cli_fini+0x10e/0x210 drivers/gpu/drm/nouveau/nouveau_drm.c:225 nouveau_cli_init+0x593/0xe10 drivers/gpu/drm/nouveau/nouveau_drm.c:324 nouveau_drm_open+0x236/0x740 drivers/gpu/drm/nouveau/nouveau_drm.c:1243 drm_file_alloc+0x5f2/0xad0 drivers/gpu/drm/drm_file.c:176 drm_open_helper+0x1d7/0x4a0 drivers/gpu/drm/drm_file.c:335 drm_open+0x190/0x3d0 drivers/gpu/drm/drm_file.c:388 drm_stub_open+0x1f2/0x460 drivers/gpu/drm/drm_drv.c:1211 chrdev_open+0x21c/0x660 fs/char_dev.c:411 do_dentry_open+0x59d/0x12b0 fs/open.c:947 vfs_open+0x82/0x390 fs/open.c:1052 do_open fs/namei.c:4700 [inline] path_openat+0x2345/0x3420 fs/namei.c:4863 do_file_open+0x207/0x460 fs/namei.c:4892 do_sys_openat2+0xd1/0x1d0 fs/open.c:1368 do_sys_open fs/open.c:1374 [inline] __do_sys_openat fs/open.c:1390 [inline] __se_sys_openat fs/open.c:1385 [inline] __x64_sys_openat+0x144/0x200 fs/open.c:1385 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff888010fcdc30 which belongs to the cache kmalloc-16 of size 16 The buggy address is located 0 bytes inside of 16-byte region [ffff888010fcdc30, ffff888010fcdc40) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10fcd flags: 0x100000000000000(node=0|zone=1) page_type: f5(slab) raw: 0100000000000000 ffff88800d441640 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000550055 00000000f5000000 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888010fcdb00: fc fc 00 04 fc fc fc fc fa fb fc fc fc fc fa fb ffff888010fcdb80: fc fc fc fc fa fb fc fc fc fc 00 07 fc fc fc fc >ffff888010fcdc00: fa fb fc fc fc fc fa fb fc fc fc fc fa fb fc fc ^ ffff888010fcdc80: fc fc fa fb fc fc fc fc 00 04 fc fc fc fc fa fb ffff888010fcdd00: fc fc fc fc 00 00 fc fc fc fc fa fb fc fc fc fc
Fix by removing the redundant teardown in nouveau_drm_open(), since nouveau_cli_init() already does the cleanup work. Also clear vmm->page after its freeing.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 4 +--- drivers/gpu/drm/nouveau/nvif/vmm.c | 1 + 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -3
@@ -1192,10 +1192,8 @@ nouveau_drm_open(struct drm_device *dev,mutex_unlock (&drm->clients_lock); done: -if (ret && cli) { -nouveau_cli_fini (cli); +if (ret && cli)kfree (cli); - }pm_runtime_mark_last_busy (dev->dev);pm_runtime_put_autosuspend (dev->dev);
drivers/gpu/drm/nouveau/nvif/vmm.c +1 -0
@@ -192,6 +192,7 @@ void nvif_vmm_dtor(struct nvif_vmm *vmm) {kfree (vmm->page); + vmm->page =NULL ;nvif_object_dtor (&vmm->object); }
Greg Kroah-Hartman
maintainerPATCH 491/877 drm/nouveau: Fix gem reference leak in validate_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 5ea72f7b7139b123713a7983448f910bc4514d9e upstream.
On the ttm_bo_reserve() failure and "vma not found" error paths, the loop breaks without adding the looked-up object to any validate list, so the reference taken by drm_gem_object_lookup() is never released; validate_fini() only walks the spliced lists. Drop the reference before breaking out on both paths.
--- drivers/gpu/drm/nouveau/nouveau_gem.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -0
@@ -522,6 +522,7 @@ retry:if (unlikely (ret)) {if (ret != -ERESTARTSYS )NV_PRINTK (err, cli,"fail reserve\n" ); +drm_gem_object_put (gem);break ; } }
@@ -531,6 +532,7 @@ retry:struct nouveau_vma *vma =nouveau_vma_find (nvbo, vmm);if (!vma) {NV_PRINTK (err, cli,"vma not found!\n" ); +drm_gem_object_put (gem); ret = -EINVAL ;break ; }
Greg Kroah-Hartman
maintainerPATCH 492/877 drm/nouveau: Fix runtime PM leak in nouveau_connector_detect()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 1e04611d3735543bd80a67d9d13dc13f503746fb upstream.
If nvif_outp_edid_get() fails, nouveau_connector_detect() returns early without dropping the runtime PM reference taken at the start of the function, keeping the device powered on until the next successful detect.
Balance the reference on the error path like the other exit paths do.
--- drivers/gpu/drm/nouveau/nouveau_connector.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_connector.c +4 -1
@@ -601,8 +601,11 @@ nouveau_connector_detect(struct drm_conn new_edid =drm_get_edid (connector, nv_encoder->i2c); }else { ret =nvif_outp_edid_get (&nv_encoder->outp, (u8 **)&new_edid); -if (ret <0 ) +if (ret <0 ) { +pm_runtime_mark_last_busy (dev->dev); +pm_runtime_put_autosuspend (dev->dev);return connector_status_disconnected; + } }nouveau_connector_set_edid (nv_connector, new_edid);
Greg Kroah-Hartman
maintainerPATCH 493/877 drm/nouveau: RCU-free the scheduler-containing nouveau_sched
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonghyuk Kim(MalHyuk) <[email protected]>
commit f7eae6d8d768fabd6b59779ca7da79e02c74e113 upstream.
struct nouveau_sched embeds a struct drm_gpu_scheduler (base). nouveau_sched_destroy() calls nouveau_sched_fini() (which does drm_sched_fini(&sched->base)) and then frees the object with plain kfree(sched).
drm_sched_fence_get_timeline_name() returns fence->sched->name, and the scheduler fence keeps a .release callback so it is not ops-detached on signalling. A finished fence exported to userspace via drm_syncobj / sync_file therefore keeps pointing at &sched->base after nouveau_sched_destroy(), and a later get_timeline_name() -- reachable unprivileged through SYNC_IOC_FILE_INFO -- dereferences freed memory (KASAN slab-use-after-free read).
Per the dma-fence lifetime contract the exporter must keep the data backing a signalled fence alive for an RCU grace period. Free the scheduler-containing object with kfree_rcu() instead of kfree().
--- drivers/gpu/drm/nouveau/nouveau_sched.c | 2 +- drivers/gpu/drm/nouveau/nouveau_sched.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_sched.c +1 -1
@@ -512,7 +512,7 @@ nouveau_sched_destroy(struct nouveau_schstruct nouveau_sched *sched = *psched;nouveau_sched_fini (sched); -kfree (sched); +kfree_rcu (sched, rcu); *psched =NULL ; }
drivers/gpu/drm/nouveau/nouveau_sched.h +1 -0
@@ -98,6 +98,7 @@ void nouveau_job_free(struct nouveau_jobstruct nouveau_sched {struct drm_gpu_scheduler base; +struct rcu_head rcu;struct drm_sched_entity entity;struct workqueue_struct *wq;struct mutex mutex;
Greg Kroah-Hartman
maintainerPATCH 494/877 drm/nouveau: dont bump pin count on failed re-pin in nouveau_bo_pin_locked()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 6a6870d3077faa501ca97760057ddca22b68418d upstream.
nouveau_bo_pin_locked() checks whether an already pinned BO is in a memory domain compatible with a new pin request. When the domains are incompatible, it sets -EBUSY but still calls ttm_bo_pin() before returning.
Callers treat a failed nouveau_bo_pin() as not having acquired a new pin, so the extra pin count is never decreased by a matching unpin. This triggers the warning in ttm_bo_release():
WARN_ON_ONCE(bo->pin_count);
Found when fuzzing the nouveau driver with a modified Syzkaller:
WARNING: drivers/gpu/drm/ttm/ttm_bo.c:256 at ttm_bo_release+0x827/0x9e0 drivers/gpu/drm/ttm/ttm_bo.c:256, CPU#1: syz.3.24/2212 Modules linked in: CPU: 1 UID: 0 PID: 2212 Comm: syz.3.24 Not tainted 7.2.0 #24 PREEMPT(lazy) nouveau 0000:01:00.0: gsp:msg fn:103 len:0x40/0x20 res:0x19 resp:0x19 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:ttm_bo_release+0x827/0x9e0 drivers/gpu/drm/ttm/ttm_bo.c:256 Code: 02 00 0f 85 51 01 00 00 48 8b 7b 08 e8 d2 20 01 00 e9 80 fd ff ff e8 d8 15 c0 fe 90 0f 0b 90 e9 e1 f8 ff ff e8 ca 15 c0 fe 90 <0f> 0b 90 e9 a4 f8 ff ff e8 bc 15 c0 fe be 03 00 00 00 4c 89 e7 e8 msg: 00000000: 05 00 d0 c1 04 00 f0 f1 01 30 00 00 2d 90 00 00 .........0..-... RSP: 0018:ffffc9000f5cf710 EFLAGS: 00010293 RAX: 0000000000000000 RBX: ffff888018e5d2a8 RCX: ffffffff82bb1b36 RDX: ffff888017b68000 RSI: 0000000000000004 RDI: ffff888018e5d2a8 msg: 00000010: 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ RBP: ffff88801261c720 R08: 0000000000000001 R09: ffffed10031cba55 R10: ffff888018e5d2ab R11: 00000000000000f3 R12: ffff888018e5d290 R13: ffff888018e5d2d4 R14: ffff88801b219c18 R15: dffffc0000000000 FS: 0000000000000000(0000) GS:ffff8880e0f6f000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b31223ffc CR3: 0000000028e00005 CR4: 0000000000770ef0 PKRU: 80000000 Call Trace: <TASK> kref_put include/linux/kref.h:65 [inline] ttm_bo_put drivers/gpu/drm/ttm/ttm_bo.c:325 [inline] ttm_bo_fini+0x55/0x80 drivers/gpu/drm/ttm/ttm_bo.c:330 nouveau_gem_object_del+0xb2/0x1b0 drivers/gpu/drm/nouveau/nouveau_gem.c:90 drm_gem_object_free+0x5f/0x90 drivers/gpu/drm/drm_gem.c:1165 kref_put include/linux/kref.h:65 [inline] __drm_gem_object_put include/drm/drm_gem.h:562 [inline] drm_gem_object_put include/drm/drm_gem.h:575 [inline] nouveau_abi16_chan_fini.constprop.0+0x44f/0x5a0 drivers/gpu/drm/nouveau/nouveau_abi16.c:195 nouveau 0000:01:00.0: syz.2.23[2209]: Unknown handle 0x00000000 nouveau_abi16_fini+0x1d0/0x340 drivers/gpu/drm/nouveau/nouveau_abi16.c:225 nouveau_drm_postclose+0x18b/0x3e0 drivers/gpu/drm/nouveau/nouveau_drm.c:1284 nouveau 0000:01:00.0: syz.2.23[2209]: validate_init drm_file_free.part.0+0x6d6/0xb60 drivers/gpu/drm/drm_file.c:267 drm_file_free drivers/gpu/drm/drm_file.c:237 [inline] drm_close_helper.isra.0+0x11a/0x160 drivers/gpu/drm/drm_file.c:290 drm_release+0x1ab/0x330 drivers/gpu/drm/drm_file.c:438 __fput+0x39c/0xa60 fs/file_table.c:512 nouveau 0000:01:00.0: syz.2.23[2209]: validate: -2 task_work_run+0x15a/0x230 kernel/task_work.c:233 exit_task_work include/linux/task_work.h:40 [inline] do_exit+0x82b/0x25a0 kernel/exit.c:1009 do_group_exit+0xc2/0x280 kernel/exit.c:1152 get_signal+0x1d6e/0x1f30 kernel/signal.c:3046 arch_do_signal_or_restart+0x7d/0x6e0 arch/x86/kernel/signal.c:337 __exit_to_user_mode_loop kernel/entry/common.c:66 [inline] exit_to_user_mode_loop+0xdf/0x440 kernel/entry/common.c:101 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline] syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:318 [inline] do_syscall_64+0x4f8/0x690 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f12bac8594d Code: Unable to access opcode bytes at 0x7f12bac85923. RSP: 002b:00007f12b96e70d8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca RAX: 0000000000000001 RBX: 00007f12baf15fa8 RCX: 00007f12bac8594d RDX: 00000000000f4240 RSI: 0000000000000081 RDI: 00007f12baf15fac RBP: 00007f12baf15fa0 R08: 00007f12baee8000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f12baf16038 R14: 0000000000000006 R15: 00007ffe2ed394b0 </TASK> irq event stamp: 47867 hardirqs last enabled at (47883): [<ffffffff815cafc6>] __up_console_sem+0x66/0x70 kernel/printk/printk.c:347 hardirqs last disabled at (47892): [<ffffffff815cafab>] __up_console_sem+0x4b/0x70 kernel/printk/printk.c:345 softirqs last enabled at (47880): [<ffffffff81434277>] __do_softirq kernel/softirq.c:656 [inline] softirqs last enabled at (47880): [<ffffffff81434277>] invoke_softirq kernel/softirq.c:496 [inline] softirqs last enabled at (47880): [<ffffffff81434277>] __irq_exit_rcu+0x137/0x1c0 kernel/softirq.c:735 softirqs last disabled at (47875): [<ffffffff81434277>] __do_softirq kernel/softirq.c:656 [inline] softirqs last disabled at (47875): [<ffffffff81434277>] invoke_softirq kernel/softirq.c:496 [inline] softirqs last disabled at (47875): [<ffffffff81434277>] __irq_exit_rcu+0x137/0x1c0 kernel/softirq.c:735
Fix by calling ttm_bo_pin() only when the existing placement is compatible with the new pin request. This matches the correct behavior in other DRM drivers such as amdgpu_bo_pin() in amdgpu.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +2 -1
@@ -501,8 +501,9 @@ int nouveau_bo_pin_locked(struct nouveau"0x%08x vs 0x%08x\n" , bo, bo->resource->mem_type, domain); ret = -EBUSY ; + }else { +ttm_bo_pin (&nvbo->bo); } -ttm_bo_pin (&nvbo->bo); goto out; }
Greg Kroah-Hartman
maintainerPATCH 495/877 drm/xe: Limit sg segment size to PAGE_SIZE on Xen PV
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Szymon Acedański <[email protected]>
commit 141008dec73521ccf64878517460cec8b3297251 upstream.
Fix display corruption on Xen PV dom0, where DMA buffers are not guaranteed machine-contiguous, in which case bounce buffering kicks in, breaking xe's memory coherency assumptions.
Apply the same workaround i915 carries in i915_sg_segment_size() since commit 78a07fe777c4 ("drm/i915: stop abusing swiotlb_max_segment").
--- drivers/gpu/drm/xe/xe_bo.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpu/drm/xe/xe_bo.h +19 -0
@@ -8,6 +8,8 @@#include <drm/ttm/ttm_tt.h> +#include <xen/xen.h> +#include "xe_bo_types.h" #include "xe_macros.h" #include "xe_vm_types.h"
@@ -328,6 +330,23 @@ static inline unsigned int xe_sg_segmentstruct scatterlist __maybe_unused sg;size_t max =BIT_ULL (sizeof (sg.length) *8 ) -1 ; +/* +* For Xen PV guests pages aren't contiguous in DMA (machine) address +* space. The DMA API takes care of that both in dma_alloc_* (by +* calling into the hypervisor to make the pages contiguous) and in +* dma_map_* (by bounce buffering). But xe (like i915, see commit +* 78a07fe777c4) ignores the coherency aspects of the DMA API and thus +* can't cope with bounce buffering actually happening, so add a hack +* here to force small allocations and mappings when running in PV +* mode on Xen. +* +* Note this will still break if bounce buffering is required for other +* reasons, like confidential computing hypervisors or PCIe root ports +* with addressing limitations. +*/ +if (xen_pv_domain ()) +return PAGE_SIZE ; + max =min_t (size_t, max,dma_max_mapping_size (dev));/*
Greg Kroah-Hartman
maintainerPATCH 496/877 drm/virtio: fix memory leak of fence event on execbuffer failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit b74aad23d99b279bb34d135795f39a6d8ecdc075 upstream.
virtio_gpu_execbuffer_ioctl() reserves a DRM event with drm_event_reserve_init() when VIRTGPU_EXECBUF_RING_IDX selects a ring that userspace has enabled polling for. virtio_gpu_init_submit() does this before the BO handles, the command buffer, the syncobj arrays and the in-fence are processed, so every later error path runs with the event already pending, including plain argument validation failures such as an invalid bo_handle or an in-syncobj that carries no fence.
On those paths, virtio_gpu_cleanup_submit() drops the out-fence without cancelling the event. The fence is freed without ever having been emitted, taking the only driver-side pointer to the event with it. Closing the DRM file does not help. drm_events_release() unlinks pending events but deliberately leaves the freeing to the driver's later drm_send_event(), which never runs for an orphaned event, so the allocation is leaked permanently.
Found when fuzzing the virtio driver with Syzkaller:
BUG: memory leak unreferenced object 0xffff88802c176e80 (size 96): comm "syz.1.367", pid 10561, jiffies 4294960122 hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ c8 6e 17 2c 80 88 ff ff 00 00 00 00 00 00 00 00 .n.,............ backtrace (crc e1973c6b): kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline] slab_post_alloc_hook mm/slub.c:4597 [inline] slab_alloc_node mm/slub.c:4917 [inline] __kmalloc_cache_noprof+0x49d/0x6f0 mm/slub.c:5485 _kmalloc_noprof include/linux/slab.h:988 [inline] _kzalloc_noprof include/linux/slab.h:1309 [inline] virtio_gpu_fence_event_create drivers/gpu/drm/virtio/virtgpu_submit.c:282 [inline] virtio_gpu_init_submit drivers/gpu/drm/virtio/virtgpu_submit.c:398 [inline] virtio_gpu_execbuffer_ioctl+0xbbf/0x1aa0 drivers/gpu/drm/virtio/virtgpu_submit.c:505 drm_ioctl_kernel+0x1f4/0x3e0 drivers/gpu/drm/drm_ioctl.c:817 drm_ioctl+0x5f4/0xc70 drivers/gpu/drm/drm_ioctl.c:914 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl fs/ioctl.c:583 [inline] __x64_sys_ioctl+0x18e/0x210 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x116/0x800 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fix by cancelling and freeing the DRM event on the execbuffer error path before dropping the fence. Clear the fence's event pointer after cancellation so it does not retain a dangling pointer.
--- drivers/gpu/drm/virtio/virtgpu_submit.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/virtio/virtgpu_submit.c +4 -0
@@ -538,6 +538,10 @@ int virtio_gpu_execbuffer_ioctl(struct dvirtio_gpu_process_post_deps (&submit);virtio_gpu_complete_submit (&submit); cleanup: +if (ret && submit.out_fence && submit.out_fence->e) { +drm_event_cancel_free (dev, &submit.out_fence->e->base); + submit.out_fence->e =NULL ; + }virtio_gpu_cleanup_submit (&submit);return ret;
Greg Kroah-Hartman
maintainerPATCH 497/877 drm/virtio: fix NULL pointer dereference on fence allocation failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 846b3c64fe3e77d9db20a7e3e62dbbb637c773e1 upstream.
virtio_gpu_fence_alloc() can fail due to memory pressure and return NULL, but its caller like virtio_gpu_init_submit() never checks it. Later, virtio_gpu_init_submit() passes the NULL fence to virtio_gpu_fence_event_create(), which unconditionally dereferences it.
Found when fuzzing the virtio driver with Syzkaller:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000012: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000090-0x0000000000000097] CPU: 1 UID: 0 PID: 9991 Comm: syz.0.121 Not tainted 7.2.0 #4 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.17.0-0-gb52ca86e094d-prebuilt.qemu.org 04/01/2014 RIP: 0010:virtio_gpu_fence_event_create drivers/gpu/drm/virtio/virtgpu_submit.c:295 [inline] RIP: 0010:virtio_gpu_init_submit drivers/gpu/drm/virtio/virtgpu_submit.c:398 [inline] RIP: 0010:virtio_gpu_execbuffer_ioctl+0xc78/0x1aa0 drivers/gpu/drm/virtio/virtgpu_submit.c:505 Code: 85 ed 0f 85 21 09 00 00 e8 05 5a c9 fb 48 8b 44 24 10 48 8d b8 90 00 00 00 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 9a 0d 00 00 48 8b 44 24 10 4c 89 b0 90 00 00 00 RSP: 0018:ffffc900039dfad0 EFLAGS: 00010216 RAX: dffffc0000000000 RBX: ffffc900039dfdd8 RCX: ffffffff85f6fd3d RDX: 0000000000000012 RSI: ffffffff85f6fd4b RDI: 0000000000000090 RBP: 0000000000000000 R0virtio_gpu_virgl_process_cmd: ctrl 0x102, error 0x1203 R10: 0000000000000000 R11: 0000000000000000 R12: ffff8880132c4000 R13: 0000000000000000 R14: ffff888073b6c700 R15: 000000000000003b FS: 00007fab480b96c0(0000) GS:ffff8880eb6e9000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007effbf5e55a8 CR3: 0000000048d19000 CR4: 0000000000350ef0 Call Trace: <TASK> drm_ioctl_kernel+0x1f4/0x3e0 drivers/gpu/drm/drm_ioctl.c:817 drm_ioctl+0x5f4/0xc70 drivers/gpu/drm/drm_ioctl.c:914 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl fs/ioctl.c:583 [inline] __x64_sys_ioctl+0x18e/0x210 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x116/0x800 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fab471a82bd Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fab480b9018 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 00007fab47435fa0 RCX: 00007fab471a82bd RDX: 00002000000000c0 RSI: 00000000c0406442 RDI: 0000000000000003 RBP: 00007fab480b9080 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000001 R13: 00007fab47436038 R14: 00007fab47435fa0 R15: 00007ffe85ab0740 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:virtio_gpu_fence_event_create drivers/gpu/drm/virtio/virtgpu_submit.c:295 [inline] RIP: 0010:virtio_gpu_init_submit drivers/gpu/drm/virtio/virtgpu_submit.c:398 [inline] RIP: 0010:virtio_gpu_execbuffer_ioctl+0xc78/0x1aa0 drivers/gpu/drm/virtio/virtgpu_submit.c:505 Code: 85 ed 0f 85 21 09 00 00 e8 05 5a c9 fb 48 8b 44 24 10 48 8d b8 90 00 00 00 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 9a 0d 00 00 48 8b 44 24 10 4c 89 b0 90 00 00 00 RSP: 0018:ffffc900039dfad0 EFLAGS: 00010216 RAX: dffffc0000000000 RBX: ffffc900039dfdd8 RCX: ffffffff85f6fd3d RDX: 0000000000000012 RSI: ffffffff85f6fd4b RDI: 0000000000000090 RBP: 0000000000000000 R08: 0000000000000005 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: ffff8880132c4000 R13: 0000000000000000 R14: ffff888073b6c700 R15: 000000000000003b FS: 00007fab480b96c0(0000) GS:ffff888098ae9000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f24c3759000 CR3: 0000000048d19000 CR4: 0000000000350ef0 ---------------- Code disassembly (best guess): 0: 85 ed test %ebp,%ebp 2: 0f 85 21 09 00 00 jne 0x929 8: e8 05 5a c9 fb call 0xfbc95a12 d: 48 8b 44 24 10 mov 0x10(%rsp),%rax 12: 48 8d b8 90 00 00 00 lea 0x90(%rax),%rdi 19: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax 20: fc ff df 23: 48 89 fa mov %rdi,%rdx 26: 48 c1 ea 03 shr $0x3,%rdx * 2a: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) <-- trapping instruction 2e: 0f 85 9a 0d 00 00 jne 0xdce 34: 48 8b 44 24 10 mov 0x10(%rsp),%rax 39: 4c 89 b0 90 00 00 00 mov %r14,0x90(%rax)
Fix by checking virtio_gpu_fence_alloc() in virtio_gpu_init_submit() and returning -ENOMEM before any later code can dereference the NULL fence.
--- drivers/gpu/drm/virtio/virtgpu_submit.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_submit.c +5 -2
@@ -389,10 +389,13 @@ static int virtio_gpu_init_submit(structif ((exbuf->flags &VIRTGPU_EXECBUF_FENCE_FD_OUT ) || exbuf->num_out_syncobjs || exbuf->num_bo_handles || - drm_fence_event) + drm_fence_event) { out_fence =virtio_gpu_fence_alloc (vgdev, fence_ctx, ring_idx); -else +if (!out_fence) +return -ENOMEM ; + }else { out_fence =NULL ; + }if (drm_fence_event) { err =virtio_gpu_fence_event_create (dev, file, out_fence, ring_idx);
Greg Kroah-Hartman
maintainerPATCH 498/877 gpio: tps65219: Fix GPIO input value reads
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 4cbe530c0233c7413aaaeb029a4f32dd6aadacbb upstream.
TPS65219_MFP_GPIO_STATUS_MASK is already BIT(4). Passing it to BIT() again tests bit 16, which cannot be set in the 8-bit MFP_CTRL register, so GPIO0 is always reported low when configured as an input.
Test the register value with the mask directly.
--- drivers/gpio/gpio-tps65219.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-tps65219.c +1 -1
@@ -53,7 +53,7 @@ static int tps65219_gpio_get(struct gpioif (ret)return ret; - ret = !!(val &BIT (TPS65219_MFP_GPIO_STATUS_MASK )); + ret = !!(val &TPS65219_MFP_GPIO_STATUS_MASK );dev_warn (dev,"GPIO%d = %d, MULTI_DEVICE_ENABLE, not a standard GPIO\n" , offset, ret);/*
Greg Kroah-Hartman
maintainerPATCH 499/877 mm/hugetlb: preserve mremap address delta when skipping page tables
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaewook You <[email protected]>
commit 9bdad082d44bdcf93716973dcba6be77e8a06e7b upstream.
move_hugetlb_page_tables() optimizes mremap() by advancing to the last entry in the page table when the source page table does not exist, either initially or after unsharing a PMD table. The common loop increment then steps to the first entry in the next page table.
However, the code advances both the source and destination addresses to the last entries in their respective page tables, which is wrong. The destination address must be advanced only by the same amount as the source address.
If the source and destination offsets within their page tables differ, the destination address can be advanced too far, causing follow-up issues. Fix this by advancing the destination address by the source advance distance.
With a reproducer, we were able to trigger a kernel panic on x86-64. With this fix in place, we can no longer reproduce the issue.
--- mm/hugetlb.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
mm/hugetlb.c +7 -4
@@ -5473,18 +5473,21 @@ int move_hugetlb_page_tables(struct vm_ahugetlb_vma_lock_write (vma);i_mmap_lock_write (mapping);for (; old_addr < old_end; old_addr += sz, new_addr += sz) { +const unsigned long offset_to_last_entry = + (old_addr | last_addr_mask) - old_addr; + src_pte =hugetlb_walk (vma, old_addr, sz);if (!src_pte) { - old_addr |= last_addr_mask; - new_addr |= last_addr_mask; + old_addr += offset_to_last_entry; + new_addr += offset_to_last_entry;continue ; }if (huge_pte_none (huge_ptep_get (mm, old_addr, src_pte)))continue ;if (huge_pmd_unshare (&tlb, vma, old_addr, src_pte)) { - old_addr |= last_addr_mask; - new_addr |= last_addr_mask; + old_addr += offset_to_last_entry; + new_addr += offset_to_last_entry;continue ; }
Greg Kroah-Hartman
maintainerPATCH 500/877 PCI: of_property: Omit bus properties without a subordinate bus
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Angel J <[email protected]>
commit 8805840aad73df7146778be243a196d48b4f6430 upstream.
A bridge (a device with a Type 1 header) may not have a secondary bus allocated (pdev->subordinate), e.g., if there are no available bus numbers or the bridge secondary/subordinate bus numbers are not writable.
The dynamic OF helpers of_pci_prop_bus_range() and of_pci_prop_intr_map() dereference pdev->subordinate without checking it. When CONFIG_PCI_DYNAMIC_OF_NODES is enabled, this can cause a NULL pointer dereference and early boot hang.
Generate 'bus-range' and 'interrupt-map' properties only when a subordinate bus exists. Keep the node and its remaining properties for bridges without one.
The problem was latent since 407d1a51921e ("PCI: Create device tree node for bridge"), but wasn't reachable until 1f340724419e ("PCI: of: Create device tree PCI host bridge node"), which appeared in v6.15. Before 1f340724419e, of_pci_make_dev_node() returned early because the parent OF node was missing.
--- drivers/pci/of_property.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pci/of_property.c +9 -2
@@ -91,9 +91,13 @@ static int of_pci_prop_bus_range(structstruct of_changeset *ocs, struct device_node *np) { - u32 bus_range[] = { pdev->subordinate->busn_res.start, - pdev->subordinate->busn_res.end }; + u32 bus_range[2]; +if (!pdev->subordinate) +return 0 ; + + bus_range[0 ] = pdev->subordinate->busn_res.start; + bus_range[1 ] = pdev->subordinate->busn_res.end;return of_changeset_add_prop_u32_array (ocs, np,"bus-range" , bus_range,ARRAY_SIZE (bus_range)); }
@@ -216,6 +220,9 @@ static int of_pci_prop_intr_map(struct pint ret;u8 pin; +if (!pdev->subordinate) +return 0 ; + pnode =pci_device_to_OF_node (pdev->bus->self);if (!pnode) pnode =pci_bus_to_OF_node (pdev->bus);
Greg Kroah-Hartman
maintainerPATCH 501/877 HID: alps: fix use-after-free on input2 registration failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Changcheng <[email protected]>
commit d3aba3442798ce4a4c8ce3104d7b286d61e605f9 upstream.
alps_input_configured() stores data->input2 before calling input_register_device(). If registration fails, input_free_device() frees the input device but data->input2 still points to the freed memory. alps_input_configured() calls hid_hw_open() before allocating input2, so URBs are already active and raw_event can fire during the failure window. A U1_SP_ABSOLUTE_REPORT_ID report arriving then causes u1_raw_event() to dereference the freed data->input2 -> use-after-free.
Fix by only storing input2 into drvdata after successful registration and adding a NULL guard in the raw_event path.
--- drivers/hid/hid-alps.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hid/hid-alps.c +4 -2
@@ -407,6 +407,8 @@ static int u1_raw_event(struct alps_devreturn 1 ;case U1_SP_ABSOLUTE_REPORT_ID : +if (!hdata->input2) +return 0 ; sp_x =get_unaligned_le16 (data+2 ); sp_y =get_unaligned_le16 (data+4 );
@@ -738,7 +740,6 @@ static int alps_input_configured(struct goto exit; } - data->input2 = input2; input2->phys = input->phys; input2->name ="DualPoint Stick" ; input2->id.bustype =BUS_I2C ;
@@ -762,11 +763,12 @@ static int alps_input_configured(struct__set_bit (INPUT_PROP_POINTER , input2->propbit);__set_bit (INPUT_PROP_POINTING_STICK , input2->propbit); -if (input_register_device (data->input2)) { +if (input_register_device (input2)) {input_free_device (input2); ret = -ENOENT ; goto exit; } + data->input2 = input2; } exit:
Greg Kroah-Hartman
maintainerPATCH 502/877 HID: quirks: add ALWAYS_POLL quirk for SDINNOVATION gaming keyboard
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junjie Cao <[email protected]>
commit cdb669a3b8f844aca71fc3224990157d61562165 upstream.
The SDINNOVATION gaming keyboard (USB ID 36ae:feab) stops reporting input events after its RGB lighting mode is switched about twice. Disabling USB autosuspend and unbinding the other HID interfaces make no difference; the issue does not occur on Windows.
HID_QUIRK_ALWAYS_POLL alone resolves it, verified on 7.1.8 via usbhid.quirks=0x36ae:0xfeab:0x400.
--- drivers/hid/hid-ids.h | 3 +++ drivers/hid/hid-quirks.c | 1 + 2 files changed, 4 insertions(+)
drivers/hid/hid-ids.h +3 -0
@@ -1218,6 +1218,9 @@#define USB_DEVICE_ID_SAMSUNG_WIRELESS_UNIVERSAL_KBD 0xa006#define USB_DEVICE_ID_SAMSUNG_WIRELESS_MULTI_HOGP_KBD 0xa064 +#define USB_VENDOR_ID_SDINNOVATION 0x36ae +#define USB_DEVICE_ID_SDINNOVATION_GAMING_KBD 0xfeab +#define USB_VENDOR_ID_SEMICO 0x1a2c#define USB_DEVICE_ID_SEMICO_USB_KEYKOARD 0x0023#define USB_DEVICE_ID_SEMICO_USB_KEYKOARD2 0x0027
drivers/hid/hid-quirks.c +1 -0
@@ -182,6 +182,7 @@ static const struct hid_device_id hid_qu { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_X52_2), HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE }, { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_X52_PRO), HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE }, { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_X65), HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE }, + { HID_USB_DEVICE(USB_VENDOR_ID_SDINNOVATION, USB_DEVICE_ID_SDINNOVATION_GAMING_KBD), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD2), HID_QUIRK_NO_INIT_REPORTS }, { HID_USB_DEVICE(USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD), HID_QUIRK_NO_INIT_REPORTS }, { HID_USB_DEVICE(USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB), HID_QUIRK_NOGET },
Greg Kroah-Hartman
maintainerPATCH 503/877 HID: wacom: fix OOB read in wacom_wac_pen_serial_enforce()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Jie LAW <[email protected]>
commit 9aa237cf66495b2426ddde8532e9b08a0ed83aaa upstream.
The 'wacom_wac_pen_serial_enforce()' function may calculate and pass an invalid offset to hid_field_extract(), resulting in memory reads at incorrect addresses -- possibly beyond the end of the report. If a field in the HID descriptor lists more usages than its Report Count actually reserves space for, the function's inner 'j' will walk past the end of the field:
for (i = 0; i < report->maxfield; i++) {
for (j = 0; j < report->field[i]->maxusage; j++) {
...
value = hid_field_extract(hdev, raw_data + 1,
offset + j * size, size);A descriptor listing 12288 usages against Report Count 1 has the loop extract the usage at index 12287 from bit offset 98296 -- about 12 KB past a 2-byte received report. The value is stored in wacom_wac->serial[0] and can reach userspace as an MSC_SERIAL event, making this an information disclosure.
Clamp the loop to field->report_count, the number of value slots the report holds. Value slots past the last declared usage are still scanned; they reuse that usage (HID 1.11, 6.2.2.8).
Verified on v6.12.105 with a UHID reproducer: a 2-byte report from such a descriptor trips KASAN before the patch and not after it.
--- drivers/hid/wacom_sys.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/wacom_sys.c +3 -2
@@ -97,8 +97,9 @@ static int wacom_wac_pen_serial_enforce(/* Queue events which have invalid tool type or serial number */ for (i =0 ; i < report->maxfield; i++) { -for (j =0 ; j < report->field[i]->maxusage; j++) { -struct hid_field *field = report->field[i]; +struct hid_field *field = report->field[i]; + +for (j =0 ; j < field->report_count; j++) {struct hid_usage *usage = &field->usage[j];unsigned int equivalent_usage =wacom_equivalent_usage (usage->hid);unsigned int offset;
Greg Kroah-Hartman
maintainerPATCH 504/877 net/mlx5: Fix rev_entry reference leak in mlx5_tc_ct_shared_counter_get()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 0bf6bb567f0edaa771e7dd208ef98da50e6a4485 upstream.
When the reverse entry is found but its counter is already being released, refcount_inc_not_zero() fails and the reference taken by mlx5_tc_ct_entry_get() is never dropped before falling through to create_counter. Drop it so the reverse entry is not kept alive forever by a shared counter lookup that did not use it.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +3 -0
@@ -1082,6 +1082,9 @@ mlx5_tc_ct_shared_counter_get(struct mlxspin_unlock_bh (&ct_priv->ht_lock); +if (rev_entry) +mlx5_tc_ct_entry_put (rev_entry); + create_counter: shared_counter =mlx5_tc_ct_counter_create (ct_priv);
Greg Kroah-Hartman
maintainerPATCH 505/877 net/mlx5e: advertise MACsec offload only when supported
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ralf Lici <[email protected]>
commit 4581c3d2adc3c73a019bc38db64ca11f28bbd7fd upstream.
Commit 339ccec8d43d ("net/mlx5: Enable MACsec offload feature for VLAN interface") added NETIF_F_HW_MACSEC unconditionally to vlan_features so that VLAN devices could inherit MACsec offload support.
mlx5e_build_nic_netdev subsequently copies vlan_features into hw_features and features. As a result, all mlx5e NIC netdevices advertise MACsec hardware offload, even when the firmware does not support it and the driver does not install macsec_ops.
Set the MACsec feature bits in mlx5e_macsec_build_netdev, after device capabilities have been validated. This preserves MACsec-over-VLAN support and the ethtool feature control on capable devices, without advertising either on unsupported hardware.
--- drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c | 2 ++ drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/macsec.c +2 -0
@@ -1727,6 +1727,8 @@ void mlx5e_macsec_build_netdev(struct mlmlx5_core_dbg (priv->mdev,"mlx5e: MACsec acceleration enabled\n" ); netdev->macsec_ops = &macsec_offload_ops; netdev->features |=NETIF_F_HW_MACSEC ; + netdev->hw_features |=NETIF_F_HW_MACSEC ; + netdev->vlan_features |=NETIF_F_HW_MACSEC ;netif_keep_dst (netdev); }
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -1
@@ -5433,7 +5433,6 @@ static void mlx5e_build_nic_netdev(struc netdev->vlan_features |=NETIF_F_SG ; netdev->vlan_features |=NETIF_F_HW_CSUM ; - netdev->vlan_features |=NETIF_F_HW_MACSEC ; netdev->vlan_features |=NETIF_F_GRO ; netdev->vlan_features |=NETIF_F_TSO ; netdev->vlan_features |=NETIF_F_TSO6 ;
Greg Kroah-Hartman
maintainerPATCH 506/877 net/sched: reject IDR error pointers when deleting actions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit c82b797abe668d0b668601a93ba2c0b071a63574 upstream.
tcf_action_delete() drops the reference held by its lookup before calling tcf_idr_delete_index() with the saved action index. An unlocked classifier can remove that action and reserve the same IDR slot with ERR_PTR(-EBUSY) in between.
tcf_idr_delete_index() only checks the lookup result for NULL. It therefore treats the reservation as a tc_action and dereferences tcfa_bindcnt. A hardware execution breakpoint was used to schedule the interleaving without changing the kernel source. KASAN reported this decoded trace:
BUG: KASAN: null-ptr-deref in tca_action_gd+0x5b9/0x1010
Read of size 4 at addr 0000000000000010 by task poc/150
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002
RIP: tca_action_gd+0x5c0/0x1010:
arch_atomic_read at arch/x86/include/asm/atomic.h:23
raw_atomic_read at include/linux/atomic/atomic-arch-fallback.h:457
atomic_read at include/linux/atomic/atomic-instrumented.h:33
tcf_idr_delete_index at net/sched/act_api.c:766
tcf_action_delete at net/sched/act_api.c:1859
tcf_del_notify at net/sched/act_api.c:2014
tca_action_gd at net/sched/act_api.c:2064
R13: 0000000000000010 R15: fffffffffffffff0
Kernel panic - not syncing: Fatal exceptionR15 contains ERR_PTR(-EBUSY), and adding the tcfa_bindcnt offset produces the address in R13. With the guard applied, the same reproducer returned -ENOENT without a KASAN report or panic. Treat error pointers as absent and return -ENOENT.
--- net/sched/act_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/act_api.c +1 -1
@@ -714,7 +714,7 @@ static int tcf_idr_delete_index(struct tmutex_lock (&idrinfo->lock); p =idr_find (&idrinfo->action_idr, index); -if (!p) { +if (IS_ERR_OR_NULL (p)) {mutex_unlock (&idrinfo->lock);return -ENOENT ; }
Greg Kroah-Hartman
maintainerPATCH 507/877 net: arp: terminate device name before lookup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijie Huang <[email protected]>
commit d8b6529e80bcb4fb8177121404cbb3377acaebd2 upstream.
The ARP ioctl copies a user-provided struct arpreq into a stack object. Its arp_dev field may contain IFNAMSIZ bytes without a NUL terminator.
Such input is passed to dev_get_by_name_rcu() or __dev_get_by_name(), where strcmp() can read past the end of the stack object when a matching alternative interface name exists.
Terminate the field before the lookup to prevent the out-of-bounds read.
--- net/ipv4/arp.c | 1 + 1 file changed, 1 insertion(+)
net/ipv4/arp.c +1 -0
@@ -1276,6 +1276,7 @@ int arp_ioctl(struct net *net, unsigned err =copy_from_user (&r, arg,sizeof (struct arpreq ));if (err)return -EFAULT ; + r.arp_dev[IFNAMSIZ -1 ] ='\0' ;break ;default :return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 508/877 net: atl1: fix soft lockup on out-of-range cmb_tpd_next_to_clean read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gajdos Tamás <[email protected]>
commit 43e746821f5f5afbbf68e388bf9fbe221e03bfca upstream.
Same issue as atl1c (see the first commit in this series, "net:
atl1c: fix soft lockup on out-of-range tpd_cons read"): the hardware can report an out-of-range cmb_tpd_next_to_clean (seen as 0xffff) while the PCIe link/MAC is resetting. An out-of-range value can never be reached and the loop below would spin forever. Treat it as "nothing new to clean" instead.
--- drivers/net/ethernet/atheros/atlx/atl1.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/atheros/atlx/atl1.c +3 -0
@@ -2066,6 +2066,9 @@ static int atl1_intr_tx(struct atl1_adap sw_tpd_next_to_clean =atomic_read (&tpd_ring->next_to_clean); cmb_tpd_next_to_clean =le16_to_cpu (adapter->cmb.cmb->tpd_cons_idx); +if (unlikely (cmb_tpd_next_to_clean >= tpd_ring->count)) + cmb_tpd_next_to_clean = sw_tpd_next_to_clean; +while (cmb_tpd_next_to_clean != sw_tpd_next_to_clean) { buffer_info = &tpd_ring->buffer_info[sw_tpd_next_to_clean];if (buffer_info->dma) {
Greg Kroah-Hartman
maintainerPATCH 509/877 net: hisilicon: hns_dsaf_mac: fix mdio device leak in hns_mac_register_phy()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 999e8295bc41d6ce45b8e54f88150efa96f3f01e upstream.
hns_dsaf_find_platform_device() returns the mdio platform device with its reference count incremented. hns_mac_register_phy() never drops that reference, so the mdio device can not be released.
Release the reference on both the deferred probe and the normal path.
--- drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +3 -0
@@ -793,6 +793,7 @@ static int hns_mac_register_phy(struct hdev_err (mac_cb->dev,"mac%d mdio is NULL, dsaf will probe again later\n" , mac_cb->mac_id); +put_device (&pdev->dev);return -EPROBE_DEFER ; }
@@ -801,6 +802,8 @@ static int hns_mac_register_phy(struct hdev_dbg (mac_cb->dev,"mac%d register phy addr:%d\n" , mac_cb->mac_id, addr); +put_device (&pdev->dev); +return rc; }
Greg Kroah-Hartman
maintainerPATCH 510/877 net: openvswitch: conntrack: avoid modifying shared unconfirmed ct entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
commit 26b2bd70d22457556e2fa01cbf1192cb1a94d619 upstream.
In a case where skb with an unconfirmed ct entry gets cloned, we may end up committing both but with different sets of extensions.
The series of events:
1. The first clone wants to commit and runs the helpers wiring up the extension pointer into the expectation list.
2. Then it looses the confirmation keeping the entry unconfirmed.
3. Second clone now wants to commit labels and adds the new extension for that breaking the pointer in the expectation list causing UAF on the destruction path later.
While this is possible to trigger, there should be no practical network pipeline where committing both clones without modifications into the same zone is needed. So, let's just reset the entry in case for some reason we got an skb with a shared one during commit. This doesn't affect any known use cases, but avoids any potential problems with sharing and modification of the unconfirmed ct entry.
The fixes tag points to the introduction of helpers, since that's the main UAF trigger for the sharing.
--- include/net/netfilter/nf_conntrack.h | 5 +++++ net/openvswitch/conntrack.c | 12 ++++++++++++ 2 files changed, 17 insertions(+)
include/net/netfilter/nf_conntrack.h +5 -0
@@ -186,6 +186,11 @@ static inline void nf_ct_put(struct nf_cnf_ct_destroy (&ct->ct_general); } +static inline bool nf_ct_shared (const struct nf_conn *ct) +{ +return refcount_read (&ct->ct_general.use) >1 ; +} +/* load module; enable/disable conntrack in this namespace */ int nf_ct_netns_get (struct net *net,u8 nfproto);void nf_ct_netns_put (struct net *net,u8 nfproto);
net/openvswitch/conntrack.c +12 -0
@@ -734,6 +734,18 @@ static int __ovs_ct_lookup(struct net *nenum ip_conntrack_info ctinfo;struct nf_conn *ct; +/* If the ct entry is not confirmed and shared with some other skb, +* e.g., a cloned one, we can't just modify it with the commit as we +* must not modify the extension set. Reset. +*/ +if (cached && info->commit) { + ct =nf_ct_get (skb, &ctinfo); +if (ct && !nf_ct_is_confirmed (ct) &&nf_ct_shared (ct)) { +nf_reset_ct (skb); + cached = false; + } + } +if (!cached) {struct nf_hook_state state = { .hook =NF_INET_PRE_ROUTING ,
Greg Kroah-Hartman
maintainerPATCH 511/877 net: openvswitch: conntrack: remove add_helper dead code
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
commit 5e6c14dd42a1c1fe938e573dc6c9098145b2b0c4 upstream.
This variable can only become 'true' when the connection is not confirmed, but it is only checked when it is confirmed. So, it can be treated as being always false and just removed.
--- net/openvswitch/conntrack.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
net/openvswitch/conntrack.c +2 -8
@@ -779,8 +779,6 @@ static int __ovs_ct_lookup(struct net *n ct =nf_ct_get (skb, &ctinfo);if (ct) { -bool add_helper = false; -/* Packets starting a new connection must be NATted before the * helper, so that the helper knows about the NAT. We enforce * this by delaying both NAT and helper calls for unconfirmed
@@ -812,7 +810,6 @@ static int __ovs_ct_lookup(struct net *n GFP_ATOMIC);if (err)return err; - add_helper = true;/* helper installed, add seqadj if NAT is required */ if (info->nat && !nfct_seqadj (ct)) {
@@ -822,13 +819,10 @@ static int __ovs_ct_lookup(struct net *n }/* Call the helper only if: -* - nf_conntrack_in() was executed above ("!cached") or a -* helper was just attached ("add_helper") for a confirmed -* connection, or +* - nf_conntrack_in() was executed above ("!cached"), or * - When committing an unconfirmed connection. */ -if ((nf_ct_is_confirmed (ct) ? !cached || add_helper : - info->commit)) { +if ((nf_ct_is_confirmed (ct) ? !cached : info->commit)) {int err =nf_ct_helper (skb, ct, ctinfo, info->family); err =verdict_to_errno (err);
Greg Kroah-Hartman
maintainerPATCH 512/877 net: openvswitch: conntrack: fix helper UAF due to extensions realloc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
commit 1a4151e6be57b098b7a5ebfbde58585e83200cdc upstream.
While calling the helpers, a raw pointer to the extensions area is wired into expectations list:
-> nf_ct_helper()
-> helper->help()
-> nf_ct_expect_related_report()
-> nf_ct_expect_insert()
-> hlist_add_head_rcu(&exp->lnode, &master_help->expectations)In case the connection is not confirmed yet, more extensions can be added afterwards with *_ext_add() calls reallocating the extension space and leaving the now invalid pointer in the expectations list that is later accessed while removing the expectation.
Make sure that helpers are called at the end after all the other extensions are already added.
Note that the helper rejection now leaves the mark and labels set, but that's not different from how the NAT was handled before or how the mark and the labels were handled on confirmation failure. And there are no atomicity guarantees provided by the API anyway.
--- net/openvswitch/conntrack.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/openvswitch/conntrack.c +15 -4
@@ -818,11 +818,14 @@ static int __ovs_ct_lookup(struct net *n } } -/* Call the helper only if: -* - nf_conntrack_in() was executed above ("!cached"), or -* - When committing an unconfirmed connection. +/* Call the helper only if nf_conntrack_in() was executed +* above ("!cached"). +* +* For unconfirmed connections it will be called later during +* commit as we need to have all the other extensions allocated +* before the call. */ -if ((nf_ct_is_confirmed (ct) ? !cached : info->commit)) { +if (nf_ct_is_confirmed (ct) && !cached) {int err =nf_ct_helper (skb, ct, ctinfo, info->family); err =verdict_to_errno (err);
@@ -1025,6 +1028,14 @@ static int ovs_ct_commit(struct net *netreturn err;nf_conn_act_ct_ext_add (skb, ct, ctinfo); + +/* Call the helpers now. We couldn't do this before as +* all the extensions must be allocated before the call. +*/ + err =nf_ct_helper (skb, ct, ctinfo, info->family); + err =verdict_to_errno (err); +if (err) +return err; }else if (IS_ENABLED (CONFIG_NF_CONNTRACK_LABELS ) &&labels_nonzero (&info->labels.mask)) { err = ovs_ct_set_labels(ct, key, &info->labels.value,
Greg Kroah-Hartman
maintainerPATCH 513/877 net: atl1c: fix soft lockup on out-of-range tpd_cons read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gajdos Tamás <[email protected]>
commit 36c2009d90f2210ef92e6f4f2850e8b57b09e754 upstream.
The hardware can report an out-of-range tpd_cons (seen as 0xffff) while the PCIe link/MAC is resetting. An out-of-range value can never be reached and the loop below would spin forever. To avoid a soft lockup treat it as "nothing new to clean" instead.
Reproduced on two machines, same NIC (Qualcomm Atheros AR8151 v2.0, 4-port), triggered by rebooting a Mikrotik CCR2004 PCIe card that the ports are directly linked to:
- Ubuntu 26.04.1 LTS, kernel 7.0.0-31-generic. The link-flap precursor, before the lockup was captured with a full trace elsewhere:
atl1c 0000:05:00.0 enp5s0f0: NETDEV WATCHDOG: CPU: 4: transmit queue 2 timed out 489984 ms
atl1c 0000:05:00.0: MAC state machine can't be idle since disabled for 10ms second
atl1c 0000:05:00.0: atl1c: enp5s0f0 NIC Link is Up<65535 Mbps Full Duplex> 65535 (0xffff) here is the same value tpd_cons reads back once the loop below gets stuck.
- Proxmox VE, kernel 7.0.14-11-pve. Same NIC/trigger, this time caught by the soft lockup watchdog with a full stack trace:
watchdog: BUG: soft lockup - CPU#12 stuck for 354s! [napi/eth%d-0:329]
CPU: 12 UID: 0 PID: 329 Comm: napi/eth%d-0 Tainted: P O L 7.0.14-11-pve #1 PREEMPT(lazy)
RIP: 0010:atl1c_clean_tx+0x142/0x2d0 [atl1c]
Call Trace:
<TASK>
__napi_poll+0x32/0x1e0
napi_threaded_poll_loop+0x286/0x2e0
napi_threaded_poll+0xfd/0x140
kthread+0xf7/0x130
ret_from_fork+0x2da/0x3a0
ret_from_fork_asm+0x1a/0x30
</TASK>--- drivers/net/ethernet/atheros/atl1c/atl1c_main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/atheros/atl1c/atl1c_main.c +3 -0
@@ -1602,6 +1602,9 @@ static int atl1c_clean_tx(struct napi_stAT_READ_REGW (&adapter->hw, atl1c_qregs[tpd_ring->num].tpd_cons, &hw_next_to_clean); +if (unlikely (hw_next_to_clean >= tpd_ring->count)) + hw_next_to_clean = next_to_clean; +while (next_to_clean != hw_next_to_clean) { buffer_info = &tpd_ring->buffer_info[next_to_clean];if (buffer_info->skb) {
Greg Kroah-Hartman
maintainerPATCH 514/877 net: atl1e: fix soft lockup on out-of-range hw_next_to_clean read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gajdos Tamás <[email protected]>
commit 374bf9e4b90f979e052332c4faca2d745c491a12 upstream.
Same issue as atl1c (see the first commit in this series, "net:
atl1c: fix soft lockup on out-of-range tpd_cons read"): the hardware can report an out-of-range hw_next_to_clean (seen as 0xffff) while the PCIe link/MAC is resetting. An out-of-range value can never be reached and the loop below would spin forever. Treat it as "nothing new to clean" instead.
--- drivers/net/ethernet/atheros/atl1e/atl1e_main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/atheros/atl1e/atl1e_main.c +3 -0
@@ -1234,6 +1234,9 @@ static bool atl1e_clean_tx_irq(struct atu16 hw_next_to_clean =AT_READ_REGW (&adapter->hw,REG_TPD_CONS_IDX );u16 next_to_clean =atomic_read (&tx_ring->next_to_clean); +if (unlikely (hw_next_to_clean >= tx_ring->count)) + hw_next_to_clean = next_to_clean; +while (next_to_clean != hw_next_to_clean) { tx_buffer = &tx_ring->tx_buffer[next_to_clean];if (tx_buffer->dma) {
Greg Kroah-Hartman
maintainerPATCH 515/877 net: bridge: mdb: restart port group walk after deletion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fourie Zhang <[email protected]>
commit ab1404ac81154a89fb61ac50ae9a04cd8d4834dc upstream.
br_mdb_flush_pgs() keeps a pointer-to-pointer cursor while walking mp->ports. br_multicast_del_pg() can re-enter the same MDB entry through br_multicast_sg_del_exclude_ports() and unlink other port groups. If the cursor points into one of those groups, the next iteration dereferences a stale cursor and can leave mp->ports pointing at freed memory.
A following RTM_GETMDB exposes the dangling pointer:
BUG: KASAN: slab-use-after-free in br_mdb_dump
Read of size 8
br_mdb_dump
rtnl_mdb_dump
rtnl_dumpit
netlink_dumpReset the cursor to mp->ports after every deletion. The deletion removes at least the selected group, so the restarted walk always makes progress.
--- net/bridge/br_mdb.c | 2 ++ 1 file changed, 2 insertions(+)
net/bridge/br_mdb.c +2 -0
@@ -1505,6 +1505,8 @@ static void br_mdb_flush_pgs(struct net_ }br_multicast_del_pg (mp, p, pp); +/* br_multicast_del_pg() can remove other groups from this list. */ + pp = &mp->ports; } }
Greg Kroah-Hartman
maintainerPATCH 516/877 net: usb: cdc_mbim: add MeiG Smart SRM821 to ZLP whitelist
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Wang <[email protected]>
commit f75f21ef36285e5f56ee0c428bd2909ee81165b9 upstream.
The MeiG Smart SRM821 5G module (0x2dee:0x4d53) crashes and drops off the USB bus when it receives a Zero Length Packet (ZLP) after sending or receiving an NTB of exactly 16384 bytes (tx_max).
According to the MBIM specification, devices do not require a ZLP if the NTB size is exactly dwNtbOutMaxSize. However, the cdc_mbim driver defaults to sending ZLPs for devices not explicitly whitelisted to accommodate non-conformant hardware. This default behavior breaks the strictly conformant MeiG SRM821 module.
Add this device to the ZLP conformance whitelist (cdc_mbim_info) so the driver will pad the NTB to avoid sending ZLPs, preventing the device firmware from crashing.
--- drivers/net/usb/cdc_mbim.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/usb/cdc_mbim.c +5 -0
@@ -634,6 +634,11 @@ static const struct usb_device_id mbim_d .driver_info = (unsigned long)&cdc_mbim_info, }, +/* MeiG Smart SRM821 ZLP conformance */ + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d53, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE), + .driver_info = (unsigned long)&cdc_mbim_info, + }, +/* Some Huawei devices, ME906s-158 (12d1:15c1) and E3372 * (12d1:157d), are known to fail unless the NDP is placed * after the IP packets. Applying the quirk to all Huawei
Greg Kroah-Hartman
maintainerPATCH 517/877 net: usb: lan78xx: Fix URB reference leak in lan78xx_submit_deferred_urbs()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 17741334d00bf5ebd37f8c1c36bc9c146a351deb upstream.
usb_get_from_anchor() hands over a reference to the URB, which the caller must release. lan78xx_submit_deferred_urbs() never does, so every deferred Tx URB keeps an extra reference: the counter grows on each suspend/resume cycle and the URBs are never freed when the buffers are released. Drop the reference after submitting, and on the path that drops the packet instead of submitting it.
--- drivers/net/usb/lan78xx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/usb/lan78xx.c +2 -0
@@ -4932,10 +4932,12 @@ static bool lan78xx_submit_deferred_urbs !netif_carrier_ok(dev->net) || pipe_halted) {lan78xx_release_tx_buf (dev, skb); +usb_put_urb (urb);continue ; } ret =usb_submit_urb (urb,GFP_ATOMIC ); +usb_put_urb (urb);if (ret ==0 ) {netif_trans_update (dev->net);
Greg Kroah-Hartman
maintainerPATCH 518/877 netfilter: ip6t_rpfilter: reject routes without inet6_dev
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit 1b9b5323725e458906c7620a3bc10398b51ad954 upstream.
ip6_route_lookup() can return an error-free route whose rt6i_idev is NULL. Lowering an external nexthop device's MTU below IPV6_MIN_MTU tears down its inet6_dev while fib6_ifdown() leaves routes using nexthop objects in the FIB. An unprivileged user can construct this state with rtnetlink in a private user and network namespace, then trigger a NULL dereference through an IPv6 rpfilter lookup:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000 KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: rpfilter_mt (net/ipv6/netfilter/ip6t_rpfilter.c:75) Call Trace: ip6t_do_table (net/ipv6/netfilter/ip6_tables.c:316) nf_hook_slow (net/netfilter/core.c:619) ipv6_rcv (net/ipv6/ip6_input.c:351) __netif_receive_skb_one_core (net/core/dev.c:6216) process_backlog (net/core/dev.c:6680) __napi_poll (net/core/dev.c:7739) net_rx_action (net/core/dev.c:7959) handle_softirqs (kernel/softirq.c:622) do_softirq.part.0 (kernel/softirq.c:523) __local_bh_enable_ip (kernel/softirq.c:450) __dev_queue_xmit (net/core/dev.c:4913) packet_sendmsg (net/packet/af_packet.c:3139) __sys_sendto (net/socket.c:2252) __x64_sys_sendto (net/socket.c:2259) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Kernel panic - not syncing: Fatal exception in interrupt
Reject routes without an inet6_dev immediately after lookup. Such routes are not eligible for reverse-path filtering, and the check protects all later rt6i_idev dereferences.
--- net/ipv6/netfilter/ip6t_rpfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/ip6t_rpfilter.c +1 -1
@@ -61,7 +61,7 @@ static bool rpfilter_lookup_reverse6(str fl6.flowi6_oif = dev->ifindex; rt = (void *)ip6_route_lookup (net, &fl6, skb, lookup_flags); -if (rt->dst.error) +if (rt->dst.error || !rt->rt6i_idev) goto out;if (rt->rt6i_flags & (RTF_REJECT |RTF_ANYCAST ))
Greg Kroah-Hartman
maintainerPATCH 519/877 netfilter: ip6t_rt: fix zero-address non-strict match out-of-bounds read
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit 82313c169eddc02b1bf5ba6b427803e272d3ec42 upstream.
rt_mt6_check() permits rules to be configured with rtinfo->addrnr == 0 even when address matching (IP6T_RT_FST_MASK) is requested.
In the IP6T_RT_FST_NSTRICT path, rt_mt6() evaluates packet routing addresses against rtinfo->addrs[i] and terminates backwards at the bottom of the loop:
if (ipv6_addr_equal(ap, &rtinfo->addrs[i])) {
i++;
}
if (i == rtinfo->addrnr)
break;When addrnr is 0, if the first packet address matches rtinfo->addrs[0], i is incremented to 1. Because i is now strictly greater than addrnr (0), the loop termination condition (i == rtinfo->addrnr) is bypassed and will never be satisfied.
If a crafted IPv6 packet contains matching routing addresses, i will advance past IP6T_RT_HOPS (16). The subsequent call to ipv6_addr_equal() reads beyond struct ip6t_rt, triggering UBSAN/KASAN out-of-bounds warnings or kernel panics.
Fix this by:
1. Rejecting rules in rt_mt6_check() where IP6T_RT_FST_MASK is set but rtinfo->addrnr is zero.
2. In rt_mt6(), moving the termination condition (i < rtinfo->addrnr) into the for-loop header condition and removing the backwards break at the end of the loop body.
--- net/ipv6/netfilter/ip6t_rt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
net/ipv6/netfilter/ip6t_rt.c +8 -3
@@ -96,7 +96,8 @@ static bool rt_mt6(const struct sk_buffunsigned int i =0 ;for (temp =0 ; - temp < (unsigned int )((hdrlen -8 ) /16 ); + temp < (unsigned int )((hdrlen -8 ) /16 ) && + i < rtinfo->addrnr; temp++) { ap =skb_header_pointer (skb, ptr
@@ -112,8 +113,6 @@ static bool rt_mt6(const struct sk_buffif (ipv6_addr_equal (ap, &rtinfo->addrs[i])) i++; -if (i == rtinfo->addrnr) -break ; }if (i == rtinfo->addrnr)return ret;
@@ -162,6 +161,12 @@ static int rt_mt6_check(const struct xt_pr_debug ("too many addresses specified\n" );return -EINVAL ; } + +if ((rtinfo->flags &IP6T_RT_FST_MASK ) && !rtinfo->addrnr) { +pr_info_ratelimited ("address list match requested but addrnr is 0\n" ); +return -EINVAL ; + } + if ((rtinfo->flags & (IP6T_RT_RES | IP6T_RT_FST_MASK)) && (!(rtinfo->flags & IP6T_RT_TYP) || (rtinfo->rt_type != 0) ||
Greg Kroah-Hartman
maintainerPATCH 520/877 netfilter: nf_tables: skip expired catchall elements on insert and delete
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aohan Mei <[email protected]>
commit 70194dc37670bd08e44b471389861cc01bd3a3c9 upstream.
nft_setelem_catchall_insert() looks up duplicates with nft_set_elem_active() only, while nft_set_catchall_lookup() and the dump path additionally skip expired elements.
Once a catchall element with a timeout expires, this predicate drift makes it invisible to userspace dumps, yet it still blocks
re-insertion: with NLM_F_EXCL the request fails with -EEXIST, and without it the request reports success but silently inserts nothing. The stale entry only goes away when the (user-tunable) gc interval elapses, so the catchall rule may silently stop matching for an arbitrarily long time after its first expiration.
The delete path shows the same drift: nft_setelem_catchall_deactivate() picks the first active-next entry in the catchall list, so with an expired entry still pending GC it retires the stale entry instead of the fresh one, and it deactivates an element that userspace no longer sees instead of failing with -ENOENT.
Align both walks with the lookup and dump predicates: only an element that is active and not expired counts as a duplicate or delete candidate, using the per-netns timestamp taken at transaction start, in line with the set backend .insert/.deactivate and catchall GC sync paths.
--- net/netfilter/nf_tables_api.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +8 -2
@@ -6617,11 +6617,14 @@ static int nft_setelem_catchall_insert(c {struct nft_set_elem_catchall *catchall;u8 genmask =nft_genmask_next (net); +u64 tstamp =nft_net_tstamp (net);struct nft_set_ext *ext;list_for_each_entry (catchall, &set->catchall_list, list) { ext =nft_set_elem_ext (set, catchall->elem); -if (nft_set_elem_active (ext, genmask)) { +if (nft_set_elem_active (ext, genmask) && + !__nft_set_elem_expired (ext, tstamp) && + !nft_set_elem_is_dead (ext)) { *priv = catchall->elem;return -EEXIST ; }
@@ -6682,11 +6685,14 @@ static int nft_setelem_catchall_deactiva struct nft_set_elem *elem) {struct nft_set_elem_catchall *catchall; +u64 tstamp =nft_net_tstamp (net);struct nft_set_ext *ext;list_for_each_entry (catchall, &set->catchall_list, list) { ext =nft_set_elem_ext (set, catchall->elem); -if (!nft_is_active_next (net, ext)) +if (!nft_is_active_next (net, ext) || +__nft_set_elem_expired (ext, tstamp) || +nft_set_elem_is_dead (ext))continue ;kfree (elem->priv);
Greg Kroah-Hartman
maintainerPATCH 521/877 nfc: fix use-after-free in nfc_get_local_general_bytes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit dcab71a7011918f6fdba7adcec02d217dcb84b8d upstream.
Commit 6709d4b7bc2e ("net: nfc: Fix use-after-free caused by nfc_llcp_find_local") attempted to fix a use-after-free (UAF) issue by invoking nfc_llcp_local_put(local) after accessing local->gb. However, if the reference count drops to zero, local is freed immediately, leading to a use-after-free when callers access the returned pointer. Alternative approaches using dynamic allocation (e.g. kmemdup) introduced memory leaks because callers consistently treat the returned pointer as borrowed memory.
Fix this properly by refactoring nfc_llcp_general_bytes() and nfc_get_local_general_bytes() to accept a caller-provided output buffer (out_gb) and its maximum length (gb_max_len). The general bytes are safely copied into out_gb before calling nfc_llcp_local_put(local), ensuring safe lifetime management without ownership transfer complications.
Update all callers across drivers (microread, pn533, pn544, st21nfca, digital_dep, and nci) to provide their own destination buffers and pass them to nfc_get_local_general_bytes().
--- drivers/nfc/microread/microread.c | 6 +++--- drivers/nfc/pn533/pn533.c | 14 ++++++++------ drivers/nfc/pn533/pn533.h | 4 +++- drivers/nfc/pn544/pn544.c | 7 +++---- drivers/nfc/st21nfca/core.c | 8 ++++---- include/net/nfc/hci.h | 2 +- include/net/nfc/nfc.h | 3 ++- net/nfc/core.c | 15 +++++++-------- net/nfc/digital_dep.c | 8 ++++---- net/nfc/llcp_core.c | 17 +++++++++++++---- net/nfc/nci/core.c | 10 +++++----- net/nfc/nfc.h | 3 ++- 12 files changed, 55 insertions(+), 42 deletions(-)
drivers/nfc/microread/microread.c +3 -3
@@ -251,9 +251,9 @@ static int microread_start_poll(struct n param[1 ] |= (1 <<1 );if ((im_protocols | tm_protocols) &NFC_PROTO_NFC_DEP_MASK ) { - hdev->gb =nfc_get_local_general_bytes (hdev->ndev, - &hdev->gb_len); -if (hdev->gb ==NULL || hdev->gb_len ==0 ) { +nfc_get_local_general_bytes (hdev->ndev, hdev->gb, +sizeof (hdev->gb), &hdev->gb_len); +if (hdev->gb_len ==0 ) { im_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; }
drivers/nfc/pn533/pn533.c +8 -6
@@ -1355,10 +1355,11 @@ static int pn533_poll_dep(struct nfc_devu8 *next, nfcid3[NFC_NFCID3_MAXSIZE ];u8 passive_data[PASSIVE_DATA_LEN ] = {0x00 ,0xff ,0xff ,0x00 ,0x3 }; -if (!dev->gb) { - dev->gb =nfc_get_local_general_bytes (nfc_dev, &dev->gb_len); - -if (!dev->gb || !dev->gb_len) { +if (!dev->gb_len) { +nfc_get_local_general_bytes (nfc_dev, dev->gb, +sizeof (dev->gb), + &dev->gb_len); +if (!dev->gb_len) { dev->poll_dep =0 ;queue_work (dev->wq, &dev->rf_work); }
@@ -1660,8 +1661,9 @@ static int pn533_start_poll(struct nfc_d }if (tm_protocols) { - dev->gb =nfc_get_local_general_bytes (nfc_dev, &dev->gb_len); -if (dev->gb ==NULL ) +nfc_get_local_general_bytes (nfc_dev, dev->gb, +sizeof (dev->gb), &dev->gb_len); +if (dev->gb_len ==0 ) tm_protocols =0 ; }
drivers/nfc/pn533/pn533.h +3 -1
@@ -6,6 +6,8 @@* Copyright (C) 2012-2013 Tieto Poland */ +#include <net/nfc/nfc.h> +#define PN533_DEVICE_STD 0x1#define PN533_DEVICE_PASORI 0x2#define PN533_DEVICE_ACR122U 0x3
@@ -166,7 +168,7 @@ struct pn533 {struct timer_list listen_timer;int cancel_listen; -u8 *gb; +u8 gb[NFC_MAX_GT_LEN ];size_t gb_len;u8 tgt_available_prots;
drivers/nfc/pn544/pn544.c +3 -4
@@ -377,10 +377,9 @@ static int pn544_hci_start_poll(struct nreturn r;if ((im_protocols | tm_protocols) &NFC_PROTO_NFC_DEP_MASK ) { - hdev->gb =nfc_get_local_general_bytes (hdev->ndev, - &hdev->gb_len); -pr_debug ("generate local bytes %p\n" , hdev->gb); -if (hdev->gb ==NULL || hdev->gb_len ==0 ) { +nfc_get_local_general_bytes (hdev->ndev, hdev->gb, +sizeof (hdev->gb), &hdev->gb_len); +if (hdev->gb_len ==0 ) { im_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; }
drivers/nfc/st21nfca/core.c +4 -4
@@ -351,10 +351,10 @@ static int st21nfca_hci_start_poll(strucif (r <0 )return r; }else { - hdev->gb =nfc_get_local_general_bytes (hdev->ndev, - &hdev->gb_len); - -if (hdev->gb ==NULL || hdev->gb_len ==0 ) { +nfc_get_local_general_bytes (hdev->ndev, hdev->gb, +sizeof (hdev->gb), + &hdev->gb_len); +if (hdev->gb_len ==0 ) { im_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; }
include/net/nfc/hci.h +1 -1
@@ -144,7 +144,7 @@ struct nfc_hci_dev {data_exchange_cb_t async_cb;void *async_cb_context; -u8 *gb; +u8 gb[NFC_MAX_GT_LEN ];size_t gb_len;unsigned long quirks;
include/net/nfc/nfc.h +2 -1
@@ -269,7 +269,8 @@ struct sk_buff *nfc_alloc_recv_skb(unsigint nfc_set_remote_general_bytes (struct nfc_dev *dev,const u8 *gt,u8 gt_len); -u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,size_t *gb_len); +u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *out_gb, +size_t gb_max_len,size_t *gb_len);int nfc_fw_download_done (struct nfc_dev *dev,const char *firmware_name,u32 result);
net/nfc/core.c +7 -8
@@ -279,10 +279,10 @@ static struct nfc_target *nfc_find_targeint nfc_dep_link_up (struct nfc_dev *dev,int target_index,u8 comm_mode) { -int rc =0 ; -u8 *gb; -size_t gb_len;struct nfc_target *target; +u8 gb[NFC_MAX_GT_LEN ]; +size_t gb_len =0 ; +int rc =0 ;pr_debug ("dev_name=%s comm %d\n" ,dev_name (&dev->dev), comm_mode);
@@ -301,7 +301,7 @@ int nfc_dep_link_up(struct nfc_dev *dev, goto error; } - gb =nfc_llcp_general_bytes (dev, &gb_len); +nfc_get_local_general_bytes (dev, gb,sizeof (gb), &gb_len);if (gb_len >NFC_MAX_GT_LEN ) { rc = -EINVAL ; goto error;
@@ -644,11 +644,10 @@ int nfc_set_remote_general_bytes(struct }EXPORT_SYMBOL (nfc_set_remote_general_bytes); -u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,size_t *gb_len) +u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *out_gb, +size_t gb_max_len,size_t *gb_len) { -pr_debug ("dev_name=%s\n" ,dev_name (&dev->dev)); - -return nfc_llcp_general_bytes (dev, gb_len); +return nfc_llcp_general_bytes (dev, out_gb, gb_max_len, gb_len); }EXPORT_SYMBOL (nfc_get_local_general_bytes);
net/nfc/digital_dep.c +4 -4
@@ -1490,14 +1490,14 @@ static int digital_tg_send_atr_res(struc struct digital_atr_req *atr_req) {struct digital_atr_res *atr_res; +u8 gb[NFC_MAX_GT_LEN ];struct sk_buff *skb; -u8 *gb, payload_bits; +u8 payload_bits;size_t gb_len;int rc; - gb =nfc_get_local_general_bytes (ddev->nfc_dev, &gb_len); -if (!gb) - gb_len =0 ; +nfc_get_local_general_bytes (ddev->nfc_dev, gb,sizeof (gb), + &gb_len); skb =digital_skb_alloc (ddev,sizeof (struct digital_atr_res ) + gb_len);if (!skb)
net/nfc/llcp_core.c +13 -4
@@ -651,23 +651,32 @@ out:return ret; } -u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,size_t *general_bytes_len) +u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,u8 *out_gb,size_t gb_max_len, +size_t *general_bytes_len) {struct nfc_llcp_local *local; +if (!out_gb || !general_bytes_len) +return NULL ; + local =nfc_llcp_find_local (dev); -if (local ==NULL ) { +if (!local) { *general_bytes_len =0 ;return NULL ; }nfc_llcp_build_gb (local); - *general_bytes_len = local->gb_len; +if (local->gb_len) { + *general_bytes_len =min_t (size_t, local->gb_len, gb_max_len); +memcpy (out_gb, local->gb, *general_bytes_len); + }else { + *general_bytes_len =0 ; + }nfc_llcp_local_put (local); -return local->gb; +return out_gb; }int nfc_llcp_set_remote_gb (struct nfc_dev *dev,const u8 *gb,u8 gb_len)
net/nfc/nci/core.c +5 -5
@@ -772,15 +772,15 @@ static int nci_set_local_general_bytes(s {struct nci_dev *ndev =nfc_get_drvdata (nfc_dev);struct nci_set_config_param param; +u8 gb[NFC_MAX_GT_LEN ];int rc; - param.val =nfc_get_local_general_bytes (nfc_dev, ¶m.len); -if ((param.val ==NULL ) || (param.len ==0 )) +nfc_get_local_general_bytes (nfc_dev, gb,sizeof (gb), + ¶m.len); +if (param.len ==0 )return 0 ; -if (param.len >NFC_MAX_GT_LEN ) -return -EINVAL ; - + param.val = gb; param.id =NCI_PN_ATR_REQ_GEN_BYTES ; rc = nci_request(ndev, nci_set_config_req, ¶m,
net/nfc/nfc.h +2 -1
@@ -49,7 +49,8 @@ void nfc_llcp_mac_is_up(struct nfc_dev *int nfc_llcp_register_device (struct nfc_dev *dev);void nfc_llcp_unregister_device (struct nfc_dev *dev);int nfc_llcp_set_remote_gb (struct nfc_dev *dev,const u8 *gb,u8 gb_len); -u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,size_t *general_bytes_len); +u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,u8 *out_gb,size_t gb_max_len, +size_t *general_bytes_len);int nfc_llcp_data_received (struct nfc_dev *dev,struct sk_buff *skb);struct nfc_llcp_local *nfc_llcp_find_local (struct nfc_dev *dev);int nfc_llcp_local_put (struct nfc_llcp_local *local);
Greg Kroah-Hartman
maintainerPATCH 522/877 nfc: llcp: drop truncated I/RR/RNR PDUs in nfc_llcp_recv_hdlc()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
commit 273f9d667cde649f8de9d72b1303cc2f4b658c50 upstream.
nfc_llcp_recv_hdlc() reads the sequence byte skb->data[2], via nfc_llcp_ns()/nfc_llcp_nr(), before any length check. The receive path only guarantees the two-byte LLCP header -- __nfc_llcp_recv() checks it with pskb_may_pull() and nfc_llcp_recv_agf() admits two-byte inner PDUs -- so a two-byte I, RR or RNR PDU reads one byte of uninitialised skb tailroom. The byte becomes N(R)/N(S); a peer can already set those with a well-formed PDU, so this is acting on uninitialised memory, not new peer control.
Guard the read with pskb_may_pull(), as commit 95674f506c63 ("nfc: llcp:
reject PDUs shorter than the LLCP header") did for the two-byte header, so the sequence byte is present and linear before it is read. RR and RNR PDUs are LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE bytes and an I PDU is longer, so no valid frame is rejected; a truncated PDU is malformed, so return without a DM reply.
--- net/nfc/llcp_core.c | 3 +++ 1 file changed, 3 insertions(+)
net/nfc/llcp_core.c +3 -0
@@ -1099,6 +1099,9 @@ static void nfc_llcp_recv_hdlc(struct nfstruct sock *sk;u8 dsap, ssap, ptype, ns, nr; +if (!pskb_may_pull (skb,LLCP_HEADER_SIZE +LLCP_SEQUENCE_SIZE )) +return ; + ptype =nfc_llcp_ptype (skb); dsap =nfc_llcp_dsap (skb); ssap =nfc_llcp_ssap (skb);
Greg Kroah-Hartman
maintainerPATCH 523/877 nfc: port100: reject frames whose declared length exceeds the received data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 092c6a605cbd6414ef499834c2e0da69c2c3388e upstream.
port100_recv_response() passes the URB transfer buffer to port100_rx_frame_is_valid(), which checksums le16_to_cpu(frame->datalen) bytes of frame->data. datalen is a 16-bit field supplied by the device and is never checked against the number of bytes actually received (urb->actual_length), so a device reporting a datalen larger than the received frame makes port100_data_checksum() read out of bounds past the transfer buffer.
Reject a response whose declared frame size does not fit the received length before validating it.
Found by 0sec (https://0sec.ai) using automated source analysis; the missing bound is evident from source. Compile-tested.
--- drivers/nfc/port100.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/nfc/port100.c +7 -0
@@ -636,6 +636,13 @@ static void port100_recv_response(struct in_frame = dev->in_urb->transfer_buffer; +if (urb->actual_length <PORT100_FRAME_HEADER_LEN || + urb->actual_length <port100_rx_frame_size (in_frame)) { +nfc_err (&dev->interface->dev,"Received a truncated frame\n" ); + cmd->status = -EIO ; + goto sched_wq; + } +if (!port100_rx_frame_is_valid (in_frame)) {nfc_err (&dev->interface->dev,"Received an invalid frame\n" ); cmd->status = -EIO ;
Greg Kroah-Hartman
maintainerPATCH 524/877 scsi: libiscsi_tcp: Check the data direction of a Data-In PDU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
commit bce07e2f37b5e4a427d36fd6b1c14067b27591db upstream.
The Data-In branch of iscsi_tcp_hdr_dissect() resolves the ITT to a task and copies the PDU's data segment into that command's scatterlist without asking whether the command was reading. iscsi_tcp_r2t_rsp() in the same file does ask, and rejects an R2T for a command that is not DMA_TO_DEVICE.
A target that answers a WRITE command's ITT with a Data-In therefore has the initiator write target-supplied bytes into the pages that write was about to send. Those are the caller's own pinned pages for an O_DIRECT write, and page cache pages for a buffered one.
Observed against a test target that emits one 512-byte Data-In naming a 128 KB write's ITT, after the R2T for that write. With O_DIRECT the caller's buffer ends up holding 512 bytes of the target's data while pwrite() returns 131072. Buffered is quieter: pwrite() and fsync() both succeed, nothing is logged, and reading those blocks back returns the target's bytes out of the page cache without a command going on the wire.
Check the direction before using the scatterlist, the way the R2T path already does.
--- drivers/scsi/libiscsi_tcp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/libiscsi_tcp.c +3 -0
@@ -491,6 +491,9 @@ static int iscsi_tcp_data_in(struct iscsint datasn =be32_to_cpu (rhdr->datasn);unsigned total_in_length = task->sc->sdb.length; +if (task->sc->sc_data_direction !=DMA_FROM_DEVICE ) +return ISCSI_ERR_PROTO ; +/* * lib iscsi will update this in the completion handling if there * is status.
Greg Kroah-Hartman
maintainerPATCH 525/877 perf/core: Fix NULL pmu_ctx passed to pmu->sched_task()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Puranjay Mohan <[email protected]>
commit 36bb85cf36cab15fb611cb44b78a5df06e4e69a2 upstream.
perf_pmu_sched_task() returns early when cpuctx->task_ctx is set, and cpc->task_epc is only non-NULL while a task context is scheduled in on this CPU. __perf_pmu_sched_task() therefore always passes NULL:
Unable to handle kernel NULL pointer dereference at virtual address 00 pc : armv8pmu_sched_task+0x14/0x50 Call trace: armv8pmu_sched_task+0x14/0x50 (P) perf_pmu_sched_task+0xac/0x108 __perf_event_task_sched_out+0x6c/0xe0
Pass &cpc->epc instead, the CPU-wide context for this PMU, which the function already dereferences a few lines up to find pmu.
armv8pmu_sched_task() is the only in-tree implementation that dereferences the argument, and it only reads ->pmu, so the oops needs BRBE, added in v6.17.
--- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/events/core.c +1 -1
@@ -3754,7 +3754,7 @@ static void __perf_pmu_sched_task(structperf_ctx_lock (cpuctx, cpuctx->task_ctx);perf_pmu_disable (pmu); - pmu->sched_task (cpc->task_epc, task, sched_in); + pmu->sched_task (&cpc->epc, task, sched_in);perf_pmu_enable (pmu);perf_ctx_unlock (cpuctx, cpuctx->task_ctx);
Greg Kroah-Hartman
maintainerPATCH 526/877 perf/core: Run sched_task() for PMUs with only CPU-wide events
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Puranjay Mohan <[email protected]>
commit 3d8d74100954a3b17e5c5e37adfe14e16b1db103 upstream.
perf_pmu_sched_task() returns early when cpuctx->task_ctx is set and leaves the work to perf_ctx_sched_task_cb(), which only walks ctx->pmu_ctx_list. A PMU whose events are all CPU-wide is not on that list, so nothing calls its sched_task(). With
perf record -b -e cycles -a -- ls
armv8pmu_sched_task() is skipped on every switch to a task that has a perf context but no event on that PMU, and BRBE records leak across the task boundary. intel_pmu_lbr_add() calls perf_sched_cb_inc() unconditionally too, so LBR records leak the same way on x86.
Drop the early return and skip only the CPCs that perf_ctx_sched_task_cb() handles. That one needs a gate of its own to make the split exact: it tests cpc->sched_cb_usage, which perf_sched_cb_inc() sets per CPU for every branch stack user, so a task with an event for that PMU pinned to another CPU would be handled twice. On x86 the second __intel_pmu_lbr_restore() finds lbr_stack_state == LBR_NONE and calls intel_pmu_lbr_reset(), throwing away the callstack the first one restored.
cpc->task_epc is set only while a task context is scheduled in, and there is one epc per PMU on ctx->pmu_ctx_list, so the two gates are inverses.
For the CPCs perf_pmu_sched_task() picks up, the callback now runs outside the perf_ctx_disable() and perf_ctx_enable() pair in perf_event_context_sched_in(). __perf_pmu_sched_task() disables the PMU around the call itself.
--- kernel/events/core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
kernel/events/core.c +9 -4
@@ -3603,6 +3603,9 @@ static void perf_ctx_sched_task_cb(struclist_for_each_entry (pmu_ctx, &ctx->pmu_ctx_list, pmu_ctx_entry) { cpc =this_cpu_ptr (pmu_ctx->pmu->cpu_pmu_context); +if (cpc->task_epc != pmu_ctx) +continue ; +if (cpc->sched_cb_usage && pmu_ctx->pmu->sched_task) pmu_ctx->pmu->sched_task (pmu_ctx, task, sched_in); }
@@ -3764,15 +3767,17 @@ static void perf_pmu_sched_task(struct t struct task_struct *next, bool sched_in) { -struct perf_cpu_context *cpuctx =this_cpu_ptr (&perf_cpu_context);struct perf_cpu_pmu_context *cpc, *cpc2; -/* cpuctx->task_ctx will be handled in perf_event_context_sched_in/out */ -if (prev == next || cpuctx->task_ctx) +if (prev == next)return ; -list_for_each_entry_safe (cpc, cpc2,this_cpu_ptr (&sched_cb_list), sched_cb_entry) +list_for_each_entry_safe (cpc, cpc2,this_cpu_ptr (&sched_cb_list), sched_cb_entry) { +if (cpc->task_epc) +continue ; +__perf_pmu_sched_task (cpc, sched_in ? next : prev, sched_in); + } } static void perf_event_switch(struct task_struct *task,
Greg Kroah-Hartman
maintainerPATCH 527/877 pinctrl: single: free the IRQ on domain creation failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 1d9bb9c870632adea249cfdec49ac37e6f069164 upstream.
pcs_irq_init_chained_handler() requests a shared IRQ on affected SoCs, but its domain creation failure path only removes a chained handler. That does not release the action installed by request_irq(). The probe can continue without interrupt support while leaving the shared IRQ action registered.
Use pcs_irq_free() to undo the appropriate type of handler registration. At this point pcs->domain is NULL, so the helper only releases the parent IRQ handler. Then mark the IRQ invalid, as the other initialization error paths already do, to prevent another release from a later probe unwind or remove.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/pinctrl/pinctrl-single.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-single.c +2 -1
@@ -1626,7 +1626,8 @@ static int pcs_irq_init_chained_handler( &pcs_irqdomain_ops, pcs_soc);if (!pcs->domain) { -irq_set_chained_handler (pcs_soc->irq,NULL ); +pcs_irq_free (pcs); + pcs_soc->irq =-1 ;return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 528/877 pinctrl: sunxi: keep a shadow copy of the data register output latches
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Titov <[email protected]>
commit a13f7f5d14af9baf34eb12c25962f8d3542b281d upstream.
On Allwinner SoCs, reading a bank's data register returns the pin level, not the output latch, for pins that are muxed as inputs. Writing a GPIO therefore corrupts the output latches of all input-muxed pins in the same bank: the read-modify-write in sunxi_pinctrl_gpio_set() reads back their pin levels and writes those into their latches.
This breaks emulated open-drain lines (e.g. a bit-banged I2C bus from i2c-gpio). Such a line is released high by muxing it as input and letting the pull-up raise it, so any concurrent GPIO write in the same bank stores 1 into its latch. Driving the line low afterwards is a non-atomic data-then-mux sequence in sunxi_pinctrl_gpio_direction_output(); if the poisoning write lands between the two steps, the pin actively drives high (push-pull) instead of low.
Observed in practice as sporadic glitches on a T507 board bit-banging I2C on port E while other PE GPIOs are toggled. On a scope the failure is unmistakable: on a clock pulse where SCL should fall to GND, the line instead steps *above* its idle high level for the whole low phase — the pad drives a strong push-pull 3.3 V high, higher than the level the pull-up sustains on the loaded bus — before the next transition recovers it. The same can hit SDA, corrupting data instead of clocks.
Steps to reproduce on any sunxi board with a bit-banged (i2c-gpio) bus:
# background: toggle any other GPIO of the same bank, e.g. line 21 gpioset -c <chip> --toggle 100us 21=0 &
# foreground: keep the bit-banged bus busy
while :; do i2cdetect -y <bus> 0x50 0x57; done
# watch SCL/SDA with a scope or logic analyzer: sporadic clock-low # phases driven high (above the pull-up level) instead of low
The bank spinlock cannot help: the racing write is a perfectly valid whole-register RMW that faithfully writes back what the hardware returned. There are no set/clear registers on this IP to write a single bit atomically.
Fix it the same way gpio-mmio handles hardware whose data register read does not return the output latch: keep a shadow copy of each bank's latches, base the read-modify-write on the shadow, and only write the register. The shadow is seeded from the hardware at probe time so pins left in output mode by the bootloader keep their state. Pins that reach output mode through the gpiolib paths write their value (and thereby their shadow bit) before the mux switch in sunxi_pinctrl_gpio_direction_output(); pins muxed to gpio_out directly through a pinmux node bypass that path, so sunxi_pmx_set() refreshes their shadow bit from the latch (readable once the pin is in output mode) to keep them driving their pre-existing level.
Seeding the shadow reads the PIO registers at probe time, which requires the bus clock to be enabled. The clock was only requested at the very end of probe, after devm_pinctrl_register() had already claimed the pin hogs described in the device tree - which mux pins, and thus access registers, with the clock still gated. Move the request ahead of both. Boards whose bootloader leaves the PIO clock running are unaffected, which is why the pre-existing hog problem has gone unnoticed since commit 950707c0eb5c ("pinctrl: sunxi: add clock support").
--- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 76 +++++++++++++++++++++++++++------- drivers/pinctrl/sunxi/pinctrl-sunxi.h | 7 +++ 2 files changed, 68 insertions(+), 15 deletions(-)
drivers/pinctrl/sunxi/pinctrl-sunxi.c +61 -15
@@ -792,6 +792,21 @@ static void sunxi_pmx_set(struct pinctrlwritel ((readl (pctl->membase + reg) & ~mask) | config << shift, pctl->membase + reg); +/* +* A pin muxed to gpio_out directly through a pinmux node bypasses +* sunxi_pinctrl_gpio_set() and drives whatever its output latch +* holds. Now that the pin is in output mode the data register +* reads back the latch, so refresh the shadow to keep such pins +* driving their pre-existing level. +*/ +if (config ==SUN4I_FUNC_OUTPUT ) { +u32 *shadow = &pctl->dat_shadow[pin /PINS_PER_BANK ]; + +sunxi_data_reg (pctl, pin, ®, &shift, &mask); + *shadow = (*shadow & ~mask) | + (readl (pctl->membase + reg) & mask); + } +raw_spin_unlock_irqrestore (&pctl->lock, flags); }
@@ -948,21 +963,29 @@ static void sunxi_pinctrl_gpio_set(struc unsigned offset, int value) {struct sunxi_pinctrl *pctl =gpiochip_get_data (chip); -u32 reg, shift, mask, val; +u32 *shadow = &pctl->dat_shadow[offset /PINS_PER_BANK ]; +u32 reg, shift, mask;unsigned long flags;sunxi_data_reg (pctl, offset, ®, &shift, &mask);raw_spin_lock_irqsave (&pctl->lock, flags); - val =readl (pctl->membase + reg); - +/* +* Reading the data register returns the pin level, not the output +* latch, for pins muxed as inputs. A read-modify-write based on +* the register would therefore corrupt the latches of input-muxed +* pins in the same bank (e.g. an emulated open-drain I2C line +* released high), making them drive the wrong level once switched +* to output. Base the read-modify-write on a shadow copy of the +* latches instead. +*/ if (value) - val |= mask; + *shadow |= mask;else - val &= ~mask; + *shadow &= ~mask; -writel (val, pctl->membase + reg); +writel (*shadow, pctl->membase + reg);raw_spin_unlock_irqrestore (&pctl->lock, flags); }
@@ -1486,7 +1509,7 @@ int sunxi_pinctrl_init_with_variant(strustruct pinctrl_pin_desc *pins;struct sunxi_pinctrl *pctl;struct pinmux_ops *pmxops; -int i, ret, last_pin, pin_idx; +int i, ret, last_pin, pin_idx, nbanks;struct clk *clk; pctl =devm_kzalloc (&pdev->dev,sizeof (*pctl),GFP_KERNEL );
@@ -1520,6 +1543,37 @@ int sunxi_pinctrl_init_with_variant(struif (!pctl->irq_array)return -ENOMEM ; +/* +* The bus clock has to be enabled before the pinctrl device +* registers, as the pin hogs claimed from there access registers. +*/ + ret =of_clk_get_parent_count (node); + clk =devm_clk_get_enabled (&pdev->dev, ret ==1 ?NULL :"apb" ); +if (IS_ERR (clk)) +return PTR_ERR (clk); + +/* +* Seed the output latch shadow from the hardware so pins the +* bootloader left in output mode keep their state; see +* sunxi_pinctrl_gpio_set() for why a shadow is needed. This must +* happen before the pinctrl device registers, as pin hogs can mux +* pins to gpio_out and thereby update the shadow. +*/ + last_pin = pctl->desc->pins[pctl->desc->npins -1 ].pin.number; + nbanks =DIV_ROUND_UP (last_pin +1 - pctl->desc->pin_base, +PINS_PER_BANK ); + pctl->dat_shadow =devm_kcalloc (&pdev->dev, nbanks, +sizeof (*pctl->dat_shadow),GFP_KERNEL ); +if (!pctl->dat_shadow) +return -ENOMEM ; + +for (i =0 ; i < nbanks; i++) { +u32 reg, shift, mask; + +sunxi_data_reg (pctl, i *PINS_PER_BANK , ®, &shift, &mask); + pctl->dat_shadow[i] =readl (pctl->membase + reg); + } + ret =sunxi_pinctrl_build_state (pdev);if (ret) {dev_err (&pdev->dev,"dt probe failed: %d\n" , ret);
@@ -1574,7 +1628,6 @@ int sunxi_pinctrl_init_with_variant(struif (!pctl->chip)return -ENOMEM ; - last_pin = pctl->desc->pins[pctl->desc->npins -1 ].pin.number; pctl->chip->owner =THIS_MODULE ; pctl->chip->request = gpiochip_generic_request; pctl->chip->free = gpiochip_generic_free;
@@ -1607,13 +1660,6 @@ int sunxi_pinctrl_init_with_variant(stru goto gpiochip_error; } - ret =of_clk_get_parent_count (node); - clk =devm_clk_get_enabled (&pdev->dev, ret ==1 ?NULL :"apb" ); -if (IS_ERR (clk)) { - ret =PTR_ERR (clk); - goto gpiochip_error; - } - pctl->irq = devm_kcalloc(&pdev->dev, pctl->desc->irq_banks, sizeof(*pctl->irq),
drivers/pinctrl/sunxi/pinctrl-sunxi.h +7 -0
@@ -80,6 +80,7 @@#define IO_BIAS_MASK GENMASK(3, 0)#define SUN4I_FUNC_INPUT 0 +#define SUN4I_FUNC_OUTPUT 1#define SUN4I_FUNC_IRQ 6#define PINCTRL_SUN5I_A10S BIT(1)
@@ -173,6 +174,12 @@ struct sunxi_pinctrl {int *irq;unsigned *irq_array;raw_spinlock_t lock; +/* +* Output latch shadow, one word per bank. Seeded lockless at +* probe before the pinctrl device registers, protected by @lock +* afterwards. +*/ +u32 *dat_shadow;struct pinctrl_dev *pctl_dev;unsigned long variant;u32 bank_mem_size;
Greg Kroah-Hartman
maintainerPATCH 529/877 s390/cio: Fix NULL pointer dereference in ccw_device_get_util_str()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
commit 5b76268dac968612f7283d59b539036de955b7d9 upstream.
The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.
Add the missing NULL check before dereferencing the returned pointer.
--- drivers/s390/cio/device_ops.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/s390/cio/device_ops.c +2 -0
@@ -517,6 +517,8 @@ u8 *ccw_device_get_util_str(struct ccw_dchp_id_init (&chpid); chpid.id = sch->schib.pmcw.chpid[chp_idx]; chp =chpid_to_chp (chpid); +if (!chp) +return NULL ; util_str =kmalloc (sizeof (chp->desc_fmt3.util_str),GFP_KERNEL );if (!util_str)
Greg Kroah-Hartman
maintainerPATCH 530/877 s390/cmf: Fix virtual vs physical address confusion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Oberparleiter <[email protected]>
commit f4d04425e66af2ecee9d1a49ae0484436f3c2fd1 upstream.
The measurement block address is an absolute address. Define the associated schib_config and schib fields as dma64_t to enable automatic detection of incorrect assignments. Also add the missing virt_to_dma64() translation.
Without this fix, a wrong address will be used by firmware when storing extended format channel measurement data on kernels built with CONFIG_RANDOMIZE_IDENTITY_BASE=y.
--- drivers/s390/cio/cio.h | 5 +++-- drivers/s390/cio/cmf.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/s390/cio/cio.h +3 -2
@@ -7,6 +7,7 @@#include <linux/mod_devicetable.h> #include <asm/chpid.h> #include <asm/cio.h> +#include <asm/dma-types.h> #include <asm/fcx.h> #include <asm/schid.h> #include <asm/tpi.h>
@@ -49,7 +50,7 @@ struct pmcw {/* Target SCHIB configuration. */ struct schib_config { -u64 mba; +dma64_t mba;u32 intparm;u16 mbi;u32 isc:3 ;
@@ -66,7 +67,7 @@ struct schib_config {struct schib {struct pmcw pmcw;/* path management control word */ union scsw scsw;/* subchannel status word */ -__u64 mba;/* measurement block address */ +dma64_t mba;/* measurement block address */ __u8 mda[4 ];/* model dependent area */ } __attribute__ ((packed,aligned (4 )));
drivers/s390/cio/cmf.c +1 -1
@@ -184,7 +184,7 @@ static int set_schib(struct ccw_device * sch->config.mbfc = mbfc;/* address can be either a block address or a block index */ if (mbfc) - sch->config.mba = address; + sch->config.mba = address ?virt_to_dma64 ((void *)address) :0 ;else sch->config.mbi = address;
Greg Kroah-Hartman
maintainerPATCH 531/877 s390/vfio-ap: fix KVM GISC and page leak when queue removed from host config
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 65e05ec252a9b79e75930d3c4dd42d8877db04c5 upstream.
Three related problems exist in the handling of KVM interrupt and page resources when a queue is removed from the host's AP configuration while assigned to a mediated device (mdev).
Problem 1:
~~~~~~~~~AP_RESPONSE_Q_NOT_AVAIL not handled in vfio_ap_mdev_reset_queue()
When the AP bus removes a queue device whose adapter or domain has been removed from the host's AP configuration, vfio_ap_mdev_remove_queue() is called. If the queue is still in the host's AP configuration at that point, it calls vfio_ap_mdev_reset_queue(), which issues a PQAP(ZAPQ). Since the adapter is already gone from the host configuration, ap_zapq() returns AP_RESPONSE_Q_NOT_AVAIL (0x01). This response code is not handled in vfio_ap_mdev_reset_queue()'s switch statement and falls through to the default case, which issues a WARN but does not call vfio_ap_free_aqic_resources(). As a result, if IRQ handling was enabled for the queue by the guest, the KVM GISC registration and the pinned guest page holding the notification indicator byte (NIB) are both leaked.
This is fixed by adding AP_RESPONSE_Q_NOT_AVAIL to the same case as AP_RESPONSE_DECONFIGURED and AP_RESPONSE_CHECKSTOPPED in vfio_ap_mdev_reset_queue(). Like those response codes, Q_NOT_AVAIL indicates the queue is not operational and no further reset attempts are possible; the correct action is to free the IRQ resources immediately.
Problem 2:
~~~~~~~~~
AP_RESPONSE_Q_NOT_AVAIL not handled in apq_status_check()
In vfio_ap_mdev_reset_queue(), there are four cases that indicate a queue reset has not yet completed, in which case apq_reset_check() is queued to a work queue to verify completion of the reset operation. This function uses the PQAP(TAPQ) function to get the queue's status and calls apq_status_check() to verify whether the reset has completed, failed or needs to be executed again. As described in Problem #1 above, apq_reset_check() does not specifically check for AP_RESPONSE_Q_NOT_AVAIL, thereby potentially leaking KVM GISC registration and the pinned guest page holding the NIB.
This is fixed by adding a case statement for AP_RESPONSE_Q_NOT_AVAIL to apq_status_check() and returning -ENODEV for that case. The caller, apq_reset_check() will then check for this return code and call vfio_ap_free_aqic_resources() to prevent the leak.
Problem 3:
~~~~~~~~~vfio_ap_free_aqic_resources() leaks saved_isc when kvm is NULL
vfio_ap_free_aqic_resources() guards the call tokvm_s390_gisc_unregister() with:
if (q->saved_isc != VFIO_AP_ISC_INVALID &&
!WARN_ON(!(q->matrix_mdev && q->matrix_mdev->kvm)))If matrix_mdev->kvm is NULL -- which can happen when vfio_ap_mdev_unset_kvm() has already run and cleared kvm before a subsequent cleanup path reaches this function -- the WARN_ON fires and the entire block is skipped. This leaves q->saved_isc set to a non-invalid value, creating a potential double-free on any subsequent call to this function.
When kvm is NULL the KVM guest is already torn down, so kvm_s390_gisc_unregister() need not and cannot be called; however, q->saved_isc must always be cleared. Fix this by separating the kvm_s390_gisc_unregister() call from the q->saved_isc reset. The WARN_ON now guards only the genuinely impossible case of matrix_mdev being NULL. A NULL kvm is handled gracefully by skipping only the unregister call, and q->saved_isc = VFIO_AP_ISC_INVALID is set unconditionally whenever saved_isc was not already invalid.
Additionally, add an else clause to the host-config check in vfio_ap_mdev_remove_queue() to call vfio_ap_free_aqic_resources() directly when the queue is not in the host's AP configuration. This serves as a backstop: when the AP bus fires the driver .remove callback after an adapter is removed from the host config, the queue is by definition no longer addressable, so vfio_ap_mdev_reset_queue() would always return Q_NOT_AVAIL. The else clause handles this case directly without the unnecessary ap_zapq() call, and ensures cleanup occurs even if kvm has already been set to NULL by a prior call to vfio_ap_mdev_unset_kvm().
Message-ID: <[email protected]>
--- drivers/s390/crypto/vfio_ap_ops.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +14 -4
@@ -277,9 +277,9 @@ static void vfio_ap_free_aqic_resources( {if (!q)return ; -if (q->saved_isc !=VFIO_AP_ISC_INVALID && - !WARN_ON (!(q->matrix_mdev && q->matrix_mdev->kvm))) { -kvm_s390_gisc_unregister (q->matrix_mdev->kvm, q->saved_isc); +if (q->saved_isc !=VFIO_AP_ISC_INVALID ) { +if (!WARN_ON (!q->matrix_mdev) && q->matrix_mdev->kvm) +kvm_s390_gisc_unregister (q->matrix_mdev->kvm, q->saved_isc); q->saved_isc =VFIO_AP_ISC_INVALID ; }if (q->saved_iova && !WARN_ON (!q->matrix_mdev)) {
@@ -1926,6 +1926,8 @@ static int apq_status_check(int apqn, st* a value indicating a reset needs to be performed again. */ return -EAGAIN ; +case AP_RESPONSE_Q_NOT_AVAIL : +return -ENODEV ;default : WARN(true, "failed to verify reset of queue %02x.%04x: TAPQ rc=%u\n",
@@ -1952,6 +1954,10 @@ static void apq_reset_check(struct work_ ret =apq_status_check (q->apqn, &status);if (ret == -EIO )return ; +if (ret == -ENODEV ) { +vfio_ap_free_aqic_resources (q); +return ; + }if (ret == -EBUSY ) { pr_notice_ratelimited(WAIT_MSG, elapsed, AP_QID_CARD(q->apqn),
@@ -1995,6 +2001,7 @@ static void vfio_ap_mdev_reset_queue(strbreak ;case AP_RESPONSE_DECONFIGURED :case AP_RESPONSE_CHECKSTOPPED : +case AP_RESPONSE_Q_NOT_AVAIL :vfio_ap_free_aqic_resources (q);break ;default :
@@ -2470,12 +2477,15 @@ void vfio_ap_mdev_remove_queue(struct ap/* * If the queue is not in the host's AP configuration, then resetting * it will fail with response code 01, (APQN not valid); so, let's make -* sure it is in the host's config. +* sure it is in the host's config. If it is not, free the KVM GISC +* resources. */ if (test_bit_inv (apid, (unsigned long *)matrix_dev->info.apm) &&test_bit_inv (apqi, (unsigned long *)matrix_dev->info.aqm)) {vfio_ap_mdev_reset_queue (q);flush_work (&q->reset_work); + }else { +vfio_ap_free_aqic_resources (q); } done:
Greg Kroah-Hartman
maintainerPATCH 532/877 KVM: Ensure memory attributes xarray nodes are accounted to the callers memcg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Ballesteros <[email protected]>
commit 382e5d514b6f35bdda2ab9044b4eed23d2ec4254 upstream.
Explicitly instantiate the memory attributes xarray with XA_FLAGS_ACCOUNT to ensure that all allocations are accounted to the memcg. Frustratingly, memory allocations done in the "fastpath" do not honor the passed in gfp, even for an explicit xa_reserve(). Only the rare, slow path __xas_nomem() honors the original gfp. E.g.
xa_reserve(..., GFP_KERNEL_ACCOUNT)
|
-> ...
|
-> __xa_cmpxchg_raw()
|
-> xas_store() <== does not take @gfp
|
-> xas_create()
|
-> xas_alloc()The bug was confirmed by observing that a process in a cgroup limited to 256 MiB grew radix_tree_node slab by ~512 MiB while its memory.current stayed near 0.
--- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
@@ -1164,7 +1164,7 @@ static struct kvm *kvm_create_vm(unsignercuwait_init (&kvm->mn_memslots_update_rcuwait);xa_init (&kvm->vcpu_array);#ifdef CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES -xa_init (&kvm->mem_attr_array); +xa_init_flags (&kvm->mem_attr_array,XA_FLAGS_ACCOUNT );#endif INIT_LIST_HEAD (&kvm->gpc_list);
Greg Kroah-Hartman
maintainerPATCH 533/877 KVM: Dont treat reserved xarray entries as having memory attributes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zeng Chi <[email protected]>
commit 277d3623d99a4fc2623bfb7d191b649ca380605d upstream.
kvm_vm_set_mem_attributes() reserves an xarray entry for every gfn in the range before storing the new attributes, so that the store loop can't fail partway through. If one of the reservations fails, e.g. with -ENOMEM, the entries that were already reserved are left in the array. That is harmless as far as xa_reserve() is concerned, as the reserved entries read back as NULL via xa_load(), but it confuses the "does this range have no attributes at all" check:
if (!attrs) return !xas_find(&xas, end - 1);
A reserved entry is XA_ZERO_ENTRY, not NULL, and xas_find() returns it as present. So a leftover reservation makes KVM report that a fully shared range has attributes even though kvm_get_memory_attributes() returns none for every gfn in the range. On x86, the next time mixed-attribute tracking is recomputed for the range (memslot creation, or a later attribute change that straddles the 2MiB page), hugepage_has_attrs() treats a fully shared 2MiB range as mixed and refuses to map it with a hugepage, until userspace happens to set attributes on the range again.
Drop the shortcut and handle the !attrs case in the per-index loop, using xas_next_entry() to find the next non-NULL entry. xas_next_entry() is essentially an optimized xas_find(), so the effective change is that the !attrs lookup now goes through xas_retry() like the attrs != 0 case, i.e. reserved entries are skipped and retry entries restart the walk. Don't check the index when no entry is found, as the xarray leaves the xas index in a bogus state in that case; no entry simply means the rest of the range has no attributes.
KVM never stores a non-NULL entry with a value of zero (clearing stores NULL), but such an entry would be returned by xas_next_entry() and trip the index check, so WARN if one is ever seen.
--- virt/kvm/kvm_main.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
virt/kvm/kvm_main.c +25 -3
@@ -2429,14 +2429,36 @@ bool kvm_range_has_memory_attributes(strreturn (kvm_get_memory_attributes (kvm, start) & mask) == attrs;guard (rcu)(); -if (!attrs) -return !xas_find (&xas, end -1 ); +/* +* Lookup the entry for each index instead of iterating over the xarray +* as KVM deletes/nullifies entries to represent "no attributes", and +* the xas index is effectively invalid when no entry is found. I.e. +* matching non-zero attributes for *every* entry effectively requires +* a manually lookup for each index. +* +* Skip pre-allocated, reserved entries, or restart the lookup if the +* xarray was concurrently modified, via xas_retry() ("retry" means the +* entry holds an internal xarray value, i.e. is either invalid or NULL +* from the caller's perspective). +* +* Use xas_next() when looking for non-zero attributes to optimize for +* the case where the start of the range (or the entire range) doesn't +* have any attributes, as xas_next() returns literally the next entry, +* whereas xas_next_entry() returns the next non-NULL entry (bounded by +* a maximum index). +*/ for (index = start; index < end; index++) {do { - entry =xas_next (&xas); + entry = attrs ?xas_next (&xas) : +xas_next_entry (&xas, end -1 ); }while (xas_retry (&xas, entry)); +if (!entry) +return !attrs; + +WARN_ON_ONCE (!xa_to_value (entry)); +if (xas.xa_index != index || (xa_to_value (entry) & mask) != attrs)return false;
Greg Kroah-Hartman
maintainerPATCH 534/877 KVM: arm64: Fix spurious warning for benign stage 2 teardown race
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes (ARM) <[email protected]>
commit 38b70fc453c3112f1a62583b89903ae41116cc27 upstream.
kvmtool was used to establish an L1 guest with 8 CPUs and 8 GiB of RAM, an L2 guest with 4 CPUs and 4 GiB of RAM and an L3 guest with 2 CPUs and 2 GiB of RAM, all of which was then exited.
Under memory pressure in the L0 host warnings were observed due to migration triggered by compaction:
WARNING: arch/arm64/kvm/mmu.c:336 at __unmap_stage2_range+0x64/0x80,
CPU#5: kcompactd0/66
Which was, in turn, triggered by an MMU notifier for the host invalidation:
mmu_notifier_invalidate_range_start()
-> ... -> kvm_mmu_notifier_invalidate_range_start()
-> kvm_mmu_unmap_gfn_range()
-> kvm_unmap_gfn_range()
-> kvm_nested_s2_unmap()
-> kvm_stage2_unmap_range()
-> __unmap_stage2_range()
-> stage2_apply_range()
<- -EINVAL, triggering a WARN_ON()Racing with L0's teardown of stage 2 page tables:
exit_mm()
-> mmput()
-> __mmput()
-> exit_mmap()
-> mmu_notifier_release()
-> ... -> kvm_mmu_notifier_release()
-> kvm_flush_shadow_all()
-> kvm_arch_flush_shadow_all()
-> kvm_free_stage2_pgd()
-> [ acquire kvm->mmu_lock for write ]
-> mmu->pgt = NULL [ among other tasks ]
-> [ release kvm->mmu_lock for write ]It turns out there is a benign race resulting in a spurious warning:
Thread A - notify: migration | Thread B - notify: release
-------------------------------|---------------------------------
< kvm->mmu_lock held > |
stage2_apply_range() |
get mmu->pgt, check !NULL |
... | kvm_arch_flush_shadow_all()
cond_resched_rwlock_write(); | < contend, sleep kvm->mmu_lock >
< drop kvm->mmu_lock > | < acquire kvm->mmu_lock>
| ...
| kvm_free_stage2_pgd()
| mmu->pgt = NULL
| < invalidate MMU >
| ...
| < release kvm->mmu_lock >
[ scheduled ] |
stage2_apply_range() |
< loop to next > |
get, mmu->pgt, check !NULL |
is NULL, return -EINVAL |
__unmap_stage2_range() |
WARN_ON(-EINVAL) <--- entirely spurious - the race was handled
correctly.Fix the spurious warning by updating stage2_apply_range() to no longer treat concurrent PGT teardown on lock release as an error - whether the walker is tearing down page tables or doing something else this is a legitimate reason to abort the operation without error.
This keeps the warning in place for all other circumstances.
In practice only __unmap_stage2_range() actually does anything with the error so this only impacts that.
--- arch/arm64/kvm/mmu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/arm64/kvm/mmu.c +12 -3
@@ -53,27 +53,36 @@ static phys_addr_t stage2_range_addr_end* long will also starve other vCPUs. We have to also make sure that the page * tables are not freed while we released the lock. */ -static int stage2_apply_range (struct kvm_s2_mmu *mmu,phys_addr_t addr, +static int stage2_apply_range (struct kvm_s2_mmu *mmu,phys_addr_t start,phys_addr_t end,int (*fn)(struct kvm_pgtable *,u64 ,u64 ),bool resched) {struct kvm *kvm =kvm_s2_mmu_to_kvm (mmu); +bool lock_dropped = false; +phys_addr_t addr = start;int ret;u64 next;do {struct kvm_pgtable *pgt = mmu->pgt; +/* +* We may be raced on PGT teardown when we release the +* kvm->mmu_lock. That's fine as the PGT is legitimately no +* longer present. +*/ if (!pgt) -return -EINVAL ; +return lock_dropped ?0 : -EINVAL ; next =stage2_range_addr_end (addr, end); ret =fn (pgt, addr, next - addr);if (ret)break ; -if (resched && next != end) +if (resched && next != end) {cond_resched_rwlock_write (&kvm->mmu_lock); + lock_dropped = true; + } }while (addr = next, addr != end);return ret;
Greg Kroah-Hartman
maintainerPATCH 535/877 RISC-V: KVM: Synchronize hrtimer callback during teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit aaad136d56d91252517272b68cd533e5714698d5 upstream.
The non-Sstc hrtimer callback clears next_set before its final uses of the enclosing vCPU. If teardown observes next_set as false while the callback is still running, kvm_riscv_vcpu_timer_cancel() skips hrtimer_cancel() and kvm_destroy_vcpus() can free the vCPU before the callback enters kvm_riscv_vcpu_set_interrupt().
A guest can arm the timer with SBI TIME and request shutdown with SBI legacy shutdown or SRST. A VMM that honors KVM_EXIT_SYSTEM_EVENT and destroys the VM supplies the teardown side of the race; no post-launch host ioctl is needed to arm or request teardown.
On upstream master 62cc90241548, generic KASAN reported:
BUG: KASAN: slab-use-after-free in do_raw_spin_lock Write of size 4 at addr ff60000005e58898
kvm_riscv_vcpu_set_interrupt
kvm_riscv_vcpu_hrtimer_expired
__hrtimer_run_queues
hrtimer_interrupt
The object was allocated by KVM_CREATE_VCPU and freed concurrently by:
kvm_destroy_vcpus
kvm_arch_destroy_vm
kvm_destroy_vm
__fput
For deterministic validation, I added mdelay(1000) immediately after the existing next_set = false assignment. This only widens the existing post-clear callback window. A no-delay trace build naturally reached the callback-after-teardown-start/before-deinit ordering in 12 of 200 runs, but 1,500 stock-kernel stress iterations did not produce a KASAN report, so natural reproduction is timing-sensitive.
Always invoke hrtimer_cancel() for an initialized timer. Preserve the existing -EINVAL result when the timer is no longer set, but only after synchronizing with a running callback.
With this patch, hrtimer_cancel() blocked for the full widened callback window before vCPU destruction. KASAN reported no error in 100 fixed-and-widened runs or 200 fix-only timing-sweep runs.
--- arch/riscv/kvm/vcpu_timer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/riscv/kvm/vcpu_timer.c +4 -1
@@ -60,10 +60,13 @@ static enum hrtimer_restart kvm_riscv_vcstatic int kvm_riscv_vcpu_timer_cancel (struct kvm_vcpu_timer *t) { -if (!t->init_done || !t->next_set) +if (!t->init_done)return -EINVAL ;hrtimer_cancel (&t->hrt); + +if (!t->next_set) +return -EINVAL ; t->next_set = false;return 0 ;
Greg Kroah-Hartman
maintainerPATCH 536/877 RISC-V: KVM: Fix HSM hart status error propagation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tan Chi <[email protected]>
commit 41e81f7e3ef96594fb840445343c0ee7723aa550 upstream.
kvm_sbi_hsm_vcpu_get_status() returns SBI_ERR_INVALID_PARAM when the requested hart does not exist. However, the HART_STATUS case returns from the SBI handler without storing this error in retdata->err_val.
As a result, a guest querying the status of a non-existent hart observes SBI_SUCCESS instead of SBI_ERR_INVALID_PARAM.
Use the common SBI error handling path for HART_STATUS after saving a valid hart state in retdata->out_val. This preserves the returned error when kvm_sbi_hsm_vcpu_get_status() fails.
--- arch/riscv/kvm/vcpu_sbi_hsm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kvm/vcpu_sbi_hsm.c +2 -2
@@ -106,9 +106,9 @@ static int kvm_sbi_ext_hsm_handler(struc ret =kvm_sbi_hsm_vcpu_get_status (vcpu);if (ret >=0 ) { retdata->out_val = ret; - retdata->err_val =0 ; + ret =0 ; } -return 0 ; +break ;case SBI_EXT_HSM_HART_SUSPEND :switch (lower_32_bits (cp->a0)) {case SBI_HSM_SUSPEND_RET_DEFAULT :
Greg Kroah-Hartman
maintainerPATCH 537/877 Bluetooth: hci_conn: fix CIS hold ownership on reuse
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit e06d549fcd4a0ba381ed67ddf1ab3c7a6ca4314c upstream.
Commit 69997d50ec57 ("Bluetooth: ISO: handle bound CIS cleanup via hci_conn") made hci_bind_cis() and hci_connect_cis() return a connection with one hold for the ISO layer. hci_bind_cis() currently takes that hold only after configuring a CIS, so its BT_CONNECTED and matching BT_BOUND paths return a bare lookup result. Its configuration failure path can likewise call hci_conn_drop() before taking a hold.
Take the hold before any state-dependent return or configuration error so every successful return follows the documented ownership contract and every error drop is balanced.
hci_connect_cis() also assumes hci_conn_link() always takes a new CIS hold before dropping the one returned by hci_bind_cis(). However, the helper returns an existing link without taking another hold. In that case, preserve the CIS hold for the caller and drop the redundant LE hold because the existing link already owns its parent hold. Returning early also avoids changing an existing CIS back to BT_CONNECT.
--- net/bluetooth/hci_conn.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/bluetooth/hci_conn.c +8 -1
@@ -1937,6 +1937,8 @@ struct hci_conn *hci_bind_cis(struct hci cis->iso_qos.ucast.cis =BT_ISO_QOS_CIS_UNSET ; } +hci_conn_hold (cis); +if (cis->state ==BT_CONNECTED )return cis;
@@ -1978,7 +1980,6 @@ struct hci_conn *hci_bind_cis(struct hcireturn ERR_PTR (-EINVAL ); } -hci_conn_hold (cis); cis->state =BT_BOUND ;return cis;
@@ -2340,6 +2341,12 @@ struct hci_conn *hci_connect_cis(structhci_conn_drop (le);return cis; } + +/* The existing link already owns the hold on its parent. */ +if (cis->link) { +hci_conn_drop (le); +return cis; + } link =hci_conn_link (le, cis);hci_conn_drop (cis);
Greg Kroah-Hartman
maintainerPATCH 538/877 Bluetooth: hci_sock: validate event length before filtering
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit b0a6cf99afd57a39598b1beca0e86ef5004980de upstream.
is_filtered_packet() reads the event code from skb->data[0] without first checking that the skb is nonempty. When an opcode filter is configured, it also reads the command opcode at offsets 3 or 4 without checking that a Command Complete or Command Status event is long enough.
hci_send_to_sock() invokes the filter before hci_event_packet() validates the event header. A malformed event supplied by a controller or a vhci device can therefore cause an out-of-bounds read.
Keep the unmasked event code for the opcode checks. The masked value is needed for the 64-bit event bitmap, but using it to identify command events aliases event codes above 0x3f. In particular, Synchronous Train Complete (0x4f) was treated as Command Status (0x0f) even though its payload has no opcode.
Reject actual command events that are too short for the field being inspected. A truncated command event cannot match a configured opcode.
--- net/bluetooth/hci_sock.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
net/bluetooth/hci_sock.c +14 -3
@@ -166,6 +166,7 @@ static bool is_filtered_packet(struct so {struct hci_filter *flt;int flt_type, flt_event; +u8 event;/* Apply filter */ flt = &hci_pi (sk)->filter;
@@ -179,7 +180,11 @@ static bool is_filtered_packet(struct soif (hci_skb_pkt_type (skb) !=HCI_EVENT_PKT )return false; - flt_event = (*(__u8 *)skb->data &HCI_FLT_EVENT_BITS ); +if (skb->len <1 ) +return true; + + event = *(__u8 *)skb->data; + flt_event = event &HCI_FLT_EVENT_BITS ;if (!hci_test_bit (flt_event, &flt->event_mask))return true;
@@ -188,11 +193,17 @@ static bool is_filtered_packet(struct soif (!flt->opcode)return false; -if (flt_event ==HCI_EV_CMD_COMPLETE && +if (event ==HCI_EV_CMD_COMPLETE && skb->len <5 ) +return true; + +if (event ==HCI_EV_CMD_COMPLETE && flt->opcode !=get_unaligned ((__le16 *)(skb->data +3 )))return true; -if (flt_event ==HCI_EV_CMD_STATUS && +if (event ==HCI_EV_CMD_STATUS && skb->len <6 ) +return true; + +if (event ==HCI_EV_CMD_STATUS && flt->opcode !=get_unaligned ((__le16 *)(skb->data +4 )))return true;
Greg Kroah-Hartman
maintainerPATCH 539/877 Bluetooth: hci_sock: reject out-of-range OCF values
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit e93fad891c72deb84cae49430163b384ebcc92b1 upstream.
The raw HCI socket security filter has 128 OCF bits per supported OGF, but masks the 10-bit OCF with 127 before looking up the command. An unprivileged socket can therefore submit a reserved OCF that aliases an allowlisted command modulo 128.
A conforming controller should reject reserved opcodes. Nevertheless, the security decision must apply to the opcode that will actually be sent, especially since controller-specific behavior is outside the host stack's control.
Reject OCF values that cannot be represented by the security filter instead of aliasing them onto an unrelated command.
--- net/bluetooth/hci_sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/hci_sock.c +2 -1
@@ -1886,7 +1886,8 @@ static int hci_sock_sendmsg(struct sockeu16 ocf =hci_opcode_ocf (opcode);if (((ogf >HCI_SFLT_MAX_OGF ) || - !hci_test_bit (ocf &HCI_FLT_OCF_BITS , + (ocf >HCI_FLT_OCF_BITS ) || + !hci_test_bit (ocf, &hci_sec_filter.ocf_mask[ogf])) && !capable (CAP_NET_RAW )) { err = -EPERM ;
Greg Kroah-Hartman
maintainerPATCH 540/877 Bluetooth: ISO: balance the parent hold in hci_bind_bis()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit 4c94557dd02569efa6c1072a0439addaef9a5224 upstream.
hci_conn_link() takes a lifetime reference to its parent with hci_conn_get(), but only takes an operational hold on the child. hci_conn_unlink() later balances both a hold and a reference on the parent.
The SCO and CIS paths pass a parent acquired from a connect helper, so it already has a hold. For an additional BIS, hci_bind_bis() obtains the parent from hci_conn_hash_lookup_big(), which returns a bare pointer. Unlinking the child then drops the parent's existing hold and can schedule it for disconnection while its socket is still using it.
Take a hold on the parent before linking it and drop that hold if linking fails. A successful link transfers the hold to hci_conn_unlink().
--- net/bluetooth/hci_conn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/hci_conn.c +4 -1
@@ -2234,10 +2234,13 @@ struct hci_conn *hci_bind_bis(struct hci parent =hci_conn_hash_lookup_big (hdev, conn->iso_qos.bcast.big);if (parent && parent != conn) { +hci_conn_hold (parent); link =hci_conn_link (parent, conn);hci_conn_drop (conn); -if (!link) +if (!link) { +hci_conn_drop (parent);return ERR_PTR (-ENOLINK ); + } }return conn;
Greg Kroah-Hartman
maintainerPATCH 541/877 Bluetooth: L2CAP: validate frame length before control and FCS access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit 6c78a213d9070b610c7f418af2c25b66180b7e37 upstream.
l2cap_data_rcv() unpacks either a two-byte or four-byte control field without first ensuring that it is present. A short ERTM or streaming-mode frame can therefore cause an out-of-bounds read.
There is a second short-frame case when CRC16 is enabled. After the control field is pulled, l2cap_check_fcs() subtracts two from skb->len without checking it. If fewer than two bytes remain, the subtraction wraps; skb_trim() leaves the buffer unchanged and the subsequent FCS load reads past the logical end of the frame.
Validate that the frame contains both its control field and, when enabled, its FCS before either field is accessed.
--- net/bluetooth/l2cap_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +9 -1
@@ -6681,9 +6681,17 @@ static int l2cap_stream_rx(struct l2cap_static int l2cap_data_rcv (struct l2cap_chan *chan,struct sk_buff *skb) {struct l2cap_ctrl *control = &bt_cb (skb)->l2cap; -u16 len; +u16 len, min_len;u8 event; + min_len =test_bit (FLAG_EXT_CTRL , &chan->flags) ? +L2CAP_EXT_CTRL_SIZE :L2CAP_ENH_CTRL_SIZE ; +if (chan->fcs ==L2CAP_FCS_CRC16 ) + min_len +=L2CAP_FCS_SIZE ; + +if (skb->len < min_len) + goto drop; +__unpack_control (chan, skb); len = skb->len;
Greg Kroah-Hartman
maintainerPATCH 542/877 Bluetooth: mgmt: fix race in read_unconf_index_list()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit b5dbb41b212c50c095a4dbee3017a84fe94f033b upstream.
read_unconf_index_list() counts unconfigured controllers before allocating its response, then checks the device flags again while filling it.
hci_dev_list_lock stabilizes list membership, but it does not serialize the per-device flags. During asynchronous controller setup, the worker can set HCI_UNCONFIGURED and clear HCI_SETUP between the two passes. A controller omitted from the allocation count can then become eligible for the fill pass, causing an out-of-bounds write to rp->index[].
Allocate space for every device on hci_dev_list. Since list membership cannot change while hci_dev_list_lock is held, the response remains large enough regardless of flag transitions. The reported count and response length still include only eligible unconfigured controllers.
--- net/bluetooth/mgmt.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
net/bluetooth/mgmt.c +2 -6
@@ -498,13 +498,9 @@ static int read_unconf_index_list(structread_lock (&hci_dev_list_lock); - count =0 ; -list_for_each_entry (d, &hci_dev_list, list) { -if (hci_dev_test_flag (d,HCI_UNCONFIGURED )) - count++; - } + count =list_count_nodes (&hci_dev_list); - rp_len =sizeof (*rp) + (2 * count); + rp_len =sizeof (*rp) + (sizeof (__le16) * count); rp =kmalloc (rp_len,GFP_ATOMIC );if (!rp) {read_unlock (&hci_dev_list_lock);
Greg Kroah-Hartman
maintainerPATCH 543/877 Bluetooth: RFCOMM: fix NULL dereference of dlc->session in RFCOMM_CONNINFO
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
commit 46f8ffd0a1f1eb6cbc94946a92c11ef601e228a1 upstream.
The RFCOMM_CONNINFO getsockopt handler accepts a socket that is not connected as long as deferred setup is enabled:
if (sk->sk_state != BT_CONNECTED &&
!rfcomm_pi(sk)->dlc->defer_setup) {
err = -ENOTCONN;
break;
}
l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;dlc->defer_setup is set in rfcomm_sock_init() when rfcomm_connect_ind() creates a child socket for an incoming connection on a listening socket that has BT_DEFER_SETUP enabled. It is never cleared afterwards. The session, however, can go away underneath it.
rfcomm_recv_disc() forces the dlc state before tearing it down:
d->state = BT_CLOSED; __rfcomm_dlc_close(d, err);
The RFCOMM_DEFER_SETUP early return in __rfcomm_dlc_close() only covers BT_CONNECT, BT_CONFIG, BT_OPEN and BT_CONNECT2, so with the state already BT_CLOSED that switch does not match and the function falls through to rfcomm_dlc_unlink(), which sets d->session = NULL, while d->defer_setup stays 1.
A getsockopt(SOL_RFCOMM, RFCOMM_CONNINFO) on the accepted socket after that point therefore skips the -ENOTCONN path -- sk->sk_state is BT_CLOSED, but dlc->defer_setup is still set -- and dereferences the NULL session. No race is needed: once the DISC has been processed, the dereference is unconditional.
Reproduced on a KASAN kernel under QEMU with a BR/EDR peer emulated over /dev/vhci: the peer brings up an ACL link, opens L2CAP on the RFCOMM PSM, starts a session and sends SABM for a channel bound with BT_DEFER_SETUP, and sends DISC for that dlci after the socket has been accepted. getsockopt(SOL_RFCOMM, RFCOMM_CONNINFO) on the accepted socket then hits:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002: 0000 [#1] SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] CPU: 1 UID: 0 PID: 150 Comm: init Tainted: G B 7.3.0-rc3-g5dd1818b15d9 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) RIP: 0010:rfcomm_sock_getsockopt+0x529/0x780 Call Trace: <TASK> do_sock_getsockopt+0x3ad/0x7d0 __sys_getsockopt+0x10e/0x1b0 __x64_sys_getsockopt+0xc2/0x160 do_syscall_64+0xda/0x4b0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
0x10 is the offset of sock in struct rfcomm_session; rfcomm_sock_getsockopt_old() is inlined into rfcomm_sock_getsockopt().
Commit 43a556b2fd43 ("Bluetooth: RFCOMM: take rfcomm_mutex for the deferred setup accept") fixed the same "a remote DISC clears the session while deferred setup is still flagged" problem in rfcomm_dlc_accept(); this is the remaining instance of it, in the getsockopt path.
Deferred setup only leaves a socket usable here once it has reached BT_CONNECT2, so restrict the exception to that state and check that a session is actually present before following it.
--- net/bluetooth/rfcomm/sock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/rfcomm/sock.c +4 -2
@@ -785,8 +785,10 @@ static int rfcomm_sock_getsockopt_old(stbreak ;case RFCOMM_CONNINFO : -if (sk->sk_state !=BT_CONNECTED && - !rfcomm_pi (sk)->dlc->defer_setup) { +if ((sk->sk_state !=BT_CONNECTED && + !(sk->sk_state ==BT_CONNECT2 && +rfcomm_pi (sk)->dlc->defer_setup)) || + !rfcomm_pi (sk)->dlc->session) { err = -ENOTCONN ;break ; }
Greg Kroah-Hartman
maintainerPATCH 544/877 smb: client: fix create context out-of-bounds reads
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit 67f4c1c6a1b51e203d986779299824d1c2c590a6 upstream.
smb2_parse_contexts() validates the complete create-context area but does not limit each record to its Next field before dispatching it. A malformed chain can therefore expose bytes beyond the current context to a handler. The QFid handler also used a full response-structure cast although it only reads DiskFileId.
The SMB2/SMB3 lease parsers made the same layout assumption: they read LeaseState and LeaseFlags at canonical offsets rather than at DataOffset. A valid non-canonical DataOffset could therefore yield unrelated in-bounds data, while a short DataLength was still accepted.
Limit each context to its Next value, reject offsets before the context header, and reject malformed chains. Bound the name range by the current context and do not dispatch a known handler when DataLength is zero. Read the QFid DiskFileId only when the context data covers that field. Parse the lease context from DataOffset and require DataLength to match the v1 or v2 lease_context size used by ksmbd. A size mismatch skips lease parsing without failing the open.
--- fs/smb/client/smb2ops.c | 28 ++++++++++++++++++++-------- fs/smb/client/smb2pdu.c | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 54 insertions(+), 18 deletions(-)
fs/smb/client/smb2ops.c +20 -8
@@ -4405,25 +4405,37 @@ smb3_create_lease_buf(u8 *lease_key, u8static __u8 smb2_parse_lease_buf (void *buf,__u16 *epoch,char *lease_key) { -struct create_lease *lc = (struct create_lease *)buf; +struct create_context *cc = buf; +struct lease_context lc; *epoch =0 ;/* not used */ -if (lc->lcontext.LeaseFlags &SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE ) +if (le32_to_cpu (cc->DataLength) !=sizeof (lc)) +return 0 ; + +memcpy (&lc, (u8 *)cc +le16_to_cpu (cc->DataOffset),sizeof (lc)); +if (lc.LeaseFlags &SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE )return SMB2_OPLOCK_LEVEL_NOCHANGE ; -return le32_to_cpu (lc->lcontext.LeaseState); +return le32_to_cpu (lc.LeaseState); }static __u8 smb3_parse_lease_buf (void *buf,__u16 *epoch,char *lease_key) { -struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; +struct create_context *cc = buf; +struct lease_context_v2 lc; + +if (le32_to_cpu (cc->DataLength) !=sizeof (lc)) { + *epoch =0 ; +return 0 ; + } - *epoch =le16_to_cpu (lc->lcontext.Epoch); -if (lc->lcontext.LeaseFlags &SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE ) +memcpy (&lc, (u8 *)cc +le16_to_cpu (cc->DataOffset),sizeof (lc)); + *epoch =le16_to_cpu (lc.Epoch); +if (lc.LeaseFlags &SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE )return SMB2_OPLOCK_LEVEL_NOCHANGE ;if (lease_key) -memcpy (lease_key, &lc->lcontext.LeaseKey,SMB2_LEASE_KEY_SIZE ); -return le32_to_cpu (lc->lcontext.LeaseState); +memcpy (lease_key, lc.LeaseKey,SMB2_LEASE_KEY_SIZE ); +return le32_to_cpu (lc.LeaseState); } static unsigned int
fs/smb/client/smb2pdu.c +34 -10
93 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 545/877 smb: client: clean up failed cached directory opens
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit d2ff5fb93ea83034025850266b5eed391f96b825 upstream.
open_cached_dir() sends CREATE and QUERY_INFO as a compound request. If the CREATE succeeds but a later command returns an error, the function must retain the CREATE FID so common cleanup can issue SMB2_close(). It also must not treat a response error as a valid CREATE.
Validate the CREATE response before using its fields, record the FIDs, and mark the handle open before handling errors from later compound commands. Move the -EREMCHG reconnect handling before response validation so a missing response does not hide the reconnect request. Count the handle when it is marked open; confirmed close responses decrement the counter, while existing close retry behavior remains best effort on transport failures.
--- fs/smb/client/cached_dir.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-)
fs/smb/client/cached_dir.c +22 -10
@@ -8,6 +8,7 @@#include <linux/namei.h> #include "cifsglob.h" #include "cifsproto.h" +#include "../common/smb2status.h" #include "cifs_debug.h" #include "smb2proto.h" #include "cached_dir.h"
@@ -294,25 +295,37 @@ replay_again: rc =compound_send_recv (xid, ses, server, flags,2 , rqst, resp_buftype, rsp_iov); -if (rc) { -if (rc == -EREMCHG ) { - tcon->need_reconnect = true; -pr_warn_once ("server share %s deleted\n" , - tcon->tree_name); - } - goto oshr_free; +if (rc == -EREMCHG ) { + tcon->need_reconnect = true; +pr_warn_once ("server share %s deleted\n" , + tcon->tree_name); } - cfid->is_open = true; -spin_lock (&cfids->cfid_list_lock); +if (!rsp_iov[0 ].iov_base || rsp_iov[0 ].iov_len <sizeof (*o_rsp)) { +if (!rc) + rc = -EIO ; + goto oshr_free; + } o_rsp = (struct smb2_create_rsp *)rsp_iov[0 ].iov_base; +if (o_rsp->hdr.Status !=STATUS_SUCCESS ) { +if (!rc) + rc = -EIO ; + goto oshr_free; + } + oparms.fid->persistent_fid = o_rsp->PersistentFileId; oparms.fid->volatile_fid = o_rsp->VolatileFileId;#ifdef CONFIG_CIFS_DEBUG2 oparms.fid->mid =le64_to_cpu (o_rsp->hdr.MessageId);#endif /* CIFS_DEBUG2 */ + cfid->is_open = true; +atomic_inc (&tcon->num_remote_opens); +if (rc) + goto oshr_free; + +spin_lock (&cfids->cfid_list_lock);if (o_rsp->OplockLevel !=SMB2_OPLOCK_LEVEL_LEASE ) {spin_unlock (&cfids->cfid_list_lock);
@@ -378,7 +391,6 @@ out:close_cached_dir (cfid); }else { *ret_cfid = cfid; -atomic_inc (&tcon->num_remote_opens); }kfree (utf16_path);
Greg Kroah-Hartman
maintainerPATCH 546/877 smb: client: validate POSIX create context length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zihan Xi <[email protected]>
commit fa2e9900dd2a3f5a1e7ef5a8c5e8d435feedbfcc upstream.
parse_posix_ctxt() reads the fixed nlink, reparse_tag, and mode fields before checking that the POSIX create context contains them. A short context can pass the generic checks and still make these fixed-width reads run past its declared data.
The current in-tree smb2_open_file() path passes a NULL posix pointer, so this handler is not reached on the ordinary open path. Still require the POSIX data to cover all three fields before reading them because the helper performs those unguarded reads. Keep the existing soft-failure behavior so malformed optional metadata does not fail the open.
--- fs/smb/client/smb2pdu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/smb/client/smb2pdu.c +5 -2
@@ -2313,12 +2313,15 @@ static void parse_posix_ctxt(struct create_context *cc, struct smb2_file_all_info *info, struct create_posix_rsp *posix) { - int sid_len; u8 *beg = (u8 *)cc + le16_to_cpu(cc->DataOffset); -u8 *end = beg +le32_to_cpu (cc->DataLength); +u32 dlen =le32_to_cpu (cc->DataLength); +u8 *end = beg + dlen; +int sid_len;u8 *sid;memset (posix,0 ,sizeof (*posix)); +if (dlen <3 *sizeof (__le32)) +return ; posix->nlink =get_unaligned_le32 (beg); posix->reparse_tag =get_unaligned_le32 (beg +4 );
Greg Kroah-Hartman
maintainerPATCH 547/877 xfs: dont assert when XFS_SCRUB_TYPE_HEALTHY scans return corruption
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit afbccf99f7f82117cba9ad4b0b006692030f49e8 upstream.
XFS_SCRUB_TYPE_HEALTHY is a synthentic scrub type so that xfs_scrub can tell the kernel "Hey, I finished a scan and saw no problems" and have the kernel forget that it saw indirect evidence of corruption.
Unfortunately, as LOLLM points out, it's possible for the health system to record a new corruption just before xfs_scrub gets to XFS_SCRUB_TYPE_HEALTHY. In this case, the existing logic doesn't return early and instead wanders into unknown regions of type_to_health_flag and trips the assert because HEALTHY doesn't have a group assignment.
Fix the logic so that we always return early for a HEALTHY scrub type, even if we decide not to call xchk_mark_all_healthy.
--- fs/xfs/scrub/health.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/xfs/scrub/health.c +3 -3
@@ -192,9 +192,9 @@ xchk_update_health(* there's no sick flag defined for it, so we branch here ahead of the * mask check. */ -if (sc->sm->sm_type ==XFS_SCRUB_TYPE_HEALTHY && - !(sc->sm->sm_flags &XFS_SCRUB_OFLAG_CORRUPT )) { -xchk_mark_all_healthy (sc->mp); +if (sc->sm->sm_type ==XFS_SCRUB_TYPE_HEALTHY ) { +if (!(sc->sm->sm_flags &XFS_SCRUB_OFLAG_CORRUPT )) +xchk_mark_all_healthy (sc->mp);return ; }
Greg Kroah-Hartman
maintainerPATCH 548/877 xfs: fix attr fork block count checks in xrep_inode_blockcounts
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit bb991b7f79dd34cc5f24db0f736bf75630c970e7 upstream.
LOLLM points out that a file has an attr fork, it will call xchk_inode_count_blocks to set @ablocks to the number of fsblocks mapped by the attr fork; but then it'll compare @blocks (aka the count of fsblocks mapped by the data fork). We already checked that and we never do anything with @acount, so I think this is clearly a bug. Fix the comparison.
--- fs/xfs/scrub/inode_repair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/inode_repair.c +1 -1
@@ -1513,7 +1513,7 @@ xrep_inode_blockcounts( &nextents, &acount);if (error)return error; -if (count >= sc->mp->m_sb.sb_dblocks) +if (acount >= sc->mp->m_sb.sb_dblocks)return -EFSCORRUPTED ; error =xrep_ino_ensure_extent_count (sc,XFS_ATTR_FORK , nextents);
Greg Kroah-Hartman
maintainerPATCH 549/877 xfs: release orphanage dir inode if chown fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 1c32cdc986467eaffeedb6c5334852809555b82d upstream.
LOLLM points out that we leak the igrab'd reference to the orphanage directory inode if chowning it fails. Fix that.
--- fs/xfs/scrub/orphanage.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/orphanage.c +5 -1
@@ -193,12 +193,16 @@ xrep_orphanage_create(/* Make sure the orphanage is owned by root. */ error =xrep_chown_orphanage (sc,XFS_I (orphanage_inode));if (error) - goto out_dput_orphanage; + goto out_rele_orphanage;/* Stash the reference for later and bail out. */ sc->orphanage =XFS_I (orphanage_inode); sc->orphanage_ilock_flags =0 ; + orphanage_inode =NULL ; +out_rele_orphanage: +if (orphanage_inode) +xchk_irele (sc,XFS_I (orphanage_inode)); out_dput_orphanage:dput (orphanage_dentry); out_unlock_root:
Greg Kroah-Hartman
maintainerPATCH 550/877 xfs: use correct jiffies comparison function in xchk_maybe_relax
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 984aab2d905a8557fafb27cd9e8713d6d12b3437 upstream.
LOLLM points out that we're supposed to use time_after_eq, not a raw >= operation here, or else jiffies wraps can go unnoticed. Fix this.
--- fs/xfs/scrub/scrub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/scrub.h +1 -1
@@ -40,7 +40,7 @@ static inline int xchk_maybe_relax(struct xchk_relax *widget)return 0 ; widget->resched_nr =0 ; -if (unlikely (widget->next_resched <= jiffies)) { +if (unlikely (time_after_eq (jiffies, widget->next_resched))) {cond_resched (); widget->next_resched =XCHK_RELAX_NEXT ; }
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 551/877 xfs: check padding field in xfs_ioc_commit_range
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 3083ba8dde765a9ab2337f3db68d00724a6b1202 upstream.
LOLLM points out that we don't check the ioctl padding field here, so let's do that. I don't think there are many users yet since exchrange requires a new feature flag, so it's a good time to try to plug this hole.
--- fs/xfs/xfs_exchrange.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_exchrange.c +1 -1
@@ -905,7 +905,7 @@ xfs_ioc_commit_range(if (copy_from_user (&args, argp,sizeof (args)))return -EFAULT ; -if (args.flags & ~XFS_EXCHANGE_RANGE_ALL_FLAGS ) +if (args.pad || (args.flags & ~XFS_EXCHANGE_RANGE_ALL_FLAGS ))return -EINVAL ;if (kern_f->magic !=XCR_FRESH_MAGIC )return -EBUSY ;
Greg Kroah-Hartman
maintainerPATCH 552/877 xfs: dont call xfs_exchange_range_finish for a dry run
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit 8fc18580ec17f90beac4c933fbe4c74dcd3b7f36 upstream.
LOLLM noticed that we strip file privileges and whatnot even for a dry run. We also shouldn't flush dirty data to disk or trim COW staging events for a dry run. Neither of those behaviors are allowed by the manpage, so fix that by exiting early on DRY_RUN in various functions.
--- fs/xfs/xfs_exchrange.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
fs/xfs/xfs_exchrange.c +8 -3
@@ -630,6 +630,9 @@ xfs_exchrange_prep(if (error)return error; +if (fxr->flags &XFS_EXCHANGE_RANGE_DRY_RUN ) +return 0 ; +trace_xfs_exchrange_flush (fxr, ip1, ip2);/* Flush the relevant ranges of both files. */
@@ -706,9 +709,11 @@ xfs_exchrange_contents(* other file write would do. This may involve turning on support for * logged xattrs if either file has security capabilities. */ - error =xfs_exchange_range_finish (fxr); -if (error) - goto out_unlock; +if (!(fxr->flags &XFS_EXCHANGE_RANGE_DRY_RUN )) { + error =xfs_exchange_range_finish (fxr); +if (error) + goto out_unlock; + } out_unlock:xfs_iunlock2_io_mmap (ip1, ip2);
Greg Kroah-Hartman
maintainerPATCH 553/877 xfs: check di_forkoff correctly in scrub
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit e9193f2f1ce32d02b9230094ffdbfab715ab6137 upstream.
The di_forkoff check in xchk_dinode is incorrect, according to LOLLM. XFS_DFORK_BOFF returns a byte count relative to the start of the literal area, not the start of the inode. Therefore, this check won't flag di_forkoff values that are larger than the literal area but not the inode size itself. Fix this check; sadly the old APTR code was correct.
--- fs/xfs/scrub/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/inode.c +1 -1
@@ -560,7 +560,7 @@ xchk_dinode( }/* di_forkoff */ -if (XFS_DFORK_BOFF (dip) >= mp->m_sb.sb_inodesize) +if (dip->di_forkoff >= (XFS_LITINO (mp) >>3 ))xchk_ino_set_corrupt (sc, ino);if (naextents !=0 && dip->di_forkoff ==0 )xchk_ino_set_corrupt (sc, ino);
Greg Kroah-Hartman
maintainerPATCH 554/877 xfs: drop dquot flush lock when we cant find a buffer to flush
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit ffb48dccce1960a9ea24463a2f3c21d124d6b672 upstream.
LOLLM noticed that xfs_qm_flush_one fails to drop the dquot flush lock if it can't grab the buffer associated with the dquot. Since there's no buffer, nobody else is going to drop the dqflock, so we need to do it ourselves.
--- fs/xfs/xfs_qm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
fs/xfs/xfs_qm.c +8 -2
@@ -1317,16 +1317,22 @@ xfs_qm_flush_one( error =xfs_dquot_use_attached_buf (dqp, &bp);if (error) - goto out_unlock; + goto out_dqflock;if (!bp) { error = -EFSCORRUPTED ; - goto out_unlock; + goto out_dqflock; } error =xfs_qm_dqflush (dqp, bp);if (!error)xfs_buf_delwri_queue (bp, buffer_list);xfs_buf_relse (bp); +mutex_unlock (&dqp->q_qlock); +xfs_qm_dqrele (dqp); +return error; + +out_dqflock: +xfs_dqfunlock (dqp); out_unlock:xfs_dqunlock (dqp);return error;
Re: [PATCH 6.12 554/877] xfs: drop dquot flush lock when we cant find a buffer to flush
Quoted 34 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit
ffb48dccce1960a9ea24463a2f3c21d124d6b672upstream.LOLLM noticed that
xfs_qm_flush_onefails to drop the dquot flush lock if it can't grab the buffer associated with the dquot. Since there's no buffer, nobody else is going to drop the dqflock, so we need to do it ourselves.Cc [email protected] # v6.13Fixes ca378189fdfa89 ("xfs: convert quotacheck to attach dquot buffers")Signed-off-by Darrick J. Wong <[email protected]>Assisted-by LOLLM # finding obvious bugsReviewed-by Christoph Hellwig <[email protected]>Signed-off-by Carlos Maiolino <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- fs/xfs/xfs_qm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)fs/xfs/xfs_qm.c +1
-1@@ -1317,16 +1317,22 @@ xfs_qm_flush_one( error =xfs_dquot_use_attached_buf (dqp, &bp);if (error) - goto out_unlock; + goto out_dqflock;if (!bp) { error = -EFSCORRUPTED ;
fs/xfs/xfs_qm.c xfs_qm_flush_one( · line 1331
Quoted 10 lines
fs/xfs/xfs_qm.c +3
-1- goto out_unlock; + goto out_dqflock; } error =xfs_qm_dqflush (dqp, bp);if (!error)xfs_buf_delwri_queue (bp, buffer_list);xfs_buf_relse (bp); +mutex_unlock (&dqp->q_qlock); +xfs_qm_dqrele (dqp);
^^
Hi Greg,
An AI assisted backport review flagged this, and I checked the upstream code against the 6.12.y tip f4ffa8dc360b.
Upstream ffb48dccce19 acquires a temporary dquot reference and balances it on the buffer-bearing return path:
if (!lockref_get_not_dead(&dqp->q_lockref))
return 0;
mutex_lock(&dqp->q_qlock);
/* ... intervening source omitted ... */
xfs_buf_relse(bp);
mutex_unlock(&dqp->q_qlock);
xfs_qm_dqrele(dqp);
return error;6.12.y starts with a mutex-only xfs_dqlock(), but copies the release:
xfs_dqlock(dqp);
if (dqp->q_flags & XFS_DQFLAG_FREEING)
goto out_unlock;
if (!XFS_DQ_IS_DIRTY(dqp))
goto out_unlock;
/* ... intervening source omitted ... */
xfs_buf_relse(bp);
mutex_unlock(&dqp->q_qlock);
xfs_qm_dqrele(dqp);
return error;Neither xfs_dqlock() nor the walker takes a reference. The new xfs_qm_dqrele() releases an unowned reference and can assert/underflow q_nrefs on dirty zero-reference dquots after quotacheck, potentially blocking purge/teardown.
Could we replace the new mutex_unlock()/xfs_qm_dqrele() pair with xfs_dqunlock(dqp), keeping the early return and out_dqflock cleanup?
or drop this fix for 6.12.y ?
thanks,
Harshit> + return error;
Quoted 9 lines
fs/xfs/xfs_qm.c +3
-0+ +out_dqflock: +xfs_dqfunlock (dqp); out_unlock:xfs_dqunlock (dqp);return error;
Greg Kroah-Hartman
maintainerRe: [PATCH 6.12 554/877] xfs: drop dquot flush lock when we cant find a buffer to flush
Quoted 85 lines · Harshit Mogalapalli
Quoted 32 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit
ffb48dccce1960a9ea24463a2f3c21d124d6b672upstream.LOLLM noticed that
xfs_qm_flush_onefails to drop the dquot flush lock if it can't grab the buffer associated with the dquot. Since there's no buffer, nobody else is going to drop the dqflock, so we need to do it ourselves.Cc [email protected] # v6.13Fixes ca378189fdfa89 ("xfs: convert quotacheck to attach dquot buffers")Signed-off-by Darrick J. Wong <[email protected]>Assisted-by LOLLM # finding obvious bugsReviewed-by Christoph Hellwig <[email protected]>Signed-off-by Carlos Maiolino <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- fs/xfs/xfs_qm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)fs/xfs/xfs_qm.c +1
-1@@ -1317,16 +1317,22 @@ xfs_qm_flush_one( error =xfs_dquot_use_attached_buf (dqp, &bp);if (error) - goto out_unlock; + goto out_dqflock;if (!bp) {fs/xfs/xfs_qm.c xfs_qm_flush_one( · line 1329
Quoted 10 lines
fs/xfs/xfs_qm.c +3
-1error = -EFSCORRUPTED ; - goto out_unlock; + goto out_dqflock; } error =xfs_qm_dqflush (dqp, bp);if (!error)xfs_buf_delwri_queue (bp, buffer_list);xfs_buf_relse (bp); +mutex_unlock (&dqp->q_qlock); +xfs_qm_dqrele (dqp);^^
Hi Greg,
An AI assisted backport review flagged this, and I checked the upstream code against the 6.12.y tip
f4ffa8dc360b.Upstream
ffb48dccce19acquires a temporary dquot reference and balances it on the buffer-bearing return path:if (!lockref_get_not_dead(&dqp->q_lockref)) return 0; mutex_lock(&dqp->q_qlock); /* ... intervening source omitted ... */ xfs_buf_relse(bp); mutex_unlock(&dqp->q_qlock); xfs_qm_dqrele(dqp); return error;6.12.y starts with a mutex-only
xfs_dqlock(), but copies the release:xfs_dqlock(dqp); if (dqp->q_flags & XFS_DQFLAG_FREEING) goto out_unlock; if (!XFS_DQ_IS_DIRTY(dqp)) goto out_unlock; /* ... intervening source omitted ... */ xfs_buf_relse(bp); mutex_unlock(&dqp->q_qlock); xfs_qm_dqrele(dqp); return error;Neither
xfs_dqlock()nor the walker takes a reference. The newxfs_qm_dqrele()releases an unowned reference and can assert/underflowq_nrefson dirty zero-reference dquots after quotacheck, potentially blocking purge/teardown.
Quoted 4 lines
Could we replace the new mutex_unlock()/xfs_qm_dqrele() pair with
xfs_dqunlock(dqp), keeping the early return andout_dqflockcleanup?or drop this fix for 6.12.y ?
Now dropped from the 6.12.y queue, thanks.
greg k-h
Sasha Levin
maintainerRe: [PATCH 6.12 554/877] xfs: drop dquot flush lock when we cant find a buffer to flush
In reply to Harshit MogalapalliQuoted 4 lines
Could we replace the new mutex_unlock()/xfs_qm_dqrele() pair with
xfs_dqunlock(dqp), keeping the early return andout_dqflockcleanup?or drop this fix for 6.12.y ?
Greg already dropped the 6.12 copy. The 6.18 queue had the same unbalanced xfs_qm_dqrele(): 6.18 doesn't have 0c5e80bd579f7 ("xfs: use a lockref for the xfs_dquot reference count", v6.19-rc1), so its xfs_qm_flush_one() never takes the lockref_get_not_dead() reference that the new exit path releases. I've dropped it from 6.18 as well.
7.2 has that reference, so it keeps the patch.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 555/877 xfs: fix blockgc group quota scanning when usrquota isnt enforced
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit f8f6382ff13109e19d0fc1d0224ff7d29641e56a upstream.
LOLLM noticed the copy-paste error here -- if user quotas aren't enforced but we're near the group quota limit, we fail to set FLAG_GID and hence we might not actually free any preallocations, causing unnecessary EDQUOT. Fix that.
--- fs/xfs/xfs_icache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_icache.c +1 -1
@@ -1593,7 +1593,7 @@ xfs_blockgc_free_dquots( do_work = true; } -if (XFS_IS_UQUOTA_ENFORCED (mp) && gdqp &&xfs_dquot_lowsp (gdqp)) { +if (XFS_IS_GQUOTA_ENFORCED (mp) && gdqp &&xfs_dquot_lowsp (gdqp)) { icw.icw_gid =make_kgid (mp->m_super->s_user_ns, gdqp->q_id); icw.icw_flags |=XFS_ICWALK_FLAG_GID ; do_work = true;
Greg Kroah-Hartman
maintainerPATCH 556/877 net: tls: fix silent data drop under pipe back-pressure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 7e7be31bfdb066c1c780dcd6b1224078fc54063f ]
tls_sw_splice_read() uses len when advancing rxm->offset / rxm->full_len after skb_splice_bits(), rather than copied (the actual number of bytes successfully spliced into the pipe). When the destination pipe cannot accept all the requested bytes, splice_to_pipe() returns fewer bytes than len, and 'len - copied' of data is effectively skipped over.
--- net/tls/tls_sw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/tls/tls_sw.c +3 -3
@@ -2337,9 +2337,9 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,if (copied <0 ) goto splice_requeue; -if (chunk < rxm->full_len) { - rxm->offset += len; - rxm->full_len -= len; +if (copied < rxm->full_len) { + rxm->offset += copied; + rxm->full_len -= copied; goto splice_requeue; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 557/877 perf test: Change all remaining #!/bin/sh to #!/bin/bash
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
commit 2f5d370dec3f800b44bbf7b68875d521e0af43cd upstream.
There are 43 instances of posix shell tests and 35 instances of bash. To give us a single consistent language for testing in, replace all #!/bin/sh to #!/bin/bash. Common sources that are included in both different shells will now work as expected. And we no longer have to fix up bashisms that appear to work when someone's system has sh symlinked to bash, but don't work on other systems that have both shells installed.
Although we could have chosen sh, it's not backwards compatible so it wouldn't be possible to bulk convert without re-writing the existing bash tests.
Choosing bash also gives us some nicer features including 'local' variable definitions and regexes in if statements that are already widely used in the tests.
It's not expected that there are any users with only sh available due to the large number of bash tests that exist.
Discussed in relation to running shellcheck here:
https://lore.kernel.org/linux-perf-users/e3751a74be34bbf3781c4644f518702a7270220b.1749785642.git.collin.funk1@gmail.com/
When commit b02027776ac5 ("perf tests: Fix flakiness in BPF counters test on hybrid systems") was backported to several stable series (v5.15.221, v6.1.188, v6.6.157, v6.12.110, v6.18.52, v7.2.6) it introduced specific bash syntax. For versions after 2f5d370dec3f ("perf
test: Change all remaining #!/bin/sh to #!/bin/bash") in v6.17-rc1 this is not a problem as the shebang was already hanged to #!/bin/bash. For the older stable series this introduced invalid syntax if #!/bin/sh is not bash:
$ sh -n tools/perf/tests/shell/stat_bpf_counters.sh
tools/perf/tests/shell/stat_bpf_counters.sh: 12: Syntax error: "(" unexpected $ checkbashism tools/perf/tests/shell/stat_bpf_counters.sh
possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 52 (bash arrays, ${name[0|*|@]}):
base_instructions=$(perf stat --no-big-num -e instructions:u -- "${workload[@]}" 2>&1 | \
awk -v i=0 -v c=0 '/instructions/ { \
if ($1 != "<not") { i++; c += $1 } \
} END { if (i > 0) printf "%.0f", c; else print "<not" }')
possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 57 (bash arrays, ${name[0|*|@]}):
bpf_instructions=$(perf stat --no-big-num --bpf-counters -e instructions:u \
-- "${workload[@]}" 2>&1 | \
awk -v i=0 -v c=0 '/instructions/ { \
if ($1 != "<not") { i++; c += $1 } \
} END { if (i > 0) printf "%.0f", c; else print "<not" }')
possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 68 (bash arrays, ${name[0|*|@]}):
stat_output=$(perf stat --no-big-num \
-e instructions/name=base_instructions/u,instructions/name=bpf_instructions/bu \
-- "${workload[@]}" 2>&1)Change shebang for the stat_bpf_counters.sh script.
No upstream commit exists for this change as for versions post 6.17-rc1 the scripts were converted to #!/bin/bash already.
--- tools/perf/tests/shell/stat_bpf_counters.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/stat_bpf_counters.sh +1 -1
@@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # perf stat --bpf-counters test # SPDX-License-Identifier: GPL-2.0
Greg Kroah-Hartman
maintainerPATCH 558/877 ring-buffer: Add helper functions for allocations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit b1e7a590a0133606d3efd41aee38cdeac630b52f ]
The allocation of the per CPU buffer descriptor, the buffer page descriptors and the buffer page data itself can be pretty ugly:
kzalloc_node(ALIGN(sizeof(struct buffer_page), cache_line_size()),
GFP_KERNEL, cpu_to_node(cpu));And the data pages:
page = alloc_pages_node(cpu_to_node(cpu),
GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_COMP | __GFP_ZERO, order); if (!page) return NULL;
bpage->page = page_address(page);
rb_init_page(bpage->page);
Add helper functions to make the code easier to read.
This does make all allocations of the data page (bpage->page) allocated with the __GFP_RETRY_MAYFAIL flag (and not just the bulk allocator). Which is actually better, as allocating the data page for the ring buffer tracing should try hard but not trigger the OOM killer.
Stable backport adjustment for e743527c5bfd:
Keep only the read-page allocation refactor needed by the target. Express alloc_cpu_data as a statement-expression macro instead of adding a C function, retaining NUMA allocation, __GFP_RETRY_MAYFAIL, compound/zeroed pages, NULL failure handling, and data-page initialization.
Rename the existing rb_init_page initializer to rb_init_data_page, without changing its implementation, and update its callers. This supplies the context expected by the target without importing the unrelated cleanup from 7cf02d0aa6bd or introducing additional functions.
Drop the CPU-buffer and buffer-page descriptor refactors and the bulk and internal reader-page allocator conversions. These are not needed by the target; leaving them intact preserves this tree's ring_buffer_meta type, __GFP_RETRY_MAYFAIL descriptor allocations, and the existing bpage->order and resize-disabled fixes. Only newly allocated external read pages switch from __GFP_NORETRY to __GFP_RETRY_MAYFAIL in this backport.
The target's change to allocate using the saved bpage->order is deliberately left for e743527c5bfd itself.
Stable-dep-of: e743527c5bfd ("ring-buffer: Fix subbuf resize race with ring_buffer_alloc_read_page()")
--- kernel/trace/ring_buffer.c | 50 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 21 deletions(-)
kernel/trace/ring_buffer.c +29 -21
@@ -382,7 +382,7 @@ struct buffer_page {#define RB_WRITE_MASK 0xfffff#define RB_WRITE_INTCNT (1 << 20) -static void rb_init_page (struct buffer_data_page *bpage) +static void rb_init_data_page (struct buffer_data_page *bpage) {local_set (&bpage->commit,0 ); }
@@ -411,6 +411,21 @@ static void free_buffer_page(struct buffkfree (bpage); } +/* Try hard to allocate data pages without invoking the OOM killer. */ +#define alloc_cpu_data (cpu, order) ({ \ + struct buffer_data_page *__rb_data = NULL; \ + struct page *__rb_page; \ + \ + __rb_page = alloc_pages_node(cpu_to_node(cpu), \ + GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_COMP | __GFP_ZERO, \ + (order)); \ + if (__rb_page) { \ + __rb_data = page_address(__rb_page); \ + rb_init_data_page(__rb_data); \ + } \ + __rb_data; \ +}) +/* * We need to fit the time_stamp delta into 27 bits. */
@@ -2016,7 +2031,7 @@ static void rb_range_meta_init(struct tr*/ for (i =0 ; i < meta->nr_subbufs; i++) { meta->buffers[i] = i; -rb_init_page (subbuf); +rb_init_data_page (subbuf); subbuf += meta->subbuf_size; } }
@@ -2187,7 +2202,7 @@ static int __rb_allocate_pages(struct riif (!page) goto free_pages; bpage->page =page_address (page); -rb_init_page (bpage->page); +rb_init_data_page (bpage->page); } bpage->order = cpu_buffer->buffer->subbuf_order;
@@ -2293,7 +2308,7 @@ rb_allocate_cpu_buffer(struct trace_buffif (!page) goto fail_free_reader; bpage->page =page_address (page); -rb_init_page (bpage->page); +rb_init_data_page (bpage->page); }INIT_LIST_HEAD (&cpu_buffer->reader_page->list);
@@ -6008,7 +6023,7 @@ static void rb_clear_buffer_page(struct {local_set (&page->write,0 );local_set (&page->entries,0 ); -rb_init_page (page->page); +rb_init_data_page (page->page); page->read =0 ; }
@@ -6394,7 +6409,6 @@ ring_buffer_alloc_read_page(struct tracestruct ring_buffer_per_cpu *cpu_buffer;struct buffer_data_read_page *bpage =NULL ;unsigned long flags; -struct page *page;if (!cpumask_test_cpu (cpu, buffer->cpumask))return ERR_PTR (-ENODEV );
@@ -6416,22 +6430,16 @@ ring_buffer_alloc_read_page(struct tracearch_spin_unlock (&cpu_buffer->lock);local_irq_restore (flags); -if (bpage->data) - goto out; - - page =alloc_pages_node (cpu_to_node (cpu), -GFP_KERNEL | __GFP_NORETRY | __GFP_COMP | __GFP_ZERO, - cpu_buffer->buffer->subbuf_order); -if (!page) { -kfree (bpage); -return ERR_PTR (-ENOMEM ); +if (bpage->data) { +rb_init_data_page (bpage->data); + }else { + bpage->data =alloc_cpu_data (cpu, cpu_buffer->buffer->subbuf_order); +if (!bpage->data) { +kfree (bpage); +return ERR_PTR (-ENOMEM ); + } } - bpage->data =page_address (page); - - out: -rb_init_page (bpage->data); -return bpage; }EXPORT_SYMBOL_GPL (ring_buffer_alloc_read_page);
@@ -6640,7 +6648,7 @@ int ring_buffer_read_page(struct trace_b cpu_buffer->read_bytes +=rb_page_size (reader);/* swap the pages */ -rb_init_page (bpage); +rb_init_data_page (bpage); bpage = reader->page; reader->page = data_page->data;local_set (&reader->write,0 );
Greg Kroah-Hartman
maintainerPATCH 559/877 ring-buffer: Fix subbuf resize race with ring_buffer_alloc_read_page()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
[ Upstream commit e743527c5bfdceda1095bc0a9e596e2aebb6a9c3 ]
ring_buffer_alloc_read_page() is racy with ring_buffer_subbuf_order_set, it can allocate a reader page with an outdated order. This isn't a big issue, the user can still re-allocate a new reader page and try again.
However, what is more problematic is if the value of subbuf_order changes in the middle of ring_buffer_alloc_read_page(). In that case, bpage->order might not match the actual allocated memory.
Use bpage->order for the allocation to prevent this race.
--- kernel/trace/ring_buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/ring_buffer.c +1 -1
@@ -6433,7 +6433,7 @@ ring_buffer_alloc_read_page(struct traceif (bpage->data) {rb_init_data_page (bpage->data); }else { - bpage->data =alloc_cpu_data (cpu, cpu_buffer->buffer->subbuf_order); + bpage->data =alloc_cpu_data (cpu, bpage->order);if (!bpage->data) {kfree (bpage);return ERR_PTR (-ENOMEM );
Greg Kroah-Hartman
maintainerPATCH 560/877 sched: Rework prev_balance() to avoid stale prev references
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Stultz <[email protected]>
[ Upstream commit 7a3a6bfbd62a2ba3e0ef1e92d6b71abb66890825 ]
Historically, the prev value from __schedule() was the rq->curr. This prev value is passed down through numerous functions, and used in the class scheduler implementations. The fact that prev was on_cpu until the end of __schedule(), meant it was stable across the rq lock drops that the class->balance() implementations often do.
However, with proxy-exec, the prev passed to functions called by __schedule() is rq->donor, which may not be the same as rq->curr and may not be on_cpu, this makes the prev value potentially unstable across rq lock drops.
A recently found issue with proxy-exec, is when we begin doing return migration from try_to_wake_up(), its possible we may be waking up the rq->donor. When we do this, we proxy_resched_idle() to put_prev_set_next() setting the rq->donor to rq->idle, allowing the rq->donor to be return migrated and allowed to run.
This however runs into trouble, as on another cpu we might be in the middle of calling __schedule(). Conceptually the rq lock is held for the majority of the time, but in calling prev_balance() its possible the class->balance() handler call may briefly drop the rq lock. This opens a window for try_to_wake_up() to wake and return migrate the rq->donor before the class logic reacquires the rq lock.
Unfortunately prev_balance() pass in a prev argument, to which we pass rq->donor. However this prev value can now become stale and incorrect across a rq lock drop.
So, to correct this, rework the prev_balance() call so that it does not take a "prev" argument.
Backport adaptation for Linux 6.12, as a dependency of f3629c63a4af ("sched/core: Make core-sched flips wait for in-flight selections"):
This tree has no proxy execution. Alias rq->donor and rq->curr in a union, as upstream does without CONFIG_SCHED_PROXY_EXEC, so the existing curr updates also provide the scheduling context without separate state. Remove the prev parameter from prev_balance(), __pick_next_task(), and both pick_next_task() variants, and read rq->donor at their call sites.
Keep the stable sched_class balance and pick_next_task interfaces and the fair and sched_ext selection paths. Pass rq->donor to these existing callbacks; it aliases the on-CPU current task and remains stable across lock drops here. Drop the upstream deadline, RT, idle, and stop callback signature changes, along with assumptions about newer selection APIs, proxy execution, and lock annotations. No functions are added.
Label the CONFIG_SCHED_CORE closing directive in struct rq to match the target's patch context. The unmodified target patch applies cleanly after this adaptation. The core-selection counter fix remains in the target.
[ sashal: Reduced backport -- upstream 7a3a6bfbd62a2 touches 6 file(s), this
backport carries 2. Not backported here:
kernel/sched/deadline.c
kernel/sched/idle.c
kernel/sched/rt.c
kernel/sched/stop_task.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: f3629c63a4af ("sched/core: Make core-sched flips wait for in-flight selections")
--- kernel/sched/core.c | 39 +++++++++++++++++++-------------------- kernel/sched/sched.h | 8 ++++++-- 2 files changed, 25 insertions(+), 22 deletions(-)
kernel/sched/core.c +19 -20
@@ -5936,10 +5936,9 @@ static inline void schedule_debug(structschedstat_inc (this_rq ()->sched_count); } -static void prev_balance (struct rq *rq,struct task_struct *prev, -struct rq_flags *rf) +static void prev_balance (struct rq *rq,struct rq_flags *rf) { -const struct sched_class *start_class = prev->sched_class; +const struct sched_class *start_class = rq->donor->sched_class;const struct sched_class *class;#ifdef CONFIG_SCHED_CLASS_EXT
@@ -5964,7 +5963,7 @@ static void prev_balance(struct rq *rq,* a runnable task of @class priority or higher. */ for_active_class_range(class, start_class, &idle_sched_class) { -if (class->balance && class->balance (rq, prev, rf)) +if (class->balance && class->balance (rq, rq->donor, rf))break ; } }
@@ -5973,7 +5972,7 @@ static void prev_balance(struct rq *rq,* Pick up the highest-prio task: */ static inline struct task_struct * -__pick_next_task (struct rq *rq,struct task_struct *prev,struct rq_flags *rf) +__pick_next_task (struct rq *rq,struct rq_flags *rf) {const struct sched_class *class;struct task_struct *p;
@@ -5985,38 +5984,38 @@ __pick_next_task(struct rq *rq, struct t/* * Optimization: we know that if all tasks are in the fair class we can -* call that function directly, but only if the @prev task wasn't of a +* call that function directly, but only if the current task wasn't of a * higher scheduling class, because otherwise those lose the * opportunity to pull in more work from other CPUs. */ -if (likely (!sched_class_above (prev->sched_class, &fair_sched_class) && +if (likely (!sched_class_above (rq->donor->sched_class, &fair_sched_class) && rq->nr_running == rq->cfs.h_nr_queued)) { - p =pick_next_task_fair (rq, prev, rf); + p =pick_next_task_fair (rq, rq->donor, rf);if (unlikely (p ==RETRY_TASK )) goto restart;/* Assume the next prioritized class is idle_sched_class */ if (!p) { p =pick_task_idle (rq); -put_prev_set_next_task (rq, prev, p); +put_prev_set_next_task (rq, rq->donor, p); }return p; } restart: -prev_balance (rq, prev, rf); +prev_balance (rq, rf);for_each_active_class (class) {if (class->pick_next_task) { - p = class->pick_next_task (rq, prev); + p = class->pick_next_task (rq, rq->donor);if (p)return p; }else { p = class->pick_task (rq);if (p) { -put_prev_set_next_task (rq, prev, p); +put_prev_set_next_task (rq, rq->donor, p);return p; } }
@@ -6065,7 +6064,7 @@ extern void task_vruntime_update(structstatic void queue_core_balance (struct rq *rq);static struct task_struct * -pick_next_task (struct rq *rq,struct task_struct *prev,struct rq_flags *rf) +pick_next_task (struct rq *rq,struct rq_flags *rf) {struct task_struct *next, *p, *max =NULL ;const struct cpumask *smt_mask;
@@ -6077,7 +6076,7 @@ pick_next_task(struct rq *rq, struct tasbool need_sync;if (!sched_core_enabled (rq)) -return __pick_next_task (rq, prev, rf); +return __pick_next_task (rq, rf); cpu =cpu_of (rq);
@@ -6090,7 +6089,7 @@ pick_next_task(struct rq *rq, struct tas*/ rq->core_pick =NULL ; rq->core_dl_server =NULL ; -return __pick_next_task (rq, prev, rf); +return __pick_next_task (rq, rf); }/*
@@ -6114,7 +6113,7 @@ pick_next_task(struct rq *rq, struct tas goto out_set_next; } -prev_balance (rq, prev, rf); +prev_balance (rq, rf); smt_mask =cpu_smt_mask (cpu); need_sync = !!rq->core->core_cookie;
@@ -6287,7 +6286,7 @@ pick_next_task(struct rq *rq, struct tas } out_set_next: -put_prev_set_next_task (rq, prev, next); +put_prev_set_next_task (rq, rq->donor, next);if (rq->core->core_forceidle_count && next == rq->idle)queue_core_balance (rq);
@@ -6512,9 +6511,9 @@ static inline void sched_core_cpu_deactistatic inline void sched_core_cpu_dying (unsigned int cpu) {}static struct task_struct * -pick_next_task (struct rq *rq,struct task_struct *prev,struct rq_flags *rf) +pick_next_task (struct rq *rq,struct rq_flags *rf) { -return __pick_next_task (rq, prev, rf); +return __pick_next_task (rq, rf); }#endif /* CONFIG_SCHED_CORE */
@@ -6682,7 +6681,7 @@ static void __sched notrace __schedule(i switch_count = &prev->nvcsw; } - next =pick_next_task (rq, prev, &rf); + next =pick_next_task (rq, &rf); picked:clear_tsk_need_resched (prev);clear_preempt_need_resched ();
kernel/sched/sched.h +6 -2
@@ -1184,7 +1184,11 @@ struct rq {*/ unsigned long nr_uninterruptible; -struct task_struct __rcu *curr; +/* Scheduling and execution contexts coincide without proxy execution. */ +union { +struct task_struct __rcu *donor; +struct task_struct __rcu *curr; + };struct sched_dl_entity *dl_server;struct task_struct *idle;struct task_struct *stop;
@@ -1326,7 +1330,7 @@ struct rq {unsigned int core_forceidle_seq;unsigned int core_forceidle_occupation;u64 core_forceidle_start; -#endif +#endif /* CONFIG_SCHED_CORE */ /* Scratch cpumask to be temporarily used under rq_lock */ cpumask_var_t scratch_mask;
Greg Kroah-Hartman
maintainerPATCH 561/877 sched/core: Make core-sched flips wait for in-flight selections
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tejun Heo <[email protected]>
[ Upstream commit f3629c63a4af3e491381780bc6c123cb498c4c40 ]
Core scheduling's pick_next_task() operates on all sibling rqs under one acquisition of the shared core-wide lock. A ->pick_task() that releases the rq lock leaves every sibling __lock momentarily free, letting __sched_core_flip(false) complete mid-selection and rebind rq_lockp() under it. The selection resumes on the split locks, touching sibling state it no longer protects, and __schedule() finally releases a lock that was never taken while leaking the one that was.
Count in-flight core-wide selections in the leader's rq->core_pick_in_flight and make __sched_core_flip() wait for the count to drain. The count only changes under the shared lock, which the flip holds while sampling, so no other ordering is needed. The wait can repeat while selections overlap, but the flip backs off between samples and flips are rare cookie-lifetime events.
sched_core_cpu_deactivate() moves the count to the new leader - a stale copy left behind would bias it forever if that CPU later returns as its own leader.
--- kernel/sched/core.c | 22 ++++++++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 23 insertions(+)
kernel/sched/core.c +22 -0
@@ -401,6 +401,17 @@ static void __sched_core_flip(bool enablsched_core_lock (cpu, &flags); +/* +* A core-wide selection may have the shared rq lock temporarily +* released by a lock-dropping ->pick_task(). Flipping would +* rebind rq_lockp() under it. Wait it out. +*/ +while (cpu_rq (cpu)->core->core_pick_in_flight) { +sched_core_unlock (cpu, &flags); +cpu_relax (); +sched_core_lock (cpu, &flags); + } +for_each_cpu (t, smt_mask)cpu_rq (t)->core_enabled = enabled;
@@ -6092,6 +6103,8 @@ pick_next_task(struct rq *rq, struct rq_return __pick_next_task (rq, rf); } + rq->core->core_pick_in_flight++; +/* * If there were no {en,de}queues since we picked (IOW, the task * pointers are all still valid), and we haven't scheduled the last
@@ -6286,6 +6299,7 @@ pick_next_task(struct rq *rq, struct rq_ } out_set_next: + rq->core->core_pick_in_flight--;put_prev_set_next_task (rq, rq->donor, next);if (rq->core->core_forceidle_count && next == rq->idle)queue_core_balance (rq);
@@ -6483,6 +6497,13 @@ static void sched_core_cpu_deactivate(un core_rq->core_forceidle_occupation = rq->core_forceidle_occupation;/* +* A stale leftover would bias the count forever if this CPU later +* returns as its own leader. Move, don't copy. +*/ + core_rq->core_pick_in_flight = rq->core_pick_in_flight; + rq->core_pick_in_flight =0 ; + +/* * Accounting edge for forced idle is handled in pick_next_task(). * Don't need another one here, since the hotplug thread shouldn't * have a cookie.
@@ -8553,6 +8574,7 @@ void __init sched_init(void) rq->core_forceidle_count =0 ; rq->core_forceidle_occupation =0 ; rq->core_forceidle_start =0 ; + rq->core_pick_in_flight =0 ; rq->core_cookie =0UL ;#endif
kernel/sched/sched.h +1 -0
@@ -1330,6 +1330,7 @@ struct rq {unsigned int core_forceidle_seq;unsigned int core_forceidle_occupation;u64 core_forceidle_start; +unsigned int core_pick_in_flight;#endif /* CONFIG_SCHED_CORE */ /* Scratch cpumask to be temporarily used under rq_lock */
Greg Kroah-Hartman
maintainerPATCH 562/877 ASoC: codecs: aw88261: reduce log spam
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Val Packett <[email protected]>
[ Upstream commit d90c361af215a9fa2a986d9f47d554d0cf3401dd ]
This driver would create a wall of logspam during initialization due to e.g. the PLL not being ready while waiting for it to stabilize. Change intermediate dev_err() calls to dev_dbg() to reduce the noise.
While here, log the detected chip ID when that check fails.
Stable-dep-of: 06b6f1245567 ("ASoC: codecs: aw88261: only check PLL and clock state at power-up")
--- sound/soc/codecs/aw88261.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-)
sound/soc/codecs/aw88261.c +14 -10
@@ -150,7 +150,7 @@ static int aw88261_dev_get_iis_status(stif (ret)return ret;if ((reg_val &AW88261_BIT_PLL_CHECK ) !=AW88261_BIT_PLL_CHECK ) { -dev_err (aw_dev->dev,"check pll lock fail,reg_val:0x%04x" , reg_val); +dev_dbg (aw_dev->dev,"check pll lock fail,reg_val:0x%04x" , reg_val);return -EINVAL ; }
@@ -164,7 +164,7 @@ static int aw88261_dev_check_mode1_pll(sfor (i =0 ; i <AW88261_DEV_SYSST_CHECK_MAX ; i++) { ret =aw88261_dev_get_iis_status (aw_dev);if (ret) { -dev_err (aw_dev->dev,"mode1 iis signal check error" ); +dev_dbg (aw_dev->dev,"mode1 iis signal check error" );usleep_range (AW88261_2000_US ,AW88261_2000_US +10 ); }else {return ret;
@@ -255,7 +255,7 @@ static int aw88261_dev_check_sysst(struc check_val = reg_val & (~AW88261_BIT_SYSST_CHECK_MASK ) &AW88261_BIT_SYSST_CHECK ;if (check_val !=AW88261_BIT_SYSST_CHECK ) { -dev_err (aw_dev->dev,"check sysst fail, reg_val=0x%04x, check:0x%x" , +dev_dbg (aw_dev->dev,"check sysst fail, reg_val=0x%04x, check:0x%x" , reg_val,AW88261_BIT_SYSST_CHECK );usleep_range (AW88261_2000_US ,AW88261_2000_US +10 ); }else {
@@ -549,7 +549,7 @@ static int aw88261_dev_start(struct aw88int ret;if (aw_dev->status ==AW88261_DEV_PW_ON ) { -dev_info (aw_dev->dev,"already power on" ); +dev_dbg (aw_dev->dev,"already power on" );return 0 ; }
@@ -559,7 +559,7 @@ static int aw88261_dev_start(struct aw88 ret =aw88261_dev_check_syspll (aw_dev);if (ret) { -dev_err (aw_dev->dev,"pll check failed cannot start" ); +dev_dbg (aw_dev->dev,"pll check failed" ); goto pll_check_fail; }
@@ -570,7 +570,7 @@ static int aw88261_dev_start(struct aw88/* check i2s status */ ret =aw88261_dev_check_sysst (aw_dev);if (ret) { -dev_err (aw_dev->dev,"sysst check failed" ); +dev_dbg (aw_dev->dev,"sysst check failed" ); goto sysst_check_fail; }
@@ -671,18 +671,22 @@ static void aw88261_start_pa(struct aw88for (i =0 ; i <AW88261_START_RETRIES ; i++) { ret =aw88261_reg_update (aw88261, aw88261->phase_sync);if (ret) { -dev_err (aw88261->aw_pa->dev,"fw update failed, cnt:%d\n" , i); +dev_dbg (aw88261->aw_pa->dev, +"aw88261_reg_update failed, cnt:%d, ret:%d\n" , i, ret);continue ; } ret =aw88261_dev_start (aw88261);if (ret) { -dev_err (aw88261->aw_pa->dev,"aw88261 device start failed. retry = %d" , i); +dev_dbg (aw88261->aw_pa->dev, +"aw88261_dev_start failed, cnt:%d, ret:%d\n" , i, ret);continue ; }else { -dev_info (aw88261->aw_pa->dev,"start success\n" ); +dev_dbg (aw88261->aw_pa->dev,"start success\n" );break ; } } +if (ret !=0 ) +dev_err (aw88261->aw_pa->dev,"start failure (%d)\n" , ret); }static void aw88261_startup_work (struct work_struct *work)
@@ -1200,7 +1204,7 @@ static int aw88261_init(struct aw88261 *return ret; }if (chip_id !=AW88261_CHIP_ID ) { -dev_err (&i2c->dev,"unsupported device" ); +dev_err (&i2c->dev,"unsupported device id = %x" , chip_id);return -ENXIO ; }
Greg Kroah-Hartman
maintainerPATCH 563/877 ASoC: codecs: aw88261: only check PLL and clock state at power-up
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jorijn van der Graaf <[email protected]>
[ Upstream commit 06b6f1245567a4be862c3e1cc74577922ceb05fb ]
The SYSST check performed during device start requires SWS (amplifier switching, bit 8) and BSTS (boost finished, bit 9) on top of PLL lock and clock stability. Those bits cannot be asserted at this point in the
sequence: the check runs after amppd release but before the hmute/ULS-hmute release, and the amplifier neither switches nor finishes ramping its boost converter while it is still muted. With the Fairphone (Gen. 6) firmware profile, aw88261_dev_start() therefore always fails with
check sysst fail, reg_val=0x0011, check:0x311
and playback aborts, even though the amplifier is fine and PLL lock and stable clocks are present.
Check only PLL lock and clock stability, for which a definition already exists; this still re-validates the clocks after amppd release (aw88261_dev_check_syspll() checked them before it). This matches the vendor aw882xx driver, which only validates PLL lock and clock stability at this stage, and the in-tree aw88399 driver, which skips the SWS check whenever the amplifier may legitimately not be switching (AW88399_BIT_SYSST_NOSWS_CHECK).
--- sound/soc/codecs/aw88261.c | 6 +++--- sound/soc/codecs/aw88261.h | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-)
sound/soc/codecs/aw88261.c +3 -3
@@ -253,10 +253,10 @@ static int aw88261_dev_check_sysst(strucreturn ret; check_val = reg_val & (~AW88261_BIT_SYSST_CHECK_MASK ) - &AW88261_BIT_SYSST_CHECK ; -if (check_val !=AW88261_BIT_SYSST_CHECK ) { + &AW88261_BIT_PLL_CHECK ; +if (check_val !=AW88261_BIT_PLL_CHECK ) {dev_dbg (aw_dev->dev,"check sysst fail, reg_val=0x%04x, check:0x%x" , - reg_val,AW88261_BIT_SYSST_CHECK ); + reg_val,AW88261_BIT_PLL_CHECK );usleep_range (AW88261_2000_US ,AW88261_2000_US +10 ); }else {return 0 ;
sound/soc/codecs/aw88261.h +0 -6
@@ -181,12 +181,6 @@ AW88261_OTHS_OT_VALUE | \ AW88261_PLLS_LOCKED_VALUE)) -#define AW88261_BIT_SYSST_CHECK \ - (AW88261_BSTS_FINISHED_VALUE | \ - AW88261_SWS_SWITCHING_VALUE | \ - AW88261_CLKS_STABLE_VALUE | \ - AW88261_PLLS_LOCKED_VALUE) -#define AW88261_ULS_HMUTE_START_BIT (14)#define AW88261_ULS_HMUTE_BITS_LEN (1)#define AW88261_ULS_HMUTE_MASK \
Greg Kroah-Hartman
maintainerPATCH 564/877 ring-buffer: Make cpu_buffer::free_page a buffer_data_read_page
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
[ Upstream commit 7a1fb95de5404134f8758c1295ce88986bdf117c ]
Discarding a cached reader page after a concurrent ring buffer resize uses the new global subbuf_order for the free_pages() call. This mismatched order may crashes the kernel or leaks memory because the cached page was allocated under the old size.
Save the actual free_page order alongside the page address to ensure we always refer to the correct value and do not rely on the potentially stalled cpu_buffer->subbuf_order value. The simplest is to make free_page a buffer_data_read_page which already covers exactly what we
need: a page address and a page order.
--- kernel/trace/ring_buffer.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
kernel/trace/ring_buffer.c +10 -10
@@ -507,7 +507,7 @@ struct ring_buffer_per_cpu {raw_spinlock_t reader_lock;/* serialize readers */ arch_spinlock_t lock;struct lock_class_key lock_key; -struct buffer_data_page *free_page; +struct buffer_data_read_page free_page;unsigned long nr_pages;unsigned int current_context;struct list_head *pages;
@@ -2376,7 +2376,7 @@ static void rb_free_cpu_buffer(struct rifree_buffer_page (bpage); } -free_pages ((unsigned long )cpu_buffer->free_page, cpu_buffer->buffer->subbuf_order); +free_pages ((unsigned long )cpu_buffer->free_page.data, cpu_buffer->free_page.order);kfree (cpu_buffer); }
@@ -6422,9 +6422,9 @@ ring_buffer_alloc_read_page(struct tracelocal_irq_save (flags);arch_spin_lock (&cpu_buffer->lock); -if (cpu_buffer->free_page) { - bpage->data = cpu_buffer->free_page; - cpu_buffer->free_page =NULL ; +if (cpu_buffer->free_page.data) { + *bpage = cpu_buffer->free_page; + cpu_buffer->free_page.data =NULL ; }arch_spin_unlock (&cpu_buffer->lock);
@@ -6476,8 +6476,8 @@ void ring_buffer_free_read_page(struct tlocal_irq_save (flags);arch_spin_lock (&cpu_buffer->lock); -if (!cpu_buffer->free_page) { - cpu_buffer->free_page = bpage; +if (!cpu_buffer->free_page.data) { + cpu_buffer->free_page = *data_page; bpage =NULL ; }
@@ -6838,7 +6838,7 @@ int ring_buffer_subbuf_order_set(struct }for_each_buffer_cpu (buffer, cpu) { -struct buffer_data_page *old_free_data_page; +struct buffer_data_read_page old_free_data_page;struct list_head old_pages;unsigned long flags;
@@ -6881,7 +6881,7 @@ int ring_buffer_subbuf_order_set(structarch_spin_lock (&cpu_buffer->lock); old_free_data_page = cpu_buffer->free_page; - cpu_buffer->free_page =NULL ; + cpu_buffer->free_page.data =NULL ;arch_spin_unlock (&cpu_buffer->lock);rb_head_page_activate (cpu_buffer);
@@ -6893,7 +6893,7 @@ int ring_buffer_subbuf_order_set(structlist_del_init (&bpage->list);free_buffer_page (bpage); } -free_pages ((unsigned long )old_free_data_page, old_order); +free_pages ((unsigned long )old_free_data_page.data, old_free_data_page.order);rb_check_pages (cpu_buffer); }
Greg Kroah-Hartman
maintainerPATCH 565/877 dmaengine: Add devm_dma_request_chan()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bence Csókás <[email protected]>
[ Upstream commit 08bf1663c21a3e815eda28fa242d84c945ca3b94 ]
Expand the arsenal of devm functions for DMA devices, this time for requesting channels.
Stable-dep-of: 777979e62711 ("i2c: mxs: fix DMA channel leak on probe error")
--- drivers/dma/dmaengine.c | 30 ++++++++++++++++++++++++++++++ include/linux/dmaengine.h | 7 +++++++ 2 files changed, 37 insertions(+)
drivers/dma/dmaengine.c +30 -0
@@ -933,6 +933,36 @@ void dma_release_channel(struct dma_chan }EXPORT_SYMBOL_GPL (dma_release_channel); +static void dmaenginem_release_channel (void *chan) +{ +dma_release_channel (chan); +} + +/** +* devm_dma_request_chan - try to allocate an exclusive slave channel +* @dev: pointer to client device structure +* @name: slave channel name +* +* Returns pointer to appropriate DMA channel on success or an error pointer. +* +* The operation is managed and will be undone on driver detach. +*/ + +struct dma_chan *devm_dma_request_chan (struct device *dev,const char *name) +{ +struct dma_chan *chan =dma_request_chan (dev, name); +int ret =0 ; + +if (!IS_ERR (chan)) + ret =devm_add_action_or_reset (dev, dmaenginem_release_channel, chan); + +if (ret) +return ERR_PTR (ret); + +return chan; +} +EXPORT_SYMBOL_GPL (devm_dma_request_chan); +/** * dmaengine_get - register interest in dma_channels */
include/linux/dmaengine.h +7 -0
@@ -1521,6 +1521,7 @@ struct dma_chan *__dma_request_channel(cstruct dma_chan *dma_request_chan (struct device *dev,const char *name);struct dma_chan *dma_request_chan_by_mask (const dma_cap_mask_t *mask); +struct dma_chan *devm_dma_request_chan (struct device *dev,const char *name);void dma_release_channel (struct dma_chan *chan);int dma_get_slave_caps (struct dma_chan *chan,struct dma_slave_caps *caps);
@@ -1557,6 +1558,12 @@ static inline struct dma_chan *dma_reque {return ERR_PTR (-ENODEV ); } + +static inline struct dma_chan *devm_dma_request_chan (struct device *dev,const char *name) +{ +return ERR_PTR (-ENODEV ); +} +static inline void dma_release_channel (struct dma_chan *chan) { }
Greg Kroah-Hartman
maintainerPATCH 566/877 i2c: mxs: fix DMA channel leak on probe error
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 777979e627115734052b323d2721cdb500e81dcf ]
mxs_i2c_probe() requests an exclusive DMA channel before resetting the controller and registering the I2C adapter. If either later operation fails, probe returns without releasing the channel because the remove callback is not invoked after a failed probe.
Use devm_dma_request_chan() so the device core releases the channel on probe failure and driver detach. Remove the manual release from the remove callback because the channel is now device-managed.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/i2c/busses/i2c-mxs.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/i2c/busses/i2c-mxs.c +1 -4
@@ -831,7 +831,7 @@ static int mxs_i2c_probe(struct platform }/* Setup the DMA */ - i2c->dmach =dma_request_chan (dev,"rx-tx" ); + i2c->dmach =devm_dma_request_chan (dev,"rx-tx" );if (IS_ERR (i2c->dmach)) {return dev_err_probe (dev,PTR_ERR (i2c->dmach),"Failed to request dma\n" );
@@ -869,9 +869,6 @@ static void mxs_i2c_remove(struct platfoi2c_del_adapter (&i2c->adapter); -if (i2c->dmach) -dma_release_channel (i2c->dmach); -writel (MXS_I2C_CTRL0_SFTRST , i2c->regs +MXS_I2C_CTRL0_SET ); }
Greg Kroah-Hartman
maintainerPATCH 567/877 lockd: fix swapped arguments in nlmsvc_match_ip()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oscar Ou <[email protected]>
[ Upstream commit b9060689f49dc663e9a3d069c4a65ff63a836e66 ]
When releasing locks by server IP address via /proc/fs/nfsd/unlock_ip, nlmsvc_unlock_all_by_ip() calls nlm_traverse_files() with the server sockaddr as the opaque @data argument:
nlm_traverse_files(server_addr, nlmsvc_match_ip, NULL);
The match callback is later invoked from nlm_traverse_locks() as:
match(lockhost, host);
where the first argument is the nlm_host that owns the lock, and the second argument is the @data that was originally passed down (here the server sockaddr). This is the convention every other match callback relies on (nlmsvc_mark_host(), nlmsvc_same_host(), nlmsvc_is_client()):
arg1 is the real nlm_host, arg2 is the caller-supplied reference value.
nlmsvc_match_ip() has had these two arguments reversed ever since the unlock-by-IP feature was introduced in commit 4373ea84c84d ("lockd:
unlock lockd locks associated with a given server ip"):
return rpc_cmp_addr(nlm_srcaddr(host), datap);
Here @host is actually the server sockaddr, so nlm_srcaddr(host) dereferences a struct sockaddr as a struct nlm_host and reads garbage at the offset of h_srcaddr; meanwhile @datap is actually the lock owner's nlm_host but is compared as a sockaddr. As a result the comparison practically never matches and locks are not released for the requested IP.
Swap the arguments so the lock owner's source address is compared against the requested server address:
return rpc_cmp_addr(nlm_srcaddr(datap), (struct sockaddr *)host);
--- fs/lockd/svcsubs.c | 2 +- include/linux/lockd/lockd.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/lockd/svcsubs.c +1 -1
@@ -493,7 +493,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sstatic int nlmsvc_match_ip (void *datap,struct nlm_host *host) { -return rpc_cmp_addr (nlm_srcaddr (host), datap); +return rpc_cmp_addr (nlm_srcaddr (datap), (struct sockaddr *)host); }/**
include/linux/lockd/lockd.h +1 -1
@@ -268,7 +268,7 @@ void nsm_release(struct nsm_handle *n* This is used in garbage collection and resource reclaim * A return value != 0 means destroy the lock/block/share */ -typedef int (*nlm_host_match_fn_t )(void *cur,struct nlm_host *ref); +typedef int (*nlm_host_match_fn_t )(void *owner,struct nlm_host *ref);/* * Server-side lock handling
Greg Kroah-Hartman
maintainerPATCH 568/877 firmware: qcom_scm: Rename peripheral as pas_id
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit 69054348cc1c2d87acad90aec5e6e0d191012aff ]
Peripheral and pas_id refers to unique id for a subsystem and used only when peripheral authentication service from secure world is utilized.
Lets rename peripheral to pas_id to reflect closer to its meaning.
Stable-dep-of: c06c5ab49453 ("remoteproc: qcom: pas: Guard dtb metadata release with dtb_pas_id check")
--- drivers/firmware/qcom/qcom_scm.c | 30 +++++++++++++++--------------- include/linux/firmware/qcom/qcom_scm.h | 10 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-)
drivers/firmware/qcom/qcom_scm.c +15 -15
@@ -572,7 +572,7 @@ static void qcom_scm_set_download_mode(u* qcom_scm_pas_init_image() - Initialize peripheral authentication service * state machine for a given peripheral, using the * metadata -* @peripheral: peripheral id +* @pas_id: peripheral authentication service id * @metadata: pointer to memory containing ELF header, program header table * and optional blob of data used for authenticating the metadata * and the rest of the firmware
@@ -585,7 +585,7 @@ static void qcom_scm_set_download_mode(u* track the metadata allocation, this needs to be released by invoking * qcom_scm_pas_metadata_release() by the caller. */ -int qcom_scm_pas_init_image (u32 peripheral,const void *metadata,size_t size, +int qcom_scm_pas_init_image (u32 pas_id,const void *metadata,size_t size,struct qcom_scm_pas_metadata *ctx) {dma_addr_t mdata_phys;
@@ -595,7 +595,7 @@ int qcom_scm_pas_init_image(u32 peripher .svc = QCOM_SCM_SVC_PIL, .cmd = QCOM_SCM_PIL_PAS_INIT_IMAGE, .arginfo = QCOM_SCM_ARGS(2, QCOM_SCM_VAL, QCOM_SCM_RW), - .args[0] = peripheral, + .args[0] = pas_id, .owner = ARM_SMCCC_OWNER_SIP, };struct qcom_scm_res res;
@@ -668,20 +668,20 @@ EXPORT_SYMBOL_GPL(qcom_scm_pas_metadata_/** * qcom_scm_pas_mem_setup() - Prepare the memory related to a given peripheral * for firmware loading -* @peripheral: peripheral id +* @pas_id: peripheral authentication service id * @addr: start address of memory area to prepare * @size: size of the memory area to prepare * * Returns 0 on success. */ -int qcom_scm_pas_mem_setup (u32 peripheral,phys_addr_t addr,phys_addr_t size) +int qcom_scm_pas_mem_setup (u32 pas_id,phys_addr_t addr,phys_addr_t size) {int ret;struct qcom_scm_desc desc = { .svc =QCOM_SCM_SVC_PIL , .cmd =QCOM_SCM_PIL_PAS_MEM_SETUP , .arginfo =QCOM_SCM_ARGS (3 ), - .args[0 ] = peripheral, + .args[0 ] = pas_id, .args[1 ] = addr, .args[2 ] = size, .owner =ARM_SMCCC_OWNER_SIP ,
@@ -709,18 +709,18 @@ EXPORT_SYMBOL_GPL(qcom_scm_pas_mem_setup/** * qcom_scm_pas_auth_and_reset() - Authenticate the given peripheral firmware * and reset the remote processor -* @peripheral: peripheral id +* @pas_id: peripheral authentication service id * * Return 0 on success. */ -int qcom_scm_pas_auth_and_reset (u32 peripheral) +int qcom_scm_pas_auth_and_reset (u32 pas_id) {int ret;struct qcom_scm_desc desc = { .svc =QCOM_SCM_SVC_PIL , .cmd =QCOM_SCM_PIL_PAS_AUTH_AND_RESET , .arginfo =QCOM_SCM_ARGS (1 ), - .args[0 ] = peripheral, + .args[0 ] = pas_id, .owner =ARM_SMCCC_OWNER_SIP , };struct qcom_scm_res res;
@@ -745,18 +745,18 @@ EXPORT_SYMBOL_GPL(qcom_scm_pas_auth_and_/** * qcom_scm_pas_shutdown() - Shut down the remote processor -* @peripheral: peripheral id +* @pas_id: peripheral authentication service id * * Returns 0 on success. */ -int qcom_scm_pas_shutdown (u32 peripheral) +int qcom_scm_pas_shutdown (u32 pas_id) {int ret;struct qcom_scm_desc desc = { .svc =QCOM_SCM_SVC_PIL , .cmd =QCOM_SCM_PIL_PAS_SHUTDOWN , .arginfo =QCOM_SCM_ARGS (1 ), - .args[0 ] = peripheral, + .args[0 ] = pas_id, .owner =ARM_SMCCC_OWNER_SIP , };struct qcom_scm_res res;
@@ -782,18 +782,18 @@ EXPORT_SYMBOL_GPL(qcom_scm_pas_shutdown)/** * qcom_scm_pas_supported() - Check if the peripheral authentication service is * available for the given peripherial -* @peripheral: peripheral id +* @pas_id: peripheral authentication service id * * Returns true if PAS is supported for this peripheral, otherwise false. */ -bool qcom_scm_pas_supported (u32 peripheral) +bool qcom_scm_pas_supported (u32 pas_id) {int ret;struct qcom_scm_desc desc = { .svc =QCOM_SCM_SVC_PIL , .cmd =QCOM_SCM_PIL_PAS_IS_SUPPORTED , .arginfo =QCOM_SCM_ARGS (1 ), - .args[0 ] = peripheral, + .args[0 ] = pas_id, .owner =ARM_SMCCC_OWNER_SIP , };struct qcom_scm_res res;
include/linux/firmware/qcom/qcom_scm.h +5 -5
@@ -72,13 +72,13 @@ struct qcom_scm_pas_metadata {ssize_t size; }; -int qcom_scm_pas_init_image (u32 peripheral,const void *metadata,size_t size, +int qcom_scm_pas_init_image (u32 pas_id,const void *metadata,size_t size,struct qcom_scm_pas_metadata *ctx);void qcom_scm_pas_metadata_release (struct qcom_scm_pas_metadata *ctx); -int qcom_scm_pas_mem_setup (u32 peripheral,phys_addr_t addr,phys_addr_t size); -int qcom_scm_pas_auth_and_reset (u32 peripheral); -int qcom_scm_pas_shutdown (u32 peripheral); -bool qcom_scm_pas_supported (u32 peripheral); +int qcom_scm_pas_mem_setup (u32 pas_id,phys_addr_t addr,phys_addr_t size); +int qcom_scm_pas_auth_and_reset (u32 pas_id); +int qcom_scm_pas_shutdown (u32 pas_id); +bool qcom_scm_pas_supported (u32 pas_id);int qcom_scm_io_readl (phys_addr_t addr,unsigned int *val);int qcom_scm_io_writel (phys_addr_t addr,unsigned int val);
Greg Kroah-Hartman
maintainerPATCH 569/877 remoteproc: pas: Replace metadata context with PAS context structure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit b13d8baf56016e7eec29395b52d18b91df081d48 ]
As a superset of the existing metadata context, the PAS context structure enables both remoteproc and non-remoteproc subsystems to better support scenarios where the SoC runs with or without the Gunyah hypervisor. To reflect this, relevant SCM and metadata functions are updated to incorporate PAS context awareness and remove metadata context data structure completely.
Stable adaptation for c06c5ab4945392d2c2aded6d832ab6b58cabe351:
This tree has neither the PAS context allocator nor the later generic PAS service and context-aware MDT loader. Define the PAS context in the existing SCM header and allocate and initialize it in adsp_probe() using devm_kzalloc(), without adding any functions. Keep the stable MDT loader interfaces and update their existing context arguments and declarations.
Rename the existing metadata release implementation and its callers to qcom_pas_metadata_release(), as used by the target fix. Keep the driver's adsp names except for the local PAS pointer in adsp_load(). Handle DTB initialization failure inline, preserving its existing cleanup behavior, so that the target can remove the shared load-failure cleanup label. The remaining load-failure path and its context now support a clean three-way cherry-pick of the target without importing the newer loader helper.
Stable-dep-of: c06c5ab49453 ("remoteproc: qcom: pas: Guard dtb metadata release with dtb_pas_id check")
--- drivers/firmware/qcom/qcom_scm.c | 14 ++--- drivers/remoteproc/qcom_q6v5_pas.c | 84 ++++++++++++++++++++------------- drivers/soc/qcom/mdt_loader.c | 4 - include/linux/firmware/qcom/qcom_scm.h | 10 ++- include/linux/soc/qcom/mdt_loader.h | 6 +- 5 files changed, 72 insertions(+), 46 deletions(-)
drivers/firmware/qcom/qcom_scm.c +7 -7
@@ -577,16 +577,16 @@ static void qcom_scm_set_download_mode(u* and optional blob of data used for authenticating the metadata * and the rest of the firmware * @size: size of the metadata -* @ctx: optional metadata context +* @ctx: optional pas context * * Return: 0 on success. * * Upon successful return, the PAS metadata context (@ctx) will be used to * track the metadata allocation, this needs to be released by invoking -* qcom_scm_pas_metadata_release() by the caller. +* qcom_pas_metadata_release() by the caller. */ int qcom_scm_pas_init_image (u32 pas_id,const void *metadata,size_t size, -struct qcom_scm_pas_metadata *ctx) +struct qcom_scm_pas_context *ctx) {dma_addr_t mdata_phys;void *mdata_buf;
@@ -649,10 +649,10 @@ out:EXPORT_SYMBOL_GPL (qcom_scm_pas_init_image);/** -* qcom_scm_pas_metadata_release() - release metadata context -* @ctx: metadata context +* qcom_pas_metadata_release() - release metadata context +* @ctx: pas context */ -void qcom_scm_pas_metadata_release (struct qcom_scm_pas_metadata *ctx) +void qcom_pas_metadata_release (struct qcom_scm_pas_context *ctx) {if (!ctx->ptr)return ;
@@ -663,7 +663,7 @@ void qcom_scm_pas_metadata_release(struc ctx->phys =0 ; ctx->size =0 ; } -EXPORT_SYMBOL_GPL (qcom_scm_pas_metadata_release); +EXPORT_SYMBOL_GPL (qcom_pas_metadata_release);/** * qcom_scm_pas_mem_setup() - Prepare the memory related to a given peripheral
drivers/remoteproc/qcom_q6v5_pas.c +53 -31
149 lines not on this page · raw message
drivers/soc/qcom/mdt_loader.c +2 -2
@@ -234,13 +234,13 @@ EXPORT_SYMBOL_GPL(qcom_mdt_read_metadata* @fw_name: name of the firmware, for construction of segment file names * @pas_id: PAS identifier * @mem_phys: physical address of allocated memory region -* @ctx: PAS metadata context, to be released by caller +* @ctx: PAS context, metadata to be released by caller * * Returns 0 on success, negative errno otherwise. */ int qcom_mdt_pas_init (struct device *dev,const struct firmware *fw,const char *fw_name,int pas_id,phys_addr_t mem_phys, -struct qcom_scm_pas_metadata *ctx) +struct qcom_scm_pas_context *ctx) {const struct elf32_phdr *phdrs;const struct elf32_phdr *phdr;
include/linux/firmware/qcom/qcom_scm.h +7 -3
@@ -66,15 +66,19 @@ int qcom_scm_set_warm_boot_addr(void *envoid qcom_scm_cpu_power_down (u32 flags);int qcom_scm_set_remote_state (u32 state,u32 id); -struct qcom_scm_pas_metadata { +struct qcom_scm_pas_context { +struct device *dev; +u32 pas_id; +phys_addr_t mem_phys; +size_t mem_size;void *ptr;dma_addr_t phys;ssize_t size; };int qcom_scm_pas_init_image (u32 pas_id,const void *metadata,size_t size, -struct qcom_scm_pas_metadata *ctx); -void qcom_scm_pas_metadata_release (struct qcom_scm_pas_metadata *ctx); +struct qcom_scm_pas_context *ctx); +void qcom_pas_metadata_release (struct qcom_scm_pas_context *ctx);int qcom_scm_pas_mem_setup (u32 pas_id,phys_addr_t addr,phys_addr_t size);int qcom_scm_pas_auth_and_reset (u32 pas_id);int qcom_scm_pas_shutdown (u32 pas_id);
include/linux/soc/qcom/mdt_loader.h +3 -3
@@ -10,14 +10,14 @@struct device ;struct firmware ; -struct qcom_scm_pas_metadata ; +struct qcom_scm_pas_context ;#if IS_ENABLED (CONFIG_QCOM_MDT_LOADER )ssize_t qcom_mdt_get_size (const struct firmware *fw);int qcom_mdt_pas_init (struct device *dev,const struct firmware *fw,const char *fw_name,int pas_id,phys_addr_t mem_phys, -struct qcom_scm_pas_metadata *pas_metadata_ctx); +struct qcom_scm_pas_context *pas_ctx); int qcom_mdt_load(struct device *dev, const struct firmware *fw, const char *fw_name, int pas_id, void *mem_region, phys_addr_t mem_phys, size_t mem_size,
@@ -39,7 +39,7 @@ static inline ssize_t qcom_mdt_get_size(static inline int qcom_mdt_pas_init (struct device *dev,const struct firmware *fw,const char *fw_name,int pas_id,phys_addr_t mem_phys, -struct qcom_scm_pas_metadata *pas_metadata_ctx) +struct qcom_scm_pas_context *pas_ctx) {return -ENODEV ; }
Greg Kroah-Hartman
maintainerPATCH 570/877 remoteproc: qcom: pas: Guard dtb metadata release with dtb_pas_id check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit c06c5ab4945392d2c2aded6d832ab6b58cabe351 ]
All other call sites of qcom_scm_pas_metadata_release() for the DTB context are guarded by a check on pas->dtb_pas_id, but the call inside qcom_pas_load() was not. Fix this by moving the call to the guarded block.
--- drivers/remoteproc/qcom_q6v5_pas.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/remoteproc/qcom_q6v5_pas.c +5 -8
@@ -247,17 +247,14 @@ static int adsp_load(struct rproc *rproc pas->dtb_pas_id, pas->dtb_mem_region, pas->dtb_mem_phys, pas->dtb_mem_size, &pas->dtb_mem_reloc); -if (ret) - goto release_dtb_metadata; +if (ret) { +qcom_pas_metadata_release (pas->dtb_pas_ctx); +release_firmware (pas->dtb_firmware); +return ret; + } }return 0 ; - -release_dtb_metadata: -qcom_pas_metadata_release (pas->dtb_pas_ctx); -release_firmware (pas->dtb_firmware); - -return ret; }static int adsp_start (struct rproc *rproc)
Greg Kroah-Hartman
maintainerPATCH 571/877 power: supply: ab8500_fg: Remove redundant dev_err()/dev_err_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pan Chuang <[email protected]>
[ Upstream commit aa5f4decedfb4fc5cd0fe49ab256ad4304d192e4 ]
The devm_request_threaded_irq() and devm_request_irq() now automatically log detailed error messages on failure. This eliminates the need for driver-specific dev_err() and dev_err_probe() calls that previously printed generic messages.
Stable-dep-of: 75b1e88d3425 ("power: supply: ab8500_fg: fix use-after-free on remove")
--- drivers/power/supply/ab8500_fg.c | 2 -- 1 file changed, 2 deletions(-)
drivers/power/supply/ab8500_fg.c +0 -2
@@ -3179,8 +3179,6 @@ static int ab8500_fg_probe(struct platfo ab8500_fg_irq[i].name, di);if (ret !=0 ) { -dev_err (dev,"failed to request %s IRQ %d: %d\n" , - ab8500_fg_irq[i].name, irq, ret);destroy_workqueue (di->fg_wq);return ret; }
Greg Kroah-Hartman
maintainerPATCH 572/877 power: supply: ab8500_fg: fix use-after-free on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 75b1e88d34254f4fb7753345e21bfee47abddd7f ]
ab8500_fg_remove() destroys the driver workqueue while the threaded interrupt handlers are still armed; they are devm-managed and freed only after ->remove() returns, so a handler that fires in that window queues work on the freed workqueue.
Tear the workqueue down through devm instead, registering its cleanup after the power supply and before the interrupt requests. devm then frees the interrupts first, so the handlers can no longer queue work, before disabling the delayed and plain work items and destroying the workqueue. Disabling the items, rather than cancelling them, keeps them disabled so no producer (including the power-supply external_power_changed callback) can requeue them.
Found by an in-house static analysis tool.
--- drivers/power/supply/ab8500_fg.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
drivers/power/supply/ab8500_fg.c +21 -9
@@ -3055,6 +3055,20 @@ static void ab8500_fg_unbind(struct deviflush_workqueue (di->fg_wq); } +/* Disable, not cancel: works stay disabled so nothing can re-arm them. */ +static void ab8500_fg_destroy_workqueue (void *data) +{ +struct ab8500_fg *di = data; + +disable_work_sync (&di->fg_acc_cur_work); +disable_work_sync (&di->fg_work); +disable_delayed_work_sync (&di->fg_reinit_work); +disable_delayed_work_sync (&di->fg_low_bat_work); +disable_delayed_work_sync (&di->fg_check_hw_failure_work); +disable_delayed_work_sync (&di->fg_periodic_work); +destroy_workqueue (di->fg_wq); +} +static const struct component_ops ab8500_fg_component_ops = { .bind = ab8500_fg_bind, .unbind = ab8500_fg_unbind,
@@ -3156,6 +3170,11 @@ static int ab8500_fg_probe(struct platforeturn PTR_ERR (di->fg_psy); } +/* Registered after fg_psy, before the IRQs: devm frees IRQ -> workqueue -> fg_psy. */ + ret =devm_add_action_or_reset (dev, ab8500_fg_destroy_workqueue, di); +if (ret) +return ret; + di->fg_samples =SEC_TO_SAMPLE (di->bm->fg_params->init_timer);/*
@@ -3168,20 +3187,16 @@ static int ab8500_fg_probe(struct platfo/* Register primary interrupt handlers */ for (i =0 ; i <ARRAY_SIZE (ab8500_fg_irq); i++) { irq =platform_get_irq_byname (pdev, ab8500_fg_irq[i].name); -if (irq <0 ) { -destroy_workqueue (di->fg_wq); +if (irq <0 )return irq; - } ret =devm_request_threaded_irq (dev, irq,NULL , ab8500_fg_irq[i].isr,IRQF_SHARED |IRQF_NO_SUSPEND |IRQF_ONESHOT , ab8500_fg_irq[i].name, di); -if (ret !=0 ) { -destroy_workqueue (di->fg_wq); +if (ret !=0 )return ret; - }dev_dbg (dev,"Requested %s IRQ %d: %d\n" , ab8500_fg_irq[i].name, irq, ret); }
@@ -3195,7 +3210,6 @@ static int ab8500_fg_probe(struct platfo ret =ab8500_fg_sysfs_init (di);if (ret) {dev_err (dev,"failed to create sysfs entry\n" ); -destroy_workqueue (di->fg_wq);return ret; }
@@ -3203,7 +3217,6 @@ static int ab8500_fg_probe(struct platfoif (ret) {dev_err (dev,"failed to create FG psy\n" );ab8500_fg_sysfs_exit (di); -destroy_workqueue (di->fg_wq);return ret; }
@@ -3223,7 +3236,6 @@ static void ab8500_fg_remove(struct plat {struct ab8500_fg *di =platform_get_drvdata (pdev); -destroy_workqueue (di->fg_wq);component_del (&pdev->dev, &ab8500_fg_component_ops);list_del (&di->node);ab8500_fg_sysfs_exit (di);
Greg Kroah-Hartman
maintainerPATCH 573/877 PCI: starfive: Use regulator APIs to control the 3v3 power supply of PCIe slots
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hal Feng <[email protected]>
[ Upstream commit 05a75df4182e301a1b0059606f77b65c74deaa9b ]
The driver has been using the "enable-gpios" property to control the 3v3 power supply of PCIe slots. But it is not documented in the dt-bindings and also using GPIO APIs is not a standard way to control PCIe slot power, so use the documented "vpcie3v3-supply" property and regulator APIs to control the slot supply.
This change will break the DTs which used "enable-gpio" or "enable-gpios" property under the controller node. Since these properties were not defined in the bindings, it is safe to switch to "vpcie3v3-supply". Any out-of-tree DTS impacted by this change should migrate to "vpcie3v3-supply" instead.
Stable-dep-of: 22877a061f81 ("PCI: starfive: Fix resource leaks on error paths in host_init()")
--- drivers/pci/controller/plda/pcie-starfive.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/pci/controller/plda/pcie-starfive.c +15 -10
@@ -55,7 +55,7 @@ struct starfive_jh7110_pcie {struct reset_control *resets;struct clk_bulk_data *clks;struct regmap *reg_syscon; -struct gpio_desc *power_gpio; +struct regulator *vpcie3v3;struct gpio_desc *reset_gpio;struct phy *phy;
@@ -153,11 +153,13 @@ static int starfive_pcie_parse_dt(structreturn dev_err_probe (dev,PTR_ERR (pcie->reset_gpio),"failed to get perst-gpio\n" ); - pcie->power_gpio =devm_gpiod_get_optional (dev,"enable" , -GPIOD_OUT_LOW ); -if (IS_ERR (pcie->power_gpio)) -return dev_err_probe (dev,PTR_ERR (pcie->power_gpio), -"failed to get power-gpio\n" ); + pcie->vpcie3v3 =devm_regulator_get_optional (dev,"vpcie3v3" ); +if (IS_ERR (pcie->vpcie3v3)) { +if (PTR_ERR (pcie->vpcie3v3) != -ENODEV ) +return dev_err_probe (dev,PTR_ERR (pcie->vpcie3v3), +"failed to get vpcie3v3 regulator\n" ); + pcie->vpcie3v3 =NULL ; + }return 0 ; }
@@ -270,8 +272,8 @@ static void starfive_pcie_host_deinit(st container_of(plda, struct starfive_jh7110_pcie, plda);starfive_pcie_clk_rst_deinit (pcie); -if (pcie->power_gpio) -gpiod_set_value_cansleep (pcie->power_gpio,0 ); +if (pcie->vpcie3v3) +regulator_disable (pcie->vpcie3v3);starfive_pcie_disable_phy (pcie); }
@@ -304,8 +306,11 @@ static int starfive_pcie_host_init(strucif (ret)return ret; -if (pcie->power_gpio) -gpiod_set_value_cansleep (pcie->power_gpio,1 ); +if (pcie->vpcie3v3) { + ret =regulator_enable (pcie->vpcie3v3); +if (ret) +dev_err_probe (dev, ret,"failed to enable vpcie3v3 regulator\n" ); + }if (pcie->reset_gpio)gpiod_set_value_cansleep (pcie->reset_gpio,1 );
Greg Kroah-Hartman
maintainerPATCH 574/877 PCI: starfive: Fix resource leaks on error paths in host_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Tariq <[email protected]>
[ Upstream commit 22877a061f81c5d58041e384b3131684bec636b9 ]
starfive_pcie_host_init() acquires the PHY, clocks/resets, and an optional regulator in sequence, but does not correctly unwind these resources when a later step fails.
If starfive_pcie_clk_rst_init() fails after the PHY has already been successfully enabled, the function returns directly without disabling the PHY, leaking it and leaving it powered.
If regulator_enable() fails for the optional vpcie3v3 regulator, the failure is only logged; the function falls through and returns success, leaving the driver believing the regulator is enabled while continuing to configure PCIe hardware that may be unpowered. This also leaves the clocks and PHY enabled with nothing to clean them up.
Disable the PHY on the clk/reset failure path, and disable the clocks/resets and PHY, then return the error, if the regulator fails to enable.
Build-tested and boot-tested on StarFive VisionFive 2 v1.2A
--- drivers/pci/controller/plda/pcie-starfive.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/pci/controller/plda/pcie-starfive.c +11 -2
@@ -304,12 +304,14 @@ static int starfive_pcie_host_init(struc ret =starfive_pcie_clk_rst_init (pcie);if (ret) -return ret; + goto err_disable_phy;if (pcie->vpcie3v3) { ret =regulator_enable (pcie->vpcie3v3); -if (ret) +if (ret) {dev_err_probe (dev, ret,"failed to enable vpcie3v3 regulator\n" ); + goto err_clk_rst; + } }if (pcie->reset_gpio)
@@ -379,6 +381,13 @@ static int starfive_pcie_host_init(strucdev_info (dev,"port link down\n" );return 0 ; + +err_clk_rst: +starfive_pcie_clk_rst_deinit (pcie); +err_disable_phy: +starfive_pcie_disable_phy (pcie); + +return ret; }static const struct plda_pcie_host_ops sf_host_ops = {
Greg Kroah-Hartman
maintainerPATCH 575/877 iommu/msm: Use helper function devm_clk_get_prepared()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Heng <[email protected]>
[ Upstream commit afc0cbc6e25b37dc9ba11d415ea6858902a7f04b ]
Since commit 7ef9651e9792 ("clk: Provide new devm_clk helpers for prepared and enabled clocks"), devm_clk_get() and clk_prepare() can now be replaced by devm_clk_get_prepared() when driver prepares the clocks for the whole lifetime of the device. Moreover, it is no longer necessary to unprepare the clocks explicitly.
Backport to 6.12: remove the .remove_new callback entry used by this stable tree instead of the upstream .remove entry. The callback only unprepares clocks, which devm_clk_get_prepared() now handles. Keep the remaining upstream changes to prepare the probe error paths for 535a200220ca ("iommu/msm: Unwind probe state on registration failure").
Stable-dep-of: 535a200220ca ("iommu/msm: Unwind probe state on registration failure")
--- drivers/iommu/msm_iommu.c | 51 +++++++++------------------------------------- 1 file changed, 11 insertions(+), 40 deletions(-)
drivers/iommu/msm_iommu.c +11 -40
@@ -725,47 +725,32 @@ static int msm_iommu_probe(struct platfo iommu->dev = &pdev->dev;INIT_LIST_HEAD (&iommu->ctx_list); - iommu->pclk =devm_clk_get (iommu->dev,"smmu_pclk" ); + iommu->pclk =devm_clk_get_prepared (iommu->dev,"smmu_pclk" );if (IS_ERR (iommu->pclk))return dev_err_probe (iommu->dev,PTR_ERR (iommu->pclk),"could not get smmu_pclk\n" ); - ret =clk_prepare (iommu->pclk); -if (ret) -return dev_err_probe (iommu->dev, ret, -"could not prepare smmu_pclk\n" ); - - iommu->clk =devm_clk_get (iommu->dev,"iommu_clk" ); -if (IS_ERR (iommu->clk)) { -clk_unprepare (iommu->pclk); + iommu->clk =devm_clk_get_prepared (iommu->dev,"iommu_clk" ); +if (IS_ERR (iommu->clk))return dev_err_probe (iommu->dev,PTR_ERR (iommu->clk),"could not get iommu_clk\n" ); - } - - ret =clk_prepare (iommu->clk); -if (ret) { -clk_unprepare (iommu->pclk); -return dev_err_probe (iommu->dev, ret,"could not prepare iommu_clk\n" ); - } r =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); iommu->base =devm_ioremap_resource (iommu->dev, r);if (IS_ERR (iommu->base)) { ret =dev_err_probe (iommu->dev,PTR_ERR (iommu->base),"could not get iommu base\n" ); - goto fail; +return ret; } ioaddr = r->start; iommu->irq =platform_get_irq (pdev,0 ); -if (iommu->irq <0 ) { - ret = -ENODEV ; - goto fail; - } +if (iommu->irq <0 ) +return -ENODEV ; ret =of_property_read_u32 (iommu->dev->of_node,"qcom,ncb" , &val);if (ret) {dev_err (iommu->dev,"could not get ncb\n" ); - goto fail; +return ret; } iommu->ncb = val;
@@ -780,8 +765,7 @@ static int msm_iommu_probe(struct platfoif (!par) {pr_err ("Invalid PAR value detected\n" ); - ret = -ENODEV ; - goto fail; +return -ENODEV ; } ret = devm_request_threaded_irq(iommu->dev, iommu->irq, NULL,
@@ -791,7 +775,7 @@ static int msm_iommu_probe(struct platfo iommu);if (ret) {pr_err ("Request IRQ %d failed with ret=%d\n" , iommu->irq, ret); - goto fail; +return ret; }list_add (&iommu->dev_node, &qcom_iommu_devices);
@@ -800,23 +784,19 @@ static int msm_iommu_probe(struct platfo "msm-smmu.%pa", &ioaddr);if (ret) {pr_err ("Could not add msm-smmu at %pa to sysfs\n" , &ioaddr); - goto fail; +return ret; } ret =iommu_device_register (&iommu->iommu, &msm_iommu_ops, &pdev->dev);if (ret) {pr_err ("Could not register msm-smmu at %pa\n" , &ioaddr); - goto fail; +return ret; }pr_info ("device mapped at %p, irq %d with %d ctx banks\n" , iommu->base, iommu->irq, iommu->ncb);return ret; -fail: -clk_unprepare (iommu->clk); -clk_unprepare (iommu->pclk); -return ret; }static const struct of_device_id msm_iommu_dt_match[] = {
@@ -824,20 +804,11 @@ static const struct of_device_id msm_iom {} }; -static void msm_iommu_remove (struct platform_device *pdev) -{ -struct msm_iommu_dev *iommu =platform_get_drvdata (pdev); - -clk_unprepare (iommu->clk); -clk_unprepare (iommu->pclk); -} -static struct platform_driver msm_iommu_driver = { .driver = { .name ="msm_iommu" , .of_match_table = msm_iommu_dt_match, }, .probe = msm_iommu_probe, - .remove_new = msm_iommu_remove, };builtin_platform_driver (msm_iommu_driver);
Greg Kroah-Hartman
maintainerPATCH 576/877 iommu/msm: Unwind probe state on registration failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weimin Xiong <[email protected]>
[ Upstream commit 535a200220ca2c83bc8bf54bd2cbe045d6ee70c4 ]
msm_iommu_probe() adds its devm-managed IOMMU object to qcom_iommu_devices before adding the IOMMU sysfs device and registering it with the IOMMU core.
If iommu_device_sysfs_add() fails, probe returns with the object still on qcom_iommu_devices. The driver core then releases the devm allocation, leaving a dangling list entry that later list walks may dereference.
If iommu_device_register() fails, the same dangling list entry remains and the sysfs device is left registered as well.
Unwind the sysfs device and global list entry in reverse setup order on the corresponding failure paths.
--- drivers/iommu/msm_iommu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iommu/msm_iommu.c +8 -2
@@ -784,19 +784,25 @@ static int msm_iommu_probe(struct platfo "msm-smmu.%pa", &ioaddr);if (ret) {pr_err ("Could not add msm-smmu at %pa to sysfs\n" , &ioaddr); -return ret; + goto err_remove_list; } ret =iommu_device_register (&iommu->iommu, &msm_iommu_ops, &pdev->dev);if (ret) {pr_err ("Could not register msm-smmu at %pa\n" , &ioaddr); -return ret; + goto err_remove_sysfs; }pr_info ("device mapped at %p, irq %d with %d ctx banks\n" , iommu->base, iommu->irq, iommu->ncb);return ret; + +err_remove_sysfs: +iommu_device_sysfs_remove (&iommu->iommu); +err_remove_list: +list_del (&iommu->dev_node); +return ret; }static const struct of_device_id msm_iommu_dt_match[] = {
Greg Kroah-Hartman
maintainerPATCH 577/877 iommufd: Pass @pasid through the device attach/replace path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yi Liu <[email protected]>
[ Upstream commit 03c9b102bea6f4f0b517c841fe1d2f9c616c95b9 ]
Most of the core logic before conducting the actual device attach/ replace operation can be shared with pasid attach/replace. So pass @pasid through the device attach/replace helpers to prepare adding pasid attach/replace.
So far the @pasid should only be IOMMU_NO_PASID. No functional change.
Stable-dep-of: 8c07df7cdfcf ("iommufd: Fix UAF in selftest IOPF reporting")
--- drivers/iommu/iommufd/device.c | 70 ++++++++++++++++++-------------- drivers/iommu/iommufd/hw_pagetable.c | 13 +++-- drivers/iommu/iommufd/iommufd_private.h | 8 +-- 3 files changed, 52 insertions(+), 39 deletions(-)
drivers/iommu/iommufd/device.c +41 -29
@@ -367,7 +367,8 @@ static bool iommufd_device_is_attached(s }static int iommufd_hwpt_attach_device (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev) +struct iommufd_device *idev, +ioasid_t pasid) {struct iommufd_attach_handle *handle;int rc;
@@ -385,6 +386,7 @@ static int iommufd_hwpt_attach_device(st } handle->idev = idev; +WARN_ON (pasid !=IOMMU_NO_PASID ); rc =iommu_attach_group_handle (hwpt->domain, idev->igroup->group, &handle->handle);if (rc)
@@ -401,25 +403,28 @@ out_free_handle: }static struct iommufd_attach_handle * -iommufd_device_get_attach_handle (struct iommufd_device *idev) +iommufd_device_get_attach_handle (struct iommufd_device *idev,ioasid_t pasid) {struct iommu_attach_handle *handle;lockdep_assert_held (&idev->igroup->lock); handle = -iommu_attach_handle_get (idev->igroup->group,IOMMU_NO_PASID ,0 ); +iommu_attach_handle_get (idev->igroup->group, pasid,0 );if (IS_ERR (handle))return NULL ;return to_iommufd_handle (handle); }static void iommufd_hwpt_detach_device (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev) +struct iommufd_device *idev, +ioasid_t pasid) {struct iommufd_attach_handle *handle; - handle =iommufd_device_get_attach_handle (idev); +WARN_ON (pasid !=IOMMU_NO_PASID ); + + handle =iommufd_device_get_attach_handle (idev, pasid);iommu_detach_group_handle (hwpt->domain, idev->igroup->group);if (hwpt->fault) {iommufd_auto_response_faults (hwpt, handle);
@@ -429,13 +434,17 @@ static void iommufd_hwpt_detach_device(s }static int iommufd_hwpt_replace_device (struct iommufd_device *idev, +ioasid_t pasid,struct iommufd_hw_pagetable *hwpt,struct iommufd_hw_pagetable *old) { -struct iommufd_attach_handle *handle, *old_handle = -iommufd_device_get_attach_handle (idev); +struct iommufd_attach_handle *handle, *old_handle;int rc; +WARN_ON (pasid !=IOMMU_NO_PASID ); + + old_handle =iommufd_device_get_attach_handle (idev, pasid); + handle =kzalloc (sizeof (*handle),GFP_KERNEL );if (!handle)return -ENOMEM ;
@@ -470,7 +479,7 @@ out_free_handle: }int iommufd_hw_pagetable_attach (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev) +struct iommufd_device *idev,ioasid_t pasid) {struct iommufd_hwpt_paging *hwpt_paging =find_hwpt_paging (hwpt);int rc;
@@ -496,7 +505,7 @@ int iommufd_hw_pagetable_attach(struct i* attachment. */ if (list_empty (&idev->igroup->device_list)) { - rc =iommufd_hwpt_attach_device (hwpt, idev); + rc =iommufd_hwpt_attach_device (hwpt, idev, pasid);if (rc) goto err_unresv; idev->igroup->hwpt = hwpt;
@@ -514,7 +523,7 @@ err_unlock: }struct iommufd_hw_pagetable * -iommufd_hw_pagetable_detach (struct iommufd_device *idev) +iommufd_hw_pagetable_detach (struct iommufd_device *idev,ioasid_t pasid) {struct iommufd_hw_pagetable *hwpt = idev->igroup->hwpt;struct iommufd_hwpt_paging *hwpt_paging =find_hwpt_paging (hwpt);
@@ -522,7 +531,7 @@ iommufd_hw_pagetable_detach(struct iommumutex_lock (&idev->igroup->lock);list_del (&idev->group_item);if (list_empty (&idev->igroup->device_list)) { -iommufd_hwpt_detach_device (hwpt, idev); +iommufd_hwpt_detach_device (hwpt, idev, pasid); idev->igroup->hwpt =NULL ; }if (hwpt_paging)
@@ -534,12 +543,12 @@ iommufd_hw_pagetable_detach(struct iommu }static struct iommufd_hw_pagetable * -iommufd_device_do_attach (struct iommufd_device *idev, +iommufd_device_do_attach (struct iommufd_device *idev,ioasid_t pasid,struct iommufd_hw_pagetable *hwpt) {int rc; - rc =iommufd_hw_pagetable_attach (hwpt, idev); + rc =iommufd_hw_pagetable_attach (hwpt, idev, pasid);if (rc)return ERR_PTR (rc);return NULL ;
@@ -588,7 +597,7 @@ err_unresv: }static struct iommufd_hw_pagetable * -iommufd_device_do_replace (struct iommufd_device *idev, +iommufd_device_do_replace (struct iommufd_device *idev,ioasid_t pasid,struct iommufd_hw_pagetable *hwpt) {struct iommufd_hwpt_paging *hwpt_paging =find_hwpt_paging (hwpt);
@@ -622,7 +631,7 @@ iommufd_device_do_replace(struct iommufd goto err_unlock; } - rc =iommufd_hwpt_replace_device (idev, hwpt, old_hwpt); + rc =iommufd_hwpt_replace_device (idev, pasid, hwpt, old_hwpt);if (rc) goto err_unresv;
@@ -655,7 +664,8 @@ err_unlock: }typedef struct iommufd_hw_pagetable *(*attach_fn )( -struct iommufd_device *idev,struct iommufd_hw_pagetable *hwpt); +struct iommufd_device *idev,ioasid_t pasid, +struct iommufd_hw_pagetable *hwpt);/* * When automatically managing the domains we search for a compatible domain in
@@ -663,7 +673,7 @@ typedef struct iommufd_hw_pagetable *(*a* Automatic domain selection will never pick a manually created domain. */ static struct iommufd_hw_pagetable * -iommufd_device_auto_get_domain (struct iommufd_device *idev, +iommufd_device_auto_get_domain (struct iommufd_device *idev,ioasid_t pasid,struct iommufd_ioas *ioas,u32 *pt_id,attach_fn do_attach) {
@@ -692,7 +702,7 @@ iommufd_device_auto_get_domain(struct io hwpt = &hwpt_paging->common;if (!iommufd_lock_obj (&hwpt->obj))continue ; - destroy_hwpt = (*do_attach)(idev, hwpt); + destroy_hwpt = (*do_attach)(idev, pasid, hwpt);if (IS_ERR (destroy_hwpt)) {iommufd_put_object (idev->ictx, &hwpt->obj);/*
@@ -710,8 +720,8 @@ iommufd_device_auto_get_domain(struct io goto out_unlock; } - hwpt_paging =iommufd_hwpt_paging_alloc (idev->ictx, ioas, idev,0 , - immediate_attach,NULL ); + hwpt_paging =iommufd_hwpt_paging_alloc (idev->ictx, ioas, idev, pasid, +0 , immediate_attach,NULL );if (IS_ERR (hwpt_paging)) { destroy_hwpt =ERR_CAST (hwpt_paging); goto out_unlock;
@@ -719,7 +729,7 @@ iommufd_device_auto_get_domain(struct io hwpt = &hwpt_paging->common;if (!immediate_attach) { - destroy_hwpt = (*do_attach)(idev, hwpt); + destroy_hwpt = (*do_attach)(idev, pasid, hwpt);if (IS_ERR (destroy_hwpt)) goto out_abort; }else {
@@ -740,8 +750,9 @@ out_unlock:return destroy_hwpt; } -static int iommufd_device_change_pt (struct iommufd_device *idev,u32 *pt_id, -attach_fn do_attach) +static int iommufd_device_change_pt (struct iommufd_device *idev, +ioasid_t pasid, +u32 *pt_id,attach_fn do_attach) {struct iommufd_hw_pagetable *destroy_hwpt;struct iommufd_object *pt_obj;
@@ -756,7 +767,7 @@ static int iommufd_device_change_pt(strustruct iommufd_hw_pagetable *hwpt = container_of(pt_obj, struct iommufd_hw_pagetable, obj); - destroy_hwpt = (*do_attach)(idev, hwpt); + destroy_hwpt = (*do_attach)(idev, pasid, hwpt);if (IS_ERR (destroy_hwpt)) goto out_put_pt_obj;break ;
@@ -765,8 +776,8 @@ static int iommufd_device_change_pt(strustruct iommufd_ioas *ioas = container_of(pt_obj, struct iommufd_ioas, obj); - destroy_hwpt =iommufd_device_auto_get_domain (idev, ioas, pt_id, - do_attach); + destroy_hwpt =iommufd_device_auto_get_domain (idev, pasid, ioas, + pt_id, do_attach);if (IS_ERR (destroy_hwpt)) goto out_put_pt_obj;break ;
@@ -803,7 +814,8 @@ int iommufd_device_attach(struct iommufd {int rc; - rc =iommufd_device_change_pt (idev, pt_id, &iommufd_device_do_attach); + rc =iommufd_device_change_pt (idev,IOMMU_NO_PASID , pt_id, + &iommufd_device_do_attach);if (rc)return rc;
@@ -833,7 +845,7 @@ EXPORT_SYMBOL_NS_GPL(iommufd_device_atta*/ int iommufd_device_replace (struct iommufd_device *idev,u32 *pt_id) { -return iommufd_device_change_pt (idev, pt_id, +return iommufd_device_change_pt (idev,IOMMU_NO_PASID , pt_id, &iommufd_device_do_replace); }EXPORT_SYMBOL_NS_GPL (iommufd_device_replace,IOMMUFD );
@@ -849,7 +861,7 @@ void iommufd_device_detach(struct iommuf {struct iommufd_hw_pagetable *hwpt; - hwpt =iommufd_hw_pagetable_detach (idev); + hwpt =iommufd_hw_pagetable_detach (idev,IOMMU_NO_PASID );iommufd_hw_pagetable_put (idev->ictx, hwpt);refcount_dec (&idev->obj.users); }
drivers/iommu/iommufd/hw_pagetable.c +7 -6
@@ -87,6 +87,7 @@ iommufd_hwpt_paging_enforce_cc(struct io* @ictx: iommufd context * @ioas: IOAS to associate the domain with * @idev: Device to get an iommu_domain for +* @pasid: PASID to get an iommu_domain for * @flags: Flags from userspace * @immediate_attach: True if idev should be attached to the hwpt * @user_data: The user provided driver specific data describing the domain to
@@ -102,8 +103,8 @@ iommufd_hwpt_paging_enforce_cc(struct io*/ struct iommufd_hwpt_paging *iommufd_hwpt_paging_alloc (struct iommufd_ctx *ictx,struct iommufd_ioas *ioas, -struct iommufd_device *idev,u32 flags, -bool immediate_attach, +struct iommufd_device *idev,ioasid_t pasid, +u32 flags,bool immediate_attach,const struct iommu_user_data *user_data) { const u32 valid_flags = IOMMU_HWPT_ALLOC_NEST_PARENT |
@@ -183,7 +184,7 @@ iommufd_hwpt_paging_alloc(struct iommufd* sequence. Once those drivers are fixed this should be removed. */ if (immediate_attach) { - rc =iommufd_hw_pagetable_attach (hwpt, idev); + rc =iommufd_hw_pagetable_attach (hwpt, idev, pasid);if (rc) goto out_abort; }
@@ -196,7 +197,7 @@ iommufd_hwpt_paging_alloc(struct iommufd out_detach:if (immediate_attach) -iommufd_hw_pagetable_detach (idev); +iommufd_hw_pagetable_detach (idev, pasid); out_abort:iommufd_object_abort_and_destroy (ictx, &hwpt->obj);return ERR_PTR (rc);
@@ -299,8 +300,8 @@ int iommufd_hwpt_alloc(struct iommufd_uc ioas = container_of(pt_obj, struct iommufd_ioas, obj);mutex_lock (&ioas->mutex); hwpt_paging =iommufd_hwpt_paging_alloc ( - ucmd->ictx, ioas, idev, cmd->flags, false, - user_data.len ? &user_data :NULL ); + ucmd->ictx, ioas, idev,IOMMU_NO_PASID , cmd->flags, + false, user_data.len ? &user_data :NULL );if (IS_ERR (hwpt_paging)) { rc =PTR_ERR (hwpt_paging); goto out_unlock;
drivers/iommu/iommufd/iommufd_private.h +4 -4
@@ -365,13 +365,13 @@ int iommufd_hwpt_get_dirty_bitmap(structstruct iommufd_hwpt_paging *iommufd_hwpt_paging_alloc (struct iommufd_ctx *ictx,struct iommufd_ioas *ioas, -struct iommufd_device *idev,u32 flags, -bool immediate_attach, +struct iommufd_device *idev,ioasid_t pasid, +u32 flags,bool immediate_attach,const struct iommu_user_data *user_data);int iommufd_hw_pagetable_attach (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev); +struct iommufd_device *idev,ioasid_t pasid);struct iommufd_hw_pagetable * -iommufd_hw_pagetable_detach (struct iommufd_device *idev); +iommufd_hw_pagetable_detach (struct iommufd_device *idev,ioasid_t pasid);void iommufd_hwpt_paging_destroy (struct iommufd_object *obj);void iommufd_hwpt_paging_abort (struct iommufd_object *obj);void iommufd_hwpt_nested_destroy (struct iommufd_object *obj);
Greg Kroah-Hartman
maintainerPATCH 578/877 iommufd: Fix UAF in selftest IOPF reporting
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
[ Upstream commit 8c07df7cdfcf52f1ff276c588612aabc6c6b8399 ]
IOMMUFD selftest TRIGGER_IOPF borrows an attach handle from group->pasid_array without synchronizing against PASID detach, then a concurrent iommu_report_device_fault() can dereference that borrowed handle's domain pointer after the detach erases the handle and frees the backing struct iommufd_attach_handle. TRIGGER_IOPF then dereferences the freed handle, causing a UAF.
Fix by adding a iopf_rwsem in mock_dev to follow the expected design of a real driver. Hold its read side across the whole iommu_report_device_fault() call, and its write side around every path that attaches, detaches, or replaces a device domain. This can block new reports and drains in-flight reports before an old attach handle or the IOPF fault parameter can be removed. Also take the write side while registering a mock device, since it can invoke the mock driver's default-domain attach callback.
--- drivers/iommu/iommufd/selftest.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/iommu/iommufd/selftest.c +20 -0
@@ -139,6 +139,7 @@ enum selftest_obj_type {struct mock_dev {struct device dev; +struct rw_semaphore iopf_rwsem;unsigned long flags;int id; };
@@ -702,6 +703,7 @@ static struct mock_dev *mock_dev_create(if (!mdev)return ERR_PTR (-ENOMEM ); +init_rwsem (&mdev->iopf_rwsem);device_initialize (&mdev->dev); mdev->flags = dev_flags; mdev->dev.release = mock_dev_release;
@@ -716,7 +718,9 @@ static struct mock_dev *mock_dev_create(if (rc) goto err_put; +down_write (&mdev->iopf_rwsem); rc =device_add (&mdev->dev); +up_write (&mdev->iopf_rwsem);if (rc) goto err_put;return mdev;
@@ -771,7 +775,9 @@ static int iommufd_test_mock_domain(stru } sobj->idev.idev = idev; +down_write (&sobj->idev.mock_dev->iopf_rwsem); rc =iommufd_device_attach (idev, &pt_id); +up_write (&sobj->idev.mock_dev->iopf_rwsem);if (rc) goto out_unbind;
@@ -786,7 +792,9 @@ static int iommufd_test_mock_domain(strureturn 0 ; out_detach: +down_write (&sobj->idev.mock_dev->iopf_rwsem);iommufd_device_detach (idev); +up_write (&sobj->idev.mock_dev->iopf_rwsem); out_unbind:iommufd_device_unbind (idev); out_mdev:
@@ -820,7 +828,9 @@ static int iommufd_test_mock_domain_repl goto out_dev_obj; } +down_write (&sobj->idev.mock_dev->iopf_rwsem); rc =iommufd_device_replace (sobj->idev.idev, &pt_id); +up_write (&sobj->idev.mock_dev->iopf_rwsem);if (rc) goto out_dev_obj;
@@ -1418,10 +1428,16 @@ static int iommufd_test_trigger_iopf(str {struct iopf_fault event = { };struct iommufd_device *idev; +struct mock_dev *mdev; idev =iommufd_get_device (ucmd, cmd->trigger_iopf.dev_id);if (IS_ERR (idev))return PTR_ERR (idev); +if (!iommufd_selftest_is_mock_dev (idev->dev)) { +iommufd_put_object (ucmd->ictx, &idev->obj); +return -EINVAL ; + } + mdev = container_of(idev->dev, struct mock_dev, dev); event.fault.prm.flags =IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE ;if (cmd->trigger_iopf.pasid !=IOMMU_NO_PASID )
@@ -1432,7 +1448,9 @@ static int iommufd_test_trigger_iopf(str event.fault.prm.grpid = cmd->trigger_iopf.grpid; event.fault.prm.perm = cmd->trigger_iopf.perm; +down_read (&mdev->iopf_rwsem);iommu_report_device_fault (idev->dev, &event); +up_read (&mdev->iopf_rwsem);iommufd_put_object (ucmd->ictx, &idev->obj);return 0 ;
@@ -1444,7 +1462,9 @@ void iommufd_selftest_destroy(struct iomswitch (sobj->type) {case TYPE_IDEV : +down_write (&sobj->idev.mock_dev->iopf_rwsem);iommufd_device_detach (sobj->idev.idev); +up_write (&sobj->idev.mock_dev->iopf_rwsem);iommufd_device_unbind (sobj->idev.idev);mock_dev_destroy (sobj->idev.mock_dev);break ;
Greg Kroah-Hartman
maintainerPATCH 579/877 platform/x86: ISST: Check for admin capability for write commands
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit 69cd1ca440a96c85dcedcddfa5e0af6012f60b8b ]
In some SST deployments, administrators want to allow reading SST capabilities for non-root users. This can be achieved by changing file permissions for "/dev/isst_interface", but they still want to prevent any changes to the SST configuration by non-root users.
This capability was available before for non-TPMI SST. Extend the same capability for TPMI SST by adding a check for CAP_SYS_ADMIN for all write commands.
Stable-dep-of: e45d6b847286 ("platform/x86: ISST: Validate max level for set feature")
--- drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +6 -5
@@ -620,7 +620,7 @@ static long isst_if_core_power_state(voireturn -EINVAL ;if (core_power.get_set) { -if (power_domain_info->write_blocked) +if (power_domain_info->write_blocked || !capable (CAP_SYS_ADMIN ))return -EPERM ; if (core_power.enable > SST_CP_MAX_ENABLE ||
@@ -679,7 +679,7 @@ static long isst_if_clos_param(void __usreturn -EINVAL ;if (clos_param.get_set) { -if (power_domain_info->write_blocked) +if (power_domain_info->write_blocked || !capable (CAP_SYS_ADMIN ))return -EPERM ;if (!in_range (clos_param.min_freq_mhz /SST_MUL_FACTOR_FREQ ,0 ,SST_MAX_FREQ +1 ))
@@ -790,7 +790,8 @@ static long isst_if_clos_assoc(void __us power_domain_info = &sst_inst->power_domain_info[part][punit_id]; -if (assoc_cmds.get_set && power_domain_info->write_blocked) +if (assoc_cmds.get_set && (power_domain_info->write_blocked || + !capable (CAP_SYS_ADMIN )))return -EPERM ; offset = SST_CLOS_ASSOC_0_OFFSET +
@@ -968,7 +969,7 @@ static int isst_if_set_perf_level(void _if (!power_domain_info)return -EINVAL ; -if (power_domain_info->write_blocked) +if (power_domain_info->write_blocked || !capable (CAP_SYS_ADMIN ))return -EPERM ;if (!(power_domain_info->pp_header.allowed_level_mask &BIT (perf_level.level)))
@@ -1028,7 +1029,7 @@ static int isst_if_set_perf_feature(voidif (!power_domain_info)return -EINVAL ; -if (power_domain_info->write_blocked) +if (power_domain_info->write_blocked || !capable (CAP_SYS_ADMIN ))return -EPERM ;if (perf_feature.feature & ~SST_PP_FEATURE_STATE_VALID_MASK )
Greg Kroah-Hartman
maintainerPATCH 580/877 platform/x86: ISST: Validate max level for set feature
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit e45d6b8472861d3bac86bb37f8556a7c5aca3266 ]
Validate the level before setting, so that it fails early instead of failing later when checking the bit mask for allowed levels.
--- drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +3 -0
@@ -969,6 +969,9 @@ static int isst_if_set_perf_level(void _if (!power_domain_info)return -EINVAL ; +if (perf_level.level > power_domain_info->max_level) +return -EINVAL ; +if (power_domain_info->write_blocked || !capable (CAP_SYS_ADMIN ))return -EPERM ;
Greg Kroah-Hartman
maintainerPATCH 581/877 mmc: via-sdmmc: cancel card-detect work on remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 57e5d877f898d5e5c9d672a77bb6bdd24f0d9bf5 ]
Disabling the device interrupt and freeing the IRQ prevents new card-detect work from being queued, but carddet_work already queued by the handler can still run after via_sd_remove() returns. via_sdc_card_detect() recovers the host through container_of() and dereferences its MMIO base; once remove() returns the host can be freed, so that work would touch freed memory.
Cancel carddet_work after freeing the IRQ and before cancelling finish_bh_work, which the card-detect handler can also queue. carddet_work can re-enable the interrupt through via_reset_pcictrl(); mask it again afterwards.
This issue was found by an in-house static analysis tool and confirmed by manual code review.
--- drivers/mmc/host/via-sdmmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/host/via-sdmmc.c +4 -0
@@ -1208,6 +1208,10 @@ static void via_sd_remove(struct pci_devfree_irq (pcidev->irq, sdhost); +cancel_work_sync (&sdhost->carddet_work); +/* carddet_work may re-enable the interrupt via via_reset_pcictrl(). */ +writeb (0x0 , sdhost->pcictrl_mmiobase +VIA_CRDR_PCIINTCTRL ); +del_timer_sync (&sdhost->timer);cancel_work_sync (&sdhost->finish_bh_work);
Greg Kroah-Hartman
maintainerPATCH 582/877 PCI: Introduce PCI_SLOT_PLACEHOLDER constant for slot_nr placeholder value
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Farhan Ali <[email protected]>
[ Upstream commit c243e6c470c4695965cc8287767925bc1d9a7867 ]
Introduce a constant for placeholder value and update the kerneldoc for pci_create_slot() to reference PCI_SLOT_PLACEHOLDER instead of -1 throughout. No functional change.
Stable backport: this tree predates 102c8b26b54e ("PCI: Allow all bus devices to use the same slot"). Include its PCI_SLOT_ALL_DEVICES definition, slot-number documentation, and core matching/address handling so that subsequent commit dcc5bec09e23 ("PCI: Allow per function PCI slots to fix slot reset on s390") applies without conflicts. Keep the PCIe hotplug callers unchanged; enabling bus-wide slots there is outside this dependency.
Retain the stable tree's kzalloc() and ATTRIBUTE_GROUPS() implementations. The placeholder conversion covers both PowerPC hotplug callers and the PCI core. All code changes stay within existing functions.
Stable-dep-of: dcc5bec09e23 ("PCI: Allow per function PCI slots to fix slot reset on s390")
--- drivers/pci/hotplug/pnv_php.c | 2 - drivers/pci/hotplug/rpaphp_slot.c | 2 - drivers/pci/slot.c | 50 ++++++++++++++++++++++++++++---------- include/linux/pci.h | 13 +++++++++ 4 files changed, 51 insertions(+), 16 deletions(-)
drivers/pci/hotplug/pnv_php.c +1 -1
@@ -800,7 +800,7 @@ static struct pnv_php_slot *pnv_php_alloif (dn->child &&PCI_DN (dn->child)) php_slot->slot_no =PCI_SLOT (PCI_DN (dn->child)->devfn);else - php_slot->slot_no =-1 ;/* Placeholder slot */ + php_slot->slot_no =PCI_SLOT_PLACEHOLDER ;/* Placeholder slot */ kref_init (&php_slot->kref); php_slot->state =PNV_PHP_STATE_INITIALIZED ;
drivers/pci/hotplug/rpaphp_slot.c +1 -1
@@ -85,7 +85,7 @@ int rpaphp_register_slot(struct slot *slstruct device_node *child;u32 my_index;int retval; -int slotno =-1 ; +int slotno =PCI_SLOT_PLACEHOLDER ; dbg("%s registering slot:path[%pOF] index[%x], name[%s] pdomain[%x] type[%d]\n", __func__, slot->dn, slot->index, slot->name,
drivers/pci/slot.c +37 -13
98 lines not on this page · raw message
include/linux/pci.h +12 -1
@@ -72,12 +72,23 @@/* return bus from PCI devid = ((u16)bus_number) << 8) | devfn */ #define PCI_BUS_NUM (x) (((x) >> 8) & 0xff) +/* +* PCI_SLOT_ALL_DEVICES indicates a slot that covers all devices on the bus. +* Used for PCIe hotplug where the physical slot is the entire secondary bus, +* and, if ARI Forwarding is enabled, functions may appear to be on multiple +* devices. +*/ +#define PCI_SLOT_ALL_DEVICES 0xfe + +/* Used to identify a slot as a placeholder */ +#define PCI_SLOT_PLACEHOLDER 0xff +/* pci_slot represents a physical slot */ struct pci_slot {struct pci_bus *bus;/* Bus this slot is on */ struct list_head list;/* Node in list of slots */ struct hotplug_slot *hotplug;/* Hotplug info (move here) */ -unsigned char number;/* PCI_SLOT(pci_dev->devfn) */ +unsigned char number;/* Device nr, or PCI_SLOT_ALL_DEVICES */ struct kobject kobj; };
Greg Kroah-Hartman
maintainerPATCH 583/877 PCI: Allow per function PCI slots to fix slot reset on s390
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Farhan Ali <[email protected]>
[ Upstream commit dcc5bec09e23bbc4f9de055a11fce9937244f2c8 ]
On s390 systems, which use a machine level hypervisor, PCI devices are always accessed through a form of PCI pass-through which fundamentally operates on a per PCI function granularity. This is also reflected in the s390 PCI hotplug driver which creates hotplug slots for individual PCI functions. Its reset_slot() function, which is a wrapper for zpci_hot_reset_device(), thus also resets individual functions.
Currently, the pci_create_slot() assigns the same pci_slot object to multifunction devices. This approach worked fine on s390 systems that only exposed virtual functions as individual PCI domains to the operating system. Since commit 44510d6fa0c0 ("s390/pci: Handling multifunctions") s390 supports exposing the topology of multifunction PCI devices by grouping them in a shared PCI domain. This creates a problem when resetting a function through the hotplug driver's slot_reset() interface.
When attempting to reset a function through the hotplug driver, the shared slot assignment causes the wrong function to be reset instead of the intended one. It also leaks memory as we do create a pci_slot object for the function, but don't correctly free it in pci_slot_release().
Add a flag for struct pci_slot to allow per function PCI slots for functions managed through a hypervisor, which exposes individual PCI functions while retaining the topology. Since we can use all 8 bits for slot 'number' (for ARI devices), change slot 'number' u16 to account for special values PCI_SLOT_PLACEHOLDER and PCI_SLOT_ALL_DEVICES.
--- drivers/pci/pci.c | 5 +++-- drivers/pci/slot.c | 29 +++++++++++++++++++++++------ include/linux/pci.h | 7 ++++--- 3 files changed, 30 insertions(+), 11 deletions(-)
drivers/pci/pci.c +3 -2
@@ -4919,8 +4919,9 @@ static int pci_reset_hotplug_slot(structstatic int pci_dev_reset_slot_function (struct pci_dev *dev,bool probe) { -if (dev->multifunction || dev->subordinate || !dev->slot || - dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET ) +if (dev->subordinate || !dev->slot || + dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET || + (dev->multifunction && !dev->slot->per_func_slot))return -ENOTTY ;return pci_reset_hotplug_slot (dev->slot->hotplug, probe);
drivers/pci/slot.c +23 -6
@@ -73,6 +73,23 @@ static ssize_t cur_speed_read_file(strucreturn bus_speed_read (slot->bus->cur_bus_speed, buf); } +static bool pci_dev_matches_slot (struct pci_dev *dev,struct pci_slot *slot) +{ +if (slot->per_func_slot) +return dev->devfn == slot->number; + +return slot->number ==PCI_SLOT_ALL_DEVICES || +PCI_SLOT (dev->devfn) == slot->number; +} + +static bool pci_slot_enabled_per_func (void ) +{ +if (IS_ENABLED (CONFIG_S390 )) +return true; + +return false; +} +static void pci_slot_release (struct kobject *kobj) {struct pci_dev *dev;
@@ -83,8 +100,7 @@ static void pci_slot_release(struct kobjdown_read (&pci_bus_sem);list_for_each_entry (dev, &slot->bus->devices, bus_list) -if (slot->number ==PCI_SLOT_ALL_DEVICES || -PCI_SLOT (dev->devfn) == slot->number) +if (pci_dev_matches_slot (dev, slot)) dev->slot =NULL ;up_read (&pci_bus_sem);
@@ -177,8 +193,7 @@ void pci_dev_assign_slot(struct pci_devmutex_lock (&pci_slot_mutex);list_for_each_entry (slot, &dev->bus->slots, list) -if (slot->number ==PCI_SLOT_ALL_DEVICES || -PCI_SLOT (dev->devfn) == slot->number) +if (pci_dev_matches_slot (dev, slot)) dev->slot = slot;mutex_unlock (&pci_slot_mutex); }
@@ -288,6 +303,9 @@ placeholder: slot->bus =pci_bus_get (parent); slot->number = slot_nr; +if (pci_slot_enabled_per_func ()) + slot->per_func_slot =1 ; + slot->kobj.kset = pci_slots_kset; slot_name =make_slot_name (name);
@@ -310,8 +328,7 @@ placeholder:down_read (&pci_bus_sem);list_for_each_entry (dev, &parent->devices, bus_list) -if (slot_nr ==PCI_SLOT_ALL_DEVICES || -PCI_SLOT (dev->devfn) == slot_nr) +if (pci_dev_matches_slot (dev, slot)) dev->slot = slot;up_read (&pci_bus_sem);
include/linux/pci.h +4 -3
@@ -78,17 +78,18 @@* and, if ARI Forwarding is enabled, functions may appear to be on multiple * devices. */ -#define PCI_SLOT_ALL_DEVICES 0xfe +#define PCI_SLOT_ALL_DEVICES 0xfeff/* Used to identify a slot as a placeholder */ -#define PCI_SLOT_PLACEHOLDER 0xff +#define PCI_SLOT_PLACEHOLDER 0xffff/* pci_slot represents a physical slot */ struct pci_slot {struct pci_bus *bus;/* Bus this slot is on */ struct list_head list;/* Node in list of slots */ struct hotplug_slot *hotplug;/* Hotplug info (move here) */ -unsigned char number;/* Device nr, or PCI_SLOT_ALL_DEVICES */ +u16 number;/* Device nr, or PCI_SLOT_ALL_DEVICES */ +unsigned int per_func_slot:1 ;/* Allow per function slot */ struct kobject kobj; };
Greg Kroah-Hartman
maintainerPATCH 584/877 platform/x86: think-lmi: Fix current password length check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 54745d563114b74f6fecebce68cd020d06c1772b ]
current_password_store() checks the password length before removing the trailing newline, which can reject valid passwords that are exactly ->maxlen bytes long.
It also passes ->maxlen to strscpy(), which truncates passwords without a newline.
Use strchrnul() to measure the password length up to the newline, then copy that many bytes and add a trailing NUL terminator using strscpy().
--- drivers/platform/x86/think-lmi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/platform/x86/think-lmi.c +3 -4
@@ -402,14 +402,13 @@ static ssize_t current_password_store(ststruct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj);size_t pwdlen; - pwdlen =strlen (buf); +/* Strip newline; setting password won't work if one is present. */ + pwdlen =strchrnul (buf,'\n' ) - buf;/* pwdlen == 0 is allowed to clear the password */ if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))return -EINVAL ; -strscpy (setting->password, buf, setting->maxlen); -/* Strip out CR if one is present, setting password won't work if it is present */ -strreplace (setting->password,'\n' ,'\0' ); +strscpy (setting->password, buf, pwdlen +1 );return count; }
Greg Kroah-Hartman
maintainerPATCH 585/877 platform/x86: think-lmi: improve check if BIOS account security enabled
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Pearson <[email protected]>
[ Upstream commit b39e8ece931a4b4f64cdf9e75fffd6e82828e471 ]
Improve determination of whether authentication account is enabled by checking if either password or certificate is enabled.
Renamed valid to pwd_enabled for better readability.
Stable-dep-of: 4f3183f5ae9b ("platform/x86: think-lmi: Fix certificate thumbprint sysfs output")
--- drivers/platform/x86/think-lmi.c | 26 +++++++++++++------------- drivers/platform/x86/think-lmi.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-)
drivers/platform/x86/think-lmi.c +13 -13
@@ -390,7 +390,7 @@ static ssize_t is_enabled_show(struct ko {struct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj); -return sysfs_emit (buf,"%d\n" , setting->valid); +return sysfs_emit (buf,"%d\n" , setting->pwd_enabled || setting->cert_installed); }static struct kobj_attribute auth_is_pass_set =__ATTR_RO (is_enabled);
@@ -467,7 +467,7 @@ static ssize_t new_password_store(structif (ret) goto out; -if (tlmi_priv.pwd_admin->valid) { +if (tlmi_priv.pwd_admin->pwd_enabled) { ret =tlmi_opcode_setting ("WmiOpcodePasswordAdmin" , tlmi_priv.pwd_admin->password);if (ret)
@@ -775,7 +775,7 @@ static ssize_t certificate_store(struct new_cert, setting->signature); }else {/* This is a fresh install */ -if (!setting->valid || !setting->password[0 ]) { +if (!setting->pwd_enabled || !setting->password[0 ]) {kfree (new_cert);return -EACCES ; }
@@ -1018,7 +1018,7 @@ static ssize_t current_value_store(struc* Workstation's require the opcode to be set before changing the * attribute. */ -if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0 ]) { +if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0 ]) { ret =tlmi_opcode_setting ("WmiOpcodePasswordAdmin" , tlmi_priv.pwd_admin->password);if (ret)
@@ -1041,7 +1041,7 @@ static ssize_t current_value_store(strucelse ret =tlmi_save_bios_settings ("" ); }else {/* old non-opcode based authentication method (deprecated) */ -if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0 ]) { +if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0 ]) { auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;", tlmi_priv.pwd_admin->password, encoding_options[tlmi_priv.pwd_admin->encoding],
@@ -1217,7 +1217,7 @@ static ssize_t save_settings_store(strucif (ret) goto out; }else if (tlmi_priv.opcode_support) { -if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0 ]) { +if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0 ]) { ret =tlmi_opcode_setting ("WmiOpcodePasswordAdmin" , tlmi_priv.pwd_admin->password);if (ret)
@@ -1225,7 +1225,7 @@ static ssize_t save_settings_store(struc } ret =tlmi_save_bios_settings ("" ); }else {/* old non-opcode based authentication method (deprecated) */ -if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0 ]) { +if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0 ]) { auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;", tlmi_priv.pwd_admin->password, encoding_options[tlmi_priv.pwd_admin->encoding],
@@ -1275,7 +1275,7 @@ static ssize_t debug_cmd_store(struct koif (!new_setting)return -ENOMEM ; -if (tlmi_priv.pwd_admin->valid && tlmi_priv.pwd_admin->password[0 ]) { +if (tlmi_priv.pwd_admin->pwd_enabled && tlmi_priv.pwd_admin->password[0 ]) { auth_str = kasprintf(GFP_KERNEL, "%s,%s,%s;", tlmi_priv.pwd_admin->password, encoding_options[tlmi_priv.pwd_admin->encoding],
@@ -1602,14 +1602,14 @@ static int tlmi_analyze(void) goto fail_clear_attr;if (tlmi_priv.pwdcfg.core.password_state &TLMI_PAP_PWD ) - tlmi_priv.pwd_admin->valid = true; + tlmi_priv.pwd_admin->pwd_enabled = true; tlmi_priv.pwd_power =tlmi_create_auth ("pop" ,"power-on" );if (!tlmi_priv.pwd_power) goto fail_clear_attr;if (tlmi_priv.pwdcfg.core.password_state &TLMI_POP_PWD ) - tlmi_priv.pwd_power->valid = true; + tlmi_priv.pwd_power->pwd_enabled = true;if (tlmi_priv.opcode_support) { tlmi_priv.pwd_system =tlmi_create_auth ("smp" ,"system" );
@@ -1617,7 +1617,7 @@ static int tlmi_analyze(void) goto fail_clear_attr;if (tlmi_priv.pwdcfg.core.password_state &TLMI_SMP_PWD ) - tlmi_priv.pwd_system->valid = true; + tlmi_priv.pwd_system->pwd_enabled = true; tlmi_priv.pwd_hdd =tlmi_create_auth ("hdd" ,"hdd" );if (!tlmi_priv.pwd_hdd)
@@ -1635,7 +1635,7 @@ static int tlmi_analyze(void)/* Check if PWD is configured and set index to first drive found */ if (tlmi_priv.pwdcfg.ext.hdd_user_password || tlmi_priv.pwdcfg.ext.hdd_master_password) { - tlmi_priv.pwd_hdd->valid = true; + tlmi_priv.pwd_hdd->pwd_enabled = true;if (tlmi_priv.pwdcfg.ext.hdd_master_password) tlmi_priv.pwd_hdd->index =ffs (tlmi_priv.pwdcfg.ext.hdd_master_password) -1 ;
@@ -1645,7 +1645,7 @@ static int tlmi_analyze(void) }if (tlmi_priv.pwdcfg.ext.nvme_user_password || tlmi_priv.pwdcfg.ext.nvme_master_password) { - tlmi_priv.pwd_nvme->valid = true; + tlmi_priv.pwd_nvme->pwd_enabled = true;if (tlmi_priv.pwdcfg.ext.nvme_master_password) tlmi_priv.pwd_nvme->index =ffs (tlmi_priv.pwdcfg.ext.nvme_master_password) -1 ;
drivers/platform/x86/think-lmi.h +1 -1
@@ -65,7 +65,7 @@ struct tlmi_pwdcfg {/* password setting details */ struct tlmi_pwd_setting {struct kobject kobj; -bool valid; +bool pwd_enabled;char password[TLMI_PWD_BUFSIZE ];const char *pwd_type;const char *role;
Greg Kroah-Hartman
maintainerPATCH 586/877 platform/x86: think-lmi: Fix certificate thumbprint sysfs output
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 4f3183f5ae9b8ddfe338d79a96146a05342bbe50 ]
cert_thumbprint() already returns the accumulated output length, but certificate_thumbprint_show() adds that value to count again, making the next line use the wrong offset. Errors returned by cert_thumbprint() are also ignored and their negative values added to count.
Assign the total length to count instead and propagate errors correctly.
--- drivers/platform/x86/think-lmi.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/platform/x86/think-lmi.c +8 -4
@@ -671,14 +671,18 @@ static ssize_t certificate_thumbprint_sh char *buf) {struct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj); -int count =0 ; +ssize_t count =0 ;if (!tlmi_priv.certificate_support || !setting->cert_installed)return -EOPNOTSUPP ; - count +=cert_thumbprint (buf,"Md5" , count); - count +=cert_thumbprint (buf,"Sha1" , count); - count +=cert_thumbprint (buf,"Sha256" , count); + count =cert_thumbprint (buf,"Md5" , count); +if (count <0 ) +return count; + count =cert_thumbprint (buf,"Sha1" , count); +if (count <0 ) +return count; + count =cert_thumbprint (buf,"Sha256" , count);return count; }
Greg Kroah-Hartman
maintainerPATCH 587/877 platform/x86: intel_sar: Check ACPI_HANDLE() against NULL
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Rafael J. Wysocki" <[email protected]>
[ Upstream commit 2765f16c12af7c2533763e46b8113b727354012d ]
Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.
Accordingly, add a requisite ACPI_HANDLE() check against NULL to the platform/x86 intel_sar driver.
For this stable dependency, also convert the existing allocations in parse_package() and sar_probe() to kmalloc_objs() and kzalloc_obj(). Both helpers are already available in this tree and retain the same allocation sizes and GFP_KERNEL flags. This makes intel_sar.c match the parent of 30c906cff490 ("platform/x86: int1092: Fix potential memory leak in sar_probe()"), allowing that target to apply unchanged. No new functions or allocation helpers are introduced.
Stable-dep-of: 30c906cff490 ("platform/x86: int1092: Fix potential memory leak in sar_probe()")
--- drivers/platform/x86/intel/int1092/intel_sar.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/platform/x86/intel/int1092/intel_sar.c +9 -4
@@ -91,8 +91,8 @@ static acpi_status parse_package(struct item->package.count <= data->total_dev_mode)return AE_ERROR ; - data->device_mode_info =kmalloc_array (data->total_dev_mode, -sizeof (struct wwan_device_mode_info ),GFP_KERNEL ); + data->device_mode_info = kmalloc_objs(struct wwan_device_mode_info, + data->total_dev_mode);if (!data->device_mode_info)return AE_ERROR ;
@@ -245,15 +245,20 @@ static void sar_get_data(int reg, structstatic int sar_probe (struct platform_device *device) {struct wwan_sar_context *context; +acpi_handle handle;int reg;int result; - context =kzalloc (sizeof (*context),GFP_KERNEL ); + handle =ACPI_HANDLE (&device->dev); +if (!handle) +return -ENODEV ; + + context =kzalloc_obj (*context);if (!context)return -ENOMEM ; context->sar_device = device; - context->handle =ACPI_HANDLE (&device->dev); + context->handle = handle;dev_set_drvdata (&device->dev, context); result =guid_parse (SAR_DSM_UUID , &context->guid);
Greg Kroah-Hartman
maintainerPATCH 588/877 platform/x86: int1092: Fix potential memory leak in sar_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abdun Nihaal <[email protected]>
[ Upstream commit 30c906cff490c3601ee9ff110fe8115fabe75fd4 ]
The memory allocated for device_mode_info in parse_package() called by sar_get_data() is not freed in some of the error paths in sar_probe(). Fix that by converting to use device managed allocations.
--- drivers/platform/x86/intel/int1092/intel_sar.c | 32 +++++++------------------ 1 file changed, 10 insertions(+), 22 deletions(-)
drivers/platform/x86/intel/int1092/intel_sar.c +10 -22
@@ -91,8 +91,10 @@ static acpi_status parse_package(struct item->package.count <= data->total_dev_mode)return AE_ERROR ; - data->device_mode_info = kmalloc_objs(struct wwan_device_mode_info, - data->total_dev_mode); + data->device_mode_info =devm_kmalloc_array (&context->sar_device->dev, + data->total_dev_mode, +sizeof (*data->device_mode_info), +GFP_KERNEL );if (!data->device_mode_info)return AE_ERROR ;
@@ -253,7 +255,7 @@ static int sar_probe(struct platform_devif (!handle)return -ENODEV ; - context =kzalloc_obj (*context); + context =devm_kzalloc (&device->dev,sizeof (*context),GFP_KERNEL );if (!context)return -ENOMEM ;
@@ -264,7 +266,7 @@ static int sar_probe(struct platform_dev result =guid_parse (SAR_DSM_UUID , &context->guid);if (result) {dev_err (&device->dev,"SAR UUID parse error: %d\n" , result); - goto r_free; +return result; }for (reg =0 ; reg <MAX_REGULATORY ; reg++)
@@ -272,43 +274,29 @@ static int sar_probe(struct platform_devif (sar_get_device_mode (device) !=AE_OK ) {dev_err (&device->dev,"Failed to get device mode\n" ); - result = -EIO ; - goto r_free; +return -EIO ; } result =sysfs_create_group (&device->dev.kobj, &intcsar_group);if (result) {dev_err (&device->dev,"sysfs creation failed\n" ); - goto r_free; +return result; }if (acpi_install_notify_handler (ACPI_HANDLE (&device->dev),ACPI_DEVICE_NOTIFY , sar_notify, (void *)device) !=AE_OK ) {dev_err (&device->dev,"Failed acpi_install_notify_handler\n" ); - result = -EIO ; - goto r_sys; +sysfs_remove_group (&device->dev.kobj, &intcsar_group); +return -EIO ; }return 0 ; - -r_sys: -sysfs_remove_group (&device->dev.kobj, &intcsar_group); -r_free: -kfree (context); -return result; }static void sar_remove (struct platform_device *device) { -struct wwan_sar_context *context =dev_get_drvdata (&device->dev); -int reg; -acpi_remove_notify_handler (ACPI_HANDLE (&device->dev),ACPI_DEVICE_NOTIFY , sar_notify);sysfs_remove_group (&device->dev.kobj, &intcsar_group); -for (reg =0 ; reg <MAX_REGULATORY ; reg++) -kfree (context->config_data[reg].device_mode_info); - -kfree (context); }static struct platform_driver sar_driver = {
Greg Kroah-Hartman
maintainerPATCH 589/877 platform/x86/amd/pmc: Move STB block into amd_pmc_s2d_init()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Sundar S K <[email protected]>
[ Upstream commit 83ad6974dd3bf34c080b3c08d36d02ebc3bd6da8 ]
Transfer the support for STB-related file operations to the amd_pmc_s2d_init() function, thereby consolidating the STB and S2D (Spill to DRAM) functionality in one location. Also, relocate the call to amd_pmc_s2d_init() to occur after the creation of the "amd_pmc" debugfs directory. This ensures that the driver's root debugfs directory is established beforehand.
For older platforms that supported S2D, exit immediately after creating debugfs. These platforms may not support the PMFW messages available on newer platforms. This adjustment is necessary due to the relocation of debugfs creation into amd_pmc_s2d_init().
Stable-dep-of: 9cef693bce96 ("platform/x86/amd/pmc: Restore msg_port on amd_stb_s2d_init() error paths")
--- drivers/platform/x86/amd/pmc/pmc.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
drivers/platform/x86/amd/pmc/pmc.c +16 -15
@@ -657,15 +657,6 @@ static void amd_pmc_dbgfs_register(struc &s0ix_stats_fops);debugfs_create_file ("amd_pmc_idlemask" ,0644 , dev->dbgfs_dir, dev, &amd_pmc_idlemask_fops); -/* Enable STB only when the module_param is set */ -if (enable_stb) { -if (amd_pmc_is_stb_supported (dev)) -debugfs_create_file ("stb_read" ,0644 , dev->dbgfs_dir, dev, - &amd_pmc_stb_debugfs_fops_v2); -else -debugfs_create_file ("stb_read" ,0644 , dev->dbgfs_dir, dev, - &amd_pmc_stb_debugfs_fops); - } }static void amd_pmc_dump_registers (struct amd_pmc_dev *dev)
@@ -1069,6 +1060,18 @@ static int amd_pmc_s2d_init(struct amd_pu32 size =0 ;int ret; +if (!enable_stb) +return 0 ; + +if (amd_pmc_is_stb_supported (dev)) { +debugfs_create_file ("stb_read" ,0644 , dev->dbgfs_dir, dev, + &amd_pmc_stb_debugfs_fops_v2); + }else { +debugfs_create_file ("stb_read" ,0644 , dev->dbgfs_dir, dev, + &amd_pmc_stb_debugfs_fops); +return 0 ; + } +/* Spill to DRAM feature uses separate SMU message port */ dev->msg_port =1 ;
@@ -1187,12 +1190,6 @@ static int amd_pmc_probe(struct platform/* Get num of IP blocks within the SoC */ amd_pmc_get_ip_info (dev); -if (enable_stb &&amd_pmc_is_stb_supported (dev)) { - err =amd_pmc_s2d_init (dev); -if (err) - goto err_pci_dev_put; - } -platform_set_drvdata (pdev, dev);if (IS_ENABLED (CONFIG_SUSPEND )) { err =acpi_register_lps0_dev (&amd_pmc_s2idle_dev_ops);
@@ -1203,6 +1200,10 @@ static int amd_pmc_probe(struct platform }amd_pmc_dbgfs_register (dev); + err =amd_pmc_s2d_init (dev); +if (err) + goto err_pci_dev_put; +if (IS_ENABLED (CONFIG_AMD_MP2_STB ))amd_mp2_stb_init (dev);pm_report_max_hw_sleep (U64_MAX );
Greg Kroah-Hartman
maintainerPATCH 590/877 platform/x86/amd/pmc: Move STB functionality to a new file for better code organization
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Sundar S K <[email protected]>
[ Upstream commit 0e914063ddd135407c0550b77a6f5bf779bf8384 ]
As the SoC evolves with each generation, the dynamics between the PMC and STB layers within the PMC driver are becoming increasingly complex, making it challenging to manage both in a single file and maintain code readability.
Additionally, during silicon bringup, the PMC functionality is often enabled first, with STB functionality added later. This can lead to missed updates in the driver, potentially causing issues.
To address these challenges, it's beneficial to move all STB-related changes to a separate file. This approach will better accommodate newer SoCs, provide improved flexibility for desktop variants, and facilitate the collection of additional debug information through STB mechanisms.
Also the additional checks for entering s2d_init have been moved from the PMC probe to amd_pmc_s2d_init(). This adjustment makes more sense following the transfer of code to the separate mp1_stb.c file.
Stable backport adaptation:
Preserve the delay_suspend module parameter and the existing stable PMC workarounds while moving the STB implementation out of pmc.c.
Rename the existing initializer to amd_stb_s2d_init(), define the two message-port constants, and move s2d_msg_id into a minimal struct stb_arg. These are the interfaces needed for 9cef693bce96 to apply unchanged; the later upstream helper functions and unrelated platform changes are not needed here. No new functions are introduced.
Retain the existing zero STB physical-address check omitted by the upstream move, and restore MSG_PORT_PMC before its -EINVAL return. This preserves the stable validation without leaving an extra mailbox error path outside the target fix.
Stable-dep-of: 9cef693bce96 ("platform/x86/amd/pmc: Restore msg_port on amd_stb_s2d_init() error paths")
--- drivers/platform/x86/amd/pmc/Makefile | 2 drivers/platform/x86/amd/pmc/mp1_stb.c | 302 +++++++++++++++++++++++++++++++++ drivers/platform/x86/amd/pmc/pmc.c | 285 ------------------------------- drivers/platform/x86/amd/pmc/pmc.h | 16 + 4 files changed, 320 insertions(+), 285 deletions(-) create mode 100644 drivers/platform/x86/amd/pmc/mp1_stb.c
drivers/platform/x86/amd/pmc/Makefile +1 -1
@@ -4,6 +4,6 @@ # AMD Power Management Controller Driver # -amd-pmc-objs := pmc.o pmc-quirks.o +amd-pmc-objs := pmc.o pmc-quirks.o mp1_stb.o obj-$(CONFIG_AMD_PMC) += amd-pmc.o amd-pmc-$(CONFIG_AMD_MP2_STB) += mp2_stb.o
drivers/platform/x86/amd/pmc/mp1_stb.c new file +302 -0
302 lines not on this page · raw message
drivers/platform/x86/amd/pmc/pmc.c +2 -283
373 lines not on this page · raw message
drivers/platform/x86/amd/pmc/pmc.h +15 -1
@@ -14,6 +14,11 @@#include <linux/types.h> #include <linux/mutex.h> +enum s2d_msg_port { +MSG_PORT_PMC , +MSG_PORT_S2D , +}; +struct amd_mp2_dev {void __iomem *mmio;void __iomem *vslbase;
@@ -25,6 +30,10 @@ struct amd_mp2_dev {bool is_stb_data; }; +struct stb_arg { +u32 s2d_msg_id; +}; +struct amd_pmc_dev {void __iomem *regbase;void __iomem *smu_virt_addr;
@@ -36,7 +45,6 @@ struct amd_pmc_dev {u32 active_ips;u32 dram_size;u32 num_ips; -u32 s2d_msg_id;u32 smu_msg;/* SMU version information */ u8 smu_program;
@@ -51,6 +59,7 @@ struct amd_pmc_dev {bool disable_8042_wakeup;bool is_first_check_after_suspend;struct amd_mp2_dev *mp2; +struct stb_arg stb_arg; };void amd_pmc_process_restore_quirks (struct amd_pmc_dev *dev);
@@ -73,4 +82,9 @@ void amd_mp2_stb_deinit(struct amd_pmc_d#define PCI_DEVICE_ID_AMD_1AH_M60H_ROOT 0x1122#define PCI_DEVICE_ID_AMD_MP2_STB 0x172c +int amd_stb_s2d_init (struct amd_pmc_dev *dev); +int amd_pmc_read_stb (struct amd_pmc_dev *dev,u32 *buf); +int amd_pmc_write_stb (struct amd_pmc_dev *dev,u32 data); +int amd_pmc_send_cmd (struct amd_pmc_dev *dev,u32 arg,u32 *data,u8 msg,bool ret); +#endif /* PMC_H */
Greg Kroah-Hartman
maintainerPATCH 591/877 platform/x86/amd/pmc: Define enum for S2D/PMC msg_port and add helper function
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Sundar S K <[email protected]>
[ Upstream commit 2851f4f8ed4e130d864c5478c6da933a4427ae52 ]
To distinguish between the PMC message port and the S2D (Spill to DRAM) message port, replace the use of 0 and 1 with an enum.
To avoid printing the S2D or PMC port multiple times in debug print, add new routine to retrieve the message port information, which can be used to print the right msg_port getting used.
Stable-dep-of: 9cef693bce96 ("platform/x86/amd/pmc: Restore msg_port on amd_stb_s2d_init() error paths")
--- drivers/platform/x86/amd/pmc/pmc.c | 22 +++++++++++++++++----- drivers/platform/x86/amd/pmc/pmc.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-)
drivers/platform/x86/amd/pmc/pmc.c +17 -5
@@ -458,11 +458,23 @@ static void amd_pmc_dbgfs_register(struc &amd_pmc_idlemask_fops); } +static char *amd_pmc_get_msg_port (struct amd_pmc_dev *dev) +{ +switch (dev->msg_port) { +case MSG_PORT_PMC : +return "PMC" ; +case MSG_PORT_S2D : +return "S2D" ; +default : +return "Invalid message port" ; + } +} +static void amd_pmc_dump_registers (struct amd_pmc_dev *dev) {u32 value, message, argument, response; -if (dev->msg_port) { +if (dev->msg_port ==MSG_PORT_S2D ) { message =AMD_S2D_REGISTER_MESSAGE ; argument =AMD_S2D_REGISTER_ARGUMENT ; response =AMD_S2D_REGISTER_RESPONSE ;
@@ -473,13 +485,13 @@ static void amd_pmc_dump_registers(struc } value =amd_pmc_reg_read (dev, response); -dev_dbg (dev->dev,"AMD_%s_REGISTER_RESPONSE:%x\n" , dev->msg_port ?"S2D" :"PMC" , value); +dev_dbg (dev->dev,"AMD_%s_REGISTER_RESPONSE:%x\n" ,amd_pmc_get_msg_port (dev), value); value =amd_pmc_reg_read (dev, argument); -dev_dbg (dev->dev,"AMD_%s_REGISTER_ARGUMENT:%x\n" , dev->msg_port ?"S2D" :"PMC" , value); +dev_dbg (dev->dev,"AMD_%s_REGISTER_ARGUMENT:%x\n" ,amd_pmc_get_msg_port (dev), value); value =amd_pmc_reg_read (dev, message); -dev_dbg (dev->dev,"AMD_%s_REGISTER_MESSAGE:%x\n" , dev->msg_port ?"S2D" :"PMC" , value); +dev_dbg (dev->dev,"AMD_%s_REGISTER_MESSAGE:%x\n" ,amd_pmc_get_msg_port (dev), value); }int amd_pmc_send_cmd (struct amd_pmc_dev *dev,u32 arg,u32 *data,u8 msg,bool ret)
@@ -489,7 +501,7 @@ int amd_pmc_send_cmd(struct amd_pmc_devmutex_lock (&dev->lock); -if (dev->msg_port) { +if (dev->msg_port ==MSG_PORT_S2D ) { message =AMD_S2D_REGISTER_MESSAGE ; argument =AMD_S2D_REGISTER_ARGUMENT ; response =AMD_S2D_REGISTER_RESPONSE ;
drivers/platform/x86/amd/pmc/pmc.h +1 -1
@@ -39,7 +39,6 @@ struct amd_pmc_dev {void __iomem *smu_virt_addr;void __iomem *stb_virt_addr;void __iomem *fch_virt_addr; -bool msg_port;u32 base_addr;u32 cpu_id;u32 active_ips;
@@ -51,6 +50,7 @@ struct amd_pmc_dev {u8 major;u8 minor;u8 rev; +u8 msg_port;struct device *dev;struct pci_dev *rdev;struct mutex lock;/* generic mutex lock */
Greg Kroah-Hartman
maintainerPATCH 592/877 platform/x86/amd/pmc: Restore msg_port on amd_stb_s2d_init() error paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 9cef693bce96bb4c6952f48d855284cf7fa4f367 ]
dev->msg_port is switched to MSG_PORT_S2D before issuing the S2D SMU commands but is only restored to MSG_PORT_PMC on the success path. The early "return -EIO" and "return -ENOMEM" leave the port stuck on MSG_PORT_S2D, so all subsequent SMU communication - including the s2idle prepare/restore handlers - is directed at the wrong mailbox.
Consolidate the exit path through a single label so the message port is always restored.
--- drivers/platform/x86/amd/pmc/mp1_stb.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/platform/x86/amd/pmc/mp1_stb.c +15 -9
@@ -253,7 +253,7 @@ int amd_stb_s2d_init(struct amd_pmc_devu32 phys_addr_low, phys_addr_hi;u64 stb_phys_addr;u32 size =0 ; -int ret; +int ret =0 ;if (!enable_stb)return 0 ;
@@ -271,8 +271,10 @@ int amd_stb_s2d_init(struct amd_pmc_dev dev->msg_port =MSG_PORT_S2D ;amd_pmc_send_cmd (dev,S2D_TELEMETRY_SIZE , &size, dev->stb_arg.s2d_msg_id, true); -if (size !=S2D_TELEMETRY_BYTES_MAX ) -return -EIO ; +if (size !=S2D_TELEMETRY_BYTES_MAX ) { + ret = -EIO ; + goto out; + }/* Get DRAM size */ ret =amd_pmc_send_cmd (dev,S2D_DRAM_SIZE , &dev->dram_size, dev->stb_arg.s2d_msg_id, true);
@@ -291,12 +293,16 @@ int amd_stb_s2d_init(struct amd_pmc_dev stb_phys_addr = ((u64 )phys_addr_hi <<32 | phys_addr_low); -/* Clear msg_port for other SMU operation */ - dev->msg_port =MSG_PORT_PMC ; - dev->stb_virt_addr =devm_ioremap (dev->dev, stb_phys_addr, dev->dram_size); -if (!dev->stb_virt_addr) -return -ENOMEM ; +if (!dev->stb_virt_addr) { + ret = -ENOMEM ; + goto out; + } + + ret =0 ; -return 0 ; +out: +/* Restore the default message port for subsequent SMU operations */ + dev->msg_port =MSG_PORT_PMC ; +return ret; }
Greg Kroah-Hartman
maintainerPATCH 593/877 platform/x86/amd/pmc: Propagate SMU errors and validate S2D address
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 0225c1d637687b03726f00ac65b6def843d2c464 ]
amd_stb_s2d_init() discards the return value of several S2D SMU commands. When the SMU refuses a command (e.g. "SMU cmd failed. err: 0xff") the failure is only noticed indirectly - if at all - and reported as -EIO, masking the real error.
More seriously, the S2D_PHYS_ADDR_LOW/HIGH return values are ignored, so on failure phys_addr_low/hi are left uninitialised and the assembled address is passed straight to devm_ioremap(). When the SMU leaves them at zero this maps physical address 0 and trips the ioremap-on-RAM warning:
amd_pmc AMDI000B:00: SMU cmd failed. err: 0xff ioremap on RAM at 0x0000000000000000 - 0x0000000000ffffff
WARNING: CPU: 13 PID: 4592 at arch/x86/mm/ioremap.c:...
Check the return value of each SMU command and propagate it, and reject a zero physical address before calling devm_ioremap().
--- drivers/platform/x86/amd/pmc/mp1_stb.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/pmc/mp1_stb.c +11 -3
@@ -270,7 +270,9 @@ int amd_stb_s2d_init(struct amd_pmc_dev/* Spill to DRAM feature uses separate SMU message port */ dev->msg_port =MSG_PORT_S2D ; -amd_pmc_send_cmd (dev,S2D_TELEMETRY_SIZE , &size, dev->stb_arg.s2d_msg_id, true); + ret =amd_pmc_send_cmd (dev,S2D_TELEMETRY_SIZE , &size, dev->stb_arg.s2d_msg_id, true); +if (ret) + goto out;if (size !=S2D_TELEMETRY_BYTES_MAX ) { ret = -EIO ; goto out;
@@ -282,8 +284,14 @@ int amd_stb_s2d_init(struct amd_pmc_dev dev->dram_size =S2D_TELEMETRY_DRAMBYTES_MAX ;/* Get STB DRAM address */ -amd_pmc_send_cmd (dev,S2D_PHYS_ADDR_LOW , &phys_addr_low, dev->stb_arg.s2d_msg_id, true); -amd_pmc_send_cmd (dev,S2D_PHYS_ADDR_HIGH , &phys_addr_hi, dev->stb_arg.s2d_msg_id, true); + ret =amd_pmc_send_cmd (dev,S2D_PHYS_ADDR_LOW , &phys_addr_low, + dev->stb_arg.s2d_msg_id, true); +if (ret) + goto out; + ret =amd_pmc_send_cmd (dev,S2D_PHYS_ADDR_HIGH , &phys_addr_hi, + dev->stb_arg.s2d_msg_id, true); +if (ret) + goto out;if (!phys_addr_hi && !phys_addr_low) {dev_err (dev->dev,"STB is not enabled on the system; disable enable_stb or contact system vendor\n" );
Greg Kroah-Hartman
maintainerPATCH 594/877 io_uring/waitid: have io_waitid_complete() remove wait queue entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit a48c0cbf28c03f6c590a14ceb31bf6e619c2f6da ]
Both callers of this need the entry potentially removed, so shift the removal into the completion side and kill it from the two callers.
While at it, add a helper for removing the wait_queue_entry based on the passed in io_kiocb.
Stable-dep-of: 2cf20c4e0f72 ("io_uring/waitid: avoid siginfo copy during ring teardown")
--- io_uring/waitid.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
io_uring/waitid.c +20 -6
@@ -115,6 +115,22 @@ static int io_waitid_finish(struct io_kireturn ret; } +static void io_waitid_remove_wq (struct io_kiocb *req) +{ + struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); +struct wait_queue_head *head; + + head =READ_ONCE (iw->head); +if (head) { +struct io_waitid_async *iwa = req->async_data; + + iw->head =NULL ; +spin_lock_irq (&head->lock); +list_del_init (&iwa->wo.child_wait.entry); +spin_unlock_irq (&head->lock); + } +} +static void io_waitid_complete (struct io_kiocb *req,int ret) { struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
@@ -125,6 +141,7 @@ static void io_waitid_complete(struct iolockdep_assert_held (&req->ctx->uring_lock);hlist_del_init (&req->hash_node); +io_waitid_remove_wq (req); ret =io_waitid_finish (req, ret);if (ret <0 )
@@ -135,7 +152,8 @@ static void io_waitid_complete(struct iostatic bool __io_waitid_cancel (struct io_ring_ctx *ctx,struct io_kiocb *req) { struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid); -struct io_waitid_async *iwa = req->async_data; + +lockdep_assert_held (&req->ctx->uring_lock);/* * Mark us canceled regardless of ownership. This will prevent a
@@ -147,9 +165,6 @@ static bool __io_waitid_cancel(struct ioif (atomic_fetch_inc (&iw->refs) &IO_WAITID_REF_MASK )return false; -spin_lock_irq (&iw->head->lock); -list_del_init (&iwa->wo.child_wait.entry); -spin_unlock_irq (&iw->head->lock);io_waitid_complete (req, -ECANCELED );io_req_queue_tw_complete (req, -ECANCELED );return true;
@@ -251,8 +266,7 @@ static void io_waitid_cb(struct io_kiocbio_waitid_drop_issue_ref (req);return ; } - -remove_wait_queue (iw->head, &iwa->wo.child_wait); +/* fall through to complete, will kill waitqueue */ } }
Greg Kroah-Hartman
maintainerPATCH 595/877 io_uring/waitid: avoid siginfo copy during ring teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
[ Upstream commit 2cf20c4e0f72d523b8673053e7120d092ff1f074 ]
During ring teardown, io_ring_exit_work() cancels outstanding requests from a kworker with a NULL tctx. The waitid cancellation path eventually reaches io_waitid_finish(), which copies the stored siginfo to the userspace pointer supplied with the request.
Ring-wide teardown does not run in the task context that submitted the request, so it must not access that task's userspace pointer. Depending on the address and mm state, the copy may fail with -EFAULT, but the uaccess itself is inappropriate from the teardown kworker.
Use a no-copy cancellation callback when io_waitid_remove_all() is called without an owning task context. Complete the request with -ECANCELED while releasing the waitid state without touching siginfo.
Keep the existing siginfo handling for explicit async cancellation and task-scoped cancellation.
--- io_uring/waitid.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
io_uring/waitid.c +11 -7
@@ -131,7 +131,7 @@ static void io_waitid_remove_wq(struct i } } -static void io_waitid_complete (struct io_kiocb *req,int ret) +static void io_waitid_complete (struct io_kiocb *req,int ret,bool copy_si) { struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
@@ -143,13 +143,17 @@ static void io_waitid_complete(struct iohlist_del_init (&req->hash_node);io_waitid_remove_wq (req); - ret =io_waitid_finish (req, ret); +if (copy_si) + ret =io_waitid_finish (req, ret); +else +io_waitid_free (req);if (ret <0 )req_set_fail (req);io_req_set_res (req, ret,0 ); } -static bool __io_waitid_cancel (struct io_ring_ctx *ctx,struct io_kiocb *req) +static bool __io_waitid_cancel (struct io_ring_ctx *ctx,struct io_kiocb *req, +bool copy_si) { struct io_waitid *iw = io_kiocb_to_cmd(req, struct io_waitid);
@@ -165,7 +169,7 @@ static bool __io_waitid_cancel(struct ioif (atomic_fetch_inc (&iw->refs) &IO_WAITID_REF_MASK )return false; -io_waitid_complete (req, -ECANCELED ); +io_waitid_complete (req, -ECANCELED , copy_si);io_req_queue_tw_complete (req, -ECANCELED );return true; }
@@ -185,7 +189,7 @@ int io_waitid_cancel(struct io_ring_ctxif (req->cqe.user_data != cd->data && !(cd->flags &IORING_ASYNC_CANCEL_ANY ))continue ; -if (__io_waitid_cancel (ctx, req)) +if (__io_waitid_cancel (ctx, req, true)) nr++;if (!(cd->flags &IORING_ASYNC_CANCEL_ALL ))break ;
@@ -211,7 +215,7 @@ bool io_waitid_remove_all(struct io_ringif (!io_match_task_safe (req, task, cancel_all))continue ;hlist_del_init (&req->hash_node); -__io_waitid_cancel (ctx, req); +__io_waitid_cancel (ctx, req, task !=NULL ); found = true; }
@@ -270,7 +274,7 @@ static void io_waitid_cb(struct io_kiocb } } -io_waitid_complete (req, ret); +io_waitid_complete (req, ret, true);io_req_task_complete (req, ts); }
Greg Kroah-Hartman
maintainerPATCH 596/877 power: supply: qcom_battmgr: fix use-after-free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit 4e40befedfc8ed86f44e1f81df92d13c149c9f8d ]
qcom_battmgr_pdr_notify() queues enable_work when the PMIC GLINK service comes up, and the worker recovers battmgr through container_of() to issue firmware requests. The PMIC GLINK client stays on the client list until its devres release action runs, so a PDR notification can keep queueing the work, and a pending or running worker can access battmgr after devres frees it.
Make enable_work device-managed with devm_work_autocancel(), registered before the PMIC GLINK client is allocated. The devres cleanup then releases the client first, so no further notification can queue the work, and cancels the work before battmgr is freed.
This issue was found by an in-house static analysis tool.
--- drivers/power/supply/qcom_battmgr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/power/supply/qcom_battmgr.c +7 -1
@@ -4,6 +4,7 @@* Copyright (c) 2022, Linaro Ltd */ #include <linux/auxiliary_bus.h> +#include <linux/devm-helpers.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/of_device.h>
@@ -1335,6 +1336,7 @@ static int qcom_battmgr_probe(struct auxconst struct of_device_id *match;struct qcom_battmgr *battmgr;struct device *dev = &adev->dev; +int ret; battmgr =devm_kzalloc (dev,sizeof (*battmgr),GFP_KERNEL );if (!battmgr)
@@ -1350,7 +1352,6 @@ static int qcom_battmgr_probe(struct aux psy_cfg_supply.supplied_to = qcom_battmgr_battery; psy_cfg_supply.num_supplicants =1 ; -INIT_WORK (&battmgr->enable_work, qcom_battmgr_enable_worker);mutex_init (&battmgr->lock);init_completion (&battmgr->ack);
@@ -1397,6 +1398,11 @@ static int qcom_battmgr_probe(struct aux "failed to register wireless charing power supply\n"); } + ret =devm_work_autocancel (dev, &battmgr->enable_work, + qcom_battmgr_enable_worker); +if (ret) +return ret; + battmgr->client = devm_pmic_glink_client_alloc(dev, PMIC_GLINK_OWNER_BATTMGR, qcom_battmgr_callback, qcom_battmgr_pdr_notify,
Greg Kroah-Hartman
maintainerPATCH 597/877 net/smc: Address spelling errors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Simon Horman <[email protected]>
[ Upstream commit cd959bf7c3bbaf64a29750c5e36776078a18a8fe ]
Address spelling errors flagged by codespell.
This patch is intended to cover all files under drivers/smc
Stable-dep-of: db51a8658c11 ("net/smc: stop killed, freed and out_of_sync sharing a byte")
--- net/smc/smc.h | 2 +- net/smc/smc_clc.h | 2 +- net/smc/smc_core.c | 2 +- net/smc/smc_core.h | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-)
net/smc/smc.h +1 -1
@@ -278,7 +278,7 @@ struct smc_connection {*/ u64 peer_token;/* SMC-D token of peer */ u8 killed : 1; /* abnormal termination */ - u8 freed : 1; /* normal termiation */ + u8 freed : 1; /* normal termination */ u8 out_of_sync : 1; /* out of sync with peer */ };
net/smc/smc_clc.h +1 -1
@@ -156,7 +156,7 @@ struct smc_clc_msg_proposal_prefix { /* }__aligned(4) ;struct smc_clc_msg_smcd {/* SMC-D GID information */ -struct smc_clc_smcd_gid_chid ism;/* ISM native GID+CHID of requestor */ +struct smc_clc_smcd_gid_chid ism;/* ISM native GID+CHID of requester */ __be16 v2_ext_offset;/* SMC Version 2 Extension Offset */ u8 vendor_oui[3 ];/* vendor organizationally unique identifier */ u8 vendor_exp_options[5 ];
net/smc/smc_core.c +1 -1
@@ -2326,7 +2326,7 @@ static struct smc_buf_desc *smcr_new_buf }if (lgr->buf_type ==SMCR_PHYS_CONT_BUFS ) goto out; - fallthrough;// try virtually continguous buf + fallthrough;// try virtually contiguous buf case SMCR_VIRT_CONT_BUFS : buf_desc->order =get_order (bufsize); buf_desc->cpu_addr =vzalloc (PAGE_SIZE << buf_desc->order);
net/smc/smc_core.h +2 -2
@@ -30,7 +30,7 @@*/ #define SMC_CONN_PER_LGR_PREFER 255/* Preferred connections per link group used for * SMC-R v2.1 and later negotiation, vendors or -* distrubutions may modify it to a value between +* distributions may modify it to a value between * 16-255 as needed. */
@@ -181,7 +181,7 @@ struct smc_link {*/ #define SMC_LINKS_PER_LGR_MAX_PREFER 2/* Preferred max links per link group used for * SMC-R v2.1 and later negotiation, vendors or -* distrubutions may modify it to a value between +* distributions may modify it to a value between * 1-2 as needed. */
Greg Kroah-Hartman
maintainerPATCH 598/877 net/smc: stop killed, freed and out_of_sync sharing a byte
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hidayath Khan <[email protected]>
[ Upstream commit db51a8658c11a82432b64999519a269c3aabb447 ]
The three connection state flags are single-bit bitfields, so they occupy one byte of struct smc_connection and every store to one is a read-modify-write of the other two:
u8 killed : 1;
u8 freed : 1;
u8 out_of_sync : 1;They are not written under a common lock. smc_cdc_msg_validate() sets out_of_sync from the receive tasklet, while smc_conn_kill() sets killed from process context under lock_sock(), and the receive path does not defer to the backlog when the socket is owned -- smc_cdc_msg_recv() takes only bh_lock_sock().
Give each flag its own byte so a store no longer touches its neighbours. All readers test them as booleans and are unchanged. struct smc_connection grows by two bytes.
--- net/smc/smc.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/smc/smc.h +3 -3
@@ -277,9 +277,9 @@ struct smc_connection {* 0 for SMC-R, 32 for SMC-D */ u64 peer_token;/* SMC-D token of peer */ - u8 killed : 1; /* abnormal termination */ - u8 freed : 1; /* normal termination */ - u8 out_of_sync : 1; /* out of sync with peer */ +u8 killed;/* abnormal termination */ +u8 freed;/* normal termination */ +u8 out_of_sync;/* out of sync with peer */ };struct smc_sock {/* smc sock container */
Greg Kroah-Hartman
maintainerPATCH 599/877 net/mlx5e: SHAMPO, Always calculate page size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dragos Tatulea <[email protected]>
[ Upstream commit dff1c3164a69284ac9fedb1c25d4c008139e9fb8 ]
Adapt the rx path in SHAMPO mode to calculate page size based on configured page_shift when dealing with payload data.
This is necessary as an upcoming patch will add support for using different page sizes.
This change has no functional changes.
Stable-dep-of: e2466392a0b8 ("net/mlx5e: do not HW-GRO coalesce small frames")
--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 34 +++++++++++++++--------- 1 file changed, 22 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +22 -12
@@ -1983,11 +1983,14 @@ mlx5e_shampo_fill_skb_data(struct sk_bufstruct mlx5e_frag_page *frag_page, u32 data_bcnt, u32 data_offset) { + u32 page_size = BIT(rq->mpwqe.page_shift); +net_prefetchw (skb->data); do { /* Non-linear mode, hence non-XSK, which always uses PAGE_SIZE. */ - u32 pg_consumed_bytes = min_t(u32, PAGE_SIZE - data_offset, data_bcnt); + u32 pg_consumed_bytes = min_t(u32, page_size - data_offset, + data_bcnt); unsigned int truesize = pg_consumed_bytes; mlx5e_add_skb_frag(rq, skb, frag_page, data_offset,
@@ -2008,6 +2011,7 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(strucu16 headlen =min_t (u16,MLX5E_RX_MAX_HEAD , cqe_bcnt);struct mlx5e_frag_page *head_page = frag_page;struct mlx5e_xdp_buff *mxbuf = &rq->mxbuf; +u32 page_size =BIT (rq->mpwqe.page_shift);u32 frag_offset = head_offset;u32 byte_cnt = cqe_bcnt;struct skb_shared_info *sinfo;
@@ -2051,9 +2055,9 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struc linear_hr =skb_headroom (skb); linear_data_len = headlen; linear_frame_sz =MLX5_SKB_FRAG_SZ (skb_end_offset (skb)); -if (unlikely (frag_offset >=PAGE_SIZE )) { +if (unlikely (frag_offset >= page_size)) { frag_page++; - frag_offset -=PAGE_SIZE ; + frag_offset -= page_size; } }
@@ -2065,7 +2069,7 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(strucwhile (byte_cnt) {/* Non-linear mode, hence non-XSK, which always uses PAGE_SIZE. */ pg_consumed_bytes = -min_t (u32,PAGE_SIZE - frag_offset, byte_cnt); +min_t (u32, page_size - frag_offset, byte_cnt);if (test_bit (MLX5E_RQ_STATE_SHAMPO , &rq->state)) truesize += pg_consumed_bytes;
@@ -2102,7 +2106,7 @@ mlx5e_skb_from_cqe_mpwrq_nonlinear(struc nr_frags_free = old_nr_frags - sinfo->nr_frags;if (unlikely (nr_frags_free)) { frag_page -= nr_frags_free; - truesize -= (nr_frags_free -1 ) *PAGE_SIZE + + truesize -= (nr_frags_free -1 ) * page_size +ALIGN (pg_consumed_bytes,BIT (rq->mpwqe.log_stride_sz)); }
@@ -2311,15 +2315,16 @@ mlx5e_shampo_flush_skb(struct mlx5e_rq * rq->hw_gro_data->skb =NULL ; } -static bool -mlx5e_hw_gro_skb_has_enough_space (struct sk_buff *skb,u16 data_bcnt) +static bool mlx5e_hw_gro_skb_has_enough_space (struct sk_buff *skb, +u16 data_bcnt, +u32 page_size) {int nr_frags =skb_shinfo (skb)->nr_frags; -if (PAGE_SIZE >=GRO_LEGACY_MAX_SIZE ) +if (page_size >=GRO_LEGACY_MAX_SIZE )return skb->len + data_bcnt <=GRO_LEGACY_MAX_SIZE ;else -return PAGE_SIZE * nr_frags + data_bcnt <=GRO_LEGACY_MAX_SIZE ; +return page_size * nr_frags + data_bcnt <=GRO_LEGACY_MAX_SIZE ; }static void mlx5e_handle_rx_cqe_mpwrq_shampo (struct mlx5e_rq *rq,struct mlx5_cqe64 *cqe)
@@ -2328,18 +2333,19 @@ static void mlx5e_handle_rx_cqe_mpwrq_shu16 header_index =mlx5e_shampo_get_cqe_header_index (rq, cqe);u32 wqe_offset =be32_to_cpu (cqe->shampo.data_offset);u16 cstrides =mpwrq_get_cqe_consumed_strides (cqe); -u32 data_offset = wqe_offset & (PAGE_SIZE -1 );u32 cqe_bcnt =mpwrq_get_cqe_byte_cnt (cqe);u16 wqe_id =be16_to_cpu (cqe->wqe_id); -u32 page_idx = wqe_offset >>PAGE_SHIFT ;u16 head_size = cqe->shampo.header_size;struct sk_buff **skb = &rq->hw_gro_data->skb;bool flush = cqe->shampo.flush;bool match = cqe->shampo.match; +u32 page_size =BIT (rq->mpwqe.page_shift);struct mlx5e_rq_stats *stats = rq->stats;struct mlx5e_rx_wqe_ll *wqe;struct mlx5e_mpw_info *wi;struct mlx5_wq_ll *wq; +u32 data_offset; +u32 page_idx; wi =mlx5e_get_mpw_info (rq, wqe_id); wi->consumed_strides += cstrides;
@@ -2355,7 +2361,11 @@ static void mlx5e_handle_rx_cqe_mpwrq_sh goto mpwrq_cqe_out; } -if (*skb && (!match || !(mlx5e_hw_gro_skb_has_enough_space (*skb, data_bcnt)))) { + data_offset = wqe_offset & (page_size -1 ); + page_idx = wqe_offset >> rq->mpwqe.page_shift; +if (*skb && + !(match &&mlx5e_hw_gro_skb_has_enough_space (*skb, data_bcnt, + page_size))) { match = false;mlx5e_shampo_flush_skb (rq, cqe, match); }
Greg Kroah-Hartman
maintainerPATCH 600/877 net/mlx5e: do not HW-GRO coalesce small frames
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Glenn Judd <[email protected]>
[ Upstream commit e2466392a0b8496000e12181cb1ee1535eb0da25 ]
When hardware GRO (SHAMPO) coalesces a small IPv4/TCP segment that was padded up to the 60-byte minimum Ethernet frame, the trailing padding is folded into the merged payload causing padding to be delivered to the user as payload.
Detecting and reproducing the issue: the selftest tools/testing/selftests/drivers/net/gro.py subtest hw_ipv4_data_lrg_1byte sends {100, 1} expecting to receive {101}. In current code, it receives {106} (100 + 1 payload + 5 pad) instead.
This patch avoids giving the user padding as payload by simply not coalescing small packets (which fails the subtest; the same approach and behavior as sw gro). This gains code simplicity at the cost of more computation (passing an extra skb up the stack) for small packets that could be coalesced.
The threshold is chosen as ETH_ZLEN + 2 * VLAN_HLEN. This is the largest frame that may still contain minimum-frame padding (+ 2 VLAN tags), so anything larger is safe to consider for coalesce. (We do not include ETH_FCS_LEN in that threshold computation as netdev_fix_features() drops NETIF_F_GRO_HW whenever NETIF_F_RXFCS is set, so retained FCS can't reach this path.)
--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +5 -0
@@ -2363,6 +2363,11 @@ static void mlx5e_handle_rx_cqe_mpwrq_sh data_offset = wqe_offset & (page_size -1 ); page_idx = wqe_offset >> rq->mpwqe.page_shift; +if (unlikely (cqe_bcnt <=ETH_ZLEN +2 *VLAN_HLEN )) { + match = false; + flush = true; + } +if (*skb && !(match &&mlx5e_hw_gro_skb_has_enough_space (*skb, data_bcnt, page_size))) {
Greg Kroah-Hartman
maintainerPATCH 601/877 ALSA: hda/ext: preserve PPLCCTL bits when clearing reset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 36aa66de481d29edd63cbad9b5c4dc18c340fdf6 ]
snd_hdac_ext_stream_reset() polls PPLCCTL for STRST by masking the register value with AZX_PPLCCTL_STRST:
val = readl(...) & AZX_PPLCCTL_STRST;
The same masked value is then used when clearing STRST. Since val contains no bits other than STRST, clearing STRST from it always produces zero. The subsequent writel() therefore writes zero to the entire PPLCCTL register instead of clearing only the reset bit.
PPLCCTL contains other stream control fields, including the stream tag in AZX_PPLCCTL_STRM_MASK. Those fields must not be modified as a side effect of clearing stream reset.
Use snd_hdac_updatel() to clear STRST, matching the existing set-reset path and preserving all unrelated PPLCCTL bits.
--- sound/hda/ext/hdac_ext_stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/hda/ext/hdac_ext_stream.c +2 -2
@@ -212,8 +212,8 @@ void snd_hdac_ext_stream_reset(struct hdbreak ;udelay (3 ); }while (--timeout); - val &= ~AZX_PPLCCTL_STRST ; -writel (val, hext_stream->pplc_addr +AZX_REG_PPLCCTL ); +snd_hdac_updatel (hext_stream->pplc_addr,AZX_REG_PPLCCTL , +AZX_PPLCCTL_STRST ,0 );udelay (3 ); timeout =50 ;
Greg Kroah-Hartman
maintainerPATCH 602/877 hwrng: drivers - Switch back to struct platform_driver::remove()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit d11c8b87a36267a2861b9010ce0393de8ff3d278 ]
After commit 0edb555a65d1 ("platform: Make platform_driver::remove() return void") .remove() is (again) the right callback to implement for platform drivers.
Convert all platform drivers below drivers/char/hw_random to use .remove(), with the eventual goal to drop struct platform_driver::remove_new(). As .remove() and .remove_new() have the same prototypes, conversion is done by just changing the structure member name in the driver initializer.
Stable-dep-of: 1163a476a568 ("hwrng: stm32 - Fix runtime PM cleanup on registration failure")
--- drivers/char/hw_random/atmel-rng.c | 2 +- drivers/char/hw_random/cctrng.c | 2 +- drivers/char/hw_random/exynos-trng.c | 2 +- drivers/char/hw_random/ingenic-rng.c | 2 +- drivers/char/hw_random/ks-sa-rng.c | 2 +- drivers/char/hw_random/mxc-rnga.c | 2 +- drivers/char/hw_random/n2-drv.c | 2 +- drivers/char/hw_random/npcm-rng.c | 2 +- drivers/char/hw_random/omap-rng.c | 2 +- drivers/char/hw_random/stm32-rng.c | 2 +- drivers/char/hw_random/timeriomem-rng.c | 2 +- drivers/char/hw_random/xgene-rng.c | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-)
drivers/char/hw_random/atmel-rng.c +1 -1
@@ -216,7 +216,7 @@ MODULE_DEVICE_TABLE(of, atmel_trng_dt_idstatic struct platform_driver atmel_trng_driver = { .probe = atmel_trng_probe, - .remove_new = atmel_trng_remove, + .remove = atmel_trng_remove, .driver = { .name ="atmel-trng" , .pm =pm_ptr (&atmel_trng_pm_ops),
drivers/char/hw_random/cctrng.c +1 -1
@@ -653,7 +653,7 @@ static struct platform_driver cctrng_dri .pm = &cctrng_pm, }, .probe = cctrng_probe, - .remove_new = cctrng_remove, + .remove = cctrng_remove, };module_platform_driver (cctrng_driver);
drivers/char/hw_random/exynos-trng.c +1 -1
@@ -335,7 +335,7 @@ static struct platform_driver exynos_trn .of_match_table = exynos_trng_dt_match, }, .probe = exynos_trng_probe, - .remove_new = exynos_trng_remove, + .remove = exynos_trng_remove, };module_platform_driver (exynos_trng_driver);
drivers/char/hw_random/ingenic-rng.c +1 -1
@@ -132,7 +132,7 @@ MODULE_DEVICE_TABLE(of, ingenic_rng_of_mstatic struct platform_driver ingenic_rng_driver = { .probe = ingenic_rng_probe, - .remove_new = ingenic_rng_remove, + .remove = ingenic_rng_remove, .driver = { .name ="ingenic-rng" , .of_match_table = ingenic_rng_of_match,
drivers/char/hw_random/ks-sa-rng.c +1 -1
@@ -272,7 +272,7 @@ static struct platform_driver ks_sa_rng_ .of_match_table = ks_sa_rng_dt_match, }, .probe = ks_sa_rng_probe, - .remove_new = ks_sa_rng_remove, + .remove = ks_sa_rng_remove, };module_platform_driver (ks_sa_rng_driver);
drivers/char/hw_random/mxc-rnga.c +1 -1
@@ -188,7 +188,7 @@ static struct platform_driver mxc_rnga_d .of_match_table = mxc_rnga_of_match, }, .probe = mxc_rnga_probe, - .remove_new = mxc_rnga_remove, + .remove = mxc_rnga_remove, };module_platform_driver (mxc_rnga_driver);
drivers/char/hw_random/n2-drv.c +1 -1
@@ -858,7 +858,7 @@ static struct platform_driver n2rng_driv .of_match_table = n2rng_match, }, .probe = n2rng_probe, - .remove_new = n2rng_remove, + .remove = n2rng_remove, };module_platform_driver (n2rng_driver);
drivers/char/hw_random/npcm-rng.c +1 -1
@@ -176,7 +176,7 @@ static struct platform_driver npcm_rng_d .of_match_table = of_match_ptr(rng_dt_id), }, .probe = npcm_rng_probe, - .remove_new = npcm_rng_remove, + .remove = npcm_rng_remove, };module_platform_driver (npcm_rng_driver);
drivers/char/hw_random/omap-rng.c +1 -1
@@ -558,7 +558,7 @@ static struct platform_driver omap_rng_d .of_match_table = of_match_ptr(omap_rng_of_match), }, .probe = omap_rng_probe, - .remove_new = omap_rng_remove, + .remove = omap_rng_remove, };module_platform_driver (omap_rng_driver);
drivers/char/hw_random/stm32-rng.c +1 -1
@@ -565,7 +565,7 @@ static struct platform_driver stm32_rng_ .of_match_table = stm32_rng_match, }, .probe = stm32_rng_probe, - .remove_new = stm32_rng_remove, + .remove = stm32_rng_remove, };module_platform_driver (stm32_rng_driver);
drivers/char/hw_random/timeriomem-rng.c +1 -1
@@ -193,7 +193,7 @@ static struct platform_driver timeriomem .of_match_table = timeriomem_rng_match, }, .probe = timeriomem_rng_probe, - .remove_new = timeriomem_rng_remove, + .remove = timeriomem_rng_remove, };module_platform_driver (timeriomem_rng_driver);
drivers/char/hw_random/xgene-rng.c +1 -1
@@ -375,7 +375,7 @@ MODULE_DEVICE_TABLE(of, xgene_rng_of_matstatic struct platform_driver xgene_rng_driver = { .probe = xgene_rng_probe, - .remove_new = xgene_rng_remove, + .remove = xgene_rng_remove, .driver = { .name ="xgene-rng" , .of_match_table = xgene_rng_of_match,
Greg Kroah-Hartman
maintainerPATCH 603/877 hwrng: stm32 - Fix runtime PM cleanup on registration failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
[ Upstream commit 1163a476a568f6c0f852d469c8e4c5a5f805adac ]
stm32_rng_probe() enables autosuspend and runtime PM before registering the hwrng. If devm_hwrng_register() fails, probe returns with runtime PM left enabled and autosuspend still selected.
The remove callback also only disables runtime PM and does not undo pm_runtime_use_autosuspend().
Use devm_pm_runtime_enable() so runtime PM is unwound automatically on probe failure and driver detach. Since the managed cleanup also disables runtime PM,drop the remove callback.
--- drivers/char/hw_random/stm32-rng.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/char/hw_random/stm32-rng.c +4 -7
@@ -366,11 +366,6 @@ static int stm32_rng_init(struct hwrng *return 0 ; } -static void stm32_rng_remove (struct platform_device *ofdev) -{ -pm_runtime_disable (&ofdev->dev); -} -static int __maybe_unused stm32_rng_runtime_suspend (struct device *dev) {struct stm32_rng_private *priv =dev_get_drvdata (dev);
@@ -516,6 +511,7 @@ static int stm32_rng_probe(struct platfostruct device_node *np = ofdev->dev.of_node;struct stm32_rng_private *priv;struct resource *res; +int ret; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );if (!priv)
@@ -553,7 +549,9 @@ static int stm32_rng_probe(struct platfopm_runtime_set_autosuspend_delay (dev,100 );pm_runtime_use_autosuspend (dev); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) +return ret;return devm_hwrng_register (dev, &priv->rng); }
@@ -565,7 +563,6 @@ static struct platform_driver stm32_rng_ .of_match_table = stm32_rng_match, }, .probe = stm32_rng_probe, - .remove = stm32_rng_remove, };module_platform_driver (stm32_rng_driver);
Greg Kroah-Hartman
maintainerPATCH 604/877 i3c: master: Do not treat master device as a duplicate target
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 4dc1b3eeba7991905a5b5b8129ebea51be7d87b7 ]
i3c_master_search_i3c_dev_duplicate() searches the bus for another I3C device with the same PID as the reference device. The search can match master->this, causing the controller itself to be returned as a duplicate.
Since the controller is not a target device, it cannot be a duplicate of one. Exclude master->this from matching so that the function only returns real duplicate target devices.
--- drivers/i3c/master.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/i3c/master.c +2 -1
@@ -2024,7 +2024,8 @@ i3c_master_search_i3c_dev_duplicate(strustruct i3c_dev_desc *i3cdev;i3c_bus_for_each_i3cdev (&master->bus, i3cdev) { -if (i3cdev != refdev && i3cdev->info.pid == refdev->info.pid) +if (i3cdev != refdev && i3cdev->info.pid == refdev->info.pid && + i3cdev != master->this)return i3cdev; }
Greg Kroah-Hartman
maintainerPATCH 605/877 wifi: mt76: mt7915: set correct background radar capability
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: StanleyYP Wang <[email protected]>
[ Upstream commit 888208d1ccc41bebe97744445787183b17bb3ea4 ]
Some of the variants do not support background radar, so add a helper to report background radar capability.
For mt7916, only the variant of 5G 2T2R + 1R supports background radar.
Stable-dep-of: 44b5adfe4949 ("wifi: mt76: mt7915: bound the device EEPROM address before the EFUSE copy")
--- drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c | 5 +++ drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 33 +++++++++++++++++++- drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h | 1 drivers/net/wireless/mediatek/mt76/mt7915/init.c | 7 ++-- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 8 +++- drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h | 3 + 6 files changed, 49 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c +5 -0
@@ -444,6 +444,11 @@ mt7915_rdd_monitor(struct seq_file *s, vmutex_lock (&dev->mt76.mutex); +if (!mt7915_eeprom_has_background_radar (dev)) { +seq_puts (s,"no background radar capability\n" ); + goto out; + } +if (!cfg80211_chandef_valid (chandef)) { ret = -EINVAL ; goto out;
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +32 -1
@@ -147,7 +147,7 @@ static int mt7915_eeprom_load(struct mt7/* read eeprom data from efuse */ block_num =DIV_ROUND_UP (eeprom_size, eeprom_blk_size);for (i =0 ; i < block_num; i++) { - ret =mt7915_mcu_get_eeprom (dev, i * eeprom_blk_size); + ret =mt7915_mcu_get_eeprom (dev, i * eeprom_blk_size,NULL );if (ret <0 )return ret; }
@@ -359,6 +359,37 @@ s8 mt7915_eeprom_get_power_delta(structreturn val &MT_EE_RATE_DELTA_SIGN ? delta : -delta; } +bool +mt7915_eeprom_has_background_radar (struct mt7915_dev *dev) +{ +u8 val, buf[MT7915_EEPROM_BLOCK_SIZE ]; +u8 band_sel, tx_path, rx_path; +int offs =MT_EE_WIFI_CONF +1 ; + +switch (mt76_chip (&dev->mt76)) { +case 0x7915 : +return true; +case 0x7906 : +/* read efuse to check background radar capability */ +if (mt7915_mcu_get_eeprom (dev, offs, buf)) +break ; + + val = buf[offs %MT7915_EEPROM_BLOCK_SIZE ]; + band_sel =u8_get_bits (val,MT_EE_WIFI_CONF0_BAND_SEL ); + tx_path =u8_get_bits (val,MT_EE_WIFI_CONF0_TX_PATH ); + rx_path =u8_get_bits (val,MT_EE_WIFI_CONF0_RX_PATH ); + +return (band_sel ==MT_EE_V2_BAND_SEL_5GHZ && + tx_path == rx_path && rx_path ==2 ); +case 0x7981 : +case 0x7986 : +default : +break ; + } + +return false; +} +const u8 mt7915_sku_group_len[] = { [SKU_CCK ] =4 , [SKU_OFDM ] =8 ,
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h +1 -0
@@ -55,6 +55,7 @@ enum mt7915_eeprom_field {#define MT_EE_CAL_DPD_SIZE_V2 (300 * MT_EE_CAL_UNIT)#define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0) +#define MT_EE_WIFI_CONF0_RX_PATH GENMASK(5, 3)#define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6)#define MT_EE_WIFI_CONF1_BAND_SEL GENMASK(7, 6)#define MT_EE_WIFI_CONF_STREAM_NUM GENMASK(7, 5)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +4 -3
@@ -389,9 +389,10 @@ mt7915_init_wiphy(struct mt7915_phy *phyif (!is_mt7915 (&dev->mt76))wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_STA_TX_PWR ); -if (!mdev->dev->of_node || - !of_property_read_bool (mdev->dev->of_node, -"mediatek,disable-radar-background" )) +if (mt7915_eeprom_has_background_radar (phy->dev) && + (!mdev->dev->of_node || + !of_property_read_bool (mdev->dev->of_node, +"mediatek,disable-radar-background" )))wiphy_ext_feature_set (wiphy,NL80211_EXT_FEATURE_RADAR_BACKGROUND );
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +5 -3
@@ -2853,7 +2853,7 @@ int mt7915_mcu_set_eeprom(struct mt7915_ &req, sizeof(req), true); } -int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset) +int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset, u8 *read_buf) { struct mt7915_mcu_eeprom_info req = { .addr = cpu_to_le32(round_down(offset,
@@ -2861,8 +2861,8 @@ int mt7915_mcu_get_eeprom(struct mt7915_ };struct mt7915_mcu_eeprom_info *res;struct sk_buff *skb; +u8 *buf = read_buf;int ret; -u8 *buf; ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(EFUSE_ACCESS),
@@ -2871,8 +2871,10 @@ int mt7915_mcu_get_eeprom(struct mt7915_return ret; res = (struct mt7915_mcu_eeprom_info *)skb->data; - buf = dev->mt76.eeprom.data +le32_to_cpu (res->addr); +if (!buf) + buf = dev->mt76.eeprom.data +le32_to_cpu (res->addr);memcpy (buf, res->data,MT7915_EEPROM_BLOCK_SIZE ); +dev_kfree_skb (skb);return 0 ;
drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h +2 -1
@@ -445,6 +445,7 @@ int mt7915_eeprom_get_target_power(strucstruct ieee80211_channel *chan, u8 chain_idx);s8 mt7915_eeprom_get_power_delta (struct mt7915_dev *dev,int band); +bool mt7915_eeprom_has_background_radar (struct mt7915_dev *dev);int mt7915_dma_init (struct mt7915_dev *dev,struct mt7915_phy *phy2);void mt7915_dma_prefetch (struct mt7915_dev *dev);void mt7915_dma_cleanup (struct mt7915_dev *dev);
@@ -495,7 +496,7 @@ int mt7915_mcu_set_fixed_rate_ctrl(strucstruct ieee80211_sta *sta, void *data, u32 field);int mt7915_mcu_set_eeprom (struct mt7915_dev *dev); -int mt7915_mcu_get_eeprom (struct mt7915_dev *dev,u32 offset); +int mt7915_mcu_get_eeprom (struct mt7915_dev *dev,u32 offset,u8 *read_buf);int mt7915_mcu_get_eeprom_free_block (struct mt7915_dev *dev,u8 *block_num);int mt7915_mcu_set_mac (struct mt7915_dev *dev,int band,bool enable,bool hdr_trans);
Greg Kroah-Hartman
maintainerPATCH 606/877 wifi: mt76: mt7915: bound the device EEPROM address before the EFUSE copy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
[ Upstream commit 44b5adfe49499f53002737f5fe81d608c08122fc ]
mt7915_mcu_get_eeprom() copies a fixed EFUSE block into the driver's dev->mt76.eeprom.data buffer at the offset reported by the MCU response (res->addr, a device-controlled __le32) without checking it against the buffer size. A malicious or malfunctioning device can report an arbitrary address and drive a 16-byte out-of-bounds write past eeprom.data.
Reject a response whose address would place the copy outside eeprom.data before deriving the destination pointer. Devices that echo the requested in-bounds offset are unaffected.
--- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +9 -2
@@ -2871,8 +2871,15 @@ int mt7915_mcu_get_eeprom(struct mt7915_return ret; res = (struct mt7915_mcu_eeprom_info *)skb->data; -if (!buf) - buf = dev->mt76.eeprom.data +le32_to_cpu (res->addr); +if (!buf) { +u32 addr =le32_to_cpu (res->addr); + +if (addr > dev->mt76.eeprom.size -MT7915_EEPROM_BLOCK_SIZE ) { +dev_kfree_skb (skb); +return -EINVAL ; + } + buf = dev->mt76.eeprom.data + addr; + }memcpy (buf, res->data,MT7915_EEPROM_BLOCK_SIZE );dev_kfree_skb (skb);
Greg Kroah-Hartman
maintainerPATCH 607/877 i3c: master: Fix use-after-free of master->this
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit feb0ed76601f3c2f91f08688c5a7d8b9d382f720 ]
sysfs attribute callbacks for the master controller device dereference master->this. However, master->this is freed in i3c_master_detach_free_devs() before the master device itself is released.
As a result, sysfs accesses can dereference a freed master->this pointer, leading to a use-after-free.
Keep master->this alive until i3c_masterdev_release(), which is called after the master device and its sysfs state are being torn down. Do not free master->this as part of the normal device detach path.
On the error path in i3c_master_set_info(), reset master->this and bus.cur_master to NULL before freeing the allocated device.
--- drivers/i3c/master.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/i3c/master.c +11 -6
@@ -700,6 +700,11 @@ static struct attribute *i3c_masterdev_a };ATTRIBUTE_GROUPS (i3c_masterdev); +static void i3c_master_free_i3c_dev (struct i3c_dev_desc *dev) +{ +kfree (dev); +} +static void i3c_masterdev_release (struct device *dev) {struct i3c_master_controller *master =dev_to_i3cmaster (dev);
@@ -712,6 +717,8 @@ static void i3c_masterdev_release(structi3c_bus_cleanup (bus);of_node_put (dev->of_node); + +i3c_master_free_i3c_dev (master->this); }static const struct device_type i3c_masterdev_type = {
@@ -899,11 +906,6 @@ static void i3c_device_release(struct dekfree (i3cdev); } -static void i3c_master_free_i3c_dev (struct i3c_dev_desc *dev) -{ -kfree (dev); -} -static struct i3c_dev_desc *i3c_master_alloc_i3c_dev (struct i3c_master_controller *master,const struct i3c_device_info *info)
@@ -1784,6 +1786,8 @@ int i3c_master_set_info(struct i3c_mastereturn 0 ; err_free_dev: + master->bus.cur_master =NULL ; + master->this =NULL ;i3c_master_free_i3c_dev (i3cdev);return ret;
@@ -1804,7 +1808,8 @@ static void i3c_master_detach_free_devs( i3cdev->boardinfo->init_dyn_addr, I3C_ADDR_SLOT_FREE); -i3c_master_free_i3c_dev (i3cdev); +if (i3cdev != master->this) +i3c_master_free_i3c_dev (i3cdev); } list_for_each_entry_safe(i2cdev, i2ctmp, &master->bus.devs.i2c,