Skip to content
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

Fails to parse go stdlib version when experiments are set #1851

Open
jonjohnsonjr opened this issue May 8, 2024 · 5 comments
Open

Fails to parse go stdlib version when experiments are set #1851

jonjohnsonjr opened this issue May 8, 2024 · 5 comments
Labels
bug Something isn't working false-negative good-first-issue Good for newcomers

Comments

@jonjohnsonjr
Copy link

What happened:

grype ghcr.io/projectcontour/contour
 ✔ Vulnerability DB                [no update available]
 ✔ Loaded image                                                                                                                                                                                                                                                                                                                    ghcr.io/projectcontour/contour:latest
 ✔ Parsed image                                                                                                                                                                                                                                                                                  sha256:3538357182affbd790c9ecaffc62c3022d8e2cc46816eaa8a8fb8acb1a82ad8b
 ✔ Cataloged contents                                                                                                                                                                                                                                                                                   bd7b5d7ab8063fa560c1164fbfea7cb4d6b90cc61b534bc2720f34f80d18db18
   ├── ✔ Packages                        [73 packages]
   └── ✔ Executables                     [1 executables]
 ✔ Scanned for vulnerabilities     [0 vulnerability matches]
   ├── by severity: 0 critical, 0 high, 0 medium, 0 low, 0 negligible
   └── by status:   0 fixed, 0 not-fixed, 0 ignored
[0000]  WARN could not match by package language (package=Pkg(type=go-module, name=stdlib, version=go1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2, upstreams=0)): matcher failed to parse version pkg="stdlib" ver="go1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2": Malformed version: 1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2
No vulnerabilities found

What you expected to happen:

Not see this warning:

[0000] WARN could not match by package language (package=Pkg(type=go-module, name=stdlib, version=go1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2, upstreams=0)): matcher failed to parse version pkg="stdlib" ver="go1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2": Malformed version: 1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2

How to reproduce it (as minimally and precisely as possible):

grype ghcr.io/projectcontour/contour

Anything else we need to know?:

This seems to be not well documented, but I found a reference to it here: https://cs.opensource.google/go/go/+/master:src/runtime/extern.go;l=340-348?q=%22X:%22%20experiment%20list&ss=go%2Fgo:src%2F

syft ghcr.io/projectcontour/contour | grep stdlib
 ✔ Loaded image                                                                                                                                                                                                                                                                                                                    ghcr.io/projectcontour/contour:latest
 ✔ Parsed image                                                                                                                                                                                                                                                                                  sha256:3538357182affbd790c9ecaffc62c3022d8e2cc46816eaa8a8fb8acb1a82ad8b
 ✔ Cataloged contents                                                                                                                                                                                                                                                                                   bd7b5d7ab8063fa560c1164fbfea7cb4d6b90cc61b534bc2720f34f80d18db18
   ├── ✔ Packages                        [73 packages]
   └── ✔ Executables                     [1 executables]
stdlib                                              go1.22.2 X:nocoverageredesign,noallocheaders,noexectracer2  go-module

Environment:

  • Output of grype version:
grype version
Application:         grype
Version:             [not provided]
BuildDate:           [not provided]
GitCommit:           [not provided]
GitDescription:      [not provided]
Platform:            darwin/arm64
GoVersion:           go1.22.0
Compiler:            gc
Syft Version:        v1.3.0
Supported DB Schema: 5

(I am running at HEAD.)

  • OS (e.g: cat /etc/os-release or similar):

MacOS 14.4.1

@jonjohnsonjr jonjohnsonjr added the bug Something isn't working label May 8, 2024
@spiffcs spiffcs added the good-first-issue Good for newcomers label May 9, 2024
@tgerla
Copy link
Contributor

tgerla commented May 9, 2024

Hi @jonjohnsonjr, thanks for the report! It looks like today we take that field as-is but we need to probably parse out the flags after the X:. We might need to find a place to record those flags somewhere. We'll put this in the backlog for a fix. Let us know if you're interested in working on it and we can help get you started.

@luhring
Copy link
Contributor

luhring commented May 10, 2024

Just adding an explicit note that this causes false negatives, too. The Go stdlib usually accounts for a large surface area in vuln-matching a Go binary, so situations where Grype doesn't take the stdlib into account would mean missing any number of vulns if Go experiments are used. Also IIUC there are worlds where using Go experiments is much more common, such as to support FIPS.

@jonjohnsonjr
Copy link
Author

Let us know if you're interested in working on it and we can help get you started.

I can take a stab at it if you can point me in the approximate direction 🙏

@willmurphyscode
Copy link
Contributor

Hi @jonjohnsonjr, thanks for offering to help with this!

The code changes to make are really in Syft. Essentially, Syft should make 2 changes:

  1. The metadata Syft emits about Go packages should include what experiments are enabled, so that this information isn't lost
  2. Syft should trim the stdlib / go version to a valid semver version (remove the space and everything after.)

The definition of the Go package metadata is here: https://github.com/anchore/syft/blob/6107e5e2ad6e60f3f74ff4d3b2ca2ccffbed26ed/syft/pkg/golang.go#L4 - this definition likely needs new fields to hold information about the experiments, and then they need to be populated.

The function that scans the go binary for build info and other information is here: https://github.com/anchore/syft/blob/3023a5a7bc870f70a3dd24213d795516288ca0df/syft/pkg/cataloger/golang/scan_binary.go#L22 - I'm not certain exactly the right factoring for where we should trim the version info and capture the metadata, but this function is in the neighborhood.

Happy to discuss further! Please let me know if you have any questions.

@jonjohnsonjr
Copy link
Author

Opened a PR in syft: anchore/syft#2893

I'm honestly not sure how necessary it is given that grype seemed to find the CVEs associated with stdlib even without my "fix", but maybe you'd have a better idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working false-negative good-first-issue Good for newcomers
Projects
Status: Ready
Development

No branches or pull requests

5 participants