Skip to content

Commit

Permalink
bpf: Do not attempt to read blob_data if the length is 0
Browse files Browse the repository at this point in the history
Signed-off-by: Daiki Ueno <[email protected]>
  • Loading branch information
ueno committed Oct 2, 2023
1 parent b8afd47 commit 8836666
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions agent/src/bpf/audit.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,6 @@ record_blob_data (struct pt_regs *ctx)
return err;
}

long value_ptr;
err = bpf_usdt_arg (ctx, 2, &value_ptr);
if (err < 0)
{
DEBUG ("unable to get the third argument: %ld\n", err);
return err;
}

long value_size;
err = bpf_usdt_arg (ctx, 3, &value_size);
if (err < 0)
Expand Down Expand Up @@ -281,12 +273,24 @@ record_blob_data (struct pt_regs *ctx)
goto error;
}

value_size &= (VALUE_SIZE - 1);
err = bpf_probe_read_user (event->value, value_size, (void *)value_ptr);
if (err < 0)
if (value_size > 0)
{
DEBUG ("unable to read event data: %ld\n", err);
goto error;
long value_ptr;

err = bpf_usdt_arg (ctx, 2, &value_ptr);
if (err < 0)
{
DEBUG ("unable to get the third argument: %ld\n", err);
goto error;
}

value_size &= (VALUE_SIZE - 1);
err = bpf_probe_read_user (event->value, value_size, (void *)value_ptr);
if (err < 0)
{
DEBUG ("unable to read event data: %ld\n", err);
goto error;
}
}

event->size = value_size;
Expand Down

0 comments on commit 8836666

Please sign in to comment.