-
Notifications
You must be signed in to change notification settings - Fork 165
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
fix(scap): properly detect threads in child pidns during /proc scan #860
Conversation
cc @incertum |
/milestone 0.11.0 |
Greg you are the best, thanks for catching these subtleties I totally wasn't aware of 🙏 ! Q: Should it also be changed here libs/userspace/libsinsp/parsers.cpp Line 1654 in c955355
boot_ts without imprecisions and that's why the method of retrieving boot_ts was also changed in that same PR in order to have it constant between agent reboots even -> however it would also be ok to remove the check there all together, sometimes I try to be over precise where it's not even needed.
|
This particular one cost me over a month of work a while back (3b7a794) so now I'm suspicious every time I see tid and vtid in the same expression ;) Thanks for pointing out the other place we need to fix :) I think we can just check libs/userspace/libsinsp/parsers.cpp Line 1088 in c955355
|
This sounds about right @gnosek would say, but I'll also actually check it as well! -> ✔️ |
@gnosek [nit] would renaming A current corner case is when you launch a container directly over
@terylt also requested something like incertum@8c79505, but am gonna hold off until we have discussed if we would even want that. |
It seems we can use
Possibly :) though I'd leave it to a separate no-op commit. Also,
I'm potentially overengineering the problem but I think I'd prefer a bitmap of non-init namespaces the thread is in and a separate filtercheck to access them, otherwise we're one PR away from |
Very nice changes, love them!
Agreed re separate PR.
Agreed and I think a bitmap would be the right engineering approach here, thanks for the valuable input ;) |
/approve |
LGTM label has been added. Git tree hash: 36cb75d3f702d685f46f873abddb6a1bed938d67
|
Hmm the obvious thing of |
Exactly ... so in the kernel instrumentation it is the time stamp of the init task in the pid namespace https://github.com/falcosecurity/libs/blob/master/driver/bpf/fillers.h#L2649, and doing cross lookups during proc scan seems not good ... |
@incertum well do I have news for you... :D
Putting these together, it seems it's enough to One downside is that we then depend on the thread having the right /proc mounted. It should always be true for actual container runtimes but not necessarily for handcrafted namespaces. Does that hurt your use case much? We could try to handle it (e.g. stat Still, at least we could claim it's the creation time of the pidns that the thread can see in its /proc, which I suppose is something ;) |
We can significantly simplify the logic of checking the pidns start time (during the initial /proc scan), based on the following observations: * the task's start time is (apparently) accessible as simply the timestamp (any timestamp) on its /proc/ * for every task, its root filesystem is accessible via /proc/<pid>/root * the first task in every pidns has pid==1 (as seen from the pidns) Putting these together, it seems it's enough to stat("/proc/<pid>/root/proc/1") and pick whichever you want out of [acm]time. Ref: falcosecurity#860 (comment) Signed-off-by: Grzegorz Nosek <[email protected]>
@incertum, can you give it a spin and see if it works for you? 1575222 (it's https://github.com/gnosek/falco-libs/tree/fix-pidns-start-scan) |
I like this a lot, it's one step up and better than the current implementation 🎉 . Primary use case is containers. Will pull and test it later tonight, ty! Initial intuition is it looks great! |
This is really great and it works @gnosek, just tested it. Feel free to include here and I re-approve or I'll approve the follow up PR! |
/hold bad push |
tid != vtid is not necessary (though sufficient) to check if a thread is in a child pid namespace. This leads to pidns_start_ts being wrong occasionally (when a thread happens to have tid == vtid by chance, even if it's in a child pidns). Signed-off-by: Grzegorz Nosek <[email protected]>
We can significantly simplify the logic of checking the pidns start time (during the initial /proc scan), based on the following observations: * the task's start time is (apparently) accessible as simply the timestamp (any timestamp) on its /proc/ * for every task, its root filesystem is accessible via /proc/<pid>/root * the first task in every pidns has pid==1 (as seen from the pidns) Putting these together, it seems it's enough to stat("/proc/<pid>/root/proc/1") and pick whichever you want out of [acm]time. Ref: falcosecurity#860 (comment) Signed-off-by: Grzegorz Nosek <[email protected]>
/unhold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
if(scap_proc_fill_pidns_start_ts(handle->m_lasterr, tinfo, dir_name) == SCAP_FAILURE) | ||
{ | ||
// ignore errors | ||
// the thread may not have /proc visible so we shouldn't kill the scan if this fails |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty!
LGTM label has been added. Git tree hash: 284201999315c5563c5811977457d15743bd9c8b
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, gnosek, incertum 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 |
tid != vtid is not necessary (though sufficient) to check if a thread is in a child pid namespace. This leads to pidns_start_ts being wrong occasionally (when a thread happens to have tid == vtid by chance, even if it's in a child pidns).
Note: the name of the flag (
PPM_CL_CHILD_IN_PIDNS
) isn't the best for this use case but it effectively means what we want ("we know this thread is in a child pidns, even if tid == vtid")What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area libscap
Does this PR require a change in the driver versions?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: