Skip to content
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: filldir64 event #4588

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rscampos
Copy link
Collaborator

@rscampos rscampos commented Feb 13, 2025

1. Explain what the PR does

6482680 fix: filldir64 event

The second parameter (`name`) of filldir64 is currently being
interpreted as the `process name`, whereas it should be
interpreted as the directory entry name (`dirent name`).

2. Explain how to test it

In order to generate the event hidden_inodes its necessary to trigger filldir64. filldir64 is triggered by getdents64 (library function readdir). Flow: readdir -> getdents64 -> filldir64

% gcc readdir -o readdir.c
% ./readdir /

readdir source code:

Source code
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>

int main(int argc, char *argv[]) {
    // Check if the directory path is provided
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <directory_path>\n", argv[0]);
        return EXIT_FAILURE;
    }
    // Open the directory
    DIR *dir = opendir(argv[1]);
    if (dir == NULL) {
        perror("opendir");
        return EXIT_FAILURE;
    }
    printf("Contents of directory %s:\n", argv[1]);
    struct dirent *entry;
    while ((entry = readdir(dir)) != NULL) {
        printf("Name: %s", entry->d_name);
        // Additional information
        switch (entry->d_type) {
            case DT_REG:
                printf(" (Regular file)\n");
                break;
            case DT_DIR:
                printf(" (Directory)\n");
                break;
            case DT_LNK:
                printf(" (Symbolic link)\n");
                break;
            default:
                printf(" (Other)\n");
                break;
        }
    }
    // Close the directory
    closedir(dir);
    return EXIT_SUCCESS;
}
sudo ./dist/tracee -s comm=readdir -e hidden_inodes.data.hidden_dirent=tmp
TIME             UID    COMM             PID     TID     RET              EVENT                     ARGS
08:12:55:823956  1000   readdir          2470122 2470122 0                hidden_inodes             hidden_dirent: tmp

3. Other comments

Notes: this C example is a partial PoC because don't trigger the event unless we comment out the lines:

    // only inode=0 is relevant, simple filter prior to program run
    unsigned long dirent_inode_number = (unsigned long) PT_REGS_PARM5(ctx);
    if (dirent_inode_number != 0)
        return 0;

For a fully PoC would be necessary to trigger the event and some how set the inode=0 before calling filldir64. Maybe using a LKM to hook filldir64 and set to 0 before passing to the original function.

@rscampos
Copy link
Collaborator Author

@OriGlassman FYI

@rscampos rscampos requested a review from geyslan February 13, 2025 14:30
@rscampos rscampos added this to the v0.24.0 milestone Feb 13, 2025
@geyslan geyslan removed this from the v0.24.0 milestone Feb 13, 2025
The second parameter (`name`) of filldir64 is currently being
interpreted as the `process name`, whereas it should be
interpreted as the directory entry name (`dirent`).
@rscampos rscampos force-pushed the fix_filldir64_event branch from 6482680 to b830f86 Compare February 14, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants