Skip to content

Commit bfa97f7

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

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

oracle/parser.go

Lines changed: 41 additions & 0 deletions
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,46 @@ 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 there's at least one ksplice CPE and not all the affected CPEs
80+
// are ksplice related, this will cause false positives we can catch.
81+
// This should rarely happen; the most common case for this is if one
82+
// of the CPEs wasn't parseable.
83+
kspliceCPEs := 0
84+
cpes := len(def.Advisory.AffectedCPEList)
85+
for _, affected := range def.Advisory.AffectedCPEList {
86+
wfn, err := cpe.Unbind(affected)
87+
if err != nil {
88+
// Found a CPE but could not parse it. Log a warning and return
89+
// successfully.
90+
zlog.Warn(ctx).
91+
Str("def_title", def.Title).
92+
Str("cpe", affected).
93+
Msg("could not parse CPE: there may be a false positive match with a userspace_ksplice package")
94+
return vs, nil
95+
}
96+
if wfn.Attr[cpe.Edition].V == "userspace_ksplice" {
97+
kspliceCPEs++
98+
}
99+
}
100+
101+
switch diff := cpes - kspliceCPEs; {
102+
case cpes == 0:
103+
// Continue if there are no CPEs.
104+
case diff == 0:
105+
zlog.Debug(ctx).Msg("skipping userspace_ksplice vulnerabilities")
106+
return nil, nil
107+
case diff > 0:
108+
zlog.Warn(ctx).
109+
Str("def_title", def.Title).
110+
Msg("potential false positives: OVAL may have a userspace_ksplice CPE which could not be skipped")
111+
default:
112+
panic("programmer error")
113+
}
114+
74115
return vs, nil
75116
}
76117
vulns, err := ovalutil.RPMDefsToVulns(ctx, &root, protoVulns)

oracle/parser_test.go

Lines changed: 1 addition & 1 deletion
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)