aboutsummaryrefslogtreecommitdiffstats
path: root/listener/godo.go (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Show filt result in tree&json, fix sth in listenerHEADmasterdevWe-unite2024-09-021-2/+2
| | | | | | | | | | | | | | In the listener, I change the order coroutines are started to avoid 'send on a closed channel'. Besides, the method to get syscall names and numbers are not so universial, so let's go back to check unistd.h. In the filter, the output is set to be written to ./log dir. Pid tree are shown in logs/tree.log, and detail info in pids.log, while file info in the logs/files.log. tree.log shows a tree just like `tree` command, the other two files are written in json. What's more, the flags while opening files are also checked ans showed in files.log.
* Write documents of the program.We-unite2024-08-221-8/+29
| | | | | | | | | | | Add README.md on the design of the whole program, and how its every part(listener, filter) works, finally how to compile and use them. Besides, notes.md records the things and technology learned in this program, such as how to read kernel src, how the pthread_create/fork/ clone syscall works on processes and threads, the techs used to make docker container works well, and books to be read. Good good study, day day up.
* Fix rootfs by cgroup, clean file name, etc.We-unite2024-08-151-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | **1. about root fs** The setns is used by a process(for example, process 12345), to enter a namespace of another process(also, process 12000). Process 12345 opens visual file /proc/12000/ns/xxx, gets a fd, then setns(fd, nstype). Here xxx represents for special type of namespace such as mnt/ipc. Param nstype can be found out in manual. In short, switching namespace uses not fileName but file descriptor, which makes it too hard to listen to setns, because the fd info may have been lost on the road, or it's still on road, not in db. This would make significant error! So, in this commit, I check /proc/pid/cgroup. Although it has nothing to do with root filesystem, it contains docker id. Record it, and deal with it in the filter: For each process that has pivot_root, it records its docker id, we remember the map from docker id to rootfs; then check all processes on the tree, if it has docker id, add the corresponding rootfs. **2. Exit time of pids to be zero** Besides, I fix the exit time of pid in this commit. After merging the same processes, sort them in ascending order, so that in each tgid node, the main pid is always the first thread. Then, check other pids' exit time, if is zero, assumpt that exit time is the same as main pid, which means the process exit while the thread is running. **3. Wrong parent** I fix the ppid of threads. For example, process 10 has a child process 20, 20 has threads 20 and 23. When pid 20 is recvd, the ppid and parentTgid in message must be 10. But then, 10 exits, and the parent process of 20 comes to be 1, then 20 makes thread 23. When pid 23 is recvd, the ppid and parentTgid is 1, that's totally wrong! Also, using the sorted process array, we can easily find the main thread, so get the real parent, and check the ppid of other threads. **4. Clean file name** The original file name in database may be complex(such as "/1/2/./../3"). Clean it with go pkg "path" **5. Next step** TODO: Fix the netlink connector, may it usable immediately after powering on. Then the view.
* Filter mainly finished, fix sth in lintenerWe-unite2024-08-141-4/+7
| | | | | | | | | | | | | | | | | | This commit I make some changes: - The filter got mainly finished. - Build a big node by the same tgid, and use the tgid node to build th tree we need by bfs. - Filt relative files, and for the files not closed, add close time stamp according to the exit time of their pids. - Put all the results into database. Besides, I enlarge the buffer size of netlink connector and channels in lintener. TODO: - the pivot_root syscall is used only by the initial shell(`docker start` makes a shell), other processes of shell change their root by changing namespace(mnt ns?), using setns syscall. So fix it. - It's time to fix the netlink connector socket.
* Add db structure, fix filePath, start filteringWe-unite2024-08-121-0/+176
This commit I made several changes: - Use structure instead of simple bson.M(interface{}). bson.M has some shortcomings: 1) It makes the database in chaos and hard to read, but this's not important; 2) Some entrys may has more or less content than others, which makes it hard to decode and filt. So I design new data structure to encode and decode. Hopes that there's no bugs. - Fix the way to calculate file path. The original method is to add all the PATH entries together, that's totally wrong! PATH entry has several types, as it shows in "objtype". I can't find it in the kernel src code, so what i know is just "PARENT" means the dir the file is in, while the filename itself has the path, so we whould ignore all "PARENT"s. When the src code is found, we should check it again. - Fix bugs in updating. The update function of mongodb is set to required to has a '$' such as 'set'/'push', so when we update a whole doc, we should use replace but not update function. And, we should never ignore the error infomation it gives us. Hope that there's no more bugs for this Big Change. Now its' time to write filter as well as viewer. Best wishes with NO BUGS!