fix(tee): reject invalid session in invoke to close NULL-deref DoS (#247) - #248
Merged
Merged
Conversation
…amsung#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a HIGH-severity, unauthenticated denial of service of the secure world,
reachable from the non-secure world through the live
cmse_nonsecure_entryioctl()veneer.tee_ioctl_invoke()(tee/kernel/entry_std.c) does not check the result oftee_ta_get_session(). A non-secure caller can sendTEE_IOC_INVOKEwith aninvalid / zero / stale
sessionid →find_session()returnsNULL→tee_ta_invoke_command()(tee/kernel/tee_ta_manager.c) dereferences it(
sess->ctx->ops->enter_invoke_cmd(...); the original OP-TEE guards arecommented out) → NULL dereference in the secure world → crash / DoS.
Fix (defense in depth, 2 files)
tee/kernel/entry_std.c—tee_ioctl_invoke(): reject aNULLsessionwith
TEEC_ERROR_BAD_PARAMETERS, placed aftercopy_in_params()and rightbefore
tee_ta_invoke_command()— so a malformed request still gets the morespecific parameter-validation error, and only an otherwise-valid request with
a bad session id gets
BAD_PARAMETERS.tee/kernel/tee_ta_manager.c—tee_ta_invoke_command(): adefense-in-depth
if (!sess) return TEE_ERROR_BAD_PARAMETERS;at the top, atthe dereference site, so no caller can trigger the fault.
close_sessionis unaffected —tee_ta_close_session()already handlesNULL(
TEE_ERROR_ITEM_NOT_FOUND). Scope: ARM only (mps2_an505_qemu,numaker_pfm_m2351); the RISC-V targets have no NS→S call boundary.Fixes #247
Type of change
How Has This Been Tested?
Built and run under QEMU (
qemu-system-arm -machine mps2-an505 -cpu cortex-m33).A dedicated negative case drives the
ioctlveneer with a valid non-secureoptee_msg_arg(num_params = 0) but a bogus session id (0xDEADBEEF).entry_std.c+tee_ta_manager.ccompile with no newwarnings on all three build targets (
mps2_an505_qemu,numaker_pfm_m2351,m2351_badge).0xffff0006(
TEEC_ERROR_BAD_PARAMETERS), no SecureFault; the secure world keepsservicing requests.
same call faults/hangs the secure world (the DoS itself), confirming the
test exercises the guard.
unaffected (the guard does not fire); the AES memref example still passes.
Test Configuration:
master+ this fixqemu-system-arm); NuMaker-PFM-M2351 (build-only)Checklist:
(QEMU negative case + counter-check, run against a local test harness kept
out of this patch)
The runtime negative-test harness is developer tooling and is intentionally
not part of this patch, which is the minimal two-file fix.