Open therealbobo opened 1 year ago
Given that
proc.name
is the name (excluding the path) of the executable generating the event. When a thread changes its name within a process, Falco should update theproc.name
value to reflect the new thread name. This should happen regardless of whether Falco was started before or after the thread was renamed. This will ensure that Falco is correctly identifying the process and can take appropriate actions as needed.
@therealbobo
I'm not convinced about that assumption. I believe the expectation for proc.name
is always to report the initial process name (i.e., the executable name without the path)
@falcosecurity/libs-maintainers WDYT? :thinking: cc @loresuso @darryk10
In my opinion the problem is that proc.name
is associated with /proc/<pid>/comm
which, in the process lifecycle, could change. This fact could mislead in the use of proc.name
. Maybe this issue can be solved just updating the docs making this crystal clear or adding, for example, proc.startname
. 😄
My point is that if it can change during the execution, rules authors can't rely on (otherwise, it can lead to bypasses).
I'd instead find a way to stick with the documented behavior and find a way to fix proc. name
if possible. But I'd like to have more opinions on that.
Moreover, we also have another field, proc.exe
, that can be a custom name (so perhaps it should reflect the last value of comm
?). Not sure about that, just guessing.
I strongly believe that updating the process name is not what we need here. This is because many rules rely on proc.name
, and for this reason, just using prctl
could lead to bypass all of them.
I am trying to think about better solution!
I think the proc.name should remain consistent and shouldn't contains the thread info. It would be helpful having another field containing the thread information without updating the proc.name field which is strongly used in detection and falco rules. This is also causing a lot of noise cause often the field proc.name is used in whitelist.
If the only way to change the process comm is via prctl, then IMO we should track the changes.
(the "if" comes from the fact that you can easily overwrite argv[0] from userspace, but IIRC it's entirely separate from comm which lives in the kernel so it should be fine).
AIUI, the confusion comes from all the different things that could be considered the name of a process (and I believe we expose at least most of them one way or another):
proc.name
proc.args
proc.exe
Since the comments appearing while I'm typing this indicate we don't want proc.name to contain updated comm, how about we introduce proc.comm for this? But in any case, if there isn't a spec for what fields contain what, let's make one and stick to it (it seems important for proc.name in particular since it implies "the" name while there isn't one).
As much as Falco has become the main user of the libs, security isn't the only use case, we can also use the comm (updated by a legit process) to troubleshoot specific processes/threads by name, e.g. in OSS Sysdig
Possible problem/question:
proc.name
as @gnosek saidproc.comm
reflects the changes. Initially proc.name
and proc.comm
are the same.Now consider this:
proc.name=foo
, proc.comm=foo
)prctl
(proc.name=foo
, proc.comm=benign
)proc.name=benign
, proc.comm=benign
) https://github.com/falcosecurity/libs/blob/master/userspace/libsinsp/parsers.cpp#L1374-L1386wdyt?
I think that proc.comm
could be a great idea! 👍
- on clone, we get again the comm (
proc.name=benign
,proc.comm=benign
) https://github.com/falcosecurity/libs/blob/master/userspace/libsinsp/parsers.cpp#L1374-L1386
This should not be ok if we want an immutable proc.name
.
Anyway, I believe the root cause depends on the usage of task->comm
, that's generally not trustable since there's at least one case where one can set it from the userspace.
Thus, why not use the executable name instead? :thinking:
It all boils down to the question: what exactly is proc.name
? In the kernel, IMO the obvious answer would be comm
, but it looks like we're gravitating towards it being the same as proc.exe
.
Since the comments appearing while I'm typing this indicate we don't want proc.name to contain updated comm, how about we introduce proc.comm for this? But in any case, if there isn't a spec for what fields contain what, let's make one and stick to it (it seems important for proc.name in particular since it implies "the" name while there isn't one).
@gnosek
My TL;DR is: I believe rules authors want proc.name
to behave like proc.exe
(ie. just the executable name, immutable, @darryk10, and @loresuso do you agree?), and I totally agree to introduce proc.comm
(that mirrors task->comm
) would be nice to reduce confusion among users.
But I believe we have to reach consensus before introducing such changes.
Hey 👋, happy to join the discussion.
proc.name
certainly can not and should never be called exe name or executable name (besides it's mostly cropped at 16 characters depending on your kernel settings which can be annoying). Perhaps all this can even be considered a bit of a broader flaw that affects most of the Falco upstream rules 🙃 . Please checkout https://github.com/falcosecurity/libs/pull/938 where we added the ability to traverse exe
and exepath
parent process lineage, because for instance for java there are many limitations as typically the app has a custom proc.name
and therefore you otherwise wouldn't know if a shell was spawned from java. Lastly, we all are painfully aware of issues for symlinked executables ...
Hence we may not need proc.comm
and can just keep the contract that proc.name
is task->comm
and similar to how we update other thread fields during its lifetime this one could be updated as well one day.
Rather we should prioritize getting the true exepath
including resolved symlinks (@loresuso) and then introduce proc.exename
which simply would be the last portion of the true full path, because proc.exe
is also not really this sometimes ... Subsequently upstream rules should be updated, but I understand what a pain this will be, so proc.comm
is a valid option, but please be aware that when changing proc.name
to not reflect task->comm
we are going against common Linux definitions, ps
util output etc, so I would not recommend this.
In summary, getting technical clarity and feature completeness would be amazing as it's such an important aspect for threat detection:
proc.exename
proc.exename
insteadbut please be aware that when changing
proc.name
to not reflecttask->comm
we are going against common Linux definitions,ps
util output etc, so I would not recommend this.
@incertum
Good point.
I thought those definitions used command name (which in my mind is task->comm
) and not process name (which in my mind is a totally arbitrary definition). Generally speaking, is there any precise definition of that in the Linux doc?
After your comment, I've changed my mind, and I'm not sure anymore that introducing proc.comm
is a good idea.
At this point, the short-term solution would be
proc.name
equals to task->comm
(and fix cases when it's not correctly updated, like in the original description of this issue)proc.name
is not always the executable name (we have to set the expectation of rules authors correctly, that's the main point here)In the long term, we have to fix the symlink problem, but it's another issue.
@leogr fully agree with touching up the docs a bit more and set expectations even better. Re true executable path and symlinks yes we will work on it and hopefully soon have a trustworthy proc.exename
... I'll tag up with @loresuso to make it a reality and @Andreagit97 also already expressed willingness to help.
Lastly, worthwhile mentioning is that proc.name
is just more convenient to use in rules since we can do in (list)
but for proc.exepath
we would need to type out endswith
each time. The good news is that we already have work planned for Falco 0.36 to make the UX better, see https://github.com/falcosecurity/falco/issues/2403.
Let's dig through the ps
utils source code? I think this could be good ground truth reference for what folks are expecting or used to.
Over the past few weeks, I have talked to everyone about this problem, and I am now totally convinced that the solution is:
- to stick with
proc.name
equals totask->comm
(and fix cases when it's not correctly updated, like in the original description of this issue)- clearly state in the documentation that
proc.name
is not always the executable name (we have to set the expectation of rules authors correctly, that's the main point here)
So, IMO the next step would be to review the field documentation.
If you all agree, I could try to help with te documentation! 😄
If you all agree, I could try to help with te documentation! smile
Yes please :pray:
This is all addressed, not just documentation wise but @therealbobo also added https://github.com/falcosecurity/libs/pull/1015
Uhm just reading again this issue I've noticed this is not completely fixed, in #1015 we added the kernel code to manage prctl
code but we never added the parsing logic in sinsp to update proc.name
, and the same for the clone caller parser. We never update the comm of the thread when a new clone happens while indeed the task->comm
could be changed between the first clone and the next one...
I would reopen the issue here to keep track of this, wdyt?
oh yes we need to fix this, thanks for checking again @Andreagit97!
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Provide feedback via https://github.com/falcosecurity/community.
/lifecycle stale
/remove-lifecycle stale
@therealbobo and @Andreagit97 just checking in where we are at for this issue? What still needs to be done? Could we add a new summary of open items?
Uhm this comment https://github.com/falcosecurity/libs/issues/1011#issuecomment-1766089275 should be still valid, AFAIK nothing has been changed :thinking:
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Provide feedback via https://github.com/falcosecurity/community.
/lifecycle stale
/remove-lifecycle stale
Describe the bug
The Falco libs use the
/proc
filesystem to retrieve information about processes when they start up. However, if a thread, during its lifecycle, changes its name using aprctl
system call, theproc.name
value is not updated. This means that Falco may not be able to accurately identify the process and could lead to errors or security issues.In the following situation Falco doesn't take into account the renaming because it's only aware of the information of the process at its creation.
On the contrary, in the following situation, given that the renaming has already taken place before Falco has started, Falco will display correctly the
proc.name
.How to reproduce it
If we consider the first situation shown above:
gcc worker.c -o worker
):void worker(void arg) { if (pthread_equal(pthread_self(), ((pthread_t)arg))) { FILE *fp; char buffer[1024]; int lines = 0; pthread_setname_np(pthread_self(), "reader");
}
int main(void) { pthread_t threads[10]; int rc; pthread_setname_np(pthread_self(), "MainThread");
}
worker
program compiled in first stepproc.name
If we consider the second situation shown above:
gcc worker.c -o worker
):void worker(void arg) { if (pthread_equal(pthread_self(), ((pthread_t)arg))) { FILE *fp; char buffer[1024]; int lines = 0; pthread_setname_np(pthread_self(), "reader");
}
int main(void) { pthread_t threads[10]; int rc; pthread_setname_np(pthread_self(), "MainThread");
}
proc.name
At the end the concept is simple: if Falco starts before the renaming, it will only use the information available at the start of the process; otherwise if Falco starts after the renaming, it will have the complete information and use the effective thread name.
Expected behaviour
Given that
proc.name
is the name (excluding the path) of the executable generating the event. When a thread changes its name within a process, Falco should update theproc.name
value to reflect the new thread name. This should happen regardless of whether Falco was started before or after the thread was renamed. This will ensure that Falco is correctly identifying the process and can take appropriate actions as needed.Screenshots Here's how Falco behaves if it starts before the matching process (first situation).
Here's how Falco behaves if it starts after (second situation) the matching process and before the actual read (so when the process has already changed its name).
Here's the output of the
ps
command after the renaming:Environment
Additional context
I think that the problem is linked to the fact that a thread is added to the thread table via
parse_clone_exit
https://github.com/falcosecurity/libs/blob/9096f420ca325e04b464d66b3bfb324c3ef60e6f/userspace/libsinsp/parsers.cpp#L1653 In this way, when aprctl
occurs, the threadcomm
is never updated. A possible solution could be to hook theprctl
and update the thread table accordingly.