Skip to content

core: tee_ree_fs: fix handling of large file offsets - #7925

Merged
jenswikl merged 2 commits into
OP-TEE:masterfrom
ysbnim:fix_ree_fs
Aug 20, 2026
Merged

core: tee_ree_fs: fix handling of large file offsets#7925
jenswikl merged 2 commits into
OP-TEE:masterfrom
ysbnim:fix_ree_fs

Conversation

@ysbnim

@ysbnim ysbnim commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

This ensures that REE FS handles large files correctly on both 32-bit and 64-bit builds.

On 64-bit builds, logical file positions above INT_MAX exceeded the range of int used by pos_to_block_num(), causing incorrect block numbers. Use size_t for file position and block number calculations.

On 32-bit builds, physical backing file offsets above 4 GiB exceeded the range of size_t and wrapped around. Calculate these offsets using 64-bit arithmetic and carry them as tee_fs_off_t through the read, write, and truncate RPC interfaces.

@ysbnim

ysbnim commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

This solves issues similar to those addressed in OP-TEE/optee_client#422

Comment thread core/tee/tee_ree_fs.c Outdated
Comment thread core/tee/tee_ree_fs.c Outdated
@ysbnim
ysbnim force-pushed the fix_ree_fs branch 2 times, most recently from 2f7df9d to 5f50be6 Compare August 14, 2026 05:09
@jenswikl

Copy link
Copy Markdown
Contributor

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

ysbnim added 2 commits August 14, 2026 21:06
REE FS supports file positions up to TEE_DATA_MAX_POSITION (0xffffffff),
but pos_to_block_num() accepted int. Positions above INT_MAX
(0x7fffffff) were narrowed when converted to block numbers.

Use size_t for the conversion and block numbers in the read and write
paths.

Fixes: a238b74 ("core: REE FS: use the new hash tree interface")
Signed-off-by: Sungbae Yoo <sungbaey@nvidia.com>
Reviewed-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
REE FS backing file offsets can exceed 4 GiB within the valid logical
position range. However, get_offs_size() stored physical offsets in
size_t.

On 32-bit builds, offsets above SIZE_MAX (0xffffffff) therefore wrapped
before being passed to the 64-bit read and write RPC interface.
The truncate length could wrap in the same way.

Calculate physical offsets with 64-bit arithmetic and carry them as
tee_fs_off_t through read, write, and truncate RPC requests.

Fixes: a238b74 ("core: REE FS: use the new hash tree interface")
Signed-off-by: Sungbae Yoo <sungbaey@nvidia.com>
Reviewed-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
@ysbnim

ysbnim commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Gentle reminder. Attached reviewed-by tags.

@jenswikl
jenswikl merged commit 9ed0cb0 into OP-TEE:master Aug 20, 2026
58 checks passed
@ysbnim
ysbnim deleted the fix_ree_fs branch August 20, 2026 13:03
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