News for hackers. Stuff that matters.
Re:Vulnerability Management for Go by biomcgary on Tuesday September 06, 2022 @02:51PM (#32741493)
This seems like a lot of work to identify the vulnerable functions that are called transitively. Could this work be reused to perform tree-shaking, so that Go only compiles the code you actually need? (Or, does Go already do this at compilation?)
Re:Vulnerability Management for Go by adonovan on Tuesday September 06, 2022 @04:58PM (#32743119)
govulncheck builds a static approximation of the call graph using Variable Type Analysis (VTA), which dynamically tabulates the set of interface method calls and the set of concrete types that each interface value may hold, to discover the set of functions potentially reachable from main. (VTA is a refinement of Rapid Type Analysis (RTA), which holds only one set of concrete types for all interface values in the whole program.) The result should be more precise than the linker.

See:

- https://pkg.go.dev/golang.org/x/tools/go/callgraph/vta

- https://pkg.go.dev/golang.org/x/tools/go/callgraph/rta

Re:Vulnerability Management for Go by lukax on Tuesday September 06, 2022 @03:24PM (#32742004)
Go is a compiled language that uses a linker which means that only the functions that are called end up in the final binary. So yes, go does "tree-shaking".
Re:Vulnerability Management for Go by jrockway on Tuesday September 06, 2022 @04:33PM (#32742836)
It's important to read the caveats: https://github.com/golang/go/blob/master/src/cmd/link/intern..., the most important of which is:

  // The third case is handled by looking to see if any of:
  //   - reflect.Value.Method or MethodByName is reachable
  //   - reflect.Type.Method or MethodByName is called (through the
  //     REFLECTMETHOD attribute marked by the compiler).
  //
  // If any of these happen, all bets are off and all exported methods
  // of reachable types are marked reachable.
Basically, if you do certain kinds of reflection, then more code is theoretically reachable and will be included in your binary. In practice, you end up with a large binary in anything that calls into autogenerated APIs.
Re:Vulnerability Management for Go by biomcgary on Thursday September 08, 2022 @01:35PM (#32768870)
That is a useful clarification. It seems to explain why the use of the fmt Go's std lib formatting and printing package, seems to pull in so much. Surely, it is performing a fair amount of reflection under the hood.
Re:Vulnerability Management for Go by barsonme on Thursday September 08, 2022 @02:38PM (#32770011)
The fmt package should not put the compiler into conservative mode. If it does, file a bug report.
Re:Vulnerability Management for Go by tucnak on Wednesday September 07, 2022 @12:44AM (#32746400)
The autogenerated APIs aren't something as prevalent as one may think.