Skip to content

Commit 081a741

Browse files
committed
oracle: omit ksplice-related vulnerabilities
Signed-off-by: Brad Lugo <[email protected]>
1 parent 5139ad3 commit 081a741

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

oracle/parser.go

+40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/quay/claircore"
1313
"github.com/quay/claircore/internal/xmlutil"
1414
"github.com/quay/claircore/libvuln/driver"
15+
"github.com/quay/claircore/pkg/cpe"
1516
"github.com/quay/claircore/pkg/ovalutil"
1617
)
1718

@@ -71,6 +72,45 @@ func (u *Updater) Parse(ctx context.Context, r io.ReadCloser) ([]*claircore.Vuln
7172
if len(vs) == 0 {
7273
return nil, fmt.Errorf("could not determine dist")
7374
}
75+
76+
// Check if the vulnerability only affects a userspace_ksplice package.
77+
// These errata should never be applied to a container since ksplice
78+
// userspace packages are not supported to be run within a container.
79+
// If we couldn't find a CPE list, make sure to include the
80+
// vulnerability. We'd rather have false positives for
81+
// userspace_ksplice packages than have false negatives for
82+
// *everything*.
83+
isOnlyKsplice := len(def.Advisory.AffectedCPEList) > 0
84+
// If there's at least one ksplice CPE and not all the affected CPEs
85+
// are ksplice related, this will cause false positives we can catch.
86+
// This should (almost) never happen.
87+
atLeastOneKsplice := false
88+
for _, affected := range def.Advisory.AffectedCPEList {
89+
wfn, err := cpe.Unbind(affected)
90+
if err != nil {
91+
// Found a CPE but could not parse it. Assume it's not a
92+
// userspace_ksplice package.
93+
zlog.Warn(ctx).Str("cpe", affected).Msg("could not parse CPE")
94+
isOnlyKsplice = false
95+
atLeastOneKsplice = true
96+
break
97+
}
98+
if wfn.Attr[cpe.Edition].V == "userspace_ksplice" {
99+
atLeastOneKsplice = true
100+
} else {
101+
isOnlyKsplice = false
102+
}
103+
}
104+
105+
if !isOnlyKsplice {
106+
// This should (almost) never happen.
107+
if atLeastOneKsplice {
108+
zlog.Warn(ctx).Str("def.Title", def.Title).Msg("potential false positives: vulnerability has at least one unskippable ksplice match")
109+
}
110+
} else {
111+
return nil, fmt.Errorf("skippable ksplice vulnerabilities")
112+
}
113+
74114
return vs, nil
75115
}
76116
vulns, err := ovalutil.RPMDefsToVulns(ctx, &root, protoVulns)

oracle/parser_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestParse(t *testing.T) {
2525
t.Fatal(err)
2626
}
2727
t.Logf("found %d vulnerabilities", len(vs))
28-
if got, want := len(vs), 6065; got != want {
28+
if got, want := len(vs), 6021; got != want {
2929
t.Fatalf("got: %d vulnerabilities, want: %d vulnerabilities", got, want)
3030
}
3131
}

0 commit comments

Comments
 (0)