Skip to content

Commit

Permalink
Fix future version compatibility
Browse files Browse the repository at this point in the history
In case kernel folks will ever release capability v4, the chances are
high v3 is still supported. Therefore, we should not error out upon
seeing an unknown version from the kernel, but assume we can go with v3.

While at it, treat the uninitialized capVers as an error. Before this
patch, it was still treated as an error, but "unknown capability version"
is not exactly what the error is, so let's be more specific.

Reported-by: Andrei Vagin <avagin@google.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jul 22, 2024
1 parent e946f33 commit 5584105
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions capability_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"syscall"
)

var errUnknownVers = errors.New("unknown capability version")

const (
linuxCapVer1 = 0x19980330
linuxCapVer2 = 0x20071026
Expand Down Expand Up @@ -100,19 +98,21 @@ func mkString(c Capabilities, max CapType) (ret string) {

func newPid(pid int) (c Capabilities, err error) {
switch capVers {
case 0:
err = errors.New("unable to get capability version from the kernel")
case linuxCapVer1:
p := new(capsV1)
p.hdr.version = capVers
p.hdr.pid = int32(pid)
c = p
case linuxCapVer2, linuxCapVer3:
default:
// linuxCapVer2, linuxCapVer3, or an unknown/future version such as v4.
// In the latter case, we fall back to v3 hoping the kernel is
// backward-compatible to v3.
p := new(capsV3)
p.hdr.version = capVers
p.hdr.pid = int32(pid)
c = p
default:
err = errUnknownVers
return
}
return
}
Expand Down

0 comments on commit 5584105

Please sign in to comment.