-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix
]: integer overflow in JumpTable.SubStr
#3496
base: HF_Echidna
Are you sure you want to change the base?
Conversation
JumpTable.SubStr
Fix
]: integer overflow in JumpTable.SubStr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shargon why isn't there a vm limit in this
"0x0a", | ||
"0x00010203040506070809", | ||
"PUSHINT32", | ||
"0x7FFFFFFF", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also add some tests for INT64, like:
byte(opcode.PUSHINT64), 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F,
byte(opcode.PUSH2),
It'll fail (in NeoGo it's at instruction 22 (SUBSTR): not an int32
), but just to make sure.
Rebase needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need a HF, previously could be a DoS but not difference in the execution. Isn't it? @roman-khimov
That's the question of "can we arrange a set of parameters that would fail with the new code, but succeed with the old one". This requires some probing. I'm not exactly sure of I'd include it into Echidna for safety reasons, but if we can prove it can't be exploited to change execution result then OK, it can go without a HF. |
I agree. Don't need a HF |
16a9c29
to
0457ccd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If doesn't use HF should go to master
it was merged with hardfork prs,,,,lets discuss it in the meeting. |
This is the already the default behavior in dotnet https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/language#checkforoverflowunderflow |
|
my bad -- integral-type |
/// <param name="instruction">The instruction being executed.</param> | ||
/// <remarks>Pop 3, Push 1</remarks> | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private static void VulnerableSubStr(ExecutionEngine engine, Instruction instruction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is not required, but you think that it is, here is the solution, jump table allow it :)
@@ -399,13 +407,42 @@ internal override void UnloadContext(ExecutionContext context) | |||
/// <returns>The engine instance created.</returns> | |||
public static ApplicationEngine Create(TriggerType trigger, IVerifiable container, DataCache snapshot, Block persistingBlock = null, ProtocolSettings settings = null, long gas = TestModeGas, IDiagnostic diagnostic = null) | |||
{ | |||
var index = persistingBlock?.Index ?? NativeContract.Ledger.CurrentIndex(snapshot); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shargon
Object reference not set to an instance of an object.
on test Neo.UnitTests.SmartContract.UT_NotifyEventArgs.TestIssue3300
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Snapshot is null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be snapshot
or GetInteroperable<HashIndexState>()
neo/src/Neo/SmartContract/Native/LedgerContract.cs
Lines 119 to 122 in eb96d14
public uint CurrentIndex(DataCache snapshot) | |
{ | |
return snapshot[CreateStorageKey(Prefix_CurrentBlock)].GetInteroperable<HashIndexState>().Index; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If is snapshot we can return 0, otherwise we should fix the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work for CurrentIndex
?
snapshot?[CreateStorageKey(Prefix_CurrentBlock)]?.GetInteroperable<HashIndexState>()?.Index ?? 0;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not change the logic in native contracts for this
.gitignore
Outdated
# UT coverage report | ||
/coverages | ||
**/.DS_Store | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a dupe of the above lines. please remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a dupe of the above lines. please remove it.
I’ll remove it later
Description
Fix integer overflow in
JumpTable.SubStr
Fixes #3495
Type of change
Checklist: