-
Notifications
You must be signed in to change notification settings - Fork 95
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
Undefined behaviour while handling variadic arguments #272
Comments
It looks like this issue can be fixed via #270 |
@mozillazg oh, I should have checked the PRs more carefully! |
@javierhonduco thank you for bringing a full analysis. We hope to definitely fix this via #270. |
javierhonduco
added a commit
to parca-dev/parca-agent
that referenced
this issue
Dec 13, 2022
- fixes the undefined behavoiur issue that we recently reported: aquasecurity/libbpfgo#272 Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]>
kakkoyun
pushed a commit
to parca-dev/parca-agent
that referenced
this issue
Dec 13, 2022
- fixes the undefined behavoiur issue that we recently reported: aquasecurity/libbpfgo#272 Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]> Signed-off-by: Francisco Javier Honduvilla Coto <[email protected]>
This was solved via #273. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
Parca Agent sometimes crashes on startup with the SIGSEGV below. We currently use v0.4.4-libbpf-1.0.1. After some investigation, it was clear that this was happening more consistently in older kernels from the 4.x series. Running one of our tests under GDB:
Spent some time trying to find for any issues in the
libbpf_print
libbpf function and surrounding code, but could not find anything nor a clear reason why this crash would occur. All the code seemed sensible and it had checks in place.Given that other BPF applications I work on that also use libbpf but don't use libbpfgo weren't experiencing this crash made me think that perhaps this issue is somewhere else.
Variadic arguments 💣
libbpfgo sets a logging callback in here to filter out certain logs. This code however contains a bug that leads to undefined behaviour. For example, in the
va_arg
calls, we are assuming that the first variadic argument is a C string, but there are no guarantees that this is the case.Indeed, after adding some debugging statements I spotted the following string (source):
As per the manpage:
To summarise:
%s
) and in the order we expect (seeva_arg
calls);%d
);Note that no variadic arguments also would cause undefined behaviour, as per the C99 spec:
Possible solutions
printf
. I have a WIP patch that implements this solution, still a WIP, but happy to discuss over the next couple of days if this is something you would consider.The text was updated successfully, but these errors were encountered: