-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initramfs: fix running on root-only readable initrd filesystem
Signed-off-by: Oldřich Jedlička <[email protected]>
- Loading branch information
Showing
14 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include <dlfcn.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#define TCSD_NO_PRIVILEGE_DROP_ENV "TCSD_NO_PRIVILEGE_DROP" | ||
|
||
static int no_privilege_drop(void) { | ||
char *no_privilege_drop_env = getenv(TCSD_NO_PRIVILEGE_DROP_ENV); | ||
return (no_privilege_drop_env != NULL | ||
&& no_privilege_drop_env[0] != '\0' | ||
&& no_privilege_drop_env[0] != '0'); | ||
} | ||
|
||
int setuid(uid_t uid) { | ||
static int (*real_setuid)(uid_t) = NULL; | ||
if (no_privilege_drop()) { | ||
return 0; | ||
} else { | ||
if (!real_setuid) { | ||
real_setuid = dlsym(RTLD_NEXT, "setuid"); | ||
} | ||
return real_setuid(uid); | ||
} | ||
} | ||
|
||
int setgid(gid_t gid) { | ||
static int (*real_setgid)(uid_t) = NULL; | ||
if (no_privilege_drop()) { | ||
return 0; | ||
} else { | ||
if (!real_setgid) { | ||
real_setgid = dlsym(RTLD_NEXT, "setgid"); | ||
} | ||
return real_setgid(gid); | ||
} | ||
return 0; | ||
} | ||
|
||
static void __attribute ((constructor)) | ||
set_line_buffering (void) | ||
{ | ||
setvbuf(stdout, NULL, _IOLBF, 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters