-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
alignment issues on solaris 11 #1700
Comments
We fixed some alignment issues in this commit: But that was released in version 4.0.1. Version 3.11 is really old, my recommendation is upgrading to the latest version. |
Just for the record. libyara.so.9.0.1 register %o0 is on a half word boundary, I believe, %o0 = 0x0000000100760c1d I think this code is near the return from _yr_re_emit, which, at first, lead me to suspect stack corruption, I tried compiling with -g, and without -O3, and get the same results |
I've fixed some alignment issues in this branch: Try with that version and let me know if you find some other alignment issues, there are probably more. |
i tried git clone of the link and ran the usually yara boostrap.sh and configure, but when I tried make (on I am not a lex person and I tried to figure it out but it's gonna take some time. |
That's probably because your system has an old version of |
That tip was helpful. Apparently the git tree already has lexer.c and grammer.c so, normally, there is no need to run lex (of flex) or yacc to get the corresponding C file. Solaris's lex and yacc don't work correctly with yara. For example, the yara makefile calls yacc with. -W flag, but there is no -W option to Solaris' yacc. But by touching the C files, there is no need to run lex/yacc. So I got the git tree to build, but, alas, I still get the alignment issue in the same place. I tried -g and -Oo, but with no better results. I need to figure out exactly which C line in _yr_re_emit is being executed when we get the bus error. |
@jedele can you confirm if the alignment issues are completely fixed? |
I took a look at the patches you've posted but they don't solve the underlying issue, which is that the arena implementation invokes undefined behaviour. With UBSan enabled it is possible to see this (on amd64 Linux):
If you call, e.g. |
To answer @plusvic, no, unfortunately I am still seeing alignment issues, sparcv9 architecture. The Sparcv9 architecture manual states: Half word accesses shall be aligned on 2-byte boundaries; word accesses (which include instruction fetches) shall be aligned on 4-byte boundaries; extended-word and doubleword accesses shall be aigned on 8-byte boundaries; and quadword quantities shall be aligned on 16-byte boundaries. An improperly aligned address in a load, store, or load-store instruction causes a trap to occur And I agree with meme's comment earlier that the arena allocator should give out addresses with 8 byte alignment. |
I've updated fix_alignment_issues branch with commit 568bdd3. Please try that and let me know if a new issue arises. |
@plusvic. I was able to install and build with your latest fix. The application I am using on Solaris 11 gets further along but still gets a bus error, another alignment issue, in a different place in the code. The code is doing a The back trace shows it in yara_yyparse: Based on the surrounding function calls, yara_yyparse() appears to be calling yr_arena_get_current_offset()
|
I've fixed more alignment issues in the Also, without having a way to run automated tests in this kind of platforms, is going to be hard to keep the code free from issues down the road. I'll try to setup some automated tests with UBSan enabled and see what comes out. |
@plusvic I updated my tree to your latest alignment tree, built everything and ran it. Again, a bus error, this As for as any automated tests, I can only offer to try anything new you want to provide since It only takes a few minutes to download and build, And when it crashes, it goes fast. Thanks for the help you have provided so far. |
Could you post the full stack trace for this crash? |
@meme could you provide more details about how did you get this error?
I'm compiling YARA with |
For some reason I don't get the errors on MacOS, but it's working fine on Linux. |
@plusvic I produced that error on 4.2.1, as described:
I assume the test suite has that exact case? It is possible that you are getting "lucky" and the allocator is returning addresses on an 8 byte alignment due to the nature of the test suite. Perhaps issue multiple callbacks and intermix different callback types to create more allocations on 4 byte boundaries. |
@plusvic. Glad to. Here you go: yaracompilescan:core> ::stack If you want more disassembly of the surrounding code, let me know. |
@jedele Could you try the latest version in the branch https://github.com/VirusTotal/yara/tree/fix_alignment_issues? |
@plusvic. Today I updated the git tree to to your latest and rebuild everything. It did not crash! But, unfortunately, when I examined the results, it was wrong! What used to match no longer matches. I tried modifying the rules, but it could not match them. I tried a very large sample with a lot of rules. It output a lot warnings, a lot of "NO MATCH" results, and then hung. yaracompilescan:core> $c yaracompilescan:core> ::dis _yr_re_fiber_sync+0x168 I can do more debugging tomorrow to see if we are in some infinite loop in yr_re_fiber_sync. But the fact that the code no longer matches any rules is enough to make me go back to an earler version (4.2.1) of yara and my code just to make sure I haven't done anything to cause it. |
Well, at least it looks like we made some progress. If you can shed some additional light about this new issue would be great. I would say that there's more than one issue going on here. The infinite loop in |
Here is a single rule matching a short list of data. The data, bigfile, is a list of full pathnames. james.edele@dtexsol01 ~/yara-alignment $ cat rulesfile $ cat bigfile james.edele@dtexsol01 ~/yara-alignment the warning message is pretty normal even when everything works. |
I built the fix_alignment_issues on Ubuntu (20.04) and it worked!. I tried it then on AIX and it hung and reported NO MATHCES in the rules and it hung. I did not verify what function it was hung in. But this is what happened on Solaris 11. See above. In both ubuntu andAIX cases, I verified that yara.4.2.1 worked correctly with my program. I'll be taking a few days off, but I can start debugging the solaris code when I get back. |
Apologies for such a long delay w/o comment. For fun, I went back to the yara 4.2.1 code and grabbed the 1 or 2 lines for RE_OPCODE_JUMP and used them. Alas, it gets a bus error. |
So, for clarifying, you are testing the latest changes in the Can you verify if
I guess the infinite loop is because somehow |
I think your most recent issue could be fixed by 8546232. Let me know if something changed. |
You are correct, jmp_len was 0. |
This branch worked on Ubuntu 20.04, Solaris 11 and AIX (current release) |
Great, I've merged it in the master branch. |
The x86 platform is very forgiving when you access a 16-bits variable stored at a memory address that is not aligned to a 2-bytes boundary, or a 32-bits variable that is not aligned to 4-bytes boundary, and so on. Other platforms, like ARM or Sparc are not that flexible, and accessing a value by dereferencing a pointer that is not aligned to the size of the value causes a processor fault. This fixes multiple issues caused by pointers that are not aligned to the size of the value. Fixes: #1700
I have a C application that links with 3.11 libyara and works fine on Ubuntu 20.04.4 LTS.
But when I install everything on Solaris 11 and build it, it does not work with the libyara shared library.
So I statically link the needed functions from libyara with the application and it builds.
But when I run it on solaris 11.4.0.15 sun4v sparc
(doing the same operations that work fine on Ubuntu) it gets a bus error, I traced it
down to an alignment error, It appears to me that yr_area_allocate_memory is returning a buffer which
is not aligned (something like 0x000100b4c301).
Are there any special libtool/make/automate or configuration flags needed to only return aligned memory?
Thank you,
jim edele
The text was updated successfully, but these errors were encountered: