Is it possible to dump inode information from the inotify subsystem?

sudo_free

I am trying to figure out what files my editor is watching on. I have learnt that count the number of inotify fds from /proc/${PID}/fd is possible, and my question is: Is it possible to dump the list of watched inodes by one process?

UPDATE: I have updated one working solution, and thanks for a helpful reference here.

UPDATE 2: well, recently I found kallsyms_lookup_name (and more symbols) not export since Linux Kernel v5.7, so I decide to update my own solution if anyone else cares.

sudo_free

Solved. With the help of kprobe mechanism used in khook , I just simply hook the __x64_sys_inotify_add_watch and use user_path_at to steal the dentry.

The code snippet is listed below, and my working solution is provided here.

#define IN_ONLYDIR          0x01000000  /* only watch the path if it is a directory */
#define IN_DONT_FOLLOW      0x02000000  /* don't follow a sym link */


//regs->(di, si, dx, r10), reference: arch/x86/include/asm/syscall_wrapper.h#L125
//SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname, u32, mask)
KHOOK_EXT(long, __x64_sys_inotify_add_watch, const struct pt_regs *);
static long khook___x64_sysinotify_add_watch(const struct pt_regs *regs)
{
    int wd;
    struct path path;
    unsigned int flags = 0;
    char buf[PATH_MAX];
    char *pname;
    // decode the registers
    int fd = (int) regs->di;
    const char __user *pathname = (char __user *) regs->si;
    u32 mask = (u32) regs->dx;

    // do the original syscall
    wd = KHOOK_ORIGIN(__x64_sys_inotify_add_watch, regs);
    // get the pathname
    if (!(mask & IN_DONT_FOLLOW))
        flags |= LOOKUP_FOLLOW;
    if (mask & IN_ONLYDIR)
        flags |= LOOKUP_DIRECTORY;
    if ( wd>=0 && (user_path_at(AT_FDCWD, pathname, flags, &path)==0) )
    {
        pname = dentry_path_raw(path.dentry, buf, PATH_MAX); //"pname" points to "buf[PATH_MAX]"
        path_put(&path);
        printk("%s, PID %d add (%d,%d): %s\n", current->comm, task_pid_nr(current), fd, wd, pname);
    }
    return wd;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Getting information from tumblr DUMP

What are watch descriptors really ? (Linux inotify subsystem)

Nginx Inode Information Leakage

Is it possible to open Windows applications from inside a Windows subsystem for Linux terminal?

Possible to dump AJAX content from webpage?

How to trace back the original Data structure information from the PERL dump?

Is possible to increase inode in ubuntu 16.04?

In SQLAlchemy is it possible to dump and load from a Table (not from a mapped class)?

Is it possible to send information from the iPhone to the Apple Watch?

Is it possible to extract coordinate information from neato or GraphViz?

Is it possible to strip Debug Information from DCUs?

linux + list inode information show 100% used

How to see information inside inode data structure

Is it possible to restore only new changes from latest PostgreSQL dump

Is it possible to trigger an Android heap dump from the command line?

Using Windbg to analyze possible memory leak from a dump file

Extracting inode from ls command

Can a file be created from an inode?

Is it possible to find all files with a given inode? Efficiently?

Is it possible to rename a file or directory using the inode?

SQL DUMP missing information in a column

How to get information from a namespace polluted memory dump, using windbg "dt" command

Is it possible to get OpenCL on Windows Linux Subsystem?

Trying to refresh ping information from a Minecraft server - possible or not?

Is it possible to get profile information in an id_token from Google?

Is it possible to view a package information from terminal before installing it?

Is it possible to populate a SQL chart with data that depends on the existence of information from that chart?

Is it possible to automatically update Google My Business information from a website?

Is it possible to access Maven project information from a custom plugin?