Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Enforce host aligned memory for program regions #16590

Merged
merged 2 commits into from
Apr 20, 2021

Conversation

jackcmay
Copy link
Contributor

Problem

Depending on the Rust allocator the memory-mapped into the program space could be miss-aligned.

Summary of Changes

  • Ensure that memory-mapped into the program space is aligned
  • Enforce that host addresses used within syscalls are aligned

This change is wip because it depends on the release of rbpf with: solana-labs/rbpf#154

Fixes #

@jackcmay jackcmay added work in progress This isn't quite right yet noCI Suppress CI on this Pull Request and removed noCI Suppress CI on this Pull Request work in progress This isn't quite right yet labels Apr 16, 2021
@jackcmay jackcmay force-pushed the enforce-aligned-host_addrs branch from d32c5a9 to 0ccb93d Compare April 16, 2021 23:02
@jackcmay jackcmay requested a review from Lichtso April 19, 2021 18:55
@codecov
Copy link

codecov bot commented Apr 19, 2021

Codecov Report

Merging #16590 (0c64f27) into master (2409bb1) will decrease coverage by 0.0%.
The diff coverage is 50.2%.

@@            Coverage Diff            @@
##           master   #16590     +/-   ##
=========================================
- Coverage    83.0%    83.0%   -0.1%     
=========================================
  Files         415      415             
  Lines      114881   114999    +118     
=========================================
+ Hits        95436    95462     +26     
- Misses      19445    19537     +92     

@jackcmay jackcmay force-pushed the enforce-aligned-host_addrs branch from 4cb6704 to 7eb149f Compare April 19, 2021 20:42
@jackcmay jackcmay removed the v1.5 label Apr 19, 2021
@Lichtso
Copy link
Contributor

Lichtso commented Apr 20, 2021

As you are about to bump the RBPF version please re-enable the code here too:

// TODO: Reenable when solana_rbpf is bumped to "0.2.8" or higher

Copy link
Contributor

@Lichtso Lichtso left a comment

Choose a reason for hiding this comment

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


if enforce_aligned_host_addrs
&& loader_id != &bpf_loader_deprecated::id()
&& (host_addr as *mut T).align_offset(align_of::<T>()) != 0
Copy link
Contributor

Choose a reason for hiding this comment

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

// Text search anchor so that it is easier to find: solana_rbpf = "=0.2.7"
// memory_mapping.resize_region::<BpfError>(0, 1).unwrap();
// assert!(translate_type::<Instruction>(&memory_mapping, 100, &bpf_loader::id()).is_err());
memory_mapping.resize_region::<BpfError>(0, 1).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

@jackcmay jackcmay merged commit 08d5253 into solana-labs:master Apr 20, 2021
@jackcmay jackcmay deleted the enforce-aligned-host_addrs branch April 20, 2021 18:07
mergify bot pushed a commit that referenced this pull request Apr 20, 2021
(cherry picked from commit 08d5253)

# Conflicts:
#	cli/Cargo.toml
#	programs/bpf/Cargo.toml
#	programs/bpf/benches/bpf_loader.rs
#	programs/bpf/tests/programs.rs
#	programs/bpf_loader/Cargo.toml
#	programs/bpf_loader/src/lib.rs
mergify bot added a commit that referenced this pull request Apr 21, 2021
…6683)

* Enforce host aligned memory for program regions (#16590)

(cherry picked from commit 08d5253)

# Conflicts:
#	cli/Cargo.toml
#	programs/bpf/Cargo.toml
#	programs/bpf/benches/bpf_loader.rs
#	programs/bpf/tests/programs.rs
#	programs/bpf_loader/Cargo.toml
#	programs/bpf_loader/src/lib.rs

* fix conflicts

Co-authored-by: Jack May <jack@solana.com>
@brooksprumo brooksprumo mentioned this pull request Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants