Skip to content

Reject ftruncate on read-only guest descriptors - #1701

Open
carlosqwqqwq wants to merge 1 commit into
qilingframework:devfrom
carlosqwqqwq:codex/qiling-issue-1687-ftruncate-readonly-20261124
Open

carlosqwqqwq wants to merge 1 commit into
qilingframework:devfrom
carlosqwqqwq:codex/qiling-issue-1687-ftruncate-readonly-20261124

Conversation

@carlosqwqqwq

Copy link
Copy Markdown

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly.
  • Essential comments are added.
  • The reference of the new code is pointed out below.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • This PR doesn't need to update Changelog.
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing

Summary

ftruncate currently resolves the guest descriptor but then truncates its pathname, so an O_RDONLY descriptor can still modify the file. This uses the open descriptor for truncation, making a read-only handle fail without changing the file while preserving truncation through writable handles.

Linux documents EBADF or EINVAL for a descriptor not open for writing and notes that Linux produces EINVAL; the regression test accepts either portable error value and checks that the file contents remain unchanged.

Fixes #1687.

Validation

  • cd tests && PYTHONPATH=.. python3 -m unittest test_syscall_ftruncate_readonly_fd — passed.
  • cd tests && PYTHONPATH=.. python3 test_posix.py TestFtruncateReadonlyFd — passed.
  • Both commands passed in Python 3.11 and Python 3.13 containers.

Reference

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.

1 participant