Skip to content

Commit

Permalink
link: Allow kprobe multi to be disabled in kernel
Browse files Browse the repository at this point in the history
Kprobe multi support is gated on CONFIG_FPROBE, without it creating the
link fails with EOPNOTSUPP: https://elixir.bootlin.com/linux/v6.0.3/source/include/linux/fprobe.h#L64

Unfortunately the standard Debian sid kernel does not have it enabled.
Update the kprobe multi test to handle EOPNOTSUPP.

Co-developed-by: Lorenz Bauer <i@lmb.io>
  • Loading branch information
arthurfabre authored and lmb committed Oct 21, 2022
1 parent cd71a9c commit 447495b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
31 changes: 16 additions & 15 deletions internal/unix/types_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ import (
)

const (
ENOENT = linux.ENOENT
EEXIST = linux.EEXIST
EAGAIN = linux.EAGAIN
ENOSPC = linux.ENOSPC
EINVAL = linux.EINVAL
EPOLLIN = linux.EPOLLIN
EINTR = linux.EINTR
EPERM = linux.EPERM
ESRCH = linux.ESRCH
ENODEV = linux.ENODEV
EBADF = linux.EBADF
E2BIG = linux.E2BIG
EFAULT = linux.EFAULT
EACCES = linux.EACCES
EILSEQ = linux.EILSEQ
ENOENT = linux.ENOENT
EEXIST = linux.EEXIST
EAGAIN = linux.EAGAIN
ENOSPC = linux.ENOSPC
EINVAL = linux.EINVAL
EPOLLIN = linux.EPOLLIN
EINTR = linux.EINTR
EPERM = linux.EPERM
ESRCH = linux.ESRCH
ENODEV = linux.ENODEV
EBADF = linux.EBADF
E2BIG = linux.E2BIG
EFAULT = linux.EFAULT
EACCES = linux.EACCES
EILSEQ = linux.EILSEQ
EOPNOTSUPP = linux.EOPNOTSUPP
)

const (
Expand Down
1 change: 1 addition & 0 deletions internal/unix/types_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
EFAULT
EACCES
EILSEQ
EOPNOTSUPP
)

// Constants are distinct to avoid breaking switch statements.
Expand Down
10 changes: 7 additions & 3 deletions link/kprobe_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,16 @@ var haveBPFLinkKprobeMulti = internal.FeatureTest("bpf_link_kprobe_multi", "5.18
Count: 1,
Syms: sys.NewStringSlicePointer([]string{"vprintk"}),
})
if errors.Is(err, unix.EINVAL) {
switch {
case errors.Is(err, unix.EINVAL):
return internal.ErrNotSupported
}
if err != nil {
// If CONFIG_FPROBE isn't set.
case errors.Is(err, unix.EOPNOTSUPP):
return internal.ErrNotSupported
case err != nil:
return err
}

fd.Close()

return nil
Expand Down

0 comments on commit 447495b

Please sign in to comment.