Skip to content

Commit

Permalink
tetragon: Fix data_event return value type
Browse files Browse the repository at this point in the history
And add comments for both data_event_bytes and data_event_str
functions.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri authored and kkourt committed Jun 1, 2023
1 parent d23650f commit 6eb0c30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
8 changes: 2 additions & 6 deletions bpf/process/bpf_execve_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ read_args(void *ctx, struct msg_execve_event *event)
(struct bpf_map_def *)&data_heap);
if (size > 0)
p->flags |= EVENT_DATA_ARGS;
else
size = 0;
}
return size;
}
Expand All @@ -114,12 +112,10 @@ read_path(void *ctx, struct msg_execve_event *event, void *filename)
size = data_event_str(ctx, (struct data_event_desc *)earg,
(unsigned long)filename,
(struct bpf_map_def *)&data_heap);
if (size < 0) {
if (size == 0)
flags |= EVENT_ERROR_FILENAME;
size = 0;
} else {
else
flags |= EVENT_DATA_FILENAME;
}
}

p->flags |= flags;
Expand Down
25 changes: 23 additions & 2 deletions bpf/process/data_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ do_str(void *ctx, struct msg_data *msg, unsigned long arg,
return -1;
}

static inline __attribute__((always_inline)) int data_event(
static inline __attribute__((always_inline)) size_t data_event(
void *ctx, struct data_event_desc *desc, unsigned long uptr,
size_t size, struct bpf_map_def *heap,
long (*do_data_event)(void *, struct msg_data *, unsigned long, size_t))
Expand All @@ -146,7 +146,7 @@ static inline __attribute__((always_inline)) int data_event(

msg = map_lookup_elem(heap, &zero);
if (!msg)
return -1;
return 0;

msg->common.op = MSG_OP_DATA;
msg->common.flags = 0;
Expand All @@ -171,13 +171,34 @@ static inline __attribute__((always_inline)) int data_event(
return sizeof(*desc);
}

/**
* data_event_bytes - sends data event for raw data
*
* @uptr: pointer to data
* @size: size of the data
*
* Sends data event with raw data specified by @uptr and @size and
* writes status values into @desc object.
*
* Returns size of struct @desc object or 0 in case of error.
*/
static inline __attribute__((always_inline)) size_t
data_event_bytes(void *ctx, struct data_event_desc *desc, unsigned long uptr,
size_t size, struct bpf_map_def *heap)
{
return data_event(ctx, desc, uptr, size, heap, do_bytes);
}

/**
* data_event_str - sends data event for string
*
* @uptr: pointer to string
*
* Sends data event with string specified by @uptr and writes status
* values into @desc object.
*
* Returns size of struct @desc object or 0 in case of error.
*/
static inline __attribute__((always_inline)) size_t
data_event_str(void *ctx, struct data_event_desc *desc, unsigned long uptr,
struct bpf_map_def *heap)
Expand Down

0 comments on commit 6eb0c30

Please sign in to comment.