Cisco-Talos / pyrebox

Python scriptable Reverse Engineering Sandbox, a Virtual Machine instrumentation and inspection framework based on QEMU
https://talosintelligence.com/pyrebox
GNU General Public License v2.0
1.65k stars 249 forks source link

Problem building pyrebox on Debian sid #114

Open Te-k opened 4 years ago

Te-k commented 4 years ago

Hi,

I am trying to build pyrebox on Debian sid. When building qemu, I get the following error in the config.log file:

config-temp/qemu-conf.c: In function ‘main’:
config-temp/qemu-conf.c:2:25: error: null argument where non-null required (argument 1) [-Werror=nonnull]
    2 | int main(void) { return sem_timedwait(0, 0); }
      |                         ^~~~~~~~~~~~~
config-temp/qemu-conf.c:2:25: error: null argument where non-null required (argument 2) [-Werror=nonnull]
cc1: all warnings being treated as errors

It seems to be the issue mentioned here but config-temp is a temporary file, I am not sure what generates it in the compiling process, so not sure how to apply this patch. Any clue where that problem is coming from?

xabiugarte commented 4 years ago

Hi Te-K, could you tell me the GCC version you are using?

Te-k commented 4 years ago

I am using gcc (Debian 10.2.0-3) 10.2.0

xabiugarte commented 4 years ago

Hi Te-K,

There are some known problems with the latest versions of GCC. This will require to update the QEMU version that PyREBox relies on. I still need to allocate some time to work on that and make and properly test the upgrade. For the time being, you could try to compile PyREBox with an older GCC version such as gcc 8. This can be easily achieved with the alternatives system in Debian based distros: https://wiki.debian.org/DebianAlternatives

Thanks,

Te-k commented 4 years ago

I got it working, it was not a GCC 10 issue, but some weird other problems. One of them is a bug in gcc configure script. The other one that is weird, is that qemu has a -Werror flag enabled by default if it is in a git repository. I solved that by forcing the --disable-werror in the build script (as explained here).

I guess it is not system dependent but I am surprised you never had these issues. Here are the paches if you want to fix them:

diff --git a/build.sh b/build.sh
index f19748fe..97ded8fb 100755
--- a/build.sh
+++ b/build.sh
@@ -95,7 +95,7 @@ if [ x"${reconfigure}" = xyes ] || [ ! -f ${qemu_path}/config-host.mak ] || [ !
     then
       qemu_configure_flags='--enable-debug'
     fi
-    ./configure --disable-docs --disable-libiscsi --target-list=i386-softmmu,x86_64-softmmu ${qemu_configure_flags}
+    ./configure --disable-werror --disable-docs --disable-libiscsi --target-list=i386-softmmu,x86_64-softmmu ${qemu_configure_flags}
     if [ $? -ne 0 ]; then
         echo -e "\n${RED}[!] Could not configure QEMU${NC}\n"
         exit 1
diff --git a/qemu/configure b/qemu/configure
index 54179416..a997e94a 100755
--- a/qemu/configure
+++ b/qemu/configure
@@ -5117,7 +5117,7 @@ fi
 sem_timedwait=no
 cat > $TMPC << EOF
 #include <semaphore.h>
-int main(void) { return sem_timedwait(0, 0); }
+int main(void) { sem_t s; struct timespec t = {0}; return sem_timedwait(&s, &t); }
 EOF
 if compile_prog "" "" ; then
     sem_timedwait=yes