Skip to contentSkip to conversation

tee: qcom: prevent potential off by one read

PATCH Applied Dan Carpenter 4 participants 10 messages Sep 18, 2025 – Sep 25, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tee: qcom: prevent potential off by one read

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +1 -1
index cc17a48d0ab7..ac134452cc9c 100644
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
 	}
 
 	/* Release any IO and OO objects not processed. */
-	for (; u[i].type && i < num_params; i++) {
+	for (; i < num_params && u[i].type; i++) {
 		if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
 		    u[i].type == QCOMTEE_ARG_TYPE_IO)
 			qcomtee_object_put(u[i].o);
Signature · 1 line
2.51.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-Sumit

Quoted 18 lines
drivers/tee/qcomtee/call.c +1 -1
index cc17a48d0ab7..ac134452cc9c 100644
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
 	}
 
 	/* Release any IO and OO objects not processed. */
-	for (; u[i].type && i < num_params; i++) {
+	for (; i < num_params && u[i].type; i++) {
 		if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
 		    u[i].type == QCOMTEE_ARG_TYPE_IO)
 			qcomtee_object_put(u[i].o);
Signature · 1 line
2.51.0
#2 lore raw
Quoted 5 lines · Sumit Garg
Quoted 3 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Quoted 7 lines
Quoted 5 lines
Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied.

/Jens

Quoted 21 lines

-Sumit

Quoted 18 lines
drivers/tee/qcomtee/call.c +1 -2
index cc17a48d0ab7..ac134452cc9c 100644
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
      }
 
      /* Release any IO and OO objects not processed. */
-     for (; u[i].type && i < num_params; i++) {
+     for (; i < num_params && u[i].type; i++) {
              if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
                  u[i].type == QCOMTEE_ARG_TYPE_IO)
                      qcomtee_object_put(u[i].o);
--

2.51.0

maintainer
#3 lore raw
In reply to Dan Carpenter
Quoted 14 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 8 lines
drivers/tee/qcomtee/call.c +1 -1
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
 	}
 
 	/* Release any IO and OO objects not processed. */
-	for (; u[i].type && i < num_params; i++) {
+	for (; i < num_params && u[i].type; i++) {
 		if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
 		    u[i].type == QCOMTEE_ARG_TYPE_IO)
 			qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Regards,
Amir

maintainer
#4 lore raw
Quoted 28 lines · Amirreza Zarrabi
Quoted 14 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 8 lines
drivers/tee/qcomtee/call.c +1 -1
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
 	}
 
 	/* Release any IO and OO objects not processed. */
-	for (; u[i].type && i < num_params; i++) {
+	for (; i < num_params && u[i].type; i++) {
 		if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
 		    u[i].type == QCOMTEE_ARG_TYPE_IO)
 			qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Quoted 4 lines

Regards,
Amir

Also, size of u is always num_params + 1 for the ending 0. (basically means i < num_params can be removed).

Anyway, it does not hurt :).

Regards,
Amir

#5 lore raw
Quoted 31 lines · Amirreza Zarrabi
Quoted 28 lines · Amirreza Zarrabi
Quoted 14 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 8 lines
drivers/tee/qcomtee/call.c +1 -1
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
 	}
 
 	/* Release any IO and OO objects not processed. */
-	for (; u[i].type && i < num_params; i++) {
+	for (; i < num_params && u[i].type; i++) {
 		if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
 		    u[i].type == QCOMTEE_ARG_TYPE_IO)
 			qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Quoted 8 lines
Quoted 4 lines

Regards,
Amir

Also, size of u is always num_params + 1 for the ending 0. (basically means i < num_params can be removed).

Yes. This is true.

regards,
dan carpenter

#6 lore raw
Quoted 38 lines · Dan Carpenter
Quoted 36 lines · Amirreza Zarrabi
Quoted 32 lines · Amirreza Zarrabi
Quoted 14 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 8 lines
drivers/tee/qcomtee/call.c +1 -1
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
   }
 
   /* Release any IO and OO objects not processed. */
-  for (; u[i].type && i < num_params; i++) {
+  for (; i < num_params && u[i].type; i++) {
           if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
               u[i].type == QCOMTEE_ARG_TYPE_IO)
                   qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Regards,
Amir

Quoted 5 lines
Quoted 3 lines

Also, size of u is always num_params + 1 for the ending 0. (basically means i < num_params can be removed).

Yes. This is true.

So this patch isn't needed. I'll drop it if no one objects.

Cheers,
Jens

#7 lore raw
Quoted 39 lines · Jens Wiklander
Quoted 38 lines · Dan Carpenter
Quoted 36 lines · Amirreza Zarrabi
Quoted 32 lines · Amirreza Zarrabi
Quoted 14 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 8 lines
drivers/tee/qcomtee/call.c +1 -1
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
   }
 
   /* Release any IO and OO objects not processed. */
-  for (; u[i].type && i < num_params; i++) {
+  for (; i < num_params && u[i].type; i++) {
           if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
               u[i].type == QCOMTEE_ARG_TYPE_IO)
                   qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Regards,
Amir

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Also, size of u is always num_params + 1 for the ending 0. (basically means i < num_params can be removed).

Yes. This is true.

So this patch isn't needed. I'll drop it if no one objects.

The patch makes the code better though... It never really makes sense to use a variable first and then check if it's valid later. In this case the check isn't required.

Ideally the code would only have one limit. We could either do:

	for (; i < num_params; i++) {
Or:
	for (; u[i].type != QCOMTEE_ARG_TYPE_INV; i++) {

Either way works...

regards,
dan carpenter

maintainer
#8 lore raw
Quoted 54 lines · Dan Carpenter
Quoted 39 lines · Jens Wiklander
Quoted 38 lines · Dan Carpenter
Quoted 36 lines · Amirreza Zarrabi
Quoted 32 lines · Amirreza Zarrabi
Quoted 14 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 8 lines
drivers/tee/qcomtee/call.c +1 -1
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
   }
 
   /* Release any IO and OO objects not processed. */
-  for (; u[i].type && i < num_params; i++) {
+  for (; i < num_params && u[i].type; i++) {
           if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
               u[i].type == QCOMTEE_ARG_TYPE_IO)
                   qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Regards,
Amir

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Also, size of u is always num_params + 1 for the ending 0. (basically means i < num_params can be removed).

Yes. This is true.

So this patch isn't needed. I'll drop it if no one objects.

The patch makes the code better though... It never really makes sense to use a variable first and then check if it's valid later. In this case the check isn't required.

Ideally the code would only have one limit. We could either do:

Quoted 9 lines
	for (; i < num_params; i++) {
Or:
	for (; u[i].type != QCOMTEE_ARG_TYPE_INV; i++) {

Either way works...

regards,
dan carpenter

Originally, it was written as

	for (; u[i].type != QCOMTEE_ARG_TYPE_INV; i++) { ...

but changed trough out the review process.
I do not have any preference. But if having it as

	for (; i < num_params && u[i].type; i++) { ...

is more readable, let's keep it.

Regards,
Amir

#9 lore raw
In reply to Amirreza Zarrabi
Quoted 17 lines · Amirreza Zarrabi
Quoted 16 lines · Dan Carpenter

Re-order these checks to check if "i" is a valid array index before using it. This prevents a potential off by one read access.

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")
---
 drivers/tee/qcomtee/call.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tee/qcomtee/call.c +0 -0
index cc17a48d0ab7..ac134452cc9c 100644
@@ -308,7 +308,7 @@ static int qcomtee_params_from_args(struct tee_param *params,
 	}
 
Quoted 10 lines

drivers/tee/qcomtee/call.c static int qcomtee_params_from_args(struct tee_param *params, · line 314

Quoted 6 lines
drivers/tee/qcomtee/call.c +1 -1
 	/* Release any IO and OO objects not processed. */
-	for (; u[i].type && i < num_params; i++) {
+	for (; i < num_params && u[i].type; i++) {
 		if (u[i].type == QCOMTEE_ARG_TYPE_OO ||
 		    u[i].type == QCOMTEE_ARG_TYPE_IO)
 			qcomtee_object_put(u[i].o);

This is not required, considering the sequence of clean up, this would never happen. i at least have been accessed once in the switch above.

Only the first iteration has been accessed. The rest no.

regards,
dan carpenter