From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>,
linux-kernel@vger.kernel.org, noralf@tronnes.org,
dri-devel@lists.freedesktop.org,
Thomas Zimmermann <tzimmermann@suse.de>,
Sumit Semwal <sumit.semwal@linaro.org>
Subject: Re: [PATCH v1 2/2] drm/gem: Check whether object is NULL in drm_gem_vunmap()
Date: Thu, 27 Oct 2022 10:28:09 +0300 [thread overview]
Message-ID: <Y1ozCWTco6dzIA7J@kadam> (raw)
In-Reply-To: <6b37315d-74d0-713a-3544-b8d4c873488d@amd.com>
On Thu, Oct 27, 2022 at 08:17:31AM +0200, Christian König wrote:
>
>
> Am 27.10.22 um 00:46 schrieb Dmitry Osipenko:
> > The drm_gem_vunmap() will crash with a NULL dereference if the passed
> > object pointer is NULL. It wasn't a problem before we added the locking
> > support to drm_gem_vunmap function because the mapping argument was always
> > NULL together with the object. Make drm_gem_vunmap() functions to handle
> > the NULL pointers better.
> >
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Link: https://lore.kernel.org/dri-devel/Y1kFEGxT8MVlf32V@kili/ Fixes:
> > 79e2cf2e7a19 ("drm/gem: Take reservation lock for vmap/vunmap
> > operations")
> > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> > ---
> > drivers/gpu/drm/drm_gem.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> > index b8db675e7fb5..ee0a246ff4ac 100644
> > --- a/drivers/gpu/drm/drm_gem.c
> > +++ b/drivers/gpu/drm/drm_gem.c
> > @@ -1175,11 +1175,11 @@ EXPORT_SYMBOL(drm_gem_vmap);
> > void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
> > {
> > - dma_resv_assert_held(obj->resv);
> > -
> > - if (iosys_map_is_null(map))
> > + if (!obj || iosys_map_is_null(map))
> > return;
>
> I'm not very keen about that. Calling a function with all parameters NULL
> doesn't make much sense and is clearly a coding error. Hiding that somehow
> doesn't help but rather makes things worse.
>
> The only execption to that are things like kfree() or *_put() which work
> with the lifetime of objects.
>
> Why is the static checker complaining about that in the first place?
>
drivers/gpu/drm/drm_client.c:240 drm_client_buffer_delete()
warn: variable dereferenced before check 'buffer->gem' (see line 238)
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Christian König" <christian.koenig@amd.com>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Sumit Semwal <sumit.semwal@linaro.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
noralf@tronnes.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] drm/gem: Check whether object is NULL in drm_gem_vunmap()
Date: Thu, 27 Oct 2022 10:28:09 +0300 [thread overview]
Message-ID: <Y1ozCWTco6dzIA7J@kadam> (raw)
In-Reply-To: <6b37315d-74d0-713a-3544-b8d4c873488d@amd.com>
On Thu, Oct 27, 2022 at 08:17:31AM +0200, Christian König wrote:
>
>
> Am 27.10.22 um 00:46 schrieb Dmitry Osipenko:
> > The drm_gem_vunmap() will crash with a NULL dereference if the passed
> > object pointer is NULL. It wasn't a problem before we added the locking
> > support to drm_gem_vunmap function because the mapping argument was always
> > NULL together with the object. Make drm_gem_vunmap() functions to handle
> > the NULL pointers better.
> >
> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> > Link: https://lore.kernel.org/dri-devel/Y1kFEGxT8MVlf32V@kili/ Fixes:
> > 79e2cf2e7a19 ("drm/gem: Take reservation lock for vmap/vunmap
> > operations")
> > Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> > ---
> > drivers/gpu/drm/drm_gem.c | 9 ++++++---
> > 1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
> > index b8db675e7fb5..ee0a246ff4ac 100644
> > --- a/drivers/gpu/drm/drm_gem.c
> > +++ b/drivers/gpu/drm/drm_gem.c
> > @@ -1175,11 +1175,11 @@ EXPORT_SYMBOL(drm_gem_vmap);
> > void drm_gem_vunmap(struct drm_gem_object *obj, struct iosys_map *map)
> > {
> > - dma_resv_assert_held(obj->resv);
> > -
> > - if (iosys_map_is_null(map))
> > + if (!obj || iosys_map_is_null(map))
> > return;
>
> I'm not very keen about that. Calling a function with all parameters NULL
> doesn't make much sense and is clearly a coding error. Hiding that somehow
> doesn't help but rather makes things worse.
>
> The only execption to that are things like kfree() or *_put() which work
> with the lifetime of objects.
>
> Why is the static checker complaining about that in the first place?
>
drivers/gpu/drm/drm_client.c:240 drm_client_buffer_delete()
warn: variable dereferenced before check 'buffer->gem' (see line 238)
regards,
dan carpenter
next prev parent reply other threads:[~2022-10-27 7:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 22:46 [PATCH v1 0/2] Fixes for dma-buf locking issues found by Smatch Dmitry Osipenko
2022-10-26 22:46 ` Dmitry Osipenko
2022-10-26 22:46 ` [PATCH v1 1/2] dma-buf: Make locking consistent in dma_buf_detach() Dmitry Osipenko
2022-10-26 22:46 ` Dmitry Osipenko
2022-10-27 6:13 ` Christian König
2022-10-27 6:13 ` Christian König
2022-10-27 10:34 ` Dmitry Osipenko
2022-10-27 10:34 ` Dmitry Osipenko
2022-10-26 22:46 ` [PATCH v1 2/2] drm/gem: Check whether object is NULL in drm_gem_vunmap() Dmitry Osipenko
2022-10-26 22:46 ` Dmitry Osipenko
2022-10-27 6:17 ` Christian König
2022-10-27 6:17 ` Christian König
2022-10-27 7:28 ` Dan Carpenter [this message]
2022-10-27 7:28 ` Dan Carpenter
2022-10-27 7:40 ` Christian König
2022-10-27 7:40 ` Christian König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y1ozCWTco6dzIA7J@kadam \
--to=dan.carpenter@oracle.com \
--cc=christian.koenig@amd.com \
--cc=dmitry.osipenko@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=noralf@tronnes.org \
--cc=sumit.semwal@linaro.org \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.