Skip to content

Commit

Permalink
Adding error checks for ctx_load_bytes.
Browse files Browse the repository at this point in the history
The function ctx_load_bytes() was being called without checking for return errors.
This could let to a possible evaluation of an uninitializaed variable.

Added a verification to drop packets when ctx_load_bytes() returns error.

Signed-off-by: Thales Paiva <thales@accuknox.com>
  • Loading branch information
trvll committed May 21, 2021
1 parent d3b5492 commit 490485d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bpf/lib/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ static __always_inline int ipv6_dec_hoplimit(struct __ctx_buff *ctx, int off)
{
__u8 hl;

ctx_load_bytes(ctx, off + offsetof(struct ipv6hdr, hop_limit),
&hl, sizeof(hl));
if (ctx_load_bytes(ctx, off + offsetof(struct ipv6hdr, hop_limit),
&hl, sizeof(hl)) < 0)
return DROP_INVALID;

if (hl <= 1)
return 1;
hl--;
Expand Down

0 comments on commit 490485d

Please sign in to comment.