Skip to content

transfer taint with memcpy #1574

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

Merged
merged 2 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions regression/goto-analyzer-taint-ansi-c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
default: tests.log

test:
@../test.pl -p -c ../../../src/goto-analyzer/goto-analyzer

tests.log: ../test.pl
@../test.pl -p -c ../../../src/goto-analyzer/goto-analyzer

show:
@for dir in *; do \
if [ -d "$$dir" ]; then \
vim -o "$$dir/*.java" "$$dir/*.out"; \
fi; \
done;

clean:
find -name '*.out' -execdir $(RM) '{}' \;
find -name '*.gb' -execdir $(RM) '{}' \;
$(RM) tests.log
15 changes: 15 additions & 0 deletions regression/goto-analyzer-taint-ansi-c/taint-memcpy1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <string.h>

void my_f(void *) { }
void my_h(void *) { }

void my_function()
{
void *o1;
my_f(o1); // T1 source

void *o2;
memcpy(o2, o1, 100);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be accompanied by a suitable #include

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the 100 important here? I don't know if this makes sense but perhaps a test where 0 is used to check it doesn't remove taint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Potentially removing taint is an issue.


my_h(o2); // T1 sink
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
{ "id": "my_f", "kind": "source", "where": "parameter1", "taint": "T1", "function": "my_f" },
{ "id": "my_h", "kind": "sink", "where": "parameter1", "taint": "T1", "function": "my_h", "message": "There is a T1 flow" }
]
7 changes: 7 additions & 0 deletions regression/goto-analyzer-taint-ansi-c/taint-memcpy1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.o
--taint taint.json
^EXIT=0$
^SIGNAL=0$
^file main.c line 12( function .*)?: There is a T1 flow \(taint rule my_h\)$
--
13 changes: 13 additions & 0 deletions src/analyses/custom_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,19 @@ void custom_bitvector_domaint::transform(
}
}
}
else if(identifier=="memcpy" ||
identifier=="memmove")
{
if(code_function_call.arguments().size()==3)
{
// we copy all tracked bits from op1 to op0
// we do not consider any bits attached to the size op2
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now the analysis only tracks taint on pointers, but the size is an integer.

dereference_exprt lhs_deref(code_function_call.arguments()[0]);
dereference_exprt rhs_deref(code_function_call.arguments()[1]);

assign_struct_rec(from, lhs_deref, rhs_deref, cba, ns);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on why we're ignoring the non-3-op case?

Copy link
Member Author

Choose a reason for hiding this comment

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

memmove: yes.
memset is harder; this might remove taint, but you'd have to make sure that the entire data structure is overwritten.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, forget memset

}
else
{
goto_programt::const_targett next=from;
Expand Down