binarly-io / fwhunt-scan

Tools for analyzing UEFI firmware and checking UEFI modules with FwHunt rules
GNU General Public License v3.0
210 stars 30 forks source link

BrokenPipeError #28

Closed hughsie closed 2 years ago

hughsie commented 2 years ago

With the new rizin code I'm getting occasionally:

  File "/home/hughsie/Code/lvfs-website/lvfs/queries/utils.py", line 43, in _query_run_shard_uefi_r2
    uefi_analyzer = UefiAnalyzer(blob=shard.blob)
  File "/home/hughsie/Code/lvfs-website/env/lib/python3.10/site-packages/uefi_r2/uefi_analyzer.py", line 83, in __init__
    self._rz.cmd("aaaa")
  File "/home/hughsie/Code/lvfs-website/env/lib/python3.10/site-packages/rzpipe/open_base.py", line 231, in cmd
    res = self._cmd(cmd, **kwargs)
  File "/home/hughsie/Code/lvfs-website/env/lib/python3.10/site-packages/rzpipe/open_sync.py", line 102, in _cmd_process
    self.process.stdin.write((cmd + "\n").encode("utf8"))
BrokenPipeError: [Errno 32] Broken pipe

any ideas? I can upload the PE binary that makes it crash somewhere if that helps.

yeggor commented 2 years ago

Do I understand correctly that rizin is installed? It seems that the problem is in the installation of rizin / rzpipe, but in any case, please upload the binary, I will check it on my side

hughsie commented 2 years ago

Do I understand correctly that rizin is installed?

rizin-0.3.0-1.fc35.x86_64

please upload the binary

Reproducer with https://people.freedesktop.org/~hughsient/temp/foo.py on https://people.freedesktop.org/~hughsient/temp/foo.efi

Any ideas welcome, thanks!

yeggor commented 2 years ago

UefiAnalyzer cannot currently work with the with keyword since I did not define the __enter__ attribute. Also, note that if you want to use shm, you should manually close the shm device by calling the close() method. Here's a code that works for me:

from uefi_r2 import UefiAnalyzer

with open("./foo.efi", "rb") as f:
    uefi_analyzer = UefiAnalyzer(blob=f.read())
    print(uefi_analyzer.get_summary())
    uefi_analyzer.close()

I agree that this is not very pretty, so in the next minor release I will fix it (to make it work through with ... as).

And the most important thing: the version you are testing uploaded on 09/27/2021 but fix for shm:// came after this release, so it makes sense to use the newer version from dev branch: https://github.com/rizinorg/rizin

hughsie commented 2 years ago

so it makes sense to use the newer version from dev branch

You're completely correct, thanks. Using rizin from git it worked.

so in the next minor release I will fix it

In the meantime I'll use something like:

from uefi_r2 import UefiAnalyzer
from typing import Optional, Type
from types import TracebackType

class _UefiAnalyzer(UefiAnalyzer):

    def __enter__(self):
        return self

    def __exit__(
        self,
        exc_type: Optional[Type[BaseException]],
        exc_value: Optional[BaseException],
        traceback: Optional[TracebackType],
    ) -> None:
        self.close()

with open("./foo.efi", "rb") as f:
    with _UefiAnalyzer(blob=f.read()) as uefi_analyzer:
        print(uefi_analyzer.get_summary())