Skip to content

Commit

Permalink
inject.py: fix BPF verification fails due to register offset
Browse files Browse the repository at this point in the history
run `./inject.py kmalloc -v '__x64_sys_mount()` gets the error:
"math between map_value pointer and register with unbounded min value is not allowed",
as the array len is 2:
    struct pid_struct {
        u64 curr_call; /* book keeping to handle recursion */
        u64 conds_met; /* stack pointer */
        u64 stack[2];
    };

but in `__x64_sys_mount_exit`

    /*
     * Generate exit logic
     */

    if (p->conds_met < 1 || p->conds_met >= 3)
            return 0;

    if (p->stack[p->conds_met - 1] == p->curr_call)
            p->conds_met--;

The check for the upper bound of the array is 3.

Signed-off-by: Wenbo Zhang <[email protected]>
  • Loading branch information
ethercflow authored and yonghong-song committed Jun 16, 2024
1 parent 1d8daaa commit 69cc7f6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _get_exit_logic(self):
if (p->stack[p->conds_met - 1] == p->curr_call)
p->conds_met--;
"""
return text % str(self.length + 1)
return text % str(self.length)

def _generate_exit(self):
prog = self._get_heading() + """
Expand Down

0 comments on commit 69cc7f6

Please sign in to comment.