Fix - Restrict address space of sysvar syscalls in SIMD-0219#7832
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #7832 +/- ##
=======================================
Coverage 83.0% 83.0%
=======================================
Files 808 808
Lines 356264 356270 +6
=======================================
+ Hits 296013 296044 +31
+ Misses 60251 60226 -25 🚀 New features to boost your workflow:
|
| // Storing the result of get_sysvar() in the input region is not allowed | ||
| // because of the 16 byte alignment requirement of the EpochRewards sysvar. |
There was a problem hiding this comment.
Shouldn't this comment say it's not allowed because it's strictly forbidden by the restrictions?
There was a problem hiding this comment.
And the reason why it is forbidden is the alignment requirement. So, the comment just skips the middle.
There was a problem hiding this comment.
I thought the whole point was to disallow aliasing of account memory regions as stack space? SIMD-0219 doesn't list EpochRewards sysvar alignment as the motivation.
There was a problem hiding this comment.
No, there can not be aliasing of account regions and the stack region anyway because we don't do overlapping memory layouts. The SIMD says that these pointers must be in the stack or heap regions (thus implicitly can not be in the account regions).
Yes, I can add the alignment requirement as a motivation for forbidding sysvar syscalls from writing to the account regions in the SIMD. Currently it only mentions the restriction, not the reason for its existence.
|
Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis. |
* Restrict address space of sysvar syscalls as well (similar to CPI). * Adds a test for the new restriction. (cherry picked from commit 2581e3f)
Problem
ABI v1 aligns the account input region to 8 bytes. Direct mapping however uses the account data allocations which align to at least 16 bytes. Syscalls check the host alignment of translated pointers. This means that syscalls which require a 16 byte alignment suddenly pass the alignment check even if their virtual address is only divisible by 8 but not 16. Currently, only the sysvars syscall has a 16 byte alignment requirement. Thus, preventing that from accessing the account input section masks this behavior.
The SDK uses the stack as destination except for the generic
get_sysvar()syscall, which could have the account input region as destination. Also, see section "Syscall parameters" in SIMD-0219.Summary of Changes
Restricts the
var_addrparameter of all sysvar syscalls whenstricter_abi_and_runtime_constraintsis active.