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

Commit 0d36c78

Browse files
Merge pull request #43 from vmware/jw-PSCLNX-7520_rename_events
Handle Basic File Rename Events
2 parents c01cdc1 + 3fbe14f commit 0d36c78

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

examples/bcc_sample.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2020 VMware, Inc.
2+
// Copyright 2020-20201 VMware, Inc.
33
// SPDX-License-Identifier: BSD-2-Clause
44
//
55

@@ -94,6 +94,11 @@ var allProbes = []probeMeta{
9494
PPCbName: "on_security_inode_unlink",
9595
IsKretProbe: false,
9696
},
97+
probeMeta{
98+
PP: "security_inode_rename",
99+
PPCbName: "on_security_inode_rename",
100+
IsKretProbe: false,
101+
},
97102

98103
//# execve and execveat syscalls
99104
probeMeta{

examples/bcc_sample.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
#
3-
# Copyright 2020 VMware, Inc.
3+
# Copyright 2020-2021 VMware, Inc.
44
# SPDX-License-Identifier: BSD-2-Clause
55
#
66

@@ -586,6 +586,10 @@ def attach_probes(bcc):
586586
pp='security_inode_unlink',
587587
pp_cb_name='on_security_inode_unlink',
588588
),
589+
Probe(
590+
pp='security_inode_rename',
591+
pp_cb_name='on_security_inode_rename',
592+
),
589593

590594
# execve and execveat syscalls
591595
Probe(

src/bcc_sensor.c

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2020 VMware, Inc.
2+
* Copyright 2019-2021 VMware, Inc.
33
* SPDX-License-Identifier: GPL-2.0
44
*/
55

@@ -953,6 +953,57 @@ int on_security_inode_unlink(struct pt_regs *ctx, struct inode *dir,
953953
return 0;
954954
}
955955

956+
int on_security_inode_rename(struct pt_regs *ctx,
957+
struct inode *old_dir, struct dentry *old_dentry,
958+
struct inode *new_dir, struct dentry *new_dentry,
959+
unsigned int flags)
960+
{
961+
struct data_t data = {};
962+
struct super_block *sb = NULL;
963+
struct inode *inode = NULL;
964+
965+
sb = _sb_from_dentry(old_dentry);
966+
if (!sb) {
967+
goto out;
968+
}
969+
970+
if (__is_special_filesystem(sb)) {
971+
goto out;
972+
}
973+
974+
__set_key_entry_data(&data, NULL);
975+
976+
data.state = PP_ENTRY_POINT;
977+
data.type = EVENT_FILE_DELETE;
978+
bpf_probe_read(&inode, sizeof(inode), &(old_dentry->d_inode));
979+
if (inode) {
980+
bpf_probe_read(&data.inode, sizeof(data.inode), &inode->i_ino);
981+
}
982+
983+
struct file_data key = { .device = data.device, .inode = data.inode };
984+
file_map.delete(&key);
985+
986+
__set_device_from_sb(&data, sb);
987+
events.perf_submit(ctx, &data, sizeof(data));
988+
__do_dentry_path(ctx, old_dentry, &data);
989+
events.perf_submit(ctx, &data, sizeof(data));
990+
991+
inode = NULL;
992+
data.state = PP_ENTRY_POINT;
993+
data.type = EVENT_FILE_CREATE;
994+
bpf_probe_read(&inode, sizeof(inode), &(new_dentry->d_inode));
995+
if (inode) {
996+
bpf_probe_read(&data.inode, sizeof(data.inode), &inode->i_ino);
997+
}
998+
__set_device_from_sb(&data, sb);
999+
events.perf_submit(ctx, &data, sizeof(data));
1000+
__do_dentry_path(ctx, new_dentry, &data);
1001+
events.perf_submit(ctx, &data, sizeof(data));
1002+
1003+
out:
1004+
return 0;
1005+
}
1006+
9561007
int on_wake_up_new_task(struct pt_regs *ctx, struct task_struct *task)
9571008
{
9581009
struct inode *pinode = NULL;

0 commit comments

Comments
 (0)