The LEFT_CHILD/RIGHT_CHILD macros used in container.c::smartlist_heapify() can overflow.
This can potentially result in using a negative array index in the smartlist memory block and writing to some out of bounds memory location.
This is probably not currently exploitable, given the limited usage of smartlist_heapify. The places where it is used look hard to control for an attacker and the amount of memory required would likely be too much for Tor to be able to allocate.
Tor should be built with ftrapv. Ticket 17983 looks like a bad idea.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items ...
Show closed items
Linked items 0
Link issues together to show that they're related.
Learn more.
Ticket #17983 (moved) is about building with -ftrapv. Please read the discussion on that ticket.
Good, the ticket description is changed now. It wasn't clear from the discussion that the decision to use ftrapv had been made, in particular with regards to TBB builds.
Ticket #17983 (moved) is about building with -ftrapv. Please read the discussion on that ticket.
Good, the ticket description is changed now. It wasn't clear from the discussion that the decision to use ftrapv had been made, in particular with regards to TBB builds.
#17983 (moved) is for Tor. Please open another ticket against "Tor Browser" if you want it to be built with -ftrapv. Tor Browser is larger, so it could be more difficult. (Getting tor to run when built under -ftrapv involved some work in 2014-2015.)
#17983 (moved) is for Tor. Please open another ticket against "Tor Browser" if you want it to be built with -ftrapv. Tor Browser is larger, so it could be more difficult. (Getting tor to run when built under -ftrapv involved some work in 2014-2015.)
I'm not talking about Firefox. I'm talking about the Tor that's bundled with TBB.
#17983 (moved) is for Tor. Please open another ticket against "Tor Browser" if you want it to be built with -ftrapv. Tor Browser is larger, so it could be more difficult. (Getting tor to run when built under -ftrapv involved some work in 2014-2015.)
I'm not talking about Firefox. I'm talking about the Tor that's bundled with TBB.
Please file a ticket against Tor Browser, as they may need to modify their tor build process, depending on exactly how we implement #17983 (moved).
Have another look at the algorithm? It starts with an idx that possibly violates the heap property by being larger than one or both of its children. If it does, it swaps a child into the current idx, and then looks to see whether the heap property is now violated at the child's old position. If HAS_CHILDREN(idx) is false, it is impossible for idx to have a pair of children -- though hm, when I wake up I should see whether it can have only a single child.
Note also that idx is monotonically increasing here, and it approximately doubles each time through the loop. So at worse we're doing a small number of iterations.
Have another look at the algorithm? It starts with an idx that possibly violates the heap property by being larger than one or both of its children. If it does, it swaps a child into the current idx, and then looks to see whether the heap property is now violated at the child's old position. If HAS_CHILDREN(idx) is false, it is impossible for idx to have a pair of children -- though hm, when I wake up I should see whether it can have only a single child.
If HAS_CHILDREN is false, idx can;t have any children.
Note also that idx is monotonically increasing here, and it approximately doubles each time through the loop. So at worse we're doing a small number of iterations.
That makes more sense.
Should we tor_assert() rather than returning?
I can't understand how returning yields a valid heap.
I can't understand how returning yields a valid heap.
Remember, the only way that the heap property can be invalid is that the value at idx may be larger than one or both of its children. If we reach a value of idx that is too large to have any children, then we know that the heap property cannot be violated.
I've tried to explain things a little better on the branch; does it make more sense now?
/* Largest IDX in the smartlist which might have children whose indices * fit inside an int. * LEFT_CHILD(MAX_PARENT_IDX) == INT_MAX-1; * RIGHT_CHILD(MAX_PARENT_IDX) == INT_MAX; * LEFT_CHILD(MAX_PARENT_IDX + 1) == INT_MAX + 1 // overflow.
Assuming INT_MAX==2147483647, MAX_PARENT_IDX works out to 1073741822. The max left child idx is 2147483645==INT_MAX-2, the max right child idx is 2147483646==INT_MAX-1.
INT_MAX is not a valid index. The maximum list size is INT_MAX, so the maximum valid index is INT_MAX-1.