You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is created to track the Stack-based Buffer Overrun Detection (-fstack-protector) suggestion from issue #18671 which included several different build flags.
The basic idea of Stack-based Buffer Overrun Detection building flag is to add a "canary" which is a
random number after the return address in the stack and check its value before returns to make sure it's not altered. Thus it could avoid a lot of stack buffer overflow attacks.
This could introduce more security but also performance lost, mainly because of the check of the canary. So, 3 different modes were provided to control how many functions are covered thus providing the trade off between security and performance. They are:
-fstack-protector
-fstack-protector-all
-fstack-protector-strong.
The -fstack-protector-all mode would affect every function and is not acceptable.
The -fstack-protector protects functions that have a character array of eight bytes or more in length on its stack which seems too restrictive.
The -fstack-protector-strong mode protects more functions than -fstack-protector but not expand to all, so is a balance between -fstack-protector and -fstack-protector-all. Some info can be found here. However it's not supported in clang 3.4.2 (while it seems it's supported from clang 3.5.0 ).
Maybe in future clang baseline increased to >= 3.5.0 we could have a try on -fstack-protector-strong. Currently we could focus on -fstack-protector, and I am taking on the performance test on it to see its impact on performance and would make a PR if the result is acceptable.
The benchmark test result is as follows, I found buffers, string_decoder and url tests are impacted more or less, then I took 30 runs on them.
My machine:
CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz with 4 cores
RAM: 32G
OS: Ubuntu 16.04 LTS
I picked the most significant data from those results:
I did suggest to enable this flag, as linux kernel and chrome also enabled this. Balance security with performance are indeed a trade off. The thing I am wondering is whether this impact can be accepted? If yes I would prepare a PR for that. Thanks.
I didn't take a full benchmark for call cases with 30 runs, that seems too time costing. I just run all of the cases for about 3 runs, then choose the cases that have significant impacts and then I rerun those selected cases with 30 runs.
I even removed some .js files and removed some configs by edit some js files, only focusing on the cases with significant impacts. So you may notice in my result there are few text than normal.
Below is my results, if it's not enough, I could re-run more cases then. :) result of benchmark/buffers:
confidence improvement accuracy (*) (**) (***)
string_decoder/string-decoder.js n=2500000 chunkLen=64 inLen=4096 encoding='utf8' *** -13.45 % ±1.19% ±1.60% ±2.11%
Be aware that when doing many comparisions the risk of a false-positive
result increases. In this case there are 1 comparisions, you can thus
expect the following amount of false-positive results:
0.05 false positives, when considering a 5% risk acceptance (*, **, ***),
0.01 false positives, when considering a 1% risk acceptance (**, ***),
0.00 false positives, when considering a 0.1% risk acceptance (***)
result of benchmark/url:
confidence improvement accuracy (*) (**) (***)
url/whatwg-url-properties.js n=300000 prop='host' input='auth' *** -5.72 % ±1.75% ±2.33% ±3.04%
url/whatwg-url-properties.js n=300000 prop='host' input='dot' *** -7.24 % ±1.29% ±1.72% ±2.24%
url/whatwg-url-properties.js n=300000 prop='host' input='file' 0.63 % ±1.69% ±2.25% ±2.93%
url/whatwg-url-properties.js n=300000 prop='host' input='idn' *** -6.43 % ±1.82% ±2.42% ±3.16%
url/whatwg-url-properties.js n=300000 prop='host' input='javascript' *** -6.57 % ±2.21% ±2.94% ±3.83%
url/whatwg-url-properties.js n=300000 prop='host' input='long' *** -6.05 % ±1.50% ±2.00% ±2.60%
url/whatwg-url-properties.js n=300000 prop='host' input='percent' *** -6.37 % ±1.55% ±2.06% ±2.68%
url/whatwg-url-properties.js n=300000 prop='host' input='short' *** -7.85 % ±1.75% ±2.33% ±3.04%
url/whatwg-url-properties.js n=300000 prop='host' input='ws' *** -5.97 % ±1.87% ±2.49% ±3.25%
Be aware that when doing many comparisions the risk of a false-positive
result increases. In this case there are 9 comparisions, you can thus
expect the following amount of false-positive results:
0.45 false positives, when considering a 5% risk acceptance (*, **, ***),
0.09 false positives, when considering a 1% risk acceptance (**, ***),
0.01 false positives, when considering a 0.1% risk acceptance (***)
Yes, I also noticed some test even have performance improve, quite strange.
I think I may need to double check my build.
As -fstack-protector-strong was not supported in clang 3.4.2, so I used -fstack-protector instead.
this and our disabling of v8's untrusted code mitigations make me wonder if we should add like a "more security" option to our configure which enables these things at the cost of performance.
While, based on latest findings that the '-fstack-protector-strong' was enabled by default in gcc for ubuntu from 14.10 (please ref here). It would be not good to forcefully use the -fstack-protector in node. I would close this issue.
Activity
tingshao commentedon Jun 7, 2018
The benchmark test result is as follows, I found buffers, string_decoder and url tests are impacted more or less, then I took 30 runs on them.
My machine:
CPU: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz with 4 cores
RAM: 32G
OS: Ubuntu 16.04 LTS
I picked the most significant data from those results:
I did suggest to enable this flag, as linux kernel and chrome also enabled this. Balance security with performance are indeed a trade off. The thing I am wondering is whether this impact can be accepted? If yes I would prepare a PR for that. Thanks.
bnoordhuis commentedon Jun 7, 2018
That's a pretty steep performance drop. Can you post the full results?
tingshao commentedon Jun 7, 2018
I didn't take a full benchmark for call cases with 30 runs, that seems too time costing. I just run all of the cases for about 3 runs, then choose the cases that have significant impacts and then I rerun those selected cases with 30 runs.
I even removed some .js files and removed some configs by edit some js files, only focusing on the cases with significant impacts. So you may notice in my result there are few text than normal.
Below is my results, if it's not enough, I could re-run more cases then. :)
result of benchmark/buffers:
result of benchmark/stirng_decoder:
result of benchmark/url:
bnoordhuis commentedon Jun 7, 2018
Odd that two of the buffer benchmarks go up by 6 or 7%.
In general the numbers look pretty bad though. A 1-2% drop might have been acceptable but this probably is not.
This is with identical builds except for
-fstack-protector-strong?tingshao commentedon Jun 8, 2018
Yes, I also noticed some test even have performance improve, quite strange.
I think I may need to double check my build.
As
-fstack-protector-strongwas not supported in clang 3.4.2, so I used-fstack-protectorinstead.devsnek commentedon Jun 8, 2018
this and our disabling of v8's untrusted code mitigations make me wonder if we should add like a "more security" option to our configure which enables these things at the cost of performance.
tingshao commentedon Jun 8, 2018
@devsnek Yes, I also think a config option may be another choice for this kind of changes which is more flexible.
tingshao commentedon Jul 2, 2018
While, based on latest findings that the
'-fstack-protector-strong'was enabled by default in gcc for ubuntu from 14.10 (please ref here). It would be not good to forcefully use the-fstack-protectorin node. I would close this issue.Thanks for providing comments! @bnoordhuis @devsnek