Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #43 from vmware/jw-PSCLNX-7520_rename_events
Browse files Browse the repository at this point in the history
Handle Basic File Rename Events
  • Loading branch information
jrmwooldridge authored Feb 19, 2021
2 parents c01cdc1 + 3fbe14f commit 0d36c78
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/bcc_sample.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 VMware, Inc.
// Copyright 2020-20201 VMware, Inc.
// SPDX-License-Identifier: BSD-2-Clause
//

Expand Down Expand Up @@ -94,6 +94,11 @@ var allProbes = []probeMeta{
PPCbName: "on_security_inode_unlink",
IsKretProbe: false,
},
probeMeta{
PP: "security_inode_rename",
PPCbName: "on_security_inode_rename",
IsKretProbe: false,
},

//# execve and execveat syscalls
probeMeta{
Expand Down
6 changes: 5 additions & 1 deletion examples/bcc_sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
# Copyright 2020 VMware, Inc.
# Copyright 2020-2021 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
#

Expand Down Expand Up @@ -586,6 +586,10 @@ def attach_probes(bcc):
pp='security_inode_unlink',
pp_cb_name='on_security_inode_unlink',
),
Probe(
pp='security_inode_rename',
pp_cb_name='on_security_inode_rename',
),

# execve and execveat syscalls
Probe(
Expand Down
53 changes: 52 additions & 1 deletion src/bcc_sensor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2020 VMware, Inc.
* Copyright 2019-2021 VMware, Inc.
* SPDX-License-Identifier: GPL-2.0
*/

Expand Down Expand Up @@ -953,6 +953,57 @@ int on_security_inode_unlink(struct pt_regs *ctx, struct inode *dir,
return 0;
}

int on_security_inode_rename(struct pt_regs *ctx,
struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct data_t data = {};
struct super_block *sb = NULL;
struct inode *inode = NULL;

sb = _sb_from_dentry(old_dentry);
if (!sb) {
goto out;
}

if (__is_special_filesystem(sb)) {
goto out;
}

__set_key_entry_data(&data, NULL);

data.state = PP_ENTRY_POINT;
data.type = EVENT_FILE_DELETE;
bpf_probe_read(&inode, sizeof(inode), &(old_dentry->d_inode));
if (inode) {
bpf_probe_read(&data.inode, sizeof(data.inode), &inode->i_ino);
}

struct file_data key = { .device = data.device, .inode = data.inode };
file_map.delete(&key);

__set_device_from_sb(&data, sb);
events.perf_submit(ctx, &data, sizeof(data));
__do_dentry_path(ctx, old_dentry, &data);
events.perf_submit(ctx, &data, sizeof(data));

inode = NULL;
data.state = PP_ENTRY_POINT;
data.type = EVENT_FILE_CREATE;
bpf_probe_read(&inode, sizeof(inode), &(new_dentry->d_inode));
if (inode) {
bpf_probe_read(&data.inode, sizeof(data.inode), &inode->i_ino);
}
__set_device_from_sb(&data, sb);
events.perf_submit(ctx, &data, sizeof(data));
__do_dentry_path(ctx, new_dentry, &data);
events.perf_submit(ctx, &data, sizeof(data));

out:
return 0;
}

int on_wake_up_new_task(struct pt_regs *ctx, struct task_struct *task)
{
struct inode *pinode = NULL;
Expand Down

0 comments on commit 0d36c78

Please sign in to comment.