Skip to content

fix(driver, userspace): fix loginuid, euid and tty types to uint32_t#1192

Merged
poiana merged 5 commits intofalcosecurity:masterfrom
incertum:loginuid-type
Aug 2, 2023
Merged

fix(driver, userspace): fix loginuid, euid and tty types to uint32_t#1192
poiana merged 5 commits intofalcosecurity:masterfrom
incertum:loginuid-type

Conversation

@incertum
Copy link
Contributor

@incertum incertum commented Jul 10, 2023

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap-engine-udig

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

loginuid shall be treated as uint32_t throughout to avoid wonky audit uids (which is currently the case in production settings). In order to keep backward compatibility change user.loginuid filtercheck field to int64_t and return -1 if the uid is invalid.

TODO: Need to bump the schema version once we have decided when to merge this PR.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix(driver, userspace): fix loginuid, euid and tty types to uint32_t

@github-actions
Copy link

github-actions bot commented Jul 10, 2023

Please double check driver/API_VERSION file. See versioning.

@incertum
Copy link
Contributor Author

incertum commented Jul 10, 2023

@FedeDP inspected the other PR again #526 and I think we cannot port changes to ERRNO or other fields into this PR as we would need to create so many new events ... almost wonder if it is time to introduce compatibility versioning for scap files since it is a large overhead for all of us to maintain compatibility and/or work around limitations.

Forgot about test running the e2e tests on my box, will address tomorrow ...

@incertum
Copy link
Contributor Author

incertum commented Jul 14, 2023

Edited:

Yes let's also address tty mentioned in #515 @Andreagit97 and re the cwd I am seeing that relying on the syscalls that do send cwd is suboptimal in production, this is why for example we introduced euid recently as to not needing to rely on setuid. Therefore, I would rather propose we go back and actually send cwd, because execve* syscalls are too important and I mentioned multiple times that in the grand schema of things those are not the frequent and noisy ones we need to worry about in most modern infrastructures.

Note that the loginuid stands out as very critical for the Falco use cases.

@poiana poiana added size/XXL and removed size/XL labels Jul 14, 2023
@incertum incertum changed the title fix(driver, userspace): fix loginuid types, new execve* events fix(driver, userspace): fix loginuid, euid and tty types, new execve* events Jul 14, 2023
@FedeDP
Copy link
Contributor

FedeDP commented Jul 17, 2023

/milestone driver-backlog

@poiana poiana added this to the driver-backlog milestone Jul 17, 2023
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.

uhm I have a major question, why do we craft new events? Apart from the hard-coded rules we imposed on ourselves do we have some real reasons? In the end, it would be enough to handle both loginuid=-1 and loginuid=UINT32_MAX in userspace, or am I missing something @FedeDP @gnosek? Let's say I would love to not change all the events every time we need to change the type of a param...

Re cwd: I would be on board to add it but not sure about the cost of potentially long string in the buffer 🤔 The issue is always the same we have no idea about perf consequence :/

#define UID_GID_MAP_MAX_BASE_EXTENTS 5
#endif

#ifndef INVALID_UID
Copy link
Member

Choose a reason for hiding this comment

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

I would put it somewhere shared between all the drivers, something like ppm_events_public.h

Copy link
Member

Choose a reason for hiding this comment

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

probably to avoid every possible collision with COS definition I would call it something like INVALID_LOGINUID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably just very specifically use UINT32_MAX everywhere, do we actually need below fallback check?

#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif

Alternatively we can go back to consistently just case -1 to uint32_t, not much of an opinion here.

[PPME_SYSCALL_MEMFD_CREATE_X] = "memfd_create_x",
[PPME_SYSCALL_PIDFD_GETFD_E] = "pidfd_getfd_e",
[PPME_SYSCALL_PIDFD_GETFD_X] = "pidfd_getfd_x",
[PPME_SYSCALL_EXECVE_20_E] = "execve_e",
Copy link
Member

Choose a reason for hiding this comment

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

here we need to replace the old execve events instead of adding new entries

@incertum
Copy link
Contributor Author

@Andreagit97 we need new events because of the scap files, see #526 ... read my comment above I think we should introduce scap files versioning so that we can for once fix all types without needing to redefine each event which is also a significant code review overhead ... #1192 (comment)

We may need the execve fix earlier as the loginuid fix is more urgent for Falco use cases, but for all other outstanding fixes I would also much more prefer not to create new events.

@poiana poiana added the size/L label Jul 28, 2023
@incertum incertum changed the title fix(driver, userspace): fix loginuid, euid and tty types, new execve* events fix(driver, userspace): fix loginuid, euid and tty types to uint32_t Jul 28, 2023
@incertum
Copy link
Contributor Author

@Andreagit97 this is ready for a fresh look now, also thanks again for the drivers tests, caught one little error while redoing it :)

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.

Apart from the INVALID_UID fix we should be fine

#endif /* COS_73_WORKAROUND */
#else
loginuid.val = UINT32_MAX;
loginuid.val = INVALID_UID;
Copy link
Member

Choose a reason for hiding this comment

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

actually loginuid.val = UINT32_MAX was right, loginuid is a kuid_t so when we use just loginuid we need to assign INVALID_UID while when we use loginuid.val we need to assign an uint32 so UINT32_MAX

Copy link
Member

Choose a reason for hiding this comment

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

Same in the other loginuid.val usage

Andreagit97
Andreagit97 previously approved these changes Aug 1, 2023
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 Aug 1, 2023

LGTM label has been added.

DetailsGit tree hash: 54658f25e6073fefcb8221f654daac3e72e83f52

@FedeDP
Copy link
Contributor

FedeDP commented Aug 2, 2023

/hold

incertum and others added 5 commits August 2, 2023 15:14
* loginuid, tty and euid now consistently uint32_t
* not a breaking UX change since we still expose -1 in case of an invalid uid in the filterchecks, user.loginuid now int64_t

Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
Co-authored-by: Andrea Terzolo <andrea.terzolo@polito.it>
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
Co-authored-by: Andrea Terzolo <andrea.terzolo@polito.it>
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
Co-authored-by: Andrea Terzolo <andrea.terzolo@polito.it>
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
Co-authored-by: Federico Di Pierro <nierro92@gmail.com>
Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
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

@FedeDP
Copy link
Contributor

FedeDP commented Aug 2, 2023

/unhold

@poiana poiana added the lgtm label Aug 2, 2023
@poiana
Copy link
Contributor

poiana commented Aug 2, 2023

LGTM label has been added.

DetailsGit tree hash: c75a0f78e2af355ae3a881f806e9df4e52054a1b

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 Aug 2, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

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,incertum]

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 a3d92ab into falcosecurity:master Aug 2, 2023
@incertum incertum deleted the loginuid-type branch December 8, 2023 20:37
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