VirtualBox

Ignore:
Timestamp:
Jan 19, 2009 5:16:00 PM (16 years ago)
Author:
vboxsync
Message:

SUPR3: don't change the capabilities if started as root

File:
1 edited

Legend:

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

    r16048 r16050  
    610610     * keep the cap_net_raw capability for ICMP sockets for the NAT stack.
    611611     */
     612    if (g_uCaps != 0)
     613    {
    612614#  ifdef USE_LIB_PCAP
    613     /* XXX cap_net_bind_service */
    614     if (!cap_set_proc(cap_from_text("all-eip cap_net_raw+ep")))
    615         prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0);
     615        /* XXX cap_net_bind_service */
     616        if (!cap_set_proc(cap_from_text("all-eip cap_net_raw+ep")))
     617            prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0);
    616618#  else
    617     if (g_uCaps != 0)
    618     {
    619619        cap_user_header_t hdr = (cap_user_header_t)alloca(sizeof(*hdr));
    620620        cap_user_data_t   cap = (cap_user_data_t)alloca(sizeof(*cap));
     
    626626        if (!capset(hdr, cap))
    627627            prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0);
    628     }
    629 #  endif
     628#  endif /* !USE_LIB_PCAP */
     629    }
    630630
    631631# elif defined(RT_OS_SOLARIS)
     
    673673
    674674    /*
    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);
     675     * Do _not_ perform any capability-related system calls for root processes
     676     * (leaving g_uCaps at 0).
     677     */
     678    if (getuid() != 0)
     679    {
     680        /*
     681         * CAP_NET_RAW.
     682         * Default: enabled.
     683         * Can be disabled with 'export VBOX_HARD_CAP_NET_RAW=0'.
     684         */
     685        pszOpt = getenv("VBOX_HARD_CAP_NET_RAW");
     686        if (   !pszOpt
     687                || memcmp(pszOpt, "0", sizeof("0")) != 0)
     688            g_uCaps = CAP_TO_MASK(CAP_NET_RAW);
     689
     690        /*
     691         * CAP_NET_BIND_SERVICE.
     692         * Default: disabled.
     693         * Can be enabled with 'export VBOX_HARD_CAP_NET_BIND_SERVICE=1'.
     694         */
     695        pszOpt = getenv("VBOX_HARD_CAP_NET_BIND_SERVICE");
     696        if (   pszOpt
     697                && memcmp(pszOpt, "0", sizeof("0")) != 0)
     698            g_uCaps |= CAP_TO_MASK(CAP_NET_BIND_SERVICE);
     699    }
    693700# endif
    694701}
     
    762769     * Re-enable the cap_net_raw capability which was disabled during setresuid.
    763770     */
     771    if (g_uCaps != 0)
     772    {
    764773#  ifdef USE_LIB_PCAP
    765     /** @todo Warn if that does not work? */
    766     /* XXX cap_net_bind_service */
    767     cap_set_proc(cap_from_text("cap_net_raw+ep"));
     774        /** @todo Warn if that does not work? */
     775        /* XXX cap_net_bind_service */
     776        cap_set_proc(cap_from_text("cap_net_raw+ep"));
    768777#  else
    769     if (g_uCaps != 0)
    770     {
    771778        cap_user_header_t hdr = (cap_user_header_t)alloca(sizeof(*hdr));
    772779        cap_user_data_t   cap = (cap_user_data_t)alloca(sizeof(*cap));
     
    778785        /** @todo Warn if that does not work? */
    779786        capset(hdr, cap);
    780     }
    781 #  endif
     787#  endif /* !USE_LIB_PCAP */
     788    }
    782789# endif
    783790}
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