* [PATCH] drm/vc4: fix dereference before NULL check
@ 2022-06-28 6:36 Yu Liao
2022-06-28 6:55 ` Boris Brezillon
2022-06-28 8:18 ` Maxime Ripard
0 siblings, 2 replies; 3+ messages in thread
From: Yu Liao @ 2022-06-28 6:36 UTC (permalink / raw)
To: emma, mripard, eric, bbrezillon; +Cc: liaoyu15, liwei391, linux-kernel
The "perfmon" pointer is equal to the return value of idr_find
which may be NULL, access by vc4_perfmon_get before checking if
it was NULL. Fix this by dereferencing "perfmon" after "perfmon"
has been null checked.
Addresses-Coverity: ("Dereference before null check")
Fixes: 65101d8c9108 ("drm/vc4: Expose performance counters to userspace")
Signed-off-by: Yu Liao <liaoyu15@huawei.com>
---
drivers/gpu/drm/vc4/vc4_perfmon.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
index c7f5adb6bcf8..ca969b8c7dde 100644
--- a/drivers/gpu/drm/vc4/vc4_perfmon.c
+++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
@@ -17,13 +17,17 @@
void vc4_perfmon_get(struct vc4_perfmon *perfmon)
{
- struct vc4_dev *vc4 = perfmon->dev;
+ struct vc4_dev *vc4;
+
+ if (!perfmon)
+ return;
+
+ vc4 = perfmon->dev;
if (WARN_ON_ONCE(vc4->is_vc5))
return;
- if (perfmon)
- refcount_inc(&perfmon->refcnt);
+ refcount_inc(&perfmon->refcnt);
}
void vc4_perfmon_put(struct vc4_perfmon *perfmon)
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/vc4: fix dereference before NULL check
2022-06-28 6:36 [PATCH] drm/vc4: fix dereference before NULL check Yu Liao
@ 2022-06-28 6:55 ` Boris Brezillon
2022-06-28 8:18 ` Maxime Ripard
1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2022-06-28 6:55 UTC (permalink / raw)
To: Yu Liao; +Cc: emma, mripard, eric, bbrezillon, liwei391, linux-kernel
On Tue, 28 Jun 2022 14:36:57 +0800
Yu Liao <liaoyu15@huawei.com> wrote:
> The "perfmon" pointer is equal to the return value of idr_find
> which may be NULL, access by vc4_perfmon_get before checking if
> it was NULL. Fix this by dereferencing "perfmon" after "perfmon"
> has been null checked.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 65101d8c9108 ("drm/vc4: Expose performance counters to userspace")
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/vc4/vc4_perfmon.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/vc4/vc4_perfmon.c b/drivers/gpu/drm/vc4/vc4_perfmon.c
> index c7f5adb6bcf8..ca969b8c7dde 100644
> --- a/drivers/gpu/drm/vc4/vc4_perfmon.c
> +++ b/drivers/gpu/drm/vc4/vc4_perfmon.c
> @@ -17,13 +17,17 @@
>
> void vc4_perfmon_get(struct vc4_perfmon *perfmon)
> {
> - struct vc4_dev *vc4 = perfmon->dev;
> + struct vc4_dev *vc4;
> +
> + if (!perfmon)
> + return;
> +
> + vc4 = perfmon->dev;
>
> if (WARN_ON_ONCE(vc4->is_vc5))
> return;
>
> - if (perfmon)
> - refcount_inc(&perfmon->refcnt);
> + refcount_inc(&perfmon->refcnt);
> }
>
> void vc4_perfmon_put(struct vc4_perfmon *perfmon)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/vc4: fix dereference before NULL check
2022-06-28 6:36 [PATCH] drm/vc4: fix dereference before NULL check Yu Liao
2022-06-28 6:55 ` Boris Brezillon
@ 2022-06-28 8:18 ` Maxime Ripard
1 sibling, 0 replies; 3+ messages in thread
From: Maxime Ripard @ 2022-06-28 8:18 UTC (permalink / raw)
To: Yu Liao; +Cc: emma, eric, bbrezillon, liwei391, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 618 bytes --]
Hi,
On Tue, Jun 28, 2022 at 02:36:57PM +0800, Yu Liao wrote:
> The "perfmon" pointer is equal to the return value of idr_find
> which may be NULL, access by vc4_perfmon_get before checking if
> it was NULL. Fix this by dereferencing "perfmon" after "perfmon"
> has been null checked.
>
> Addresses-Coverity: ("Dereference before null check")
> Fixes: 65101d8c9108 ("drm/vc4: Expose performance counters to userspace")
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
A similar patch has already been merged:
https://lore.kernel.org/dri-devel/20220622080243.22119-1-maxime@cerno.tech/
Thanks!
Maxime
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-28 8:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 6:36 [PATCH] drm/vc4: fix dereference before NULL check Yu Liao
2022-06-28 6:55 ` Boris Brezillon
2022-06-28 8:18 ` Maxime Ripard
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.