-
Notifications
You must be signed in to change notification settings - Fork 18k
x/vuln: govulncheck hangs when collecting stacks of all runtime
usages
#60708
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
Comments
runtime
usages
runtime
usagesruntime
usages
cc @zpavlinovic |
I don't think I'm the only one with this problem, I think it will also be present with old go 1.20 (but I cannot test now) |
@golang/vulndb |
Thanks for reporting this. Indeed, govulncheck tries to find the "best" call stack for each reachable vulnerable symbol for better user experience. It does so by choosing from all "representative" call stacks of a symbol. If there are a lot of reachable vulnerable symbols, computing all representative call stacks for each such symbol might take time. We should probably introduce some heuristic, in the lines of what you described, to counter examples such as GO-2023-1840 where all symbols of a package are deemed vulnerable, which should not happen too often. |
Change https://go.dev/cl/504155 mentions this issue: |
Change https://go.dev/cl/504715 mentions this issue: |
Call stacks going through standard library were designated as more likely to be true positive, i.e., we have more confidence in them. This does not seem to have a firm footing. If the call stack consists of static calls, then the vulnerable symbol is a std symbol, in which case comparison to other call stacks boils down to length comparison (which we do) since standard library packages import only standard library packages. Otherwise if the call stacks have dynamic call sites, there is no reason to believe that a callee of a dynamic site is more likely to be correctly inferred compared to a dynamic site outside of the standard library. Updates golang/go#60708 Change-Id: Ib8cdd778ccf8902f5e42473fe145e452d28f3960 Reviewed-on: https://go-review.googlesource.com/c/vuln/+/504715 Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
Feel free to re-open the issue if the problem persists. We couldn't verify if it solves the problem on your code, but it did for another large project we considered. |
What version of Go are you using (
go version
)?Does this issue reproduce at the latest version of golang.org/x/vuln?
Yes
What operating system and processor architecture are you using (
go env
)?Darwin
What did you do?
I have a rather big project.
I was using go 1.19.9. Then, this vulnerability was published
https://pkg.go.dev/vuln/GO-2023-1840
When I run
govulncheck ./...
, it eats 8 cores for 5 minutes.That is not normal. Go vulncheck should not take that much longer than code build. When before this vuln, it took seconds.
I know that I am using an old go version, which I did not notice. But then govulncheck should warn me, not hang.
Below is the actual issue in the govulncheck code.
When doing pprof, I figured out it's collecting all the traces where any function from
runtime
was used, and spending all the time on sorting slices.The issue is at
func CallStacks(res *Result) map[*Vuln][]CallStack {
It seems that the
for _, vuln := range res.Vulns {
is run 2052 times, and for each one, there is about 50000 of them for each.When I made a small adjustment to the code, it fixed it instantly. That is, in witness.go - https://go.googlesource.com/vuln/+/refs/heads/master/internal/vulncheck/witness.go , instead of
I added (very dumb)
it worked well.
I think govulncheck is trying to get all the usages of all
runtime
functions, which then tries to somehow sort thousands of call stacks over and over. (2000 times getting and sorting 50.000 call stacks, I guess)The simple fix is to just limit how many stacks will this collect. As the user still sees just 27 stacks....
What did you expect to see?
See above
What did you see instead?
See above
The text was updated successfully, but these errors were encountered: