xen/gntdev: fix gntdev_mmap() error exit path
Subsystems (2)
Juergen Gross
maintainerPATCH 1/1 xen/gntdev: fix gntdev_mmap() error exit path
Commit d3eeb1d77c5d0af ("xen/gntdev: use mmu_interval_notifier_insert") introduced an error in gntdev_mmap(): in case the call of mmu_interval_notifier_insert_locked() fails the exit path should not call mmu_interval_notifier_remove(), as this might result in NULL dereferences.
One reason for failure is e.g. a signal pending for the running process.
--- drivers/xen/gntdev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/xen/gntdev.c +3 -1
@@ -1017,8 +1017,10 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) err =mmu_interval_notifier_insert_locked ( &map->notifier, vma->vm_mm, vma->vm_start, vma->vm_end - vma->vm_start, &gntdev_mmu_ops); -if (err) +if (err) { + map->vma =NULL ; goto out_unlock_put; + } }mutex_unlock (&priv->lock);
Signature · 1 line
2.26.2
Quoted 42 lines · Juergen Gross
Commit
d3eeb1d77c5d0af("xen/gntdev: usemmu_interval_notifier_insert") introduced an error ingntdev_mmap(): in case the call ofmmu_interval_notifier_insert_locked()fails the exit path should not callmmu_interval_notifier_remove(), as this might result in NULL dereferences.One reason for failure is e.g. a signal pending for the running process.
Fixes d3eeb1d77c5d0af ("xen/gntdev: use mmu_interval_notifier_insert")Reported-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Juergen Gross <[email protected]>---
drivers/xen/gntdev.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/gntdev.c +3
-1@@ -1017,8 +1017,10 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) err =mmu_interval_notifier_insert_locked ( &map->notifier, vma->vm_mm, vma->vm_start, vma->vm_end - vma->vm_start, &gntdev_mmu_ops); -if (err) +if (err) { + map->vma =NULL ; goto out_unlock_put; + } }mutex_unlock (&priv->lock);Signature · 1 line
2.26.2
Hi Juergen,
I can see from the code that there is another path to out_unlock_put label some lines before:
[…]
vma->vm_private_data = map;
if (map->flags) {
if ((vma->vm_flags & VM_WRITE) &&
(map->flags & GNTMAP_readonly))
goto out_unlock_put;
} else {
map->flags = GNTMAP_host_map;
if (!(vma->vm_flags & VM_WRITE))
map->flags |= GNTMAP_readonly;
}
[…]Can be the case that use_ptemod is != 0 also for that path?
Cheers,
Luca
Juergen Gross
maintainerQuoted 60 lines · Luca Fancellu
Quoted 42 lines · Juergen Gross
Commit
d3eeb1d77c5d0af("xen/gntdev: usemmu_interval_notifier_insert") introduced an error ingntdev_mmap(): in case the call ofmmu_interval_notifier_insert_locked()fails the exit path should not callmmu_interval_notifier_remove(), as this might result in NULL dereferences.One reason for failure is e.g. a signal pending for the running process.
Fixes d3eeb1d77c5d0af ("xen/gntdev: use mmu_interval_notifier_insert")Reported-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Juergen Gross <[email protected]>---
drivers/xen/gntdev.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/gntdev.c +3
-1@@ -1017,8 +1017,10 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) err =mmu_interval_notifier_insert_locked ( &map->notifier, vma->vm_mm, vma->vm_start, vma->vm_end - vma->vm_start, &gntdev_mmu_ops); -if (err) +if (err) { + map->vma =NULL ; goto out_unlock_put; + } }mutex_unlock (&priv->lock);Signature · 1 line
2.26.2Hi Juergen,
I can see from the code that there is another path to
out_unlock_putlabel some lines before:[…] vma->vm_private_data = map; if (map->flags) { if ((vma->vm_flags & VM_WRITE) && (map->flags & GNTMAP_readonly)) goto out_unlock_put; } else { map->flags = GNTMAP_host_map; if (!(vma->vm_flags & VM_WRITE)) map->flags |= GNTMAP_readonly; } […]
Quoted 1 line
Can be the case that
use_ptemodis != 0 also for that path?
map->vma will be NULL in this case, so there will be no problem resulting from that path.
Juergen
Luca Fancellu
Reviewed-byQuoted 61 lines · Juergen Gross
Quoted 54 lines · Luca Fancellu
Quoted 40 lines · Juergen Gross
Commit
d3eeb1d77c5d0af("xen/gntdev: usemmu_interval_notifier_insert") introduced an error ingntdev_mmap(): in case the call ofmmu_interval_notifier_insert_locked()fails the exit path should not callmmu_interval_notifier_remove(), as this might result in NULL dereferences.One reason for failure is e.g. a signal pending for the running process.
Fixes d3eeb1d77c5d0af ("xen/gntdev: use mmu_interval_notifier_insert")Reported-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Juergen Gross <[email protected]>---
drivers/xen/gntdev.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/xen/gntdev.c +3
-1@@ -1017,8 +1017,10 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) err =mmu_interval_notifier_insert_locked ( &map->notifier, vma->vm_mm, vma->vm_start, vma->vm_end - vma->vm_start, &gntdev_mmu_ops); -if (err) +if (err) { + map->vma =NULL ; goto out_unlock_put; + } }mutex_unlock (&priv->lock);Signature · 1 line
2.26.2Hi Juergen,
I can see from the code that there is another path toout_unlock_putlabel some lines before:[…] vma->vm_private_data = map; if (map->flags) { if ((vma->vm_flags & VM_WRITE) && (map->flags & GNTMAP_readonly)) goto out_unlock_put; } else { map->flags = GNTMAP_host_map; if (!(vma->vm_flags & VM_WRITE)) map->flags |= GNTMAP_readonly; } […]Quoted 1 line
Can be the case that
use_ptemodis != 0 also for that path?
Quoted 3 lines
map->vmawill be NULL in this case, so there will be no problem resulting from that path.
Right, thanks, seems good to me.
Cheers,
Luca
Quoted 3 lines
Juergen
<OpenPGP_0xB0DE9DD628BF132F.asc>
Quoted 18 lines · Luca Fancellu
Quoted 18 lines · Juergen Gross
Quoted 16 lines · Luca Fancellu
Quoted 16 lines · Juergen Gross
Commit
d3eeb1d77c5d0af("xen/gntdev: usemmu_interval_notifier_insert") introduced an error ingntdev_mmap(): in case the call ofmmu_interval_notifier_insert_locked()fails the exit path should not callmmu_interval_notifier_remove(), as this might result in NULL dereferences.One reason for failure is e.g. a signal pending for the running process.
Fixes d3eeb1d77c5d0af ("xen/gntdev: use mmu_interval_notifier_insert")Reported-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Juergen Gross <[email protected]>
(...)
Quoted 3 lines
Right, thanks, seems good to me.
Reviewed-by Luca Fancellu <[email protected]>
Can somebody ack this fix please?
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
Quoted 6 lines · Juergen Gross
Commit
d3eeb1d77c5d0af("xen/gntdev: usemmu_interval_notifier_insert") introduced an error ingntdev_mmap(): in case the call ofmmu_interval_notifier_insert_locked()fails the exit path should not callmmu_interval_notifier_remove(), as this might result in NULL dereferences.
Quoted 8 lines
One reason for failure is e.g. a signal pending for the running process.
Fixes d3eeb1d77c5d0af ("xen/gntdev: use mmu_interval_notifier_insert")Reported-by Marek Marczykowski-Górecki <[email protected]>Signed-off-by Juergen Gross <[email protected]>
Pushed to xen/tip.git for-linus-5.13b
Juergen