Skip to content

cleanup(driver,userspace/libscap): let kmod use syscalls mask instead of events mask, like bpf and modern bpf#728

Merged
poiana merged 4 commits intomasterfrom
cleanup/kmod_use_syscalls
Nov 24, 2022
Merged

cleanup(driver,userspace/libscap): let kmod use syscalls mask instead of events mask, like bpf and modern bpf#728
poiana merged 4 commits intomasterfrom
cleanup/kmod_use_syscalls

Conversation

@FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Nov 23, 2022

What type of PR is this?

/kind cleanup

Any specific area of the project related to this PR?

/area driver-kmod
/area libscap-engine-kmod

Does this PR require a change in the driver versions?

/version driver-API-version-major

But we already bumped major in #709

What this PR does / why we need it:

Both bpf and modern bpf use a syscalls of interest concept; kmod was instead using an event of interest concept.
I ported kmod to use same concept of bpf and modern bpf.
NOTE: using event of interest also carried bugs, because when an user enforce certain ppm_sc through the scap/sinsp APIs, we would also lose all other non-syscalls event types generated by kmod (ie: signals, drops...), because kmod internally zeroed the event mask.

Which issue(s) this PR fixes:

Described above.

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

cleanup(driver)!: port kmod to use syscalls mask instead of events mask.

… of events mask, like bpf and modern bpf.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@FedeDP FedeDP force-pushed the cleanup/kmod_use_syscalls branch from 308227e to 761dec9 Compare November 23, 2022 09:39
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 23, 2022

/cc @gnosek @Andreagit97

@poiana poiana requested a review from gnosek November 23, 2022 09:39
@Andreagit97
Copy link
Member

/milestone 0.10.0

@poiana poiana added this to the 0.10.0 milestone Nov 23, 2022
@Andreagit97 Andreagit97 modified the milestones: 0.10.0, next-driver Nov 23, 2022
Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor question

consumer->fullcapture_port_range_end = 0;
consumer->statsd_port = PPM_PORT_STATSD;
bitmap_fill(consumer->events_mask, PPM_EVENT_MAX); /* Enable all syscall to be passed to userspace */
bitmap_fill(consumer->syscalls_mask, SYSCALL_TABLE_SIZE); /* Enable all syscalls to be passed to userspace */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to enable all the syscalls here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this is a default; i don't think it is necessary given that scap_kmod will set all the interesting syscalls at startup time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it there for now :)

@gnosek
Copy link
Contributor

gnosek commented Nov 23, 2022

This needs an API version bump, and ideally a new ioctl name/number instead of changing the behavior of existing ones

EDIT:

But we already bumped major in #709

I still disagree about this but I know I'm outnumbered so 🤷‍♂️ 🙃

@Andreagit97
Copy link
Member

I agree with the rename but do we really need the old feature on events_mask? do we have to disable events that are not syscalls?

@gnosek
Copy link
Contributor

gnosek commented Nov 23, 2022

do we have to disable events that are not syscalls?
We probably have to do this via tracepoints now.

In any case, we cannot just change the ioctl behavior and use the same number (there's tons of fun to be had if you e.g. use an ancient consumer with a new driver). IMO:

  • introduce a completely new ioctl for this
  • make the old ioctl return -ENOTTY or something so that we can't mess up by accidentally mismatching versions

@Andreagit97
Copy link
Member

Andreagit97 commented Nov 23, 2022

We probably have to do this via tracepoints now.

The tracepoint events shouldn't be masked, they should be always available, we just directly attach and detach the tracepoints 🤔 if the tracepoint is not there it cannot generate any event (probably this is exactly what you said 😆 )

In any case, we cannot just change the ioctl behavior and use the same number (there's tons of fun to be had if you e.g. use an ancient consumer with a new driver). IMO:

introduce a completely new ioctl for this
make the old ioctl return -ENOTTY or something so that we can't mess up by accidentally mismatching versions

Absolutely agree with that!

@gnosek
Copy link
Contributor

gnosek commented Nov 23, 2022

The tracepoint events shouldn't be masked, they should be always available, we just directly attach and detach the tracepoints 🤔 if the tracepoint is not there it cannot generate any event

yeah, this is what I mean

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 23, 2022

This needs an API version bump, and ideally a new ioctl name/number instead of changing the behavior of existing ones

Api version bump, as said in the op, was already done in this release cycle for #709; no more changes are required.
For the ioctl: note that an old client is not expected to work, given the api maj version bump; that is the reason we added those semver checks!

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 23, 2022

I still disagree about this but I know I'm outnumbered so man_shrugging upside_down_face

We are going to reach chromium version in a couple of weeks if we bump every time we break 😆

…ated ioctls; added new ioctls for syscalls mask.

Moreover, renamed `scap_eventmask_op` values accordingly.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@poiana poiana added size/L and removed size/M labels Nov 23, 2022
@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 23, 2022

@gnosek everything should be ok now :) I dropped the old ioctls and added new ones.

… do not need to be bound to kmod ioctls.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>

Co-authored-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
@dwindsor
Copy link
Contributor

Both bpf and modern bpf use a syscalls of interest concept; kmod was instead using an event of interest concept.
I ported kmod to use same concept of bpf and modern bpf.

Where does this leave the non-syscall kmod tracepoints (sched_process_exit, page_fault_user et al)?

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 23, 2022

Where does this leave the non-syscall kmod tracepoints (sched_process_exit, page_fault_user et al)?

Well, the ppm_sc API is for disabling syscalls (while leaving sys_enter and sys_exit tracepoints attached). You can still disable tracepoints too.
Basically, we have events that maps 1:1 with tracepoints for all tracepoints except sys_enter and sys_exit.
These latter tracepoints map 1:N with events (ie: each tracepoints manages all syscall related enter/exit events).

@dwindsor
Copy link
Contributor

dwindsor commented Nov 23, 2022

Makes sense. I guess what I was getting at was this:

// #define PPM_IOCTL_DISABLE_SIGNAL_DELIVER _IO(PPM_IOCTL_MAGIC, 14) Support dropped
// #define PPM_IOCTL_ENABLE_SIGNAL_DELIVER _IO(PPM_IOCTL_MAGIC, 15) Support dropped

☝️this change (96aa1686) seems fairly recent, does it mean that we can no longer disable these tracepoints (there are others that were disabled as well).

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 23, 2022

Of course you can :) but there is now a proper Scap API for that and a TPMASK ioctl! (A bit lower in that very same file)

Copy link
Member

@leogr leogr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM, however, we should also bump the DRIVER API version, shouldn't we?
cc @gnosek @FedeDP @Andreagit97

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 24, 2022

Answered above to grzeg with the same question! 😄
See the OP of this PR !
We already bumped API version a week ago when #709 was merged!

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Nov 24, 2022

LGTM label has been added.

DetailsGit tree hash: 17ca6765b5bdac9f93e80b7f231108ce36d4c3a8

@FedeDP
Copy link
Contributor Author

FedeDP commented Nov 24, 2022

@gnosek mind to approve if you are ok?

Copy link
Contributor

@hbrueckner hbrueckner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@poiana
Copy link
Contributor

poiana commented Nov 24, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, gnosek, hbrueckner

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,gnosek]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit f6e014b into master Nov 24, 2022
@poiana poiana deleted the cleanup/kmod_use_syscalls branch November 24, 2022 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants