Bug 1761883 - file misidentifies some executables
Summary: file misidentifies some executables
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: file
Version: 35
Hardware: Unspecified
OS: Unspecified
low
medium
Target Milestone: ---
Assignee: Vincent Mihalkovič
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-10-15 13:53 UTC by Steve Grubb
Modified: 2022-12-13 15:13 UTC (History)
5 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2022-12-13 15:13:34 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Steve Grubb 2019-10-15 13:53:02 UTC
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

Comment 1 Kamil Dudka 2019-10-15 15:05:37 UTC
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

Comment 2 Steve Grubb 2019-10-15 16:17:51 UTC
> 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.

Comment 3 Steve Grubb 2019-10-18 16:15:35 UTC
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.

Comment 4 Kamil Dudka 2019-10-21 14:31:35 UTC
(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...

Comment 5 Steve Grubb 2019-10-21 15:10:20 UTC
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

Comment 6 Steve Grubb 2019-10-24 15:57:03 UTC
Removing the bug from CCC tracker since it was worked around.

Kamil, do you see any reason to keep this bug open?

Comment 7 Kamil Dudka 2019-10-24 16:13:02 UTC
Thanks!  I would prefer not to change file's classification of ELF files in RHEL-8.  Let's move this effort to Fedora/upstream.

Comment 8 Steve Grubb 2019-10-24 16:23:07 UTC
OK, moving this to rawhide.

Comment 9 Ben Cotton 2020-02-11 17:50:42 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 32 development cycle.
Changing version to 32.

Comment 10 Fedora Program Management 2021-04-29 17:21:22 UTC
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.

Comment 11 Ben Cotton 2021-08-10 13:47:25 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 35 development cycle.
Changing version to 35.

Comment 12 Ian Laurie 2022-08-25 01:54:28 UTC
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.

Comment 13 Steve Grubb 2022-08-25 14:28:42 UTC
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?

Comment 14 Ian Laurie 2022-08-25 21:23:42 UTC
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.

Comment 15 Ben Cotton 2022-11-29 16:46:51 UTC
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.

Comment 16 Ian Laurie 2022-11-29 20:25:54 UTC
This needs to be moved to Fedora 37.  I am unable to do that.

Comment 17 Steve Grubb 2022-11-29 22:46:42 UTC
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

Comment 18 Ben Cotton 2022-12-13 15:13:34 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.