Skip to content
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

Invalid order of calculation - cmpxchg #18

Open
mfaerevaag opened this issue Aug 23, 2017 · 0 comments
Open

Invalid order of calculation - cmpxchg #18

mfaerevaag opened this issue Aug 23, 2017 · 0 comments

Comments

@mfaerevaag
Copy link
Collaborator

mfaerevaag commented Aug 23, 2017

Description

When executing cmpxchg, the semantics for comparison is accumulator minus destination operand, but they are switched.

Reference:
Ref. Intel 64 and IA-32 Architecture Software Developer's Manual Vol. 2A 3-181

Affected instructions:

0x0fb100    #cmpxchg

Reproduction guide

Instruction:

00000000  0FB100            cmpxchg [eax],eax

Input:

binsec disasm -decode 0fb100

Observed output:

                   ⎧ 0: res32 := (@[eax₍₃₂₎]₄ - eax₍₃₂₎)
                   ⎪ 1: OF := ((@[eax₍₃₂₎]₄{31} ≠ eax₍₃₂₎{31}) && (@[eax₍₃₂₎]₄{31} ≠ res32₍₃₂₎{31}))
                   ⎪ 2: SF := (res32₍₃₂₎ <𝒔 0₍₃₂₎)
                   ⎪ 3: ZF := (res32₍₃₂₎ = 0₍₃₂₎)
                   ⎪ 4: AF := (@[eax₍₃₂₎]₄{0,7} <𝒖 eax₍₃₂₎{0,7})
                   ⎪ 5: PF := ¬(((((((res32₍₃₂₎{0} ⨁ res32₍₃₂₎{1}) ⨁ res32₍₃₂₎{2}) ⨁ res32₍₃₂₎{3}) ⨁ res32₍₃₂₎{4}) ⨁ res32₍₃₂₎{5}) ⨁ res32₍₃₂₎{6}) ⨁ res32₍₃₂₎{7})
cmpxchg [eax], eax ⎨ 6: CF := (@[eax₍₃₂₎]₄ <𝒖 eax₍₃₂₎)
                   ⎪ 7: if (eax₍₃₂₎ = @[eax₍₃₂₎]₄) goto 10 else goto 8
                   ⎪ 8: eax := @[eax₍₃₂₎]₄
                   ⎪ 9: goto 11 
                   ⎪10: @[eax₍₃₂₎]₄ := eax₍₃₂₎
                   ⎩11: goto ({0x00000003; 32}, 0)

Expected output:
Correct order of operands during calculation.

System Info

OS:

# uname -a
Linux ubuntu 4.10.0-28-generic #32-Ubuntu SMP Fri Jun 30 05:32:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=17.04
DISTRIB_CODENAME=zesty
DISTRIB_DESCRIPTION="Ubuntu 17.04"

BINSEC: 20170301 0.1

@soomin-kim soomin-kim changed the title Invalid order of execution - cmpxchg Invalid order of calculation - cmpxchg Sep 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant