Skip to contentSkip to conversation

staging: android: ion: Fix error handling in ion_query_heaps()

PATCH Superseded Dan Carpenter 2 participants 2 messages Oct 12, 2016 – Oct 13, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: android: ion: Fix error handling in ion_query_heaps()

copy_to_user() returns the number of bytes remaining to be copied. We want to return -EFAULT here instead. Also there seems like no point in continuing the loop if copy_to_user() fails.

Fixes 02b23803c6af ('staging: android: ion: Add ioctl to query available heaps')

---
The error handling still might be wrong here. Do we really want to change query->cnt? Please review.

drivers/staging/android/ion/ion.c +4 -2
index 396ded5..4cec0b2 100644
@@ -1187,8 +1187,10 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query)
 		hdata.type = heap->type;
 		hdata.heap_id = heap->id;
 
-		ret = copy_to_user(&buffer[cnt],
-				   &hdata, sizeof(hdata));
+		if (copy_to_user(&buffer[cnt], &hdata, sizeof(hdata))) {
+			ret = -EFAULT;
+			break;
+		}
 
 		cnt++;
 		if (cnt >= max_cnt)
#1 lore raw
Quoted 18 lines · Dan Carpenter

copy_to_user() returns the number of bytes remaining to be copied. We want to return -EFAULT here instead. Also there seems like no point in continuing the loop if copy_to_user() fails.

Fixes 02b23803c6af ('staging: android: ion: Add ioctl to query available heaps')

---
The error handling still might be wrong here. Do we really want to change query->cnt? Please review.

drivers/staging/android/ion/ion.c +0 -0
index 396ded5..4cec0b2 100644
@@ -1187,8 +1187,10 @@ int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query)
 		hdata.type = heap->type;
 		hdata.heap_id = heap->id;

drivers/staging/android/ion/ion.c int ion_query_heaps(struct ion_client *client, struct ion_heap_query *query) · line 1196

Quoted 10 lines
drivers/staging/android/ion/ion.c +4 -2
 
-		ret = copy_to_user(&buffer[cnt],
-				   &hdata, sizeof(hdata));
+		if (copy_to_user(&buffer[cnt], &hdata, sizeof(hdata))) {
+			ret = -EFAULT;
+			break;
+		}
 
 		cnt++;
 		if (cnt >= max_cnt)

Yeah, I really butchered the error handling on this. You are correct, query->cnt shouldn't be updated. break can be changed to 'goto out'.

Thanks,
Laura