Skip to content

Js math taint propagation#3

Closed
alexbara2000 wants to merge 15 commits into
tmbrbr:primitaint-mergefrom
alexbara2000:JSMathTaint
Closed

Js math taint propagation#3
alexbara2000 wants to merge 15 commits into
tmbrbr:primitaint-mergefrom
alexbara2000:JSMathTaint

Conversation

@alexbara2000

Copy link
Copy Markdown

Added taint propagation for the JSMath builtin library.
Added tests for the JSMath builtin library propagation.

@alexbara2000 alexbara2000 changed the base branch from main to primitaint-merge August 1, 2024 21:21
@leeN

leeN commented Aug 2, 2024

Copy link
Copy Markdown

First of all: Thanks for contributing to foxhound!

I had a cursory look at the changes, and they look fine. What's slightly unclear to me is the intention behind these changes. Could you provide some examples of JavaScript code that does not propagate taints if one uses the primitaint-merge HEAD vs. your changes?
That would be fantastic :)
You probably spoke with Tom about this during a call, but for reference, it might be useful to spell this out here again.

@alexbara2000

Copy link
Copy Markdown
Author

Yes of course, I will provide a bit more information about the changes. Javascript has a builtin library called Math which gives users access to math functions like Math.round(x). Since this library is builtin, it needs to be defined in the JS engine which in the case of Firefox it can be found in js/src/jsmath.cpp.

The issue was that this builtin library was not taint aware meaning that any JS code that uses it would loose it's taint. The simplest example is if you have the following statement var a = Math.round(b). Before these changes, if b was tainted, a would not be tainted. The tests that I created are examples of operations that would loose their taint.

This pull request solves this issue by making the whole math library taint aware. Math library is where you can find all the methods that are part of the math library which I have made taint aware. I can also give a more low level explanation of the changes I made if needed.

@leeN

leeN commented Aug 2, 2024

Copy link
Copy Markdown

Ah, interesting, thank you! That makes a ton of sense :)

I wonder how this might have impacted the fp-tracer study, as max/min/round seem fairly common operations heh.

Comment thread js/src/jsmath.cpp Outdated
Comment thread js/src/jsmath.cpp Outdated
NumberObject *taintedResult = NumberObject::create(cx, 0);
bool isTainted = false;

if(isTaintedNumber(lhs)){

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Another thing I noticed - I think a lot of this code can be replaced by a call to JS::getAnyNumberTaint in jstaint.cpp.

Have a look at e.g. the AddOperation in Interpreter-inl.h for an example how this is done.

I have recently (last week!) updated the logic for combining two taint flows together so that in principle both parents in the taint flow are saved. If you use the getAnyNumberTaint call then all of this will be taken in account automatically.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

PS - you might need to update your branch to the HEAD of primitaint-merge to get the latest changes.

leeN and others added 5 commits August 5, 2024 12:15
In this branch properties of WebIDL files can be marked as taint
sources with an attribute. This is super nice, but if one wants to
disable one of them one has to note down their names during a build.
This is pretty cumbersome. This commit tries to resolve this issue,
as it simply adds every IDL based source to the properties
defaults.
tmbrbr pushed a commit that referenced this pull request Sep 5, 2025
…hrow)`. r=firefox-build-system-reviewers,sergesanspaille,sylvestre

Unfortunately, GCC-14 appears to be generating this warning due to its own
frontend/codegen [interactions?].

This is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85783, which was
WONTFIX'd. Comment #3 admits:
> The excessive constant argument is introduced by the C++ front-end, in
> cp/build_operator_new_call(), which emits a call to operator new[](size_t).
> The code was added in r190546 as a solution to prevent unsigned wrapping
> (when array new expression must compute the amount of space to allocate as a
> product of the number of elements and element size).  When the replacement
> operator new[] is inlined the excessive argument is propagated to malloc()
> and ultimately triggers the warning.

Differential Revision: https://phabricator.services.mozilla.com/D239424
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.

4 participants