Skip to content

Commit 4fa2ee1

Browse files
danbevjasnell
authored andcommitted
src: add linux getauxval(AT_SECURE) in SafeGetenv
This commit attempts to fix the following TODO: // TODO(bnoordhuis) Should perhaps also check whether getauxval(AT_SECURE) is non-zero on Linux. This can be manually tested at the moment using the following steps: $ setcap cap_net_raw+ep out/Release/node $ NODE_PENDING_DEPRECATION="1" out/Release/node -p "process.binding('config').pendingDeprecation" true $ useradd test $ su test $ NODE_PENDING_DEPRECATION="1" out/Release/node -p "process.binding('config').pendingDeprecation" undefined PR-URL: #12548 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 46bd32e commit 4fa2ee1

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/node.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ bool config_expose_internals = false;
230230

231231
bool v8_initialized = false;
232232

233+
bool linux_at_secure = false;
234+
233235
// process-relative uptime base, initialized at start-up
234236
static double prog_start_time;
235237

@@ -965,13 +967,15 @@ Local<Value> UVException(Isolate* isolate,
965967
// Look up environment variable unless running as setuid root.
966968
bool SafeGetenv(const char* key, std::string* text) {
967969
#ifndef _WIN32
968-
// TODO(bnoordhuis) Should perhaps also check whether getauxval(AT_SECURE)
969-
// is non-zero on Linux.
970970
if (getuid() != geteuid() || getgid() != getegid()) {
971971
text->clear();
972972
return false;
973973
}
974974
#endif
975+
if (linux_at_secure) {
976+
text->clear();
977+
return false;
978+
}
975979
if (const char* value = getenv(key)) {
976980
*text = value;
977981
return true;

src/node_main.cc

+25
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,32 @@ int wmain(int argc, wchar_t *wargv[]) {
7171
}
7272
#else
7373
// UNIX
74+
#ifdef __linux__
75+
#include <elf.h>
76+
#ifdef __LP64__
77+
#define Elf_auxv_t Elf64_auxv_t
78+
#else
79+
#define Elf_auxv_t Elf32_auxv_t
80+
#endif // __LP64__
81+
extern char** environ;
82+
#endif // __linux__
83+
84+
namespace node {
85+
extern bool linux_at_secure;
86+
} // namespace node
87+
7488
int main(int argc, char *argv[]) {
89+
#if defined(__linux__)
90+
char** envp = environ;
91+
while (*envp++ != nullptr) {}
92+
Elf_auxv_t* auxv = reinterpret_cast<Elf_auxv_t*>(envp);
93+
for (; auxv->a_type != AT_NULL; auxv++) {
94+
if (auxv->a_type == AT_SECURE) {
95+
node::linux_at_secure = auxv->a_un.a_val;
96+
break;
97+
}
98+
}
99+
#endif
75100
// Disable stdio buffering, it interacts poorly with printf()
76101
// calls elsewhere in the program (e.g., any logging from V8.)
77102
setvbuf(stdout, nullptr, _IONBF, 0);

0 commit comments

Comments
 (0)