ftrace-hook | Using ftrace for function hooking in Linux kernel
kandi X-RAY | ftrace-hook Summary
kandi X-RAY | ftrace-hook Summary
Using ftrace for function hooking in Linux kernel
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ftrace-hook
ftrace-hook Key Features
ftrace-hook Examples and Code Snippets
Community Discussions
Trending Discussions on ftrace-hook
QUESTION
I am writing a small kernel driver that has the job to act as a honeypot and monitor actions taken on a specific file on the system. To start things off, I used the code in this repository, which I then slightly modified for simplicity reasons so that it works only for one system call: sys_open
.
Now I need to gather information for the process and the user that run that system call to open this file, but I could not find any way to do it. I thought that I could use the file descriptor to identify which process has it, but after a discussion with my university professor, he told me that file descriptors are NOT unique system-wide, but only process-wide.
To conclude, is there a way that could give me the PID of the process that implicitly called sys_open
?
ANSWER
Answered 2020-Feb-03 at 15:29When running in kernel code, information about the currently running process is stored in the current
global variable (it's actually a platform specific macro rather than a global variable, to be precise), which is a struct task_struct
. If you are inside a syscall handler (or a hook to one), then current
will be the process which started the syscall, and you can just check current->pid
to get its PID.
To get the current process' UID, GID, EUID, EGID (and so on) you can use the set of macros defined in linux/cred.h
. From the the relative kernel documentation page:
There are convenience wrappers for retrieving specific aspects of a task’s credentials (the value is simply returned in each case):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ftrace-hook
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page