@@ -735,7 +735,6 @@ BPF_LRU_HASH(network_map, net_id_t, net_ctx_t, 10240); // network identifier to
735735BPF_ARRAY (config_map , config_entry_t , 1 ); // various configurations
736736BPF_ARRAY (file_filter , path_filter_t , 3 ); // filter vfs_write events
737737BPF_PERCPU_ARRAY (bufs , buf_t , MAX_BUFFERS ); // percpu global buffer variables
738- BPF_PERCPU_ARRAY (bufs_off , u32 , MAX_BUFFERS ); // holds offsets to bufs respectively
739738BPF_PROG_ARRAY (prog_array , MAX_TAIL_CALL ); // store programs for tail calls
740739BPF_PROG_ARRAY (prog_array_tp , MAX_TAIL_CALL ); // store programs for tail calls
741740BPF_PROG_ARRAY (sys_enter_tails , MAX_EVENT_ID ); // store programs for tail calls
@@ -1646,16 +1645,6 @@ static __always_inline buf_t *get_buf(int idx)
16461645 return bpf_map_lookup_elem (& bufs , & idx );
16471646}
16481647
1649- static __always_inline void set_buf_off (int buf_idx , u32 new_off )
1650- {
1651- bpf_map_update_elem (& bufs_off , & buf_idx , & new_off , BPF_ANY );
1652- }
1653-
1654- static __always_inline u32 * get_buf_off (int buf_idx )
1655- {
1656- return bpf_map_lookup_elem (& bufs_off , & buf_idx );
1657- }
1658-
16591648// The biggest element that can be saved with this function should be defined here
16601649#define MAX_ELEMENT_SIZE sizeof(struct sockaddr_un)
16611650
@@ -2036,7 +2025,6 @@ static __always_inline void *get_path_str(struct path *path)
20362025 bpf_probe_read (& (string_p -> buf [(MAX_PERCPU_BUFSIZE >> 1 ) - 1 ]), 1 , & zero );
20372026 }
20382027
2039- set_buf_off (STRING_BUF_IDX , buf_off );
20402028 return & string_p -> buf [buf_off ];
20412029}
20422030
@@ -2094,7 +2082,6 @@ static __always_inline void *get_dentry_path_str(struct dentry *dentry)
20942082 bpf_probe_read (& (string_p -> buf [(MAX_PERCPU_BUFSIZE >> 1 ) - 1 ]), 1 , & zero );
20952083 }
20962084
2097- set_buf_off (STRING_BUF_IDX , buf_off );
20982085 return & string_p -> buf [buf_off ];
20992086}
21002087
@@ -4647,14 +4634,10 @@ static __always_inline int do_file_write_operation_tail(struct pt_regs *ctx, u32
46474634 }
46484635 loff_t * pos = (loff_t * ) saved_args .args [3 ];
46494636
4650- // Get per-cpu string buffer
4651- buf_t * string_p = get_buf (STRING_BUF_IDX );
4652- if (string_p == NULL )
4653- return -1 ;
4654- get_path_str (GET_FIELD_ADDR (file -> f_path ));
4655- u32 * off = get_buf_off (STRING_BUF_IDX );
4656- if (off == NULL )
4637+ void * file_path = get_path_str (GET_FIELD_ADDR (file -> f_path ));
4638+ if (data .buf_off > MAX_PERCPU_BUFSIZE - MAX_STRING_SIZE )
46574639 return -1 ;
4640+ bpf_probe_read_str (& (data .submit_p -> buf [data .buf_off ]), MAX_STRING_SIZE , file_path );
46584641
46594642// Check if capture write was requested for this path
46604643#pragma unroll
@@ -4669,10 +4652,11 @@ static __always_inline int do_file_write_operation_tail(struct pt_regs *ctx, u32
46694652
46704653 has_filter = true;
46714654
4672- if (* off > MAX_PERCPU_BUFSIZE - MAX_STRING_SIZE )
4655+ if (data . buf_off > MAX_PERCPU_BUFSIZE - MAX_STRING_SIZE )
46734656 break ;
46744657
4675- if (has_prefix (filter_p -> path , (char * ) & string_p -> buf [* off ], MAX_PATH_PREF_SIZE )) {
4658+ if (has_prefix (
4659+ filter_p -> path , (char * ) & data .submit_p -> buf [data .buf_off ], MAX_PATH_PREF_SIZE )) {
46764660 filter_match = true;
46774661 break ;
46784662 }
@@ -4698,10 +4682,10 @@ static __always_inline int do_file_write_operation_tail(struct pt_regs *ctx, u32
46984682 u64 id = bpf_get_current_pid_tgid ();
46994683 u32 pid = data .context .task .pid ;
47004684
4701- if (* off > MAX_PERCPU_BUFSIZE - MAX_STRING_SIZE )
4685+ if (data . buf_off > MAX_PERCPU_BUFSIZE - MAX_STRING_SIZE )
47024686 return -1 ;
47034687
4704- if (!has_prefix ("/dev/null" , (char * ) & string_p -> buf [* off ], 10 ))
4688+ if (!has_prefix ("/dev/null" , (char * ) & data . submit_p -> buf [data . buf_off ], 10 ))
47054689 pid = 0 ;
47064690
47074691 if (data .config -> options & OPT_CAPTURE_FILES ) {
0 commit comments