Description of problem: fapolicyd relies on correctly identifying file types to make access control decisions. It was recently found that it can't tell the difference between executables and libraries. file --mime-type /usr/bin/bash /usr/bin/bash: application/x-sharedlib file --mime-type /usr/lib64/libaudit.so.1.0.0 /usr/lib64/libaudit.so.1.0.0: application/x-sharedlib It used to do a better job than that. The current version on Fedora 30 seems to one thing right: file --mime-type /usr/bin/bash /usr/bin/bash: application/x-pie-executable But now it identifies libraries as the same thing: file --mime-type /usr/lib64/libaudit.so.1.0.0 /usr/lib64/libaudit.so.1.0.0: application/x-pie-executable Not sure what to do, but the detection is off. Version-Release number of selected component (if applicable): file-5.33-8.el8.x86_64
file's behavior in RHEL-8 is (intentionally) compatible with RHEL-7. The difference is caused mainly by the way how the binaries are built in RHEL-8. The use of hardening flags caused more binaries to be classified "incorrectly", even when using the same patterns. file's upstream implemented a heuristic based on the executable permission bit but it did not work on Fedora because all shared libraries are executable on Fedora. So we reverted the heuristic: http://pkgs.devel.redhat.com/cgit/rpms/file/tree/file-5.33-pie-executable-revert.patch?h=rhel-8.2.0 In any case, distinguishing of shared objects and dynamically linked executables has never worked reliably and still does not work. You can try the following quick test on any Fedora/RHEL release: $ for i in /usr/bin/*; do file --mime $i; done | grep shared $ for i in /usr/lib64/*; do file --mime $i; done | grep exec Related bugs: bug #1713832 bug #1581343 bug #1570246 bug #1296868
> file's behavior in RHEL-8 is (intentionally) compatible with RHEL-7. Is that desirable? :-) I can understand not wanting to drag pie/RELRO into it and leaving things as application/x-executable and application/x-sharedlib. I think the decision tree is like this: Is there ELF magic, no, something else, yes: does it have an interpreter section, yes application/x-executable, no: does it have a dynamic section, yes application/x-sharedlib, no: does it have a text section yes application/x-executable <- static exe, no malformed binary. Noting whether or not its compiled with pie, relro, or static really doesn't matter. But I don't understand why we would preserve bad behavior.
I wrote my own ELF parser to work around this problem. I really think the preserved behavior is wrong. The above decision tree is almost correct. Turns out libc and libpthreads have an interpreter. :-) Since this problem is worked around, I suppose it can be closed.
(In reply to Steve Grubb from comment #3) > I wrote my own ELF parser to work around this problem. Thanks! I believe this is the best solution for RHEL-8. Too many programs rely on the buggy output of file(1). > I really think the preserved behavior is wrong. By preserving the RHEL-7 behavior I meant this patch: http://pkgs.devel.redhat.com/cgit/rpms/file/tree/file-5.33-pie-executable-revert.patch?h=rhel-8.2.0 If I removed it, all ELF binaries would be reported as executables because of the executable permission bit. > The above decision tree is almost correct. > Turns out libc and libpthreads have an interpreter. :-) Thanks for the suggestion! I think we should give it a try upstream...
This is the decision tree in case it helps: https://github.com/linux-application-whitelisting/fapolicyd/blob/master/src/file.c#L257 The parser which picks out the artifacts to use in the decision tree is here: https://github.com/linux-application-whitelisting/fapolicyd/blob/master/src/file.c#L419
Removing the bug from CCC tracker since it was worked around. Kamil, do you see any reason to keep this bug open?
Thanks! I would prefer not to change file's classification of ELF files in RHEL-8. Let's move this effort to Fedora/upstream.
OK, moving this to rawhide.
This bug appears to have been reported against 'rawhide' during the Fedora 32 development cycle. Changing version to 32.
This message is a reminder that Fedora 32 is nearing its end of life. Fedora will stop maintaining and issuing updates for Fedora 32 on 2021-05-25. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as EOL if it remains open with a Fedora 'version' of '32'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, simply change the 'version' to a later Fedora version. Thank you for reporting this issue and we are sorry that we were not able to fix it before Fedora 32 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora, you are encouraged change the 'version' to a later Fedora version prior this bug is closed as described in the policy above. Although we aim to fix as many bugs as possible during every release's lifetime, sometimes those efforts are overtaken by events. Often a more recent Fedora release includes newer upstream software that fixes bugs or makes them obsolete.
This bug appears to have been reported against 'rawhide' during the Fedora 35 development cycle. Changing version to 35.
I have a Python script being picked as "Objective-C source, ASCII text". I do appreciate that "file" is inherently heuristic in nature, but the Python script in question has the usual shebang line #!/usr/bin/python3 as the first line in the file. Seems rather odd "file" doesn't check for a shebang on files it correctly detects as text. Maybe this bug should be moved to Fedora 37.
I'm wondering if you have ^#import in the file? If so, it matches Objective-C with a strength of 25, where #!\040/usr/bin/python has a strength of 15. It would seem very plausible for someone to comment out an import statement. I'm just wondering why Objective-C would be stronger than a python shebang?
One of my import lines was commented out, if I remove the line "file" identifies it as a python script. Seems odd the shebang would have a lower priority, since if the shebang were wrong I think the whole script would fail. I think shebang lines should prevail in all cases, be the definitive factor since they have to be correct.
This message is a reminder that Fedora Linux 35 is nearing its end of life. Fedora will stop maintaining and issuing updates for Fedora Linux 35 on 2022-12-13. It is Fedora's policy to close all bug reports from releases that are no longer maintained. At that time this bug will be closed as EOL if it remains open with a 'version' of '35'. Package Maintainer: If you wish for this bug to remain open because you plan to fix it in a currently maintained version, change the 'version' to a later Fedora Linux version. Thank you for reporting this issue and we are sorry that we were not able to fix it before Fedora Linux 35 is end of life. If you would still like to see this bug fixed and are able to reproduce it against a later version of Fedora Linux, you are encouraged to change the 'version' to a later version prior to this bug being closed.
This needs to be moved to Fedora 37. I am unable to do that.
I asked about this on the file development mail list. The original problem is solved. This should be closed out. The recent issue is reported. Progress can be watched here (at the bottom): https://mailman.astron.com/pipermail/file/2022-November/thread.html
Fedora Linux 35 entered end-of-life (EOL) status on 2022-12-13. Fedora Linux 35 is no longer maintained, which means that it will not receive any further security or bug fix updates. As a result we are closing this bug. If you can reproduce this bug against a currently maintained version of Fedora Linux please feel free to reopen this bug against that version. Note that the version field may be hidden. Click the "Show advanced fields" button if you do not see the version field. If you are unable to reopen this bug, please file a new report against an active release. Thank you for reporting this bug and we are sorry it could not be fixed.