Skip to content

Commit afef59a

Browse files
bmolodanclaude
authored andcommitted
fix(tee): reject invalid session in invoke to close NULL-deref DoS (#247)
tee_ioctl_invoke() did not check the result of tee_ta_get_session(). A non-secure caller could send TEE_IOC_INVOKE with an invalid, zero, or stale session id; find_session() returns NULL and tee_ta_invoke_command() then dereferences it (sess->ctx->ops->enter_invoke_cmd, the original guards are commented out), faulting in the secure world -> DoS reachable through the live cmse_nonsecure_entry ioctl veneer. Reject a NULL session with TEEC_ERROR_BAD_PARAMETERS in tee_ioctl_invoke before the session is used, and add a defense-in-depth NULL guard at the top of tee_ta_invoke_command() so no caller can trigger the dereference. close_session is unaffected: tee_ta_close_session() already handles NULL. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 371b0ac commit afef59a

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

tee/kernel/entry_std.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,19 @@ TEEC_Result tee_ioctl_invoke(/*ctx,*/ struct tee_ioctl_buf_data *buf_data)
406406
if (res != TEE_SUCCESS)
407407
goto out;
408408

409+
if (!sess) {
410+
/*
411+
* A Non-Secure caller can supply an invalid/zero/stale session id.
412+
* find_session() then returns NULL and, since the guards in
413+
* tee_ta_invoke_command() are disabled, the secure world would
414+
* dereference NULL (sess->ctx->...) -> secure-world crash/DoS.
415+
* Reject before invoking. Placed after copy_in_params so a malformed
416+
* request still gets the more specific error from parameter validation.
417+
*/
418+
res = TEEC_ERROR_BAD_PARAMETERS;
419+
goto out;
420+
}
421+
409422
res = tee_ta_invoke_command(&err, sess, arg->func, &param);
410423

411424
copy_out_param(&param, arg->num_params, arg->params, saved_attr);

tee/kernel/tee_ta_manager.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,15 @@ TEE_Result tee_ta_invoke_command(TEE_ErrorOrigin *err,
637637
{
638638
TEE_Result res;
639639

640+
/*
641+
* Defense in depth: never dereference a NULL session. Callers (e.g. the
642+
* Non-Secure ioctl veneer) obtain sess from tee_ta_get_session(), which
643+
* returns NULL for an unknown session id; without this guard the line
644+
* below would fault in the secure world.
645+
*/
646+
if (!sess)
647+
return TEE_ERROR_BAD_PARAMETERS;
648+
640649
// if (check_client(sess, clnt_id) != TEE_SUCCESS)
641650
// return TEE_ERROR_BAD_PARAMETERS; /* intentional generic error */
642651
//

0 commit comments

Comments
 (0)