tee: qcom: prevent potential off by one read
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.
--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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);
Signature · 1 line
2.51.0
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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
-Sumit
Quoted 18 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);Signature · 1 line
2.51.0
Jens Wiklander
AppliedQuoted 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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Sumit Garg <[email protected]>
Applied.
/Jens
Quoted 21 lines
-Sumit
Quoted 18 lines
drivers/tee/qcomtee/call.c +1
-2@@ -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
Amirreza Zarrabi
maintainerQuoted 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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0
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
Amirreza Zarrabi
maintainerQuoted 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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0drivers/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.
iat 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
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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0@@ -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.
iat least have been accessed once in the switch above.
Only the first iteration has been accessed. The rest no.
regards,
dan carpenter
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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0drivers/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.
iat least have been accessed once in the switch above.
Quoted 8 lines
Quoted 4 lines
Regards,
AmirAlso, size of u is always
num_params+ 1 for the ending 0. (basically meansi < num_paramscan be removed).
Yes. This is true.
regards,
dan carpenter
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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0drivers/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.
iat 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 meansi < num_paramscan be removed).Yes. This is true.
So this patch isn't needed. I'll drop it if no one objects.
Cheers,
Jens
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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0drivers/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.
iat 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 meansi < num_paramscan 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
Amirreza Zarrabi
maintainerQuoted 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")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/qcomtee/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tee/qcomtee/call.c +0
-0drivers/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.
iat least have been accessed once in the switch above.Regards,
AmirQuoted 7 lines
Quoted 5 lines
Quoted 3 lines
Also, size of u is always
num_params+ 1 for the ending 0. (basically meansi < num_paramscan 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