x86_64: fix near jump check#352
Conversation
|
It looks like a valid issue. It is interesting if this is never caused any issues before. Testing: code space is usually allocated above the 4GB area, so if you jump to a static function, it is > 2GB jump. |
|
I think the original code used the "worst" value for both directions. When you jump backwards, (instr_addr + 6)-MAX_NEGATIVE_DISTANCE limits the jump, and when you jump forward, (instr_addr + 5)+MAX_POSITIVE_DISTANCE limits the jump regardless of jcc/jmp types. Maybe the two numbers (+5 and +6) were accidentally swapped. The proposed change is better anyway. Another question is whether <= and >= could be used. |
or Vol. 2A 3-496~497, Manuals for Intel® 64 and IA-32 Architectures So, for
We donot use |
| sljit_s32 short_jump; | ||
| sljit_uw label_addr; | ||
| sljit_uw jump_addr; | ||
| sljit_uw rel_size; |
There was a problem hiding this comment.
Probably you need to add #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) arond this as well.
|
I understand the concept. I was just thinking how the old code worked. Since this is really just 1-2 bytes we loose from 4GB range, probably the effect was little. Range inverting can have side effects as well, since INT_MIN and -INT_MIN is the same. |
Seems a bug around x86-64 near jump/far jump check.
Problem: In
detect_near_jump_type,the x86-64 boundary check uses
+6for the upper bound and+5for the lower bound regardless of jump type:sljit/sljit_src/sljitNativeX86_common.c
Lines 694 to 699 in acf9f8f
This mixes
jccandjmplengths and only rejects cases where both forms are out of range.Impact: Edge cases where only one near jump form is out of range are allowed to pass.
If the emitted instruction is
jmp/call(5-byte rel32) orjcc(6-byte rel32) andits displacement is out-of-range, later patching asserts or incorrect displacement can occur.
xref: range check in
reduce_code_sizesljit/sljit_src/sljitNativeX86_common.c
Lines 858 to 873 in acf9f8f
But I'm not sure how to add a test for this issue.
background
Found by downstream project: digitalgust/miniJVM
When build with win64,
sljitwill crash with "Assertion failed at ..\minijvm\c\utils\sljit\sljitNativeX86_common.c:777"sljit/sljit_src/sljitNativeX86_common.c
Line 777 in acf9f8f