|
|
@@ -311,81 +311,6 @@ done:
|
|
|
}
|
|
|
|
|
|
|
|
|
-static __always_inline void
|
|
|
-cw_append_item_to_slice(void *new_item, u32 item_size, void *slice_user_ptr) {
|
|
|
- // read the slice descriptor
|
|
|
- struct go_slice_ot slice = {0};
|
|
|
- long res = bpf_probe_read_user(&slice, sizeof(slice), slice_user_ptr);
|
|
|
- if (res != 0) {
|
|
|
- cw_bpf_debug("cw_append_item_to_slice: failed to read slice descriptor, res=%ld\n", res);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // cw_bpf_debug("cw_append_item_to_slice len is %d\n", slice.len);
|
|
|
- // cw_bpf_debug("cw_append_item_to_slice cap is %d\n", slice.cap);
|
|
|
- // cw_bpf_debug("cw_append_item_to_slice array is %p\n", slice.array);
|
|
|
-
|
|
|
- u64 slice_len = slice.len;
|
|
|
- u64 slice_cap = slice.cap;
|
|
|
- if (slice_len < slice_cap && slice.array != NULL) {
|
|
|
- // Room available on current array, append to the underlying array
|
|
|
- // cw_bpf_debug("enter the cw_append_item_to_slice11111\n");
|
|
|
- res = bpf_probe_write_user(slice.array + (item_size * slice_len), new_item, item_size);
|
|
|
- } else {
|
|
|
- // No room on current array - try to copy new one of size item_size * (len + 1)
|
|
|
- u32 alloc_size = item_size * slice_len;
|
|
|
- if (alloc_size >= MAX_SLICE_ARRAY_SIZE) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Get temporary buffer
|
|
|
- u32 index = 0;
|
|
|
- struct slice_array_buff *map_buff = bpf_map_lookup_elem(&slice_array_buff_map, &index);
|
|
|
- if (!map_buff) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- unsigned char *new_slice_array = map_buff->buff;
|
|
|
- // help the verifier
|
|
|
- alloc_size &= (MAX_SLICE_ARRAY_SIZE - 1);
|
|
|
- if (alloc_size + item_size > MAX_SLICE_ARRAY_SIZE) {
|
|
|
- // No room for new item
|
|
|
- return;
|
|
|
- }
|
|
|
- // Append to buffer
|
|
|
- if (slice.array != NULL) {
|
|
|
- bpf_probe_read_user(new_slice_array, alloc_size, slice.array);
|
|
|
- // cw_bpf_debug("append_item_to_slice: copying %d bytes to new array from address 0x%llx",
|
|
|
- // alloc_size,
|
|
|
- // slice.array);
|
|
|
- }
|
|
|
- copy_byte_arrays(new_item, new_slice_array + alloc_size, item_size);
|
|
|
-
|
|
|
- // Copy buffer to userspace
|
|
|
- u32 new_array_size = alloc_size + item_size;
|
|
|
-
|
|
|
- void *new_array = write_target_data(new_slice_array, new_array_size);
|
|
|
- if (new_array == NULL) {
|
|
|
- cw_bpf_debug("append_item_to_slice: failed to copy new array to userspace");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Update array pointer of slice
|
|
|
- slice.array = new_array;
|
|
|
- slice.cap++;
|
|
|
-
|
|
|
- // cw_bpf_debug("enter the cw_append_item_to_slice222222\n");
|
|
|
- }
|
|
|
-
|
|
|
- // Update len
|
|
|
- slice.len++;
|
|
|
- // cw_bpf_debug("after cw_append_item_to_slice len is %d\n", slice.len);
|
|
|
- long success = bpf_probe_write_user(slice_user_ptr, &slice, sizeof(slice));
|
|
|
- if (success != 0) {
|
|
|
- cw_bpf_debug("append_item_to_slice: failed to update slice in userspace");
|
|
|
- return;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
SEC("uprobe/loopyWriter_headerHandler")
|
|
|
int uprobe_LoopyWriter_HeaderHandler(struct pt_regs *ctx) {
|