Skip to contentSkip to conversation

drm/panthor: avoid garbage value in panthor_ioctl_dev_query()

PATCH Applied Su Hui 4 participants 6 messages Jan 19, 2025 – Feb 7, 2025

Subsystems (4)
lore
Share & tools
lore

Su Hui

author
#0 lore raw

PATCH 1/1 drm/panthor: avoid garbage value in panthor_ioctl_dev_query()

'priorities_info' is uninitialized, and the uninitialized value is copied to user object when calling PANTHOR_UOBJ_SET(). Using memset to initialize 'priorities_info' to avoid this garbage value problem.

Fixes f70000ef2352 ("drm/panthor: Add DEV_QUERY_GROUP_PRIORITIES_INFO dev query")
---
 drivers/gpu/drm/panthor/panthor_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 0b3fbee3d37a..44f5c72d46c3 100644
@@ -802,6 +802,7 @@ static void panthor_query_group_priorities_info(struct drm_file *file,
 {
 	int prio;
 
+	memset(arg, 0, sizeof(*arg));
 	for (prio = PANTHOR_GROUP_PRIORITY_REALTIME; prio >= 0; prio--) {
 		if (!group_priority_permit(file, prio))
 			arg->allowed_mask |= BIT(prio);
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Su Hui

'priorities_info' is uninitialized, and the uninitialized value is copied to user object when calling PANTHOR_UOBJ_SET(). Using memset to initialize 'priorities_info' to avoid this garbage value problem.

Fixes f70000ef2352 ("drm/panthor: Add DEV_QUERY_GROUP_PRIORITIES_INFO dev query")

How did you find this bug?

regards,
dan carpenter

author
#2 lore raw
Quoted 10 lines · Dan Carpenter
Quoted 6 lines · Su Hui

'priorities_info' is uninitialized, and the uninitialized value is copied to user object when calling PANTHOR_UOBJ_SET(). Using memset to initialize 'priorities_info' to avoid this garbage value problem.

Fixes f70000ef2352 ("drm/panthor: Add DEV_QUERY_GROUP_PRIORITIES_INFO dev query")

How did you find this bug?

Clang found this bug, run command like this:
scan-build  --use-cc=clang    make CC=clang drivers/gpu/drm/panthor/panthor_drv.o

There will be some warnings, one is this:
drivers/gpu/drm/panthor/panthor_drv.c:807:22: warning: The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage [core.uninitialized.Assign] 807 |                         arg->allowed_mask |= BIT(prio);
      |                         ~~~~~~~~~~~~~~~~~ ^

regards,
su hui

maintainer Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 9 lines · On Mon, 20 Jan 2025 10:21:49 +0300 Dan Carpenter <[email protected]>…
Quoted 6 lines · Su Hui

'priorities_info' is uninitialized, and the uninitialized value is copied to user object when calling PANTHOR_UOBJ_SET(). Using memset to initialize 'priorities_info' to avoid this garbage value problem.

Fixes f70000ef2352 ("drm/panthor: Add DEV_QUERY_GROUP_PRIORITIES_INFO dev query")

Queued to drm-misc-fixes.

Quoted 6 lines

How did you find this bug?

regards,
dan carpenter

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Su Hui
Quoted 6 lines · On Sun, 19 Jan 2025 10:58:29 +0800 Su Hui <[email protected]> wrote:

'priorities_info' is uninitialized, and the uninitialized value is copied to user object when calling PANTHOR_UOBJ_SET(). Using memset to initialize 'priorities_info' to avoid this garbage value problem.

Fixes f70000ef2352 ("drm/panthor: Add DEV_QUERY_GROUP_PRIORITIES_INFO dev query")
Quoted 16 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 0b3fbee3d37a..44f5c72d46c3 100644
@@ -802,6 +802,7 @@ static void panthor_query_group_priorities_info(struct drm_file *file,
 {
 	int prio;
 
+	memset(arg, 0, sizeof(*arg));
 	for (prio = PANTHOR_GROUP_PRIORITY_REALTIME; prio >= 0; prio--) {
 		if (!group_priority_permit(file, prio))
 			arg->allowed_mask |= BIT(prio);
maintainer Reviewed-by on v1 1/1
#5 lore raw
In reply to Su Hui
Quoted 6 lines · Su Hui

'priorities_info' is uninitialized, and the uninitialized value is copied to user object when calling PANTHOR_UOBJ_SET(). Using memset to initialize 'priorities_info' to avoid this garbage value problem.

Fixes f70000ef2352 ("drm/panthor: Add DEV_QUERY_GROUP_PRIORITIES_INFO dev query")
Quoted 16 lines
---
 drivers/gpu/drm/panthor/panthor_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/panthor/panthor_drv.c +1 -0
index 0b3fbee3d37a..44f5c72d46c3 100644
@@ -802,6 +802,7 @@ static void panthor_query_group_priorities_info(struct drm_file *file,
 {
 	int prio;
 
+	memset(arg, 0, sizeof(*arg));
 	for (prio = PANTHOR_GROUP_PRIORITY_REALTIME; prio >= 0; prio--) {
 		if (!group_priority_permit(file, prio))
 			arg->allowed_mask |= BIT(prio);