Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure in argument name resolution results in empty value #3892

Open
oshaked1 opened this issue Feb 22, 2024 · 4 comments · May be fixed by #4442
Open

Failure in argument name resolution results in empty value #3892

oshaked1 opened this issue Feb 22, 2024 · 4 comments · May be fixed by #4442
Assignees
Labels
Milestone

Comments

@oshaked1
Copy link
Contributor

Description

When tracee tries to resolve a numeric argument to a string (e.g. cmd value of bpf syscall), if the resolution fails, the event field will contain an empty string.

For example, running the following command, which uses a new eBPF feature not supported on my kernel:

sudo bpftool gen skeleton -L hello.bpf.o > hello.skel.h

Results in the following tracee event:

TIME             UID    COMM             PID     TID     RET              EVENT                     ARGS
11:37:28:562345  0      bpftool          211739  211739  -22              bpf                       cmd: , attr: 0x7ffc011cdec0, size: 8

The strace output shows that this command is not supported, which explains why the resolution fails:

bpf(0x24 /* BPF_??? */, 0x7ffe6338f210, 8) = -1 EINVAL (Invalid argument)

This is only one example of incorrect handling of failed name resolutions, another example I found is ptrace commands, and there are possibly many others.

An example of a correctly handled name resolution is the syscall name of sys_enter, where an unknown syscall will result in the syscall number as the value.

Output of tracee version:

Tracee version: v0.20.0

Output of uname -a:

Linux ********* 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Additional details

@geyslan
Copy link
Member

geyslan commented Feb 22, 2024

@oshaked1 is this somehow related to #3891? If so, please test it again using this patch #3848.

@oshaked1
Copy link
Contributor Author

#3891 is not related though I did encounter these together. I tried your patch anyways, it doesn't seem to fix it.

@yanivagman yanivagman added this to the v0.22.0 milestone May 9, 2024
@geyslan geyslan modified the milestones: v0.22.0, v0.23.0 Aug 23, 2024
@ShohamBit
Copy link
Collaborator

Hey @oshaked1,

I’m currently working on recreating the issue but couldn’t reproduce it fully. Here's what I did step-by-step:

  1. I ran Tracee from the /tracee directory using:

    sudo ./dist/tracee -e bpf
  2. In another console, I moved to /tracee/dist and ran:

    sudo bpftool gen skeleton -L tracee.bpf.o > hello.skell.h
  3. The following error was printed:

    libbpf: elf: skipping unrecognized data section(301) .rodata.str1.1
    libbpf: prog 'suspicious_syscall_source': bad map relo against '.rodata.str1.1' in section '.rodata.str1.1'
    Error: failed to open BPF object file: Relocation failed

However, nothing was captured by Tracee during this process.

Additional Details:

  • Tracee version:

    Tracee version: v0.22.0-123-g84aca9d8b4
    
  • Kernel version (uname -a):

    Linux ****** 5.15.0-125-generic #135-Ubuntu SMP Fri Sep 27 13:53:58 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
    

Let me know if there's anything specific I should test further, or if you have any suggestions for debugging this.

@oshaked1
Copy link
Contributor Author

oshaked1 commented Dec 17, 2024

@ShohamBit Use this code:

import ctypes
import errno
import os

# BPF syscall number (x86_64 Linux)
SYS_BPF = 321  # Verify on your system, e.g., using `man syscall`

# Invalid BPF command
BPF_INVALID_CMD = 9999

# Load the libc shared library
libc = ctypes.CDLL("libc.so.6", use_errno=True)

# Prepare dummy arguments
arg1 = ctypes.c_void_p(0)
arg2 = ctypes.c_void_p(0)
arg3 = ctypes.c_void_p(0)

# Call the syscall
ret = libc.syscall(SYS_BPF, BPF_INVALID_CMD, arg1, arg2, arg3)

if ret == -1:
    err = ctypes.get_errno()
    print(f"Error: {os.strerror(err)} (errno={err})")
    if err == errno.EINVAL:
        print("As expected, got EINVAL for an invalid BPF command.")
    else:
        print("Unexpected error occurred.")

@ShohamBit ShohamBit linked a pull request Dec 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants