VirtualBox

Changeset 16048 in vbox for trunk/src


Ignore:
Timestamp:
Jan 19, 2009 4:50:43 PM (16 years ago)
Author:
vboxsync
Message:

SUPR3: added environment options VBOX_HARD_CAP_NET_RAW and VBOX_HARD_CAP_NET_BIND_SERVICE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp

    r15884 r16048  
    133133/** The real GID at startup. */
    134134static gid_t g_gid;
     135# ifdef RT_OS_LINUX
     136static __u32 g_uCaps;
     137# endif
    135138#endif
    136139
     
    608611     */
    609612#  ifdef USE_LIB_PCAP
     613    /* XXX cap_net_bind_service */
    610614    if (!cap_set_proc(cap_from_text("all-eip cap_net_raw+ep")))
    611615        prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0);
    612616#  else
    613     cap_user_header_t hdr = (cap_user_header_t)alloca(sizeof(*hdr));
    614     cap_user_data_t   cap = (cap_user_data_t)alloca(sizeof(*cap));
    615     memset(hdr, 0, sizeof(*hdr));
    616     hdr->version = _LINUX_CAPABILITY_VERSION;
    617     memset(cap, 0, sizeof(*cap));
    618     cap->effective = CAP_TO_MASK(CAP_NET_RAW);
    619     cap->permitted = CAP_TO_MASK(CAP_NET_RAW);
    620     if (!capset(hdr, cap))
    621         prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0);
     617    if (g_uCaps != 0)
     618    {
     619        cap_user_header_t hdr = (cap_user_header_t)alloca(sizeof(*hdr));
     620        cap_user_data_t   cap = (cap_user_data_t)alloca(sizeof(*cap));
     621        memset(hdr, 0, sizeof(*hdr));
     622        hdr->version = _LINUX_CAPABILITY_VERSION;
     623        memset(cap, 0, sizeof(*cap));
     624        cap->effective = g_uCaps;
     625        cap->permitted = g_uCaps;
     626        if (!capset(hdr, cap))
     627            prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0);
     628    }
    622629#  endif
    623630
     
    655662}
    656663
     664/*
     665 * Look at the environment for some special options.
     666 */
     667static void supR3GrabOptions(void)
     668{
     669    const char *pszOpt;
     670
     671# ifdef RT_OS_LINUX
     672    g_uCaps = 0;
     673
     674    /*
     675     * CAP_NET_RAW.
     676     * Default: enabled.
     677     * Can be disabled with 'export VBOX_HARD_CAP_NET_RAW=0'.
     678     */
     679    pszOpt = getenv("VBOX_HARD_CAP_NET_RAW");
     680    if (   !pszOpt
     681        || memcmp(pszOpt, "0", sizeof("0")) != 0)
     682        g_uCaps = CAP_TO_MASK(CAP_NET_RAW);
     683
     684    /*
     685     * CAP_NET_BIND_SERVICE.
     686     * Default: disabled.
     687     * Can be enabled with 'export VBOX_HARD_CAP_NET_BIND_SERVICE=1'.
     688     */
     689    pszOpt = getenv("VBOX_HARD_CAP_NET_BIND_SERVICE");
     690    if (   pszOpt
     691        && memcmp(pszOpt, "0", sizeof("0")) != 0)
     692        g_uCaps |= CAP_TO_MASK(CAP_NET_BIND_SERVICE);
     693# endif
     694}
     695
    657696/**
    658697 * Drop any root privileges we might be holding.
     
    725764#  ifdef USE_LIB_PCAP
    726765    /** @todo Warn if that does not work? */
     766    /* XXX cap_net_bind_service */
    727767    cap_set_proc(cap_from_text("cap_net_raw+ep"));
    728768#  else
    729     cap_user_header_t hdr = (cap_user_header_t)alloca(sizeof(*hdr));
    730     cap_user_data_t   cap = (cap_user_data_t)alloca(sizeof(*cap));
    731     memset(hdr, 0, sizeof(*hdr));
    732     hdr->version = _LINUX_CAPABILITY_VERSION;
    733     memset(cap, 0, sizeof(*cap));
    734     cap->effective = CAP_TO_MASK(CAP_NET_RAW);
    735     cap->permitted = CAP_TO_MASK(CAP_NET_RAW);
    736     /** @todo Warn if that does not work? */
    737     capset(hdr, cap);
     769    if (g_uCaps != 0)
     770    {
     771        cap_user_header_t hdr = (cap_user_header_t)alloca(sizeof(*hdr));
     772        cap_user_data_t   cap = (cap_user_data_t)alloca(sizeof(*cap));
     773        memset(hdr, 0, sizeof(*hdr));
     774        hdr->version = _LINUX_CAPABILITY_VERSION;
     775        memset(cap, 0, sizeof(*cap));
     776        cap->effective = g_uCaps;
     777        cap->permitted = g_uCaps;
     778        /** @todo Warn if that does not work? */
     779        capset(hdr, cap);
     780    }
    738781#  endif
    739782# endif
     
    953996     */
    954997    supR3HardenedGetFullExePath();
     998
    955999# endif
     1000
     1001    /*
     1002     * Grab any options from the environment.
     1003     */
     1004    supR3GrabOptions();
    9561005
    9571006    /*
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