Browse Source

Always null out the tunDevice after freeing it, otherwise use-after-free bugs await

Caleb James DeLisle 4 years ago
parent
commit
042c5537ef
2 changed files with 8 additions and 2 deletions
  1. 4 0
      admin/angel/Core.c
  2. 4 2
      android_do

+ 4 - 0
admin/angel/Core.c

@@ -165,6 +165,7 @@ static void initSocket2(String* socketFullPath,
     if (ctx->tunDevice) {
         Iface_unplumb(ctx->tunDevice, &ctx->nc->tunAdapt->tunIf);
         Allocator_free(ctx->tunAlloc);
+        ctx->tunDevice = NULL;
     }
     ctx->tunAlloc = Allocator_child(ctx->alloc);
 
@@ -195,6 +196,7 @@ static void initTunnel2(String* desiredDeviceName,
     if (ctx->tunDevice) {
         Iface_unplumb(&ctx->nc->tunAdapt->tunIf, ctx->tunDevice);
         Allocator_free(ctx->tunAlloc);
+        ctx->tunDevice = NULL;
     }
     ctx->tunAlloc = Allocator_child(ctx->alloc);
     ctx->tunDevice = TUNInterface_new(
@@ -243,6 +245,7 @@ static void initTunFd0(
     if (ctx->tunDevice) {
         Iface_unplumb(&ctx->nc->tunAdapt->tunIf, ctx->tunDevice);
         Allocator_free(ctx->tunAlloc);
+        ctx->tunDevice = NULL;
     }
     Assert_true(!ctx->nc->tunAdapt->tunIf.connectedIf);
     ctx->tunAlloc = tunAlloc;
@@ -272,6 +275,7 @@ static void stopTun(Dict* args, void* vcontext, String* txid, struct Allocator*
     if (ctx->tunDevice) {
         Iface_unplumb(&ctx->nc->tunAdapt->tunIf, ctx->tunDevice);
         Allocator_free(ctx->tunAlloc);
+        ctx->tunDevice = NULL;
         sendResponse(String_new("none", requestAlloc), ctx->admin, txid, requestAlloc);
     } else {
         sendResponse(

+ 4 - 2
android_do

@@ -1,7 +1,10 @@
 #!/bin/sh
 
-# Android build on fedora
+# Fedora
 # dnf install wget git make which patch findutils unzip
+# Ubuntu
+# apt install wget git build-essential unzip time python
+
 # ./android_do
 die() { echo "Error: $1"; exit 1; }
 need() { which "$1" >/dev/null 2>/dev/null || die "Missing $1"; }
@@ -124,7 +127,6 @@ for i in `seq 0 100`; do
   mkdir -p $(pwd)/build_android/out/${APP_ABI}/${VERSION}/
   rm -rf build_linux
 
-  #export PLATFORM=android
   export SYSTEM=linux
 
   CROSS_PATH=$CJDNS_NDK_PATH/toolchains/llvm/prebuilt/${TYPE}-${cpu_arch}/bin