VirtualBox

Changeset 86952 in vbox


Ignore:
Timestamp:
Nov 23, 2020 9:37:24 AM (4 years ago)
Author:
vboxsync
Message:

FE/VirtualBox: Try another method to find the issetugid() import for patching in AppKit because the current one using dladdr() fails on BigSur with SIP disabled (working fine with SIP enabled) for some unknown reason

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r84751 r86952  
    6262# include <dlfcn.h>
    6363# include <sys/mman.h>
    64 # ifdef VBOX_RUNTIME_UI
    65 //# include <mach-o/dyld.h>
    66 extern "C" const char *_dyld_get_image_name(uint32_t);
    67 # endif
    6864#endif /* VBOX_WS_MAC */
    6965#ifdef VBOX_WS_X11
     
    136132# include <dlfcn.h>
    137133# include <iprt/formats/mach-o.h>
     134
     135//# include <mach-o/dyld.h> /* Not included because of definiton clashes with our own Mach-O header. */
     136extern "C" const char *_dyld_get_image_name(uint32_t);
     137extern "C" const mach_header_64_t *_dyld_get_image_header(uint32_t);
     138extern "C" uint32_t _dyld_image_count(void);
    138139
    139140/**
     
    368369static void HideSetUidRootFromAppKit()
    369370{
    370     void *pvAddr;
    371371    /* Find issetguid() and make it always return 0 by modifying the code: */
    372372# if 0
    373     pvAddr = dlsym(RTLD_DEFAULT, "issetugid");
     373    void *pvAddr = dlsym(RTLD_DEFAULT, "issetugid");
    374374    int rc = mprotect((void *)((uintptr_t)pvAddr & ~(uintptr_t)0xfff), 0x2000, PROT_WRITE | PROT_READ | PROT_EXEC);
    375375    if (!rc)
     
    379379    {
    380380        /* Failing that, find AppKit and patch its import table: */
     381# if 0 /* Fails with BigSur and SIP disabled for some unknown reason (SIP enabled works fine). */
    381382        void *pvAppKit = dlopen("/System/Library/Frameworks/AppKit.framework/AppKit", RTLD_NOLOAD);
    382         pvAddr = dlsym(pvAppKit, "NSApplicationMain");
     383        void *pvAddr = dlsym(pvAppKit, "NSApplicationMain");
    383384        Dl_info Info = {0};
    384385        if (   dladdr(pvAddr, &Info)
     
    394395        else
    395396            write(2, RT_STR_TUPLE("WARNING: Failed to patch issetugid in AppKit! (dladdr)\n"));
     397# else
     398#  define APP_KIT_FRAMEWORK_PATH "/System/Library/Frameworks/AppKit.framework"
     399        for (uint32_t i = 0; i < _dyld_image_count(); i++)
     400        {
     401            const char *pszImageName = _dyld_get_image_name(i);
     402            if (!strncmp(pszImageName, APP_KIT_FRAMEWORK_PATH, sizeof(APP_KIT_FRAMEWORK_PATH) - 1))
     403            {
     404                if (!patchExtSym((mach_header_64_t *)_dyld_get_image_header(i), "_issetugid", (uintptr_t)&issetugid_for_AppKit))
     405                    write(2, RT_STR_TUPLE("WARNING: Failed to patch issetugid in AppKit! (patchExtSym)\n"));
     406#  ifdef DEBUG
     407                else
     408                    write(2, RT_STR_TUPLE("INFO: Successfully patched _issetugid import for AppKit!\n"));
     409#  endif
     410                break;
     411            }
     412        }
     413# endif
    396414    }
    397415
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette