Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(modern_bpf): add support for bpf, flock, ioctl, quotactl, unshare, mount, umount2 #549

Merged
merged 8 commits into from
Aug 30, 2022

Conversation

Andreagit97
Copy link
Member

What type of PR is this?

/kind feature

Any specific area of the project related to this PR?

/area driver-modern-bpf

/area libpman

/area tests

Does this PR require a change in the driver versions?

What this PR does / why we need it:

This PR is part of a series #513, the final aim is to support the most important syscalls also in the new probe. This PR introduces:

  • bpf
  • flock
  • ioctl
  • quotactl
  • unshare
  • mount
  • umount2

Which issue(s) this PR fixes:

Special notes for your reviewer:

Today we define the events PPME_SYSCALL_UMOUNT_E and PPME_SYSCALL_UMOUNT_X, but we use them for the umount2 syscall, we don't instrument the umount. This is probably due to the fact that in many x64 architectures __NR_umount is not defined

Does this PR introduce a user-facing change?:

new(modern_bpf): add support for `bpf`, `flock`, `ioctl`, `quotactl`, `unshare`, `mount`, `umount2`

/*=============================== COLLECT PARAMETERS ===========================*/

/* Parameter 1: cmd (type: PT_FLAGS16) */
unsigned long cmd = extract__syscall_argument(regs, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @Andreagit97 ,

here I get an test failure on s390x:

[ RUN      ] SyscallEnter.quotactlE
/root/git/falcosecurity/libs/test/modern_bpf/event_class/event_class.cpp:212: Failure
Expected equality of these values:
  *(T*)(m_event_params[m_current_param].valptr)
    Which is: 0
  param
    Which is: 128
>>>>> value of the param is not correct. Param id = 1

[  FAILED  ] SyscallEnter.quotactlE (0 ms)

With some bpf_printk() instrumentation:

--- a/driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/quotactl.bpf.c
+++ b/driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/quotactl.bpf.c
@@ -27,6 +27,7 @@ int BPF_PROG(quotactl_e,
 
        /* Parameter 1: cmd (type: PT_FLAGS16) */
        unsigned long cmd = extract__syscall_argument(regs, 0);
+       bpf_printk("quotctl cmd=%x (%x) scap=%x\n", cmd, cmd >> SUBCMDSHIFT, quotactl_cmd_to_scap(cmd));
        u16 scap_cmd = quotactl_cmd_to_scap(cmd);
        ringbuf__store_u16(&ringbuf, scap_cmd);
 

the following is printed:

        bpf_test-11439   [001] d.... 326644.488183: bpf_trace_printk: quotctl cmd=80000100 (ff800001) scap=0

Changing from unsigned long (s390x defaults to 64-bit) to unsigned int (s390x defaults to 32-bit) let the test run successful:

--- a/driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/quotactl.bpf.c
+++ b/driver/modern_bpf/programs/tail_called/events/syscall_dispatched_events/quotactl.bpf.c
@@ -26,7 +26,8 @@ int BPF_PROG(quotactl_e,
        /*=============================== COLLECT PARAMETERS  ===========================*/
 
        /* Parameter 1: cmd (type: PT_FLAGS16) */
-       unsigned long cmd = extract__syscall_argument(regs, 0);
+       unsigned int cmd = extract__syscall_argument(regs, 0);
+       bpf_printk("quotctl cmd=%x (%x) scap=%x\n", cmd, cmd >> SUBCMDSHIFT, quotactl_cmd_to_scap(cmd));
        u16 scap_cmd = quotactl_cmd_to_scap(cmd);
        ringbuf__store_u16(&ringbuf, scap_cmd);
 

and for completeness the trace output:

bpf_test-11557   [000] d.... 326958.038886: bpf_trace_printk: quotctl cmd=80000100 (800001) scap=80

For reference, the Linux kernel quota syscall also uses an unsigned int.

Copy link
Contributor

@hbrueckner hbrueckner Aug 15, 2022

Choose a reason for hiding this comment

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

I will also give #550 a test run before I leave for vacation and a review then later when I am back.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you very much for this @hbrueckner! The fix seems good I will try it!

Copy link
Member Author

Choose a reason for hiding this comment

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

I've applied the solution!! Thank you for the fix as always ❤️

@Andreagit97 Andreagit97 added this to the 3.0.0+driver milestone Aug 30, 2022
@Andreagit97 Andreagit97 force-pushed the miscellaneous_syscalls branch from 6e0aab9 to 9f649cd Compare August 30, 2022 13:05
@@ -79,5 +79,16 @@
#define RENAMEAT2_E_SIZE HEADER_LEN
#define PIPE_E_SIZE HEADER_LEN
#define PIPE_X_SIZE HEADER_LEN + sizeof(int64_t) * 3 + sizeof(uint64_t) + PARAM_LEN * 4
#define BPF_E_SIZE HEADER_LEN + sizeof(int64_t) + PARAM_LEN
Copy link
Contributor

Choose a reason for hiding this comment

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

I definitely want to find a solution for this file :D

Copy link
Member Author

Choose a reason for hiding this comment

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

yes probably we will add these dims in the event table at the end of the work 🤔

@poiana
Copy link
Contributor

poiana commented Aug 30, 2022

LGTM label has been added.

Git tree hash: d2eca8cbc58506d31312cca3665d5e4b29a2e5b1

Copy link
Contributor

@FedeDP FedeDP 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 Aug 30, 2022

[APPROVALNOTIFIER] This PR is APPROVED

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

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

The pull request process is described here

Needs approval from an approver in each of these files:

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 3f5c13b into master Aug 30, 2022
@poiana poiana deleted the miscellaneous_syscalls branch August 30, 2022 14:05
return 0;
}

/// TODO: This event should be called `PPME_SYSCALL_UMOUNT2_E`.
Copy link
Contributor

Choose a reason for hiding this comment

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

@Andreagit97 when renaming this event, will you then add a separate event for umount only? I guess this would then also change the schema version etc. Also adding introduction of umount syscall event to #515 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this would change the schema version the final idea will be to have for every syscall, it PPM_SC_CODE and its event pair enter and exit. Added it :)

if(dqinfo.dqi_valid & IIF_FLAGS)
{
/* Parameter 13: dqi_flags (type: PT_FLAGS8) */
auxmap__store_u8_param(auxmap, dqinfo.dqi_flags);
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably yet another missing scap mapper for dqi_flags for #515 .

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice to see you again !! 🚀 Added! thank you

Copy link
Contributor

Choose a reason for hiding this comment

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

:-) Looked thru your commits... and they are all nice. Catching up with the others PRs over the next days.

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.

5 participants