Skip to contentSkip to conversation

tee: qcomtee: add missing va_end in early return qcomtee_object_user_init()

PATCH Superseded Robertus Diawan Chris 2 participants 6 messages May 13 – May 18

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tee: qcomtee: add missing va_end in early return qcomtee_object_user_init()

qcomtee_object_user_init() is a variadic function and when the function return because there's no dispatch callback in QCOMTEE_OBJECT_TYPE_CB case, there's no va_end to cleanup "ap" object initialized by va_start and that can cause undefined behavior. So make sure to use va_end before returning the error code when there's no dispatch callback.

This is reported by Coverity Scan as "Missing varargs init or cleanup".

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")

---
I don't have the device, so I am not sure how to test this change. Thank you.

 drivers/tee/qcomtee/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tee/qcomtee/core.c +6 -2
index b1cb50e434f0..901a31e8201f 100644
@@ -306,8 +306,10 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 		break;
 	case QCOMTEE_OBJECT_TYPE_CB:
 		object->ops = ops;
-		if (!object->ops->dispatch)
-			return -EINVAL;
+		if (!object->ops->dispatch) {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If failed, "no-name". */
 		object->name = kvasprintf_const(GFP_KERNEL, fmt, ap);
@@ -320,6 +322,8 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 	default:
 		ret = -EINVAL;
 	}
+
+out:
 	va_end(ap);
 
 	return ret;

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Signature · 1 line
2.54.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 44 lines · Robertus Diawan Chris

qcomtee_object_user_init() is a variadic function and when the function return because there's no dispatch callback in QCOMTEE_OBJECT_TYPE_CB case, there's no va_end to cleanup "ap" object initialized by va_start and that can cause undefined behavior. So make sure to use va_end before returning the error code when there's no dispatch callback.

This is reported by Coverity Scan as "Missing varargs init or cleanup".

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")

---
I don't have the device, so I am not sure how to test this change. Thank you.

 drivers/tee/qcomtee/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tee/qcomtee/core.c +6 -2
index b1cb50e434f0..901a31e8201f 100644
@@ -306,8 +306,10 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 		break;
 	case QCOMTEE_OBJECT_TYPE_CB:
 		object->ops = ops;
-		if (!object->ops->dispatch)
-			return -EINVAL;
+		if (!object->ops->dispatch) {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If failed, "no-name". */
 		object->name = kvasprintf_const(GFP_KERNEL, fmt, ap);
@@ -320,6 +322,8 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 	default:
 		ret = -EINVAL;
 	}
+
+out:
 	va_end(ap);
 
 	return ret;
Quoted 1 line

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Thanks.
Amir

maintainer
#2 lore raw
In reply to Robertus Diawan Chris

Hi,

Forgot to mention: how about using a break instead of a goto. Then feel free to add Reviewed-by.

Thanks,
Amir

Quoted 45 lines · Robertus Diawan Chris

qcomtee_object_user_init() is a variadic function and when the function return because there's no dispatch callback in QCOMTEE_OBJECT_TYPE_CB case, there's no va_end to cleanup "ap" object initialized by va_start and that can cause undefined behavior. So make sure to use va_end before returning the error code when there's no dispatch callback.

This is reported by Coverity Scan as "Missing varargs init or cleanup".

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")

---
I don't have the device, so I am not sure how to test this change. Thank you.

 drivers/tee/qcomtee/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tee/qcomtee/core.c +6 -2
index b1cb50e434f0..901a31e8201f 100644
@@ -306,8 +306,10 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 		break;
 	case QCOMTEE_OBJECT_TYPE_CB:
 		object->ops = ops;
-		if (!object->ops->dispatch)
-			return -EINVAL;
+		if (!object->ops->dispatch) {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If failed, "no-name". */
 		object->name = kvasprintf_const(GFP_KERNEL, fmt, ap);
@@ -320,6 +322,8 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 	default:
 		ret = -EINVAL;
 	}
+
+out:
 	va_end(ap);
 
 	return ret;

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

#3 lore raw

Hello Amir,

Quoted 43 lines · Amirreza Zarrabi
Quoted 42 lines · Robertus Diawan Chris

qcomtee_object_user_init() is a variadic function and when the function return because there's no dispatch callback in QCOMTEE_OBJECT_TYPE_CB case, there's no va_end to cleanup "ap" object initialized by va_start and that can cause undefined behavior. So make sure to use va_end before returning the error code when there's no dispatch callback.

This is reported by Coverity Scan as "Missing varargs init or cleanup".

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")

---
I don't have the device, so I am not sure how to test this change. Thank you.

 drivers/tee/qcomtee/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tee/qcomtee/core.c +6 -2
index b1cb50e434f0..901a31e8201f 100644
@@ -306,8 +306,10 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 		break;
 	case QCOMTEE_OBJECT_TYPE_CB:
 		object->ops = ops;
-		if (!object->ops->dispatch)
-			return -EINVAL;
+		if (!object->ops->dispatch) {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If failed, "no-name". */
 		object->name = kvasprintf_const(GFP_KERNEL, fmt, ap);
@@ -320,6 +322,8 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 	default:
 		ret = -EINVAL;
 	}
+
+out:
 	va_end(ap);
 
Quoted 7 lines
Quoted 3 lines
drivers/tee/qcomtee/core.c +0 -0
 	return ret;

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Hi,

Forgot to mention: how about using a break instead of a goto.

Oh right. In this case, using "break" statement is enough. I will send the v2 of the patch. Maybe something like this:

	if (!object->ops->dispatch) {
		ret = -EINVAL;
		break;
	}

and then remove the "out" label.

Quoted 1 line

Then feel free to add Reviewed-by.

I want to confirm first, if I changed the patch using "break" statement, do I need to add "Reviewed-by" tag in the v2 of the patch or not? I am still not sure when to add "Reviewed-by" tag, like can we add "Reviewed-by" tag when we changed the patch?

Thank you.

Best regards,
Robertus Diawan Chris

maintainer
#4 lore raw

Hi,

Quoted 62 lines · Robertus Diawan Chris

Hello Amir,

Quoted 43 lines · Amirreza Zarrabi
Quoted 42 lines · Robertus Diawan Chris

qcomtee_object_user_init() is a variadic function and when the function return because there's no dispatch callback in QCOMTEE_OBJECT_TYPE_CB case, there's no va_end to cleanup "ap" object initialized by va_start and that can cause undefined behavior. So make sure to use va_end before returning the error code when there's no dispatch callback.

This is reported by Coverity Scan as "Missing varargs init or cleanup".

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")

---
I don't have the device, so I am not sure how to test this change. Thank you.

 drivers/tee/qcomtee/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tee/qcomtee/core.c +6 -2
index b1cb50e434f0..901a31e8201f 100644
@@ -306,8 +306,10 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 		break;
 	case QCOMTEE_OBJECT_TYPE_CB:
 		object->ops = ops;
-		if (!object->ops->dispatch)
-			return -EINVAL;
+		if (!object->ops->dispatch) {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If failed, "no-name". */
 		object->name = kvasprintf_const(GFP_KERNEL, fmt, ap);
@@ -320,6 +322,8 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 	default:
 		ret = -EINVAL;
 	}
+
+out:
 	va_end(ap);
 
Quoted 7 lines
Quoted 3 lines
drivers/tee/qcomtee/core.c +0 -0
 	return ret;

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Hi,

Forgot to mention: how about using a break instead of a goto.

Oh right. In this case, using "break" statement is enough. I will send the v2 of the patch. Maybe something like this:

	if (!object->ops->dispatch) {
		ret = -EINVAL;
		break;
	}
Quoted 9 lines

and then remove the "out" label.

Quoted 1 line

Then feel free to add Reviewed-by.

I want to confirm first, if I changed the patch using "break" statement, do I need to add "Reviewed-by" tag in the v2 of the patch or not? I am still not sure when to add "Reviewed-by" tag, like can we add "Reviewed-by" tag when we changed the patch?

This is a small change. You can add the tag when sending your v2 as long as you include the change.

Best Regards,
Amir

Quoted 4 lines

Thank you.

Best regards,
Robertus Diawan Chris

#5 lore raw

Hello Amir,

Quoted 69 lines · Amirreza Zarrabi

Hi,

Quoted 66 lines · Robertus Diawan Chris

Hello Amir,

Quoted 43 lines · Amirreza Zarrabi
Quoted 42 lines · Robertus Diawan Chris

qcomtee_object_user_init() is a variadic function and when the function return because there's no dispatch callback in QCOMTEE_OBJECT_TYPE_CB case, there's no va_end to cleanup "ap" object initialized by va_start and that can cause undefined behavior. So make sure to use va_end before returning the error code when there's no dispatch callback.

This is reported by Coverity Scan as "Missing varargs init or cleanup".

Fixes d6e290837e50 ("tee: add Qualcomm TEE driver")

---
I don't have the device, so I am not sure how to test this change. Thank you.

 drivers/tee/qcomtee/core.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tee/qcomtee/core.c +6 -2
index b1cb50e434f0..901a31e8201f 100644
@@ -306,8 +306,10 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 		break;
 	case QCOMTEE_OBJECT_TYPE_CB:
 		object->ops = ops;
-		if (!object->ops->dispatch)
-			return -EINVAL;
+		if (!object->ops->dispatch) {
+			ret = -EINVAL;
+			goto out;
+		}
 
 		/* If failed, "no-name". */
 		object->name = kvasprintf_const(GFP_KERNEL, fmt, ap);
@@ -320,6 +322,8 @@ int qcomtee_object_user_init(struct qcomtee_object *object,
 	default:
 		ret = -EINVAL;
 	}
+
+out:
 	va_end(ap);
 
Quoted 7 lines
Quoted 3 lines
drivers/tee/qcomtee/core.c +0 -0
 	return ret;

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Hi,

Forgot to mention: how about using a break instead of a goto.

Oh right. In this case, using "break" statement is enough. I will send the v2 of the patch. Maybe something like this:

	if (!object->ops->dispatch) {
		ret = -EINVAL;
		break;
	}

and then remove the "out" label.

Quoted 1 line

Then feel free to add Reviewed-by.

Quoted 8 lines
Quoted 5 lines

I want to confirm first, if I changed the patch using "break" statement, do I need to add "Reviewed-by" tag in the v2 of the patch or not? I am still not sure when to add "Reviewed-by" tag, like can we add "Reviewed-by" tag when we changed the patch?

This is a small change. You can add the tag when sending your v2 as long as you include the change.

I see. Alright, I will send the patch v2 with the change and the "Reviewed-by" tag later. Thanks.

Best regards,
Robertus Diawan Chris