drm/syncobj: Fix syncobj leak in drm_syncobj_eventfd_ioctl
Subsystems (2)
PATCH 1/1 drm/syncobj: Fix syncobj leak in drm_syncobj_eventfd_ioctl
A syncobj reference is taken in drm_syncobj_find, but not released if eventfd_ctx_fdget or kzalloc fails. Put the reference in these error paths.
--- drivers/gpu/drm/drm_syncobj.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_syncobj.c +13 -4
@@ -1464,6 +1464,7 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,struct drm_syncobj *syncobj;struct eventfd_ctx *ev_fd_ctx;struct syncobj_eventfd_entry *entry; +int ret;if (!drm_core_check_feature (dev,DRIVER_SYNCOBJ_TIMELINE ))return -EOPNOTSUPP ;
@@ -1479,13 +1480,15 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,return -ENOENT ; ev_fd_ctx =eventfd_ctx_fdget (args->fd); -if (IS_ERR (ev_fd_ctx)) -return PTR_ERR (ev_fd_ctx); +if (IS_ERR (ev_fd_ctx)) { + ret =PTR_ERR (ev_fd_ctx); + goto err_fdget; + } entry =kzalloc (sizeof (*entry),GFP_KERNEL );if (!entry) { -eventfd_ctx_put (ev_fd_ctx); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_kzalloc; } entry->syncobj = syncobj; entry->ev_fd_ctx = ev_fd_ctx;
@@ -1496,6 +1499,12 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,drm_syncobj_put (syncobj);return 0 ; + +err_kzalloc: +eventfd_ctx_put (ev_fd_ctx); +err_fdget: +drm_syncobj_put (syncobj); +return ret; }int
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Quoted 46 lines · T.J. Mercier
A syncobj reference is taken in
drm_syncobj_find, but not released ifeventfd_ctx_fdgetor kzalloc fails. Put the reference in these error paths.Reported-by Xingyu Jin <[email protected]>Fixes c7a472297169 ("drm/syncobj: add IOCTL to register an eventfd")Signed-off-by T.J. Mercier <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_syncobj.c +7
-4@@ -1464,6 +1464,7 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,struct drm_syncobj *syncobj;struct eventfd_ctx *ev_fd_ctx;struct syncobj_eventfd_entry *entry; +int ret;if (!drm_core_check_feature (dev,DRIVER_SYNCOBJ_TIMELINE ))return -EOPNOTSUPP ;@@ -1479,13 +1480,15 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,return -ENOENT ; ev_fd_ctx =eventfd_ctx_fdget (args->fd); -if (IS_ERR (ev_fd_ctx)) -return PTR_ERR (ev_fd_ctx); +if (IS_ERR (ev_fd_ctx)) { + ret =PTR_ERR (ev_fd_ctx); + goto err_fdget; + } entry =kzalloc (sizeof (*entry),GFP_KERNEL );if (!entry) { -eventfd_ctx_put (ev_fd_ctx); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_kzalloc; } entry->syncobj = syncobj; entry->ev_fd_ctx = ev_fd_ctx;@@ -1496,6 +1499,12 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,drm_syncobj_put (syncobj);
drivers/gpu/drm/drm_syncobj.c drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, · line 1510
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c +6
-0return 0 ; + +err_kzalloc: +eventfd_ctx_put (ev_fd_ctx); +err_fdget: +drm_syncobj_put (syncobj); +return ret; }int
Easy enough to review while browsing the list:
Regards,
Tvrtko
Am 10.09.24 um 09:26 schrieb Tvrtko Ursulin:
Quoted 59 lines · T.J. Mercier
Quoted 53 lines
A syncobj reference is taken in
drm_syncobj_find, but not released ifeventfd_ctx_fdgetor kzalloc fails. Put the reference in these error paths.Reported-by Xingyu Jin <[email protected]>Fixes c7a472297169 ("drm/syncobj: add IOCTL to register an eventfd")Signed-off-by T.J. Mercier <[email protected]>---
drivers/gpu/drm/drm_syncobj.c| 17 +++++++++++++----1 file changed, 13 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_syncobj.c +13
-4@@ -1464,6 +1464,7 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, struct drm_syncobj *syncobj; struct eventfd_ctx *ev_fd_ctx; struct syncobj_eventfd_entry *entry; + int ret; if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE)) return -EOPNOTSUPP;@@ -1479,13 +1480,15 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, return -ENOENT; ev_fd_ctx = eventfd_ctx_fdget(args->fd); - if (IS_ERR(ev_fd_ctx)) - return PTR_ERR(ev_fd_ctx); + if (IS_ERR(ev_fd_ctx)) { + ret = PTR_ERR(ev_fd_ctx); + goto err_fdget; + } entry = kzalloc(sizeof(*entry), GFP_KERNEL); if (!entry) { - eventfd_ctx_put(ev_fd_ctx); - return -ENOMEM; + ret = -ENOMEM; + goto err_kzalloc; } entry->syncobj = syncobj; entry->ev_fd_ctx = ev_fd_ctx;@@ -1496,6 +1499,12 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, drm_syncobj_put(syncobj); return 0; + +err_kzalloc: + eventfd_ctx_put(ev_fd_ctx); +err_fdget: + drm_syncobj_put(syncobj); + return ret; }Quoted 1 line
int
Easy enough to review while browsing the list:
Quoted 1 line
Reviewed-by Tvrtko Ursulin <[email protected]>
Looks reasonable to me as well.
Reviewed-by. Christian König <[email protected]>
CC: stable?
Let me know when you need someone to push it to drm-misc-fixes.
Regards,
Christian.
Quoted 4 lines
Regards,
Tvrtko
Quoted 62 lines · Christian König
Am 10.09.24 um 09:26 schrieb Tvrtko Ursulin:
Quoted 60 lines · T.J. Mercier
Quoted 45 lines
A syncobj reference is taken in
drm_syncobj_find, but not released ifeventfd_ctx_fdgetor kzalloc fails. Put the reference in these error paths.Reported-by Xingyu Jin <[email protected]>Fixes c7a472297169 ("drm/syncobj: add IOCTL to register an eventfd")Signed-off-by T.J. Mercier <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_syncobj.c +7
-4@@ -1464,6 +1464,7 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, struct drm_syncobj *syncobj;struct eventfd_ctx *ev_fd_ctx;struct syncobj_eventfd_entry *entry; +int ret;if (!drm_core_check_feature (dev,DRIVER_SYNCOBJ_TIMELINE ))return -EOPNOTSUPP ;@@ -1479,13 +1480,15 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, return -ENOENT ; ev_fd_ctx =eventfd_ctx_fdget (args->fd); -if (IS_ERR (ev_fd_ctx)) -return PTR_ERR (ev_fd_ctx); +if (IS_ERR (ev_fd_ctx)) { + ret =PTR_ERR (ev_fd_ctx); + goto err_fdget; + } entry =kzalloc (sizeof (*entry),GFP_KERNEL );if (!entry) { -eventfd_ctx_put (ev_fd_ctx); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_kzalloc; } entry->syncobj = syncobj; entry->ev_fd_ctx = ev_fd_ctx;@@ -1496,6 +1499,12 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/drm_syncobj.c drm_syncobj_eventfd_ioctl(struct drm_device · line 1509
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c +6
-0drm_syncobj_put (syncobj);return 0 ; + +err_kzalloc: +eventfd_ctx_put (ev_fd_ctx); +err_fdget: +drm_syncobj_put (syncobj); +return ret; }int Easy enough to review while browsing the list:
Quoted 5 lines
Quoted 1 line
Reviewed-by Tvrtko Ursulin <[email protected]>Looks reasonable to me as well.
Reviewed-by. Christian König <[email protected]>
Thanks!
Quoted 1 line
CC stable?
Yes, I think we should. 6.6 and 6.10
Quoted 1 line
Let me know when you need someone to push it to drm-misc-fixes.
Anytime is good, no rush for this one.
Quoted 9 lines
Regards,
Christian.Quoted 4 lines
Regards,
Tvrtko
Am 10.09.24 um 16:47 schrieb T.J. Mercier:
Quoted 64 lines
Quoted 62 lines · Christian König
Am 10.09.24 um 09:26 schrieb Tvrtko Ursulin:
Quoted 58 lines · T.J. Mercier
Quoted 45 lines
A syncobj reference is taken in
drm_syncobj_find, but not released ifeventfd_ctx_fdgetor kzalloc fails. Put the reference in these error paths.Reported-by Xingyu Jin <[email protected]>Fixes c7a472297169 ("drm/syncobj: add IOCTL to register an eventfd")Signed-off-by T.J. Mercier <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_syncobj.c +7
-4@@ -1464,6 +1464,7 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, struct drm_syncobj *syncobj;struct eventfd_ctx *ev_fd_ctx;struct syncobj_eventfd_entry *entry; +int ret;if (!drm_core_check_feature (dev,DRIVER_SYNCOBJ_TIMELINE ))return -EOPNOTSUPP ;@@ -1479,13 +1480,15 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data, return -ENOENT ; ev_fd_ctx =eventfd_ctx_fdget (args->fd); -if (IS_ERR (ev_fd_ctx)) -return PTR_ERR (ev_fd_ctx); +if (IS_ERR (ev_fd_ctx)) { + ret =PTR_ERR (ev_fd_ctx); + goto err_fdget; + } entry =kzalloc (sizeof (*entry),GFP_KERNEL );if (!entry) { -eventfd_ctx_put (ev_fd_ctx); -return -ENOMEM ; + ret = -ENOMEM ; + goto err_kzalloc; } entry->syncobj = syncobj; entry->ev_fd_ctx = ev_fd_ctx;@@ -1496,6 +1499,12 @@ drm_syncobj_eventfd_ioctl(struct drm_device *dev, void *data,drivers/gpu/drm/drm_syncobj.c drm_syncobj_eventfd_ioctl(struct drm_device · line 1509
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c +6
-0drm_syncobj_put (syncobj);return 0 ; + +err_kzalloc: +eventfd_ctx_put (ev_fd_ctx); +err_fdget: +drm_syncobj_put (syncobj); +return ret; }int Easy enough to review while browsing the list:
Quoted 1 line
Reviewed-by Tvrtko Ursulin <[email protected]>Looks reasonable to me as well.
Quoted 8 lines
Quoted 1 line
Reviewed-by. Christian König <[email protected]>
Thanks!
Quoted 1 line
CC stable?Yes, I think we should. 6.6 and 6.10
Quoted 1 line
Let me know when you need someone to push it to drm-misc-fixes.
Anytime is good, no rush for this one.
Done.
Christian.
Quoted 7 lines
Quoted 7 lines
Regards,
Christian.Quoted 3 lines
Regards,
Tvrtko