Skip to content

fix(platform): guard against unverified CPU architectures - #95

Merged
namanONcode merged 1 commit into
namanONcode:masterfrom
aaditya-dakhore:fix/linux-arch-guard
Oct 12, 2026
Merged

namanONcode merged 1 commit into
namanONcode:masterfrom
aaditya-dakhore:fix/linux-arch-guard

Conversation

@aaditya-dakhore

@aaditya-dakhore aaditya-dakhore commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

The Linux runtime currently verifies that the operating system is Linux but does not verify that the CPU architecture is supported.

The native struct layouts used by zThread's Linux implementation are verified for x86_64. Running on an unverified architecture may result in incorrect native memory interpretation and unsafe runtime behavior.

The runtime should fail fast with a clear ConfigurationException when the CPU architecture has not been verified.

Motivation

Failing safely is preferable to allowing the runtime to use an unverified native struct layout that could cause memory corruption or incorrect event handling.

This is a defensive safety fix. It does not add AArch64 support; support for additional architectures is tracked separately in #96.

Changes

  • Add Platform.ensureSupportedArchitecture() to reject unverified CPU architectures.
  • Invoke the architecture guard from LinuxRuntimeFactory.
  • Add unit tests for supported and unsupported architecture values.
  • Update CHANGELOG.md.

Testing

  • Unit tests added/updated.
  • Integration tests added/updated.
  • All tests pass (./mvnw clean verify) on Kali Linux x86_64.
  • Quality checks pass (./mvnw verify -Pquality).

Note: The prescribed quality profile encountered a Google Java Format version incompatibility with JDK 25. The separate Checkstyle, PMD, and SpotBugs checks completed successfully.

Checklist

  • Code follows Google Java Style (run ./mvnw spotless:apply).
  • Javadoc added for public APIs.
  • No breaking changes (the unsupported-architecture behavior is documented above).
  • CHANGELOG.md updated.

StructLayouts hardcodes the epoll_event struct as a 12-byte packed
layout, which is only correct on x86_64 - the Linux kernel's own
eventpoll.h applies the packed attribute solely when __x86_64__ is
defined. On other 64-bit architectures (aarch64 included) the real
layout is 16 bytes, so running there would silently misread events,
including via raw kernel writes into a buffer sized for the wrong
struct - outside anything the FFM API's bounds checking can catch.

Platform.ensureLinux() only checked the OS, not the architecture,
and the existing isAarch64()/isX8664() detection methods were never
actually called anywhere at runtime.

Add Platform.ensureSupportedArchitecture(), called from
LinuxRuntimeFactory right after the existing OS check, so unsupported
architectures fail fast with a clear ConfigurationException instead
of silently corrupting memory. Covered by new PlatformTest cases and
noted in the changelog.

Ref: ZT-01 in the earlier code review.
@namanONcode

Copy link
Copy Markdown
Owner

@aaditya-dakhore raise issue first then continue

@aaditya-dakhore

Copy link
Copy Markdown
Contributor Author

Closes #97

@namanONcode namanONcode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all changes are approved

@namanONcode
namanONcode enabled auto-merge October 12, 2026 10:11
@namanONcode
namanONcode self-requested a review October 12, 2026 10:11
@namanONcode
namanONcode disabled auto-merge October 12, 2026 10:11
@namanONcode
namanONcode merged commit dab3006 into namanONcode:master Oct 12, 2026
3 checks passed
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