- Timestamp:
- Jan 19, 2009 4:50:43 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r15884 r16048 133 133 /** The real GID at startup. */ 134 134 static gid_t g_gid; 135 # ifdef RT_OS_LINUX 136 static __u32 g_uCaps; 137 # endif 135 138 #endif 136 139 … … 608 611 */ 609 612 # ifdef USE_LIB_PCAP 613 /* XXX cap_net_bind_service */ 610 614 if (!cap_set_proc(cap_from_text("all-eip cap_net_raw+ep"))) 611 615 prctl(PR_SET_KEEPCAPS, /*keep=*/1, 0, 0, 0); 612 616 # 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 } 622 629 # endif 623 630 … … 655 662 } 656 663 664 /* 665 * Look at the environment for some special options. 666 */ 667 static 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 657 696 /** 658 697 * Drop any root privileges we might be holding. … … 725 764 # ifdef USE_LIB_PCAP 726 765 /** @todo Warn if that does not work? */ 766 /* XXX cap_net_bind_service */ 727 767 cap_set_proc(cap_from_text("cap_net_raw+ep")); 728 768 # 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 } 738 781 # endif 739 782 # endif … … 953 996 */ 954 997 supR3HardenedGetFullExePath(); 998 955 999 # endif 1000 1001 /* 1002 * Grab any options from the environment. 1003 */ 1004 supR3GrabOptions(); 956 1005 957 1006 /*
Note:
See TracChangeset
for help on using the changeset viewer.