Skip to content

Commit 9ca719d

Browse files
committed
tracing: CapabilitiesGained requires large progs
Set the CapabilitiesGained operator to only work when large progrs are supported in the kernel, since loading the generic program fails in 4.19. Signed-off-by: Kornilios Kourtis <[email protected]>
1 parent 3f7db1d commit 9ca719d

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

bpf/process/types/basic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@ selector_arg_offset(__u8 *f, struct msg_generic_kprobe *e, __u32 selidx,
16591659
case cap_prm_ty:
16601660
case cap_eff_ty:
16611661
case kernel_cap_ty:
1662+
#ifdef __LARGE_BPF_PROG
16621663
if (filter->op == op_capabilities_gained) {
16631664
__u64 cap_old = *(__u64 *)args;
16641665
__u32 index2 = *((__u32 *)&filter->value);
@@ -1667,6 +1668,7 @@ selector_arg_offset(__u8 *f, struct msg_generic_kprobe *e, __u32 selidx,
16671668
break;
16681669
}
16691670
/* falltrough */
1671+
#endif
16701672
case syscall64_type:
16711673
case s64_ty:
16721674
case u64_ty:

pkg/selectors/kernel.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,13 @@ func writePostfixStrings(k *KernelSelectorState, values []string, ty uint32) err
755755

756756
func checkOp(op uint32) error {
757757
switch op {
758-
case SelectorOpGT, SelectorOpLT:
758+
case SelectorOpGT, SelectorOpLT, SelectorOpCapabilitiesGained:
759759
if !config.EnableLargeProgs() {
760-
return errors.New("GT/LT operators are only supported in kernels >= 5.3")
760+
opName := selectorOpStringTable[op]
761+
return fmt.Errorf(
762+
"operator %d (%s) is only supported in kernels supporting large programs (normally versions >= 5.3)",
763+
op, opName,
764+
)
761765
}
762766
}
763767
return nil

pkg/sensors/tracing/kprobe_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6825,6 +6825,10 @@ func TestCapabilitiesGained(t *testing.T) {
68256825

68266826
testCapabilitiesGained := testutils.RepoRootPath("contrib/tester-progs/capabilities-gained")
68276827

6828+
if !config.EnableLargeProgs() {
6829+
t.Skip("CapabilitiesGained is not supported in kernels without large program support")
6830+
}
6831+
68286832
spec := &v1alpha1.TracingPolicySpec{
68296833
KProbes: []v1alpha1.KProbeSpec{{
68306834
// int security_capset(struct cred *new, const struct cred *old,

0 commit comments

Comments
 (0)