Commit Graph

7 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
2ac9968401
replace uses of os/exec with golang.org/x/sys/execabs
Go 1.15.7 contained a security fix for CVE-2021-3115, which allowed arbitrary
code to be executed at build time when using cgo on Windows. This issue also
affects Unix users who have “.” listed explicitly in their PATH and are running
“go get” outside of a module or with module mode disabled.

This issue is not limited to the go command itself, and can also affect binaries
that use `os.Command`, `os.LookPath`, etc.

From the related blogpost (ttps://blog.golang.org/path-security):

> Are your own programs affected?
>
> If you use exec.LookPath or exec.Command in your own programs, you only need to
> be concerned if you (or your users) run your program in a directory with untrusted
> contents. If so, then a subprocess could be started using an executable from dot
> instead of from a system directory. (Again, using an executable from dot happens
> always on Windows and only with uncommon PATH settings on Unix.)
>
> If you are concerned, then we’ve published the more restricted variant of os/exec
> as golang.org/x/sys/execabs. You can use it in your program by simply replacing

This patch replaces all uses of `os/exec` with `golang.org/x/sys/execabs`. While
some uses of `os/exec` should not be problematic (e.g. part of tests), it is
probably good to be consistent, in case code gets moved around.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-25 18:11:09 +02:00
Sebastiaan van Stijn
3d20fa9309
fix TestSetOOMScoreBoundaries
(this was introduced in 44240116aa)

Setting the oom-score-adj to -1000 is only possible if the parent process
either has no score set, or if the score is set to -1000.

However, the current implementation of GetOOMScoreAdj conflates situations
where either _no_ oom-score is set, _or_ oom-score is set, but set to 0.

In the latter case, the test would fail:

    --- FAIL: TestSetOOMScoreBoundaries (0.01s)
        oom_linux_test.go:79: assertion failed: 0 (adjustment int) != -1000 (OOMScoreAdjMin int)
    FAIL

To prevent failures in this situation, skip that part of the test in the
above situation.

Also update the description of GetOOMScoreAdj to clarify its behavior.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-08 13:14:04 +02:00
Sebastiaan van Stijn
44240116aa
sys: add boundary checks to SetOOMScore()
Produce a more user-friendly error in the odd case we would try to set a
score out of range

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:55 +02:00
Sebastiaan van Stijn
ace1912bba
sys: use assert for error checks in OOM tests
Slightly easier to read, and we were already using assert in this file

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:53 +02:00
Sebastiaan van Stijn
6e72715226
sys: add missing pre-condition checks in tests
SetOOMScore requires both privileged (root) and non-user namespace,
for negative values, so adjust the pre-conditions accordingly.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:51 +02:00
Sebastiaan van Stijn
badd60d3f6
sys: un-export runningPrivileged(), remove runningUnprivileged()
These are currently only used inside this package, so we might
as well un-export them until we need them elsewhere.

Also updated SetOOMScore() to first check for privileged; check for privileged
looks to be the "faster" path, and checking it first could (in case of non-
privileged) save having to read and parse /proc/self/uid_map.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-04-07 19:16:49 +02:00
Maksym Pavlenko
eb7c7c71e2 Fix oom tests on non Linux
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-03-23 11:57:24 -07:00