vendor: update github.com/opencontainers/runc
when the systemd cgroup manager is used, controllers not handled by systemd are created manually afterwards. libcontainer didn't correctly cleanup these cgroups that were leaked on cgroup v1. Closes: https://github.com/kubernetes/kubernetes/issues/92766 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
168
vendor/github.com/cilium/ebpf/prog.go
generated
vendored
168
vendor/github.com/cilium/ebpf/prog.go
generated
vendored
@@ -3,18 +3,16 @@ package ebpf
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/cilium/ebpf/asm"
|
||||
"github.com/cilium/ebpf/internal"
|
||||
"github.com/cilium/ebpf/internal/btf"
|
||||
"github.com/cilium/ebpf/internal/unix"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
// ErrNotSupported is returned whenever the kernel doesn't support a feature.
|
||||
@@ -48,11 +46,24 @@ type ProgramOptions struct {
|
||||
type ProgramSpec struct {
|
||||
// Name is passed to the kernel as a debug aid. Must only contain
|
||||
// alpha numeric and '_' characters.
|
||||
Name string
|
||||
Type ProgramType
|
||||
AttachType AttachType
|
||||
Instructions asm.Instructions
|
||||
License string
|
||||
Name string
|
||||
// Type determines at which hook in the kernel a program will run.
|
||||
Type ProgramType
|
||||
AttachType AttachType
|
||||
// Name of a kernel data structure to attach to. It's interpretation
|
||||
// depends on Type and AttachType.
|
||||
AttachTo string
|
||||
Instructions asm.Instructions
|
||||
|
||||
// License of the program. Some helpers are only available if
|
||||
// the license is deemed compatible with the GPL.
|
||||
//
|
||||
// See https://www.kernel.org/doc/html/latest/process/license-rules.html#id1
|
||||
License string
|
||||
|
||||
// Version used by tracing programs.
|
||||
//
|
||||
// Deprecated: superseded by BTF.
|
||||
KernelVersion uint32
|
||||
|
||||
// The BTF associated with this program. Changing Instructions
|
||||
@@ -84,9 +95,10 @@ type Program struct {
|
||||
// otherwise it is empty.
|
||||
VerifierLog string
|
||||
|
||||
fd *internal.FD
|
||||
name string
|
||||
abi ProgramABI
|
||||
fd *internal.FD
|
||||
name string
|
||||
abi ProgramABI
|
||||
attachType AttachType
|
||||
}
|
||||
|
||||
// NewProgram creates a new Program.
|
||||
@@ -107,8 +119,8 @@ func NewProgramWithOptions(spec *ProgramSpec, opts ProgramOptions) (*Program, er
|
||||
}
|
||||
|
||||
handle, err := btf.NewHandle(btf.ProgramSpec(spec.BTF))
|
||||
if err != nil && !xerrors.Is(err, btf.ErrNotSupported) {
|
||||
return nil, xerrors.Errorf("can't load BTF: %w", err)
|
||||
if err != nil && !errors.Is(err, btf.ErrNotSupported) {
|
||||
return nil, fmt.Errorf("can't load BTF: %w", err)
|
||||
}
|
||||
|
||||
return newProgramWithBTF(spec, handle, opts)
|
||||
@@ -152,7 +164,7 @@ func newProgramWithBTF(spec *ProgramSpec, btf *btf.Handle, opts ProgramOptions)
|
||||
}
|
||||
|
||||
err = internal.ErrorWithLog(err, logBuf, logErr)
|
||||
return nil, xerrors.Errorf("can't load program: %w", err)
|
||||
return nil, fmt.Errorf("can't load program: %w", err)
|
||||
}
|
||||
|
||||
// NewProgramFromFD creates a program from a raw fd.
|
||||
@@ -162,7 +174,7 @@ func newProgramWithBTF(spec *ProgramSpec, btf *btf.Handle, opts ProgramOptions)
|
||||
// Requires at least Linux 4.11.
|
||||
func NewProgramFromFD(fd int) (*Program, error) {
|
||||
if fd < 0 {
|
||||
return nil, xerrors.New("invalid fd")
|
||||
return nil, errors.New("invalid fd")
|
||||
}
|
||||
bpfFd := internal.NewFD(uint32(fd))
|
||||
|
||||
@@ -185,15 +197,15 @@ func newProgram(fd *internal.FD, name string, abi *ProgramABI) *Program {
|
||||
|
||||
func convertProgramSpec(spec *ProgramSpec, handle *btf.Handle) (*bpfProgLoadAttr, error) {
|
||||
if len(spec.Instructions) == 0 {
|
||||
return nil, xerrors.New("Instructions cannot be empty")
|
||||
return nil, errors.New("Instructions cannot be empty")
|
||||
}
|
||||
|
||||
if len(spec.License) == 0 {
|
||||
return nil, xerrors.New("License cannot be empty")
|
||||
return nil, errors.New("License cannot be empty")
|
||||
}
|
||||
|
||||
if spec.ByteOrder != nil && spec.ByteOrder != internal.NativeEndian {
|
||||
return nil, xerrors.Errorf("can't load %s program on %s", spec.ByteOrder, internal.NativeEndian)
|
||||
return nil, fmt.Errorf("can't load %s program on %s", spec.ByteOrder, internal.NativeEndian)
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(make([]byte, 0, len(spec.Instructions)*asm.InstructionSize))
|
||||
@@ -222,7 +234,7 @@ func convertProgramSpec(spec *ProgramSpec, handle *btf.Handle) (*bpfProgLoadAttr
|
||||
|
||||
recSize, bytes, err := btf.ProgramLineInfos(spec.BTF)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("can't get BTF line infos: %w", err)
|
||||
return nil, fmt.Errorf("can't get BTF line infos: %w", err)
|
||||
}
|
||||
attr.lineInfoRecSize = recSize
|
||||
attr.lineInfoCnt = uint32(uint64(len(bytes)) / uint64(recSize))
|
||||
@@ -230,13 +242,23 @@ func convertProgramSpec(spec *ProgramSpec, handle *btf.Handle) (*bpfProgLoadAttr
|
||||
|
||||
recSize, bytes, err = btf.ProgramFuncInfos(spec.BTF)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("can't get BTF function infos: %w", err)
|
||||
return nil, fmt.Errorf("can't get BTF function infos: %w", err)
|
||||
}
|
||||
attr.funcInfoRecSize = recSize
|
||||
attr.funcInfoCnt = uint32(uint64(len(bytes)) / uint64(recSize))
|
||||
attr.funcInfo = internal.NewSlicePointer(bytes)
|
||||
}
|
||||
|
||||
if spec.AttachTo != "" {
|
||||
target, err := resolveBTFType(spec.AttachTo, spec.Type, spec.AttachType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if target != nil {
|
||||
attr.attachBTFID = target.ID()
|
||||
}
|
||||
}
|
||||
|
||||
return attr, nil
|
||||
}
|
||||
|
||||
@@ -278,7 +300,7 @@ func (p *Program) Clone() (*Program, error) {
|
||||
|
||||
dup, err := p.fd.Dup()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("can't clone program: %w", err)
|
||||
return nil, fmt.Errorf("can't clone program: %w", err)
|
||||
}
|
||||
|
||||
return newProgram(dup, p.name, &p.abi), nil
|
||||
@@ -288,8 +310,8 @@ func (p *Program) Clone() (*Program, error) {
|
||||
//
|
||||
// This requires bpffs to be mounted above fileName. See http://cilium.readthedocs.io/en/doc-1.0/kubernetes/install/#mounting-the-bpf-fs-optional
|
||||
func (p *Program) Pin(fileName string) error {
|
||||
if err := bpfPinObject(fileName, p.fd); err != nil {
|
||||
return xerrors.Errorf("can't pin program: %w", err)
|
||||
if err := internal.BPFObjPin(fileName, p.fd); err != nil {
|
||||
return fmt.Errorf("can't pin program: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -313,7 +335,7 @@ func (p *Program) Close() error {
|
||||
func (p *Program) Test(in []byte) (uint32, []byte, error) {
|
||||
ret, out, _, err := p.testRun(in, 1, nil)
|
||||
if err != nil {
|
||||
return ret, nil, xerrors.Errorf("can't test program: %w", err)
|
||||
return ret, nil, fmt.Errorf("can't test program: %w", err)
|
||||
}
|
||||
return ret, out, nil
|
||||
}
|
||||
@@ -332,12 +354,12 @@ func (p *Program) Test(in []byte) (uint32, []byte, error) {
|
||||
func (p *Program) Benchmark(in []byte, repeat int, reset func()) (uint32, time.Duration, error) {
|
||||
ret, _, total, err := p.testRun(in, repeat, reset)
|
||||
if err != nil {
|
||||
return ret, total, xerrors.Errorf("can't benchmark program: %w", err)
|
||||
return ret, total, fmt.Errorf("can't benchmark program: %w", err)
|
||||
}
|
||||
return ret, total, nil
|
||||
}
|
||||
|
||||
var haveProgTestRun = internal.FeatureTest("BPF_PROG_TEST_RUN", "4.12", func() bool {
|
||||
var haveProgTestRun = internal.FeatureTest("BPF_PROG_TEST_RUN", "4.12", func() (bool, error) {
|
||||
prog, err := NewProgram(&ProgramSpec{
|
||||
Type: SocketFilter,
|
||||
Instructions: asm.Instructions{
|
||||
@@ -348,28 +370,23 @@ var haveProgTestRun = internal.FeatureTest("BPF_PROG_TEST_RUN", "4.12", func() b
|
||||
})
|
||||
if err != nil {
|
||||
// This may be because we lack sufficient permissions, etc.
|
||||
return false
|
||||
return false, err
|
||||
}
|
||||
defer prog.Close()
|
||||
|
||||
fd, err := prog.fd.Value()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Programs require at least 14 bytes input
|
||||
in := make([]byte, 14)
|
||||
attr := bpfProgTestRunAttr{
|
||||
fd: fd,
|
||||
fd: uint32(prog.FD()),
|
||||
dataSizeIn: uint32(len(in)),
|
||||
dataIn: internal.NewSlicePointer(in),
|
||||
}
|
||||
|
||||
_, err = internal.BPF(_ProgTestRun, unsafe.Pointer(&attr), unsafe.Sizeof(attr))
|
||||
err = bpfProgTestRun(&attr)
|
||||
|
||||
// Check for EINVAL specifically, rather than err != nil since we
|
||||
// otherwise misdetect due to insufficient permissions.
|
||||
return !xerrors.Is(err, unix.EINVAL)
|
||||
return !errors.Is(err, unix.EINVAL), nil
|
||||
})
|
||||
|
||||
func (p *Program) testRun(in []byte, repeat int, reset func()) (uint32, []byte, time.Duration, error) {
|
||||
@@ -411,19 +428,19 @@ func (p *Program) testRun(in []byte, repeat int, reset func()) (uint32, []byte,
|
||||
}
|
||||
|
||||
for {
|
||||
_, err = internal.BPF(_ProgTestRun, unsafe.Pointer(&attr), unsafe.Sizeof(attr))
|
||||
err = bpfProgTestRun(&attr)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if xerrors.Is(err, unix.EINTR) {
|
||||
if errors.Is(err, unix.EINTR) {
|
||||
if reset != nil {
|
||||
reset()
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
return 0, nil, 0, xerrors.Errorf("can't run test: %w", err)
|
||||
return 0, nil, 0, fmt.Errorf("can't run test: %w", err)
|
||||
}
|
||||
|
||||
if int(attr.dataSizeOut) > cap(out) {
|
||||
@@ -439,7 +456,7 @@ func (p *Program) testRun(in []byte, repeat int, reset func()) (uint32, []byte,
|
||||
|
||||
func unmarshalProgram(buf []byte) (*Program, error) {
|
||||
if len(buf) != 4 {
|
||||
return nil, xerrors.New("program id requires 4 byte value")
|
||||
return nil, errors.New("program id requires 4 byte value")
|
||||
}
|
||||
|
||||
// Looking up an entry in a nested map or prog array returns an id,
|
||||
@@ -460,10 +477,12 @@ func (p *Program) MarshalBinary() ([]byte, error) {
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
// Attach a Program to a container object fd
|
||||
// Attach a Program.
|
||||
//
|
||||
// Deprecated: use link.RawAttachProgram instead.
|
||||
func (p *Program) Attach(fd int, typ AttachType, flags AttachFlags) error {
|
||||
if fd < 0 {
|
||||
return xerrors.New("invalid fd")
|
||||
return errors.New("invalid fd")
|
||||
}
|
||||
|
||||
pfd, err := p.fd.Value()
|
||||
@@ -471,20 +490,26 @@ func (p *Program) Attach(fd int, typ AttachType, flags AttachFlags) error {
|
||||
return err
|
||||
}
|
||||
|
||||
attr := bpfProgAlterAttr{
|
||||
targetFd: uint32(fd),
|
||||
attachBpfFd: pfd,
|
||||
attachType: uint32(typ),
|
||||
attachFlags: uint32(flags),
|
||||
attr := internal.BPFProgAttachAttr{
|
||||
TargetFd: uint32(fd),
|
||||
AttachBpfFd: pfd,
|
||||
AttachType: uint32(typ),
|
||||
AttachFlags: uint32(flags),
|
||||
}
|
||||
|
||||
return bpfProgAlter(_ProgAttach, &attr)
|
||||
return internal.BPFProgAttach(&attr)
|
||||
}
|
||||
|
||||
// Detach a Program from a container object fd
|
||||
// Detach a Program.
|
||||
//
|
||||
// Deprecated: use link.RawDetachProgram instead.
|
||||
func (p *Program) Detach(fd int, typ AttachType, flags AttachFlags) error {
|
||||
if fd < 0 {
|
||||
return xerrors.New("invalid fd")
|
||||
return errors.New("invalid fd")
|
||||
}
|
||||
|
||||
if flags != 0 {
|
||||
return errors.New("flags must be zero")
|
||||
}
|
||||
|
||||
pfd, err := p.fd.Value()
|
||||
@@ -492,21 +517,20 @@ func (p *Program) Detach(fd int, typ AttachType, flags AttachFlags) error {
|
||||
return err
|
||||
}
|
||||
|
||||
attr := bpfProgAlterAttr{
|
||||
targetFd: uint32(fd),
|
||||
attachBpfFd: pfd,
|
||||
attachType: uint32(typ),
|
||||
attachFlags: uint32(flags),
|
||||
attr := internal.BPFProgDetachAttr{
|
||||
TargetFd: uint32(fd),
|
||||
AttachBpfFd: pfd,
|
||||
AttachType: uint32(typ),
|
||||
}
|
||||
|
||||
return bpfProgAlter(_ProgDetach, &attr)
|
||||
return internal.BPFProgDetach(&attr)
|
||||
}
|
||||
|
||||
// LoadPinnedProgram loads a Program from a BPF file.
|
||||
//
|
||||
// Requires at least Linux 4.11.
|
||||
func LoadPinnedProgram(fileName string) (*Program, error) {
|
||||
fd, err := bpfGetObject(fileName)
|
||||
fd, err := internal.BPFObjGet(fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -514,7 +538,7 @@ func LoadPinnedProgram(fileName string) (*Program, error) {
|
||||
name, abi, err := newProgramABIFromFd(fd)
|
||||
if err != nil {
|
||||
_ = fd.Close()
|
||||
return nil, xerrors.Errorf("can't get ABI for %s: %w", fileName, err)
|
||||
return nil, fmt.Errorf("can't get ABI for %s: %w", fileName, err)
|
||||
}
|
||||
|
||||
return newProgram(fd, name, abi), nil
|
||||
@@ -540,7 +564,7 @@ func SanitizeName(name string, replacement rune) string {
|
||||
//
|
||||
// Returns ErrNotExist, if there is no next eBPF program.
|
||||
func ProgramGetNextID(startID ProgramID) (ProgramID, error) {
|
||||
id, err := objGetNextID(_ProgGetNextID, uint32(startID))
|
||||
id, err := objGetNextID(internal.BPF_PROG_GET_NEXT_ID, uint32(startID))
|
||||
return ProgramID(id), err
|
||||
}
|
||||
|
||||
@@ -548,7 +572,7 @@ func ProgramGetNextID(startID ProgramID) (ProgramID, error) {
|
||||
//
|
||||
// Returns ErrNotExist, if there is no eBPF program with the given id.
|
||||
func NewProgramFromID(id ProgramID) (*Program, error) {
|
||||
fd, err := bpfObjGetFDByID(_ProgGetFDByID, uint32(id))
|
||||
fd, err := bpfObjGetFDByID(internal.BPF_PROG_GET_FD_BY_ID, uint32(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -570,3 +594,29 @@ func (p *Program) ID() (ProgramID, error) {
|
||||
}
|
||||
return ProgramID(info.id), nil
|
||||
}
|
||||
|
||||
func resolveBTFType(name string, progType ProgramType, attachType AttachType) (btf.Type, error) {
|
||||
kernel, err := btf.LoadKernelSpec()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't resolve BTF type %s: %w", name, err)
|
||||
}
|
||||
|
||||
type match struct {
|
||||
p ProgramType
|
||||
a AttachType
|
||||
}
|
||||
|
||||
target := match{progType, attachType}
|
||||
switch target {
|
||||
case match{Tracing, AttachTraceIter}:
|
||||
var target btf.Func
|
||||
if err := kernel.FindType("bpf_iter_"+name, &target); err != nil {
|
||||
return nil, fmt.Errorf("can't resolve BTF for iterator %s: %w", name, err)
|
||||
}
|
||||
|
||||
return &target, nil
|
||||
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user