-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Verify format specifiers in bpf_trace_printk in rewriter #1046
Conversation
6882f8c
to
bd9e50c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks ok.
[buildbot, test this please]
@@ -523,6 +524,54 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) { | |||
return true; | |||
} | |||
|
|||
bool BTypeVisitor::checkFormatSpecifiers(string fmt, SourceLocation loc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not const string&
to avoid copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
} | ||
if (fmt[i] != '%') | ||
continue; | ||
if (nb_specifiers >= 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like printing literal "%%"
isn't supported here or in the kernel. Is that the right interpretation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. @4ast Is that on purpose?
Buildbot, you're not listening! |
bd9e50c
to
533c25e
Compare
Build failed legitimately on fedora it seems. Failed in py_test_clang with:
|
The three errors are expected (see the Ubuntu builds), but we get a segfault afterwards:
I'll have to start a Fedora to check it out. |
@pchaigno Have you had any luck reproducing the build issue? |
@goldshtn Yes, I'm able to reproduce. It doesn't look related to the changes I made though, since I'm able to reproduce by copying the new tests on the master branch. Weirdly, if I replace: bpf_trace_printk("%0.2f\\n", 1.0); with bpf_trace_printk("%0.2f\\n", 1); the segfault disappears... I'm trying to get more information, but my day job doesn't leave me much free time. I'd appreciate any help :-) |
Yup, I can confirm that just an empty script that uses
/cc @drzaeus77 |
Hmm, maybe something with how LLVM deals with floats (unsupported in bpf), that only happens on Fedora due to the LLVM version that is used. I would suggest fixing up this PR to use |
Verifies format specifiers while rewriting calls to bpf_trace_printk and prints a warning the printk will be rejected by the kernel at runtime. For tests, redirects stderr at the file descriptor level in order to catch warnings from the C library.
533c25e
to
9341942
Compare
Verifies format specifiers while rewriting calls to bpf_trace_printk
and prints a warning the printk will be rejected by the kernel at
runtime.
For tests, redirects stderr at the file descriptor level in order to
catch warnings from the C library.
Fixes #124.
/cc @drzaeus77
I noticed the kernel doesn't check that the number of format
specifiers equals the number of arguments. Is that normal?
(
CAP_SYS_ADMIN
is required to callbpf_trace_printk
, but it stillfeels weird.)