diff --git a/tee/kernel/entry_std.c b/tee/kernel/entry_std.c index 88b462b1..b2ddc3da 100644 --- a/tee/kernel/entry_std.c +++ b/tee/kernel/entry_std.c @@ -406,6 +406,19 @@ TEEC_Result tee_ioctl_invoke(/*ctx,*/ struct tee_ioctl_buf_data *buf_data) if (res != TEE_SUCCESS) goto out; + if (!sess) { + /* + * A Non-Secure caller can supply an invalid/zero/stale session id. + * find_session() then returns NULL and, since the guards in + * tee_ta_invoke_command() are disabled, the secure world would + * dereference NULL (sess->ctx->...) -> secure-world crash/DoS. + * Reject before invoking. Placed after copy_in_params so a malformed + * request still gets the more specific error from parameter validation. + */ + res = TEEC_ERROR_BAD_PARAMETERS; + goto out; + } + res = tee_ta_invoke_command(&err, sess, arg->func, ¶m); copy_out_param(¶m, arg->num_params, arg->params, saved_attr); diff --git a/tee/kernel/tee_ta_manager.c b/tee/kernel/tee_ta_manager.c index 2cadb4d2..ebaa3813 100644 --- a/tee/kernel/tee_ta_manager.c +++ b/tee/kernel/tee_ta_manager.c @@ -637,6 +637,15 @@ TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err, { TEE_Result res; + /* + * Defense in depth: never dereference a NULL session. Callers (e.g. the + * Non-Secure ioctl veneer) obtain sess from tee_ta_get_session(), which + * returns NULL for an unknown session id; without this guard the line + * below would fault in the secure world. + */ + if (!sess) + return TEE_ERROR_BAD_PARAMETERS; + // if (check_client(sess, clnt_id) != TEE_SUCCESS) // return TEE_ERROR_BAD_PARAMETERS; /* intentional generic error */ //