Skip to content

Conversation

@gitoleg
Copy link
Contributor

@gitoleg gitoleg commented Aug 14, 2018

The root of the problem was the rooter, which was producing roots that were pointing in the middle of an instruction. Since the disassembler was cutting a block on the start of each root this led to an incorrect CFG with non-connected components.

It's fine for a rooter to produce such garbage, however, the disassembler shall not take rooter's output as granted. The new implementation keeps track of the set of addresses that start valid instructions and once this set is fully discovered removes those roots that do not belong to this set.

Some significant problems can happen if one of our rooters give
us some wrong roots. We can even miss instructions and build a
wrong cfg. So this PR removes wrong roots on the early stages
of the disassembler, so they don't influence of the late ones.
Copy link
Member

@ivg ivg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the proposed algorithm looks insufficient and it will still allow invalid roots to pass through the stage1.

Why can't we just after stage 1 is completed remove all initial roots that didn't prove to be valid?

Also, does this removal play nice with the case when we have several code segments?

addr : addr;
visited : Span.t;
visited : Span.t;
insns : Addr.Set.t;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misleading name, let's name it valid instead

| r :: roots when Span.mem s.visited r ->
loop {s with roots}
if Set.mem s.insns r then loop {s with roots}
else loop {s with roots; inits = Set.remove s.inits r}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will remove an invalid root only in case if we have discovered that it is invalid before we extract it from the worklist. Since the worklist is an unordered sequence, this won't work in general.

@gitoleg
Copy link
Contributor Author

gitoleg commented Aug 14, 2018

speaking about several segments case, this removal plays nice, just because the roots from other segment are not taking in account even without these changes.

@gitoleg gitoleg assigned ivg and unassigned gitoleg Aug 14, 2018
@ivg ivg changed the title Removes wrong roots between stages of diasasm fixes the bug that was producing unreachable blocks Aug 15, 2018
@ivg ivg merged commit 0c05c80 into BinaryAnalysisPlatform:master Aug 15, 2018
@gitoleg gitoleg deleted the removes-wrong-roots branch October 10, 2018 13:05
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

Successfully merging this pull request may close these issues.

2 participants