Skip to content

Commit

Permalink
tools/ttysnoop: Fix uninitialized 'buf' error
Browse files Browse the repository at this point in the history
ENV: LLVM 13.0.1, Kernel 5.15.67, aarch64

Overview of the error:

The verifier is unhappy, if '(r10 -32)' is not initialized, see also [0].

  $ sudo ./ttysnoop.py 10
  bpf: Failed to load program: Permission denied
  3: (7b) *(u64 *)(r10 -8) = r6
  4: (7b) *(u64 *)(r10 -16) = r6
  5: (7b) *(u64 *)(r10 -24) = r6
  6: (bf) r1 = r10
  ...
  91: (67) r0 <<= 32
  92: (77) r0 >>= 32
  ; if (bpf_probe_read_user(&data->buf, BUFSIZE, (void *)buf))
  93: (55) if r0 != 0x0 goto pc+356
  R0_w=inv0 R6=invP0 R7=map_value(id=0,off=0,ks=4,vs=260,imm=0) R8=map_value(
    id=0,off=4,ks=4,vs=260,imm=0) R9=inv256 R10=fp0 fp-8=mmmmmmmm
    fp-16=mmmmmmmm fp-24=mmmmmmmm
  94: (79) r2 = *(u64 *)(r10 -32)
  invalid read from stack R10 off=-32 size=8
  processed 593 insns (limit 1000000) max_states_per_insn 1 total_states 48
    peak_states 48 mark_read 3

This issue can also be resolved by upgrading LLVM>=14  and recompile and install
bcc.

[0] iovisor#2623

Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax authored and yonghong-song committed Feb 3, 2023
1 parent 3f84544 commit 39b62cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/ttysnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def usage():
#else
PROBE_TTY_WRITE
{
const char __user *buf;
const char __user *buf = NULL;
const struct kvec *kvec;
size_t count;
size_t count = 0;
if (iocb->ki_filp->f_inode->i_ino != PTS)
return 0;
Expand Down

0 comments on commit 39b62cb

Please sign in to comment.