RDMA/rdmavt: Fix potential use-after-free in rvt_mmap()
Subsystems (2)
PATCH 1/1 RDMA/rdmavt: Fix potential use-after-free in rvt_mmap()
rvt_mmap() drops the pending lock and only takes the VMA reference in rvt_vma_open() after remap_vmalloc_range() returns. A concurrent owner teardown can free ip->obj and ip between list_del_init() and the later kref_get(), leaving rvt_mmap() operating on freed memory.
Apply the same fix pattern as the RXE provider (CVE-2026-64582): take the reference with kref_get_unless_zero() while pending_lock is held, release the lock only after the reference is secured, and on remap failure clear the VMA state and put the reference.
--- drivers/infiniband/sw/rdmavt/mmap.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
drivers/infiniband/sw/rdmavt/mmap.c +19 -4
@@ -100,15 +100,30 @@ int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)if (size > ip->size)break ; +/* +* Increment refcount and check whether it is being freed atm +* while holding the lock to prevent UAF, matching the RXE +* provider fix. +*/ +if (!kref_get_unless_zero (&ip->ref)) { +spin_unlock_irq (&rdi->pending_lock); + ret = -ENXIO ; + goto done; + } +list_del_init (&ip->pending_mmaps);spin_unlock_irq (&rdi->pending_lock); - ret =remap_vmalloc_range (vma, ip->obj,0 ); -if (ret) - goto done; vma->vm_ops = &rvt_vm_ops; vma->vm_private_data = ip; -rvt_vma_open (vma); + + ret =remap_vmalloc_range (vma, ip->obj,0 ); +if (ret) { + vma->vm_private_data =NULL ; + vma->vm_ops =NULL ; +kref_put (&ip->ref, rvt_release_mmap_info); + goto done; + } goto done; }spin_unlock_irq (&rdi->pending_lock);
Signature · 1 line
2.53.0
Dennis Dalessandro
maintainerQuoted 44 lines · Nguyen Van Tien
rvt_mmap()drops the pending lock and only takes the VMA reference inrvt_vma_open()afterremap_vmalloc_range()returns. A concurrent owner teardown can freeip->objand ip betweenlist_del_init()and the laterkref_get(), leavingrvt_mmap()operating on freed memory.Apply the same fix pattern as the RXE provider (CVE-2026-64582): take the reference with
kref_get_unless_zero()whilepending_lockis held, release the lock only after the reference is secured, and on remap failure clear the VMA state and put the reference.Signed-off-by Nguyen Van Tien <[email protected]>--- drivers/infiniband/sw/rdmavt/mmap.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)drivers/infiniband/sw/rdmavt/mmap.c +12
-4@@ -100,15 +100,30 @@ int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)if (size > ip->size)break ; +/* +* Increment refcount and check whether it is being freed atm +* while holding the lock to prevent UAF, matching the RXE +* provider fix. +*/ +if (!kref_get_unless_zero (&ip->ref)) { +spin_unlock_irq (&rdi->pending_lock); + ret = -ENXIO ; + goto done; + } +list_del_init (&ip->pending_mmaps);spin_unlock_irq (&rdi->pending_lock); - ret =remap_vmalloc_range (vma, ip->obj,0 ); -if (ret) - goto done; vma->vm_ops = &rvt_vm_ops; vma->vm_private_data = ip; -rvt_vma_open (vma); +
drivers/infiniband/sw/rdmavt/mmap.c int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) · line 129
Quoted 10 lines
drivers/infiniband/sw/rdmavt/mmap.c +7
-0+ ret =remap_vmalloc_range (vma, ip->obj,0 ); +if (ret) { + vma->vm_private_data =NULL ; + vma->vm_ops =NULL ; +kref_put (&ip->ref, rvt_release_mmap_info); + goto done; + } goto done; }spin_unlock_irq (&rdi->pending_lock);
My AI cranked out basically the same patch. Only it will be tested and reviewed. I'd say drop this and pick up my validated version. If you go with this one the commit message should be updated to explain why we aren't calling rvt_vma_open() anymore.
-Denny
Jason Gunthorpe
maintainerQuoted 4 lines · Dennis Dalessandro
My AI cranked out basically the same patch. Only it will be tested and reviewed. I'd say drop this and pick up my validated version. If you go with this one the commit message should be updated to explain why we aren't calling
rvt_vma_open()anymore.
It's been a month are you sending yours?
Jason
Dennis Dalessandro
maintainerQuoted 8 lines · Jason Gunthorpe
Quoted 4 lines · Dennis Dalessandro
My AI cranked out basically the same patch. Only it will be tested and reviewed. I'd say drop this and pick up my validated version. If you go with this one the commit message should be updated to explain why we aren't calling
rvt_vma_open()anymore.It's been a month are you sending yours?
I have it tacked onto my set of patches for hfi2 but it could go separately ahead of time if you want to get Nguyen's patch applied instead.
On that topic, I'm doing another round of Sashiko fixes. Should be on the list in a few days after 0-day builds chews on it.
-Denny