Message ID | 20190226204726.92256-1-ebiggers@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | drm/vgem: fix use-after-free when drm_gem_handle_create() fails | expand |
Quoting Eric Biggers (2019-02-26 20:47:26) > From: Eric Biggers <ebiggers@google.com> > > If drm_gem_handle_create() fails in vgem_gem_create(), then the > drm_vgem_gem_object is freed twice: once when the reference is dropped > by drm_gem_object_put_unlocked(), and again by __vgem_gem_destroy(). > > This was hit by syzkaller using fault injection. > > Fix it by skipping the second free. > > Reported-by: syzbot+e73f2fb5ed5a5df36d33@syzkaller.appspotmail.com > Fixes: 5ba6c9ff961a ("drm/vgem: Fix mmaping") That's the wrong fixes line, it's Fixes: af33a9190d02 ("drm/vgem: Enable dmabuf import interfaces") Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Laura Abbott <labbott@redhat.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Sadly I reviewed it so I'm still culpable, but the fix is correct as the put purposely frees it on error. > Cc: stable@vger.kernel.org > Signed-off-by: Eric Biggers <ebiggers@google.com> > --- > drivers/gpu/drm/vgem/vgem_drv.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c > index 5930facd6d2d8..70646d9da1596 100644 > --- a/drivers/gpu/drm/vgem/vgem_drv.c > +++ b/drivers/gpu/drm/vgem/vgem_drv.c > @@ -189,15 +189,13 @@ static struct drm_gem_object *vgem_gem_create(struct drm_device *dev, > return ERR_CAST(obj); > > ret = drm_gem_handle_create(file, &obj->base, handle); > + > drm_gem_object_put_unlocked(&obj->base); > + The pattern in the other GEM drivers is not to have these extra newlines. Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> > if (ret) > - goto err; > + return ERR_PTR(ret); > > return &obj->base; > - > -err: > - __vgem_gem_destroy(obj); > - return ERR_PTR(ret); > } > > static int vgem_gem_dumb_create(struct drm_file *file, struct drm_device *dev, > -- > 2.21.0.rc2.261.ga7da99ff1b-goog >
On Tue, Feb 26, 2019 at 09:01:29PM +0000, Chris Wilson wrote: > Quoting Eric Biggers (2019-02-26 20:47:26) > > From: Eric Biggers <ebiggers@google.com> > > > > If drm_gem_handle_create() fails in vgem_gem_create(), then the > > drm_vgem_gem_object is freed twice: once when the reference is dropped > > by drm_gem_object_put_unlocked(), and again by __vgem_gem_destroy(). > > > > This was hit by syzkaller using fault injection. > > > > Fix it by skipping the second free. > > > > Reported-by: syzbot+e73f2fb5ed5a5df36d33@syzkaller.appspotmail.com > > Fixes: 5ba6c9ff961a ("drm/vgem: Fix mmaping") > > That's the wrong fixes line, it's > Fixes: af33a9190d02 ("drm/vgem: Enable dmabuf import interfaces") > Cc: Chris Wilson <chris@chris-wilson.co.uk> > Cc: Laura Abbott <labbott@redhat.com> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > > Sadly I reviewed it so I'm still culpable, but the fix is correct as the > put purposely frees it on error. > You're right; I misread the code at that commit. I'll resend with the correct tags. > > Cc: stable@vger.kernel.org > > Signed-off-by: Eric Biggers <ebiggers@google.com> > > > --- > > drivers/gpu/drm/vgem/vgem_drv.c | 8 +++----- > > 1 file changed, 3 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c > > index 5930facd6d2d8..70646d9da1596 100644 > > --- a/drivers/gpu/drm/vgem/vgem_drv.c > > +++ b/drivers/gpu/drm/vgem/vgem_drv.c > > @@ -189,15 +189,13 @@ static struct drm_gem_object *vgem_gem_create(struct drm_device *dev, > > return ERR_CAST(obj); > > > > ret = drm_gem_handle_create(file, &obj->base, handle); > > + > > drm_gem_object_put_unlocked(&obj->base); > > + > > The pattern in the other GEM drivers is not to have these extra > newlines. > > Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> > > > if (ret) > > - goto err; > > + return ERR_PTR(ret); > > > > return &obj->base; > > - > > -err: > > - __vgem_gem_destroy(obj); > > - return ERR_PTR(ret); > > } > > > > static int vgem_gem_dumb_create(struct drm_file *file, struct drm_device *dev, > > -- > > 2.21.0.rc2.261.ga7da99ff1b-goog > >
Hi, [This is an automated email] This commit has been processed because it contains a "Fixes:" tag, fixing commit: 5ba6c9ff961a drm/vgem: Fix mmaping. The bot has tested the following trees: v4.20.12, v4.19.25, v4.14.103, v4.9.160. v4.20.12: Build OK! v4.19.25: Build OK! v4.14.103: Build OK! v4.9.160: Failed to apply! Possible dependencies: 024b6a63138c ("gpu: drm: gma500: Use vma_pages()") 1a29d85eb0f1 ("mm: use vmf->address instead of of vmf->virtual_address") 82b0f8c39a38 ("mm: join struct fault_env and vm_fault") 953c66c2b22a ("mm: THP page cache support for ppc64") af33a9190d02 ("drm/vgem: Enable dmabuf import interfaces") c54fd47aa5b8 ("drm/vgem: switch to drm_*_get(), drm_*_put() helpers") fd60775aea80 ("mm, thp: avoid unlikely branches for split_huge_pmd") How should we proceed with this patch? -- Thanks, Sasha
diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c index 5930facd6d2d8..70646d9da1596 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.c +++ b/drivers/gpu/drm/vgem/vgem_drv.c @@ -189,15 +189,13 @@ static struct drm_gem_object *vgem_gem_create(struct drm_device *dev, return ERR_CAST(obj); ret = drm_gem_handle_create(file, &obj->base, handle); + drm_gem_object_put_unlocked(&obj->base); + if (ret) - goto err; + return ERR_PTR(ret); return &obj->base; - -err: - __vgem_gem_destroy(obj); - return ERR_PTR(ret); } static int vgem_gem_dumb_create(struct drm_file *file, struct drm_device *dev,