2n part of ICryptoTransform.#1054
Conversation
Detecting potential unsafe usage (object shared across multiple threads) on variables captured by Lambda
calumgrant
left a comment
There was a problem hiding this comment.
Hi Raul, Many thanks for your contribution, we really appreciate it. I've made a few minor suggestions, but my main request is whether we could also extend this query to cover other ways of creating threads, in particular, Parallel.Invoke. Thanks again for your work.
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.qhelp
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
...y-tests/Likely Bugs/ThreadUnsafeICryptoTransformLambda/ThreadUnsafeICryptoTransformLambda.cs
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
Thanks a lot. I covered |
Please let em know if this pattern works, and I can add other mechanisms to start new threads with a shared object. Please also let me know what other mechanisms would you like me to add, I would like to focus on the most commonly used ones first. Thanks
|
Please also let me know what other mechanisms would you like me to add, I would like to focus on the most commonly used ones first. Thanks |
|
Good to have this extra coverage of and so on for the other cases. Then they can be combined into one configuration, thus This is exactly the same logic that you had before, but just removing the duplicate parts and abstracting them into The big idea is that we'll probably want to add more parallel sinks in future, and even move the For now, we can keep them in the query file until we need to reuse them. Does this make sense? |
jf205
left a comment
There was a problem hiding this comment.
Hi @raulgarciamsft.
I have two very minor comments about the query metadata that would be good to fix.
The qhelp documentation LGTM.
Thanks.
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
csharp/ql/src/Likely Bugs/ThreadUnsafeICryptoTransformLambda.ql
Outdated
Show resolved
Hide resolved
Fixing bugs from code review.
|
I added 2 QLL libraries, one for |
…com/raulgarciamsft/ql into users/raulga/ICryptoTransformLambda
|
Thanks for fixing the typos 👍 |
calumgrant
left a comment
There was a problem hiding this comment.
Awesome. One last thing. I'm not sure we want to tailor the error message for each different sink type - ultimately the lambda is run concurrently using a variety of ways to kick off a thread. If this is the case, then perhaps we could merge the two configurations into one, and then the isSink predicate would look like
override predicate isSink(DataFlow::Node sink) {
sink instanceof ParallelSink
or
exists( DelegateCreation dc, Expr e |
e = sink.asExpr() |
dc.getArgument() = e
and dc.getType().getName().matches("%Start")
)
}
Then we can make the further refactoring by moving exists( DelegateCreation dc, Expr e | e = this.asExpr() | dc.getArgument() = e and dc.getType().getName().matches("%Start") ) into ParallelSink.qll as an additional class:
class ThreadStartParallelSink extends ParallelSink {
ThreadStartParallelSink() {
exists( DelegateCreation dc, Expr e |
e = sink.asExpr() |
dc.getArgument() = e
and dc.getType().getName().matches("%Start")
)
}
}
If you really wanted to tailor the error message, then it could be a predicate on class ParallelSink.
The reason for this comment, is that we don't normally use several data flow configurations in one query.
Another quite minor thing, is that you could consider turning this query into a "path query" - but this is completely optional.
calumgrant
left a comment
There was a problem hiding this comment.
Thanks, Raul. LGTM, merging.
Detecting potential unsafe usage (object shared across multiple threads) on variables captured by Lambda