-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-27315 Add timeout to JavaRegexEngine #4720
base: master
Are you sure you want to change the base?
Conversation
💔 -1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
|
||
@Override | ||
public char charAt(int index) { | ||
final long diff = EnvironmentEdgeManager.currentTime() - startMillis; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is a bit tricky... And will this slow down the normal process? As we will do a System.currentTimeMillis call every time when we want to get a char...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Apache9
Thank you for your review.
I've heard that ReDoS is caused by backtracking.
Therefore, I considered adding RE2J as a new engine to prevent ReDoS.
(RE2J does not use backtracking.)
However, in the case of RE2J, the syntax and results were slightly different from the existing engines.
I couldn't have confidence if it was okay to add a RE2J engine.
so I looked for an alternative other than adding a RE2J engine.
For the Java Regex engine, I founded that the engine call charAt method every time.
Java Regex engine does not provide a timeout feature, but it seemed that it could be implemented (anomalously) with charAt.
I considered checking the timeout with additional Threads.
However, I felt that running additional Threads was a waste of resources.
When monitored the internal cluster, no large overhead was found due to System.currentTimeMillis calls in the pattern matching operation.
(There may be some overhead, of course.)
By default, TimeoutCharSequence is not used, so most HBase users are unlikely to be affected by System.currentTimeMillis overhead.
I wanted to provide a way to solve the ReDoS.
If there is another good way, I would like to get some advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Apache9
I changed to not call System.currentTimeMillis every time.
Could you please check this PR again?
💔 -1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
@@ -255,11 +258,20 @@ static interface Engine { | |||
* This is the default engine. | |||
*/ | |||
static class JavaRegexEngine implements Engine { | |||
private static final Configuration conf = HBaseConfiguration.create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we find a way to pass this Configuration in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Apache9
I think it is possible.
RSRpcService
pass configuration to ProtobufUtil
.
hbase/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RSRpcServices.java
Line 2456 in f27823e
Get clientGet = ProtobufUtil.toGet(get); |
->
Get clientGet = ProtobufUtil.toGet(get, regionServer.conf);
ProtobufUtil#toComparator
pass configuration to ByteArrayComparable
when calling parseFrom method.
hbase/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java
Line 1559 in f27823e
return (ByteArrayComparable) parseFrom.invoke(null, value); |
->
public static ByteArrayComparable toComparator(ComparatorProtos.Comparator proto, Configuration conf) {
return (ByteArrayComparable)parseFrom.invoke(null, value, conf);
}
I'll try to make the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To pass configurations to RegexStringComparator, a new class ConfigurationHolder was created. It holds the configuration as a member variable. When HMaster and HRegionserver are started, it registers itself as an observer to the ConfigurationManager.
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
778b2ac
to
16968a7
Compare
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
💔 -1 overall
This message was automatically generated. |
Add timeout to JavaRegexEngine to prevent ReDoS.
https://issues.apache.org/jira/browse/HBASE-27315