Skip to content

Commit

Permalink
Merge pull request #66 from yonhan3/umbrella-pid-feature
Browse files Browse the repository at this point in the history
bomtrace3 use smaller param_buf for depfile instrumentation
  • Loading branch information
yonhan3 authored Feb 6, 2024
2 parents a03320a + 3493b55 commit 3f02c2f
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/patches/bomtrace3.patch
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ index a9224543b..c09d2d1d7 100644
printpath(tcp, tcp->u_arg[index + 0]);
tprint_arg_next();
diff --git a/src/strace.c b/src/strace.c
index 780e51e91..4067b11e2 100644
index 780e51e91..77f179331 100644
--- a/src/strace.c
+++ b/src/strace.c
@@ -43,6 +43,8 @@
Expand All @@ -61,7 +61,7 @@ index 780e51e91..4067b11e2 100644

case TE_EXITED:
+ /* Run the hook program to do analysis */
+ bomsh_hook_program(current_tcp->pid);
+ bomsh_hook_program(current_tcp->pid, status);
print_exited(current_tcp, current_tcp->pid, status);
droptcb(current_tcp);
return true;
Expand Down
25 changes: 23 additions & 2 deletions .devcontainer/src/bomsh_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static int bomsh_is_program_inlist(char *prog, char **prog_list, int num_progs)

// special programs that are usually named with some prefix
static const char *bomsh_special_progs[] = {"gcc", "cc", "g++", "clang", "clang++", "strip", "objcopy", "ld", "ld.gold", "ld.bfd", "ar", "ranlib"} ;
//static const char *bomsh_special_progs[] = {"gcc", "cc", "g++", "clang", "clang++", "strip", "objcopy", "ld", "ld.gold", "ld.bfd", "ar", "as", "ranlib"} ;
static const char *bomsh_special_pre_exec_progs[] = {"strip", "objcopy", "ranlib", "ar"} ;

// check if a path ends with a specific suffix, progs array must be sorted
Expand Down Expand Up @@ -382,6 +383,8 @@ bomsh_log_configs(int level)
bomsh_log_printf(level, "hash algorithm: %d\n", g_bomsh_config.hash_alg);
//bomsh_log_printf(level, "metadata to record: %d\n", g_bomsh_config.metadata_to_record);
bomsh_log_printf(level, "generate depfile: %d\n", g_bomsh_config.generate_depfile);
bomsh_log_printf(level, "depfile stack offset: %d\n", g_bomsh_config.depfile_stack_offset);
bomsh_log_printf(level, "handle CGO cc cmd: %d\n", g_bomsh_config.handle_cgo_cc_cmd);
bomsh_log_printf(level, "handle conftest: %d\n", g_bomsh_config.handle_conftest);
bomsh_log_printf(level, "handle GNU AS cmd: %d\n", g_bomsh_config.handle_gnu_as_cmd);
bomsh_log_printf(level, "handle pkg build cmd: %d\n", g_bomsh_config.handle_pkg_build_cmd);
Expand All @@ -407,6 +410,8 @@ bomsh_print_configs(void)
fprintf(stderr, "hash algorithm: %d\n", g_bomsh_config.hash_alg);
//fprintf(stderr, "metadata to record: %d\n", g_bomsh_config.metadata_to_record);
fprintf(stderr, "generate depfile: %d\n", g_bomsh_config.generate_depfile);
fprintf(stderr, "depfile stack offset: %d\n", g_bomsh_config.depfile_stack_offset);
fprintf(stderr, "handle CGO cc cmd: %d\n", g_bomsh_config.handle_cgo_cc_cmd);
fprintf(stderr, "handle conftest: %d\n", g_bomsh_config.handle_conftest);
fprintf(stderr, "handle GNU AS cmd: %d\n", g_bomsh_config.handle_gnu_as_cmd);
fprintf(stderr, "handle pkg build cmd: %d\n", g_bomsh_config.handle_pkg_build_cmd);
Expand Down Expand Up @@ -440,6 +445,8 @@ bomsh_read_value_for_keys(char *line_start, char *value_equal, char *value_newli
{
char *hash_alg_str = NULL;
char *generate_depfile_str = NULL;
char *depfile_stack_offset_str = NULL;
char *handle_cgo_cc_cmd_str = NULL;
char *handle_conftest_str = NULL;
char *handle_gnu_as_cmd_str = NULL;
char *handle_pkg_build_cmd_str = NULL;
Expand All @@ -449,8 +456,8 @@ bomsh_read_value_for_keys(char *line_start, char *value_equal, char *value_newli
char *strict_prog_path_str = NULL;
static const char *bomsh_config_keys[] = {"hook_script_file", "hook_script_cmdopt", "shell_cmd_file",
"tmpdir", "logfile", "raw_logfile", "syscalls",
"hash_alg", "generate_depfile", "handle_conftest",
"handle_gnu_as_cmd", "handle_pkg_build_cmd",
"hash_alg", "generate_depfile", "depfile_stack_offset", "handle_cgo_cc_cmd",
"handle_conftest", "handle_gnu_as_cmd", "handle_pkg_build_cmd",
"trace_execve_cmd_only", "record_raw_info_flags",
"skip_checking_prog_access", "strict_prog_path"};
char ** bomsh_config_fields[] = {
Expand All @@ -463,6 +470,8 @@ bomsh_read_value_for_keys(char *line_start, char *value_equal, char *value_newli
&g_bomsh_config.syscalls,
&hash_alg_str,
&generate_depfile_str,
&depfile_stack_offset_str,
&handle_cgo_cc_cmd_str,
&handle_conftest_str,
&handle_gnu_as_cmd_str,
&handle_pkg_build_cmd_str,
Expand Down Expand Up @@ -503,6 +512,14 @@ bomsh_read_value_for_keys(char *line_start, char *value_equal, char *value_newli
g_bomsh_config.generate_depfile = atoi(generate_depfile_str);
free(generate_depfile_str);
}
if (depfile_stack_offset_str) {
g_bomsh_config.depfile_stack_offset = atoi(depfile_stack_offset_str);
free(depfile_stack_offset_str);
}
if (handle_cgo_cc_cmd_str) {
g_bomsh_config.handle_cgo_cc_cmd = atoi(handle_cgo_cc_cmd_str);
free(handle_cgo_cc_cmd_str);
}
if (handle_conftest_str) {
g_bomsh_config.handle_conftest = atoi(handle_conftest_str);
free(handle_conftest_str);
Expand Down Expand Up @@ -688,12 +705,16 @@ void bomsh_init(int argc, char *argv[])
}
bomsh_log_printf(0, "successful with logfiles, verbose level: %d\n", bomsh_verbose);
bomsh_log_configs(8);
if (g_bomsh_global.logfile) fflush(g_bomsh_global.logfile);

argv += optind;
argc -= optind;
if (argc <= 0) {
error_msg_and_help("must have PROG [ARGS]");
}
if (!g_bomsh_config.depfile_stack_offset) {
g_bomsh_config.depfile_stack_offset = 4096;
}
if (!g_bomsh_config.strict_prog_path) {
bomsh_watched_program_names = create_watched_program_names(bomsh_watched_programs, bomsh_num_watched_programs);
bomsh_num_watched_program_names = bomsh_num_watched_programs;
Expand Down
9 changes: 8 additions & 1 deletion .devcontainer/src/bomsh_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ struct bomsh_configs {
// 0 generates depfile with instrumentation, 1 generates with subprocess, and 2 not generating depfile
int generate_depfile;

// number of offset bytes to stack top for instrumentation, default is 4096
int depfile_stack_offset;

// C compiling command invoked by CGO tool is ignored by default.
// 0 means not handling, 1 means handling such commands, 2 means recording for info-only
int handle_cgo_cc_cmd;

// conftest/conftest.o/libconftest.a are output files during ./configure
// these output files are ignored by default, since they are not very useful.
int handle_conftest;
Expand All @@ -47,7 +54,7 @@ struct bomsh_configs {
int trace_execve_cmd_only;

// flags to specify the behavior of recording raw logfile.
// if flags=1, we will not record information-only ADF (Artifact Dependency Fragment)
// if flags=1, we will record information-only ADF (Artifact Dependency Fragment)
int record_raw_info_flags;

// by default, we check prog R_OK|X_OK permission before recording a command.
Expand Down
Loading

0 comments on commit 3f02c2f

Please sign in to comment.