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

casting from number to unsigned can cause in x86_32 mode have 64bit size offset #35

Closed
StarGazerM opened this issue Sep 10, 2021 · 3 comments

Comments

@StarGazerM
Copy link

StarGazerM commented Sep 10, 2021

Hi:
When I am reading souffle code in src/datalog/value_analysis.dl.

// mov DWORD from memory
value_reg_edge(EA,Reg,EA,"NONE",0,Val):-
    def_used_for_address(EA,Reg),
    arch.move_operation(Operation),
    instruction(EA,_,_,Operation,Op1,Op2,0,0,_,_),
    op_regdirect_contains_reg(Op2,Reg),
    op_indirect(Op1,"NONE","NONE","NONE",_,Offset,32),
    Offset_addr = as(Offset,address),                                           // here
    data_byte(Offset_addr,Byte0),
    data_byte(Offset_addr+1,Byte1),
    data_byte(Offset_addr+2,Byte2),
    data_byte(Offset_addr+3,Byte3),
    Byte3 <= 128,
    Val = as(Byte3*2^24+ Byte2*2^16 + Byte1*2^8 + Byte0,number).

I found in line 123, a variable has type number is casted to address(unsigned). ddisasm require enable 64bit domain when compiling souffle, so this casting will always make Offset_addr become a u64 address even when handling 32bit binary. For example, -1 will be converted into 18446744073709551615, while in 32bit mode it should be 4294967295.

Yihao

@aeflores
Copy link
Collaborator

Hi Yihao, I think you might be right. In this case, we should restrict the rule to only positive offsets. I'll make a fix.

@aeflores
Copy link
Collaborator

this is fixed now a51fb7b

@StarGazerM
Copy link
Author

StarGazerM commented Sep 21, 2021

This is not the only every places, every conversion from sign to unsigned number can cause overflow, if possible could you kindly check all datalog code base for pattern as\(.+,address\). I searched on repo there are a lot of possible overflow places. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants