Changeset 12111 in vbox for trunk/src/VBox
- Timestamp:
- Sep 4, 2008 10:11:21 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 36052
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r11843 r12111 272 272 /** 273 273 * Returns the full path to the executable. 274 * 274 * 275 275 * @returns IPRT status code. 276 276 * @param pszPath Where to store it. … … 322 322 # error needs porting. 323 323 #endif 324 324 325 325 /* 326 326 * Strip off the filename part (RTPathStripFilename()). … … 334 334 /** 335 335 * Checks if we can read /proc/self/exe. 336 * 337 * This is used on linux to see if we have to call init 336 * 337 * This is used on linux to see if we have to call init 338 338 * with program path or not. 339 * 339 * 340 340 * @returns true / false. 341 341 */ … … 540 540 if (!supR3HardenedMainIsProcSelfExeAccssible()) 541 541 pszExePath = g_szSupLibHardenedExePath; 542 #endif 542 #endif 543 543 rc = pfnRTInitEx(0, pszExePath, !(fFlags & SUPSECMAIN_FLAGS_DONT_OPEN_DEV)); 544 544 if (RT_FAILURE(rc)) … … 636 636 geteuid(), getegid(), uid, gid); 637 637 638 # ifdef RT_OS_LINUX 639 /* 638 # ifdef RT_OS_LINUX 639 /* 640 640 * On linux we have to make sure the path is initialized because we 641 641 * *might* not be able to access /proc/self/exe after the seteuid call. … … 665 665 /* 666 666 * Drop any root privileges we might be holding. 667 */ 668 setegid(gid); 669 seteuid(uid); 670 if ( geteuid() != uid 671 || getegid() != gid) 672 supR3HardenedFatal("SUPR3HardenedMain: failed to drop root privileges! (euid=%d egid=%d; wanted %d and %d)\n", 673 geteuid(), getegid(), uid, gid); 667 * 668 * Try use setre[ug]id since this will clear the save uid/gid and thus 669 * leave fewer traces behind that libs like GTK+ may pick up. 670 */ 671 uid_t euid, ruid, suid; 672 gid_t egid, rgid, sgid; 673 # if defined(RT_OS_DARWIN) 674 /* The really great thing here is that setreuid isn't available on 675 OS X 10.4, libc emulates it. While 10.4 have a sligtly different and 676 non-standard setuid implementation compared to 10.5, the following 677 works the same way with both version since we're super user (10.5 req). 678 So, the following will set all three variants of the group and user ids. */ 679 setgid(gid); 680 setuid(uid); 681 euid = geteuid(); 682 ruid = suid = getuid(); 683 egid = getegid(); 684 rgid = sgid = getgid(); 685 686 # elif defined(RT_SOLARIS) 687 /* Solaris doesn't have setresuid, but the setreuid interface is BSD 688 compatible and will set the saved uid to euid when we pass it a ruid 689 that isn't -1 (which we do). */ 690 setregid(gid, gid); 691 setreuid(uid, uid); 692 euid = geteuid(); 693 ruid = suid = getuid(); 694 egid = getegid(); 695 rgid = sgid = getgid(); 696 697 # else 698 /* This is the preferred one, full control no questions about semantics. 699 PORTME: If this isn't work, try join one of two other gangs above. */ 700 setresgid(gid, gid, gid); 701 setresuid(uid, uid, gid); 702 if (getresuid(&ruid, &euid, &suid) != 0) 703 { 704 euid = geteuid(); 705 ruid = suid = getuid(); 706 } 707 if (getresgid(&rgid, &egid, &sgid) != 0) 708 { 709 egid = getegid(); 710 rgid = sgid = getgid(); 711 } 712 # endif 713 714 /* Check that it worked out all right. */ 715 if ( euid != uid 716 || ruid != uid 717 || suid != uid 718 || egid != gid 719 || rgid != gid 720 || sgid != gid) 721 supR3HardenedFatal("SUPR3HardenedMain: failed to drop root privileges!" 722 " (euid=%d ruid=%d suid=%d egid=%d rgid=%d sgid=%d; wanted uid=%d and gid=%d)\n", 723 euid, ruid, suid, egid, rgid, sgid, uid, gid); 674 724 #endif 675 725
Note:
See TracChangeset
for help on using the changeset viewer.