Skip to content

core: spmc: reject too small mem_access_size - #7945

Open
anarchyj wants to merge 1 commit into
OP-TEE:masterfrom
anarchyj:anarchyj-patch-2
Open

core: spmc: reject too small mem_access_size#7945
anarchyj wants to merge 1 commit into
OP-TEE:masterfrom
anarchyj:anarchyj-patch-2

Conversation

@anarchyj

Copy link
Copy Markdown
Contributor

spmc_read_mem_transaction() reads mem_access_size, mem_access_count and mem_access_offs from a normal-world memory transaction descriptor and checks that the endpoint memory access descriptor array fits within the fragment (mem_access_offs + mem_access_size * mem_access_count <= frag_len). mem_access_size is bounded from above but not from below.

The array elements are dereferenced as struct ffa_mem_access_common, in get_acc_perms() and, on the S-EL0 secure partition path, in spmc_sp_add_share(). With mem_access_size smaller than that structure the array-fit check no longer keeps each element read in range; with mem_access_size 0 and mem_access_offs equal to frag_len the read lands past the mapped buffer. The descriptor comes from the normal world, so this is an out-of-bounds read in the SPMC.

Reject a mem_access_size smaller than struct ffa_mem_access_common. Both dereference sites take mem_access_size from this function, so the single check covers both.

Comment thread core/arch/arm/kernel/thread_spmc.c Outdated
@anarchyj
anarchyj force-pushed the anarchyj-patch-2 branch 3 times, most recently from 65ffe80 to ebc1b3d Compare August 26, 2026 10:38
Comment thread core/arch/arm/kernel/spmc_sp_handler.c Outdated
Comment thread core/arch/arm/kernel/thread_spmc.c
@anarchyj
anarchyj force-pushed the anarchyj-patch-2 branch 2 times, most recently from 8782f5d to 93bd7a2 Compare August 27, 2026 16:24
Comment thread core/arch/arm/kernel/thread_spmc.c
@jenswikl

Copy link
Copy Markdown
Contributor

Reviewed-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>

The endpoint memory access descriptor array in an FF-A memory
transaction is described by mem_access_size, mem_access_count and
mem_access_offs, read from a normal-world (or SP) descriptor.
spmc_read_mem_transaction() checks that the array fits in the fragment
but does not bound mem_access_size from below.

Each array element is dereferenced as struct ffa_mem_access_common by
its users: get_acc_perms(), spmc_sp_add_share(), ffa_mem_retrieve(),
is_sp_op() and thread_spmc_populate_mobj_from_rx(). With mem_access_size
smaller than that structure the array-fit check no longer keeps each
element read in range; with mem_access_size 0 and mem_access_offs equal
to frag_len the read lands past the mapped buffer, an out-of-bounds read
in the SPMC.

Check mem_access_size against sizeof(struct ffa_mem_access_common) in
each user of the descriptor. Also reject mem_access_count 0 in
ffa_mem_retrieve() and thread_spmc_populate_mobj_from_rx(), which
dereference the first descriptor before the count is otherwise checked.

Signed-off-by: Guled Hasan <Law.Zoldyck@proton.me>
Reviewed-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
@anarchyj

Copy link
Copy Markdown
Contributor Author

Applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants