Clean entire arg block when setting process name.
When Android processes fork from Zygote, we rewrite the command line with a new name, eg. "system_server". When we do this, we should fill the entire block with zeros to remove corrupted argument information that may otherwise remain in the /proc/<pid>/cmdline buffer and be seen in tools and stack dumps. Fixed an issue where VM options could be overwritten after setting the nice name if the name was too long. Bug: 17474152 Change-Id: Ie6cf9ed7752a04300a340e26cd6812bb35c59e1b
This commit is contained in:
@@ -133,8 +133,7 @@ static size_t computeArgBlockSize(int argc, char* const argv[]) {
|
||||
// names if the zygote command line decreases in size.
|
||||
uintptr_t start = reinterpret_cast<uintptr_t>(argv[0]);
|
||||
uintptr_t end = reinterpret_cast<uintptr_t>(argv[argc - 1]);
|
||||
end += strlen(argv[argc - 1]);
|
||||
|
||||
end += strlen(argv[argc - 1]) + 1;
|
||||
return (end - start);
|
||||
}
|
||||
|
||||
@@ -220,15 +219,27 @@ int main(int argc, char* const argv[])
|
||||
//
|
||||
// For zygote starts, all remaining arguments are passed to the zygote.
|
||||
// main function.
|
||||
//
|
||||
// Note that we must copy argument string values since we will rewrite the
|
||||
// entire argument block when we apply the nice name to argv0.
|
||||
|
||||
|
||||
int i = runtime.addVmArguments(argc, argv);
|
||||
int i;
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (argv[i][0] != '-') {
|
||||
break;
|
||||
}
|
||||
if (argv[i][1] == '-' && argv[i][2] == 0) {
|
||||
++i; // Skip --.
|
||||
break;
|
||||
}
|
||||
runtime.addOption(strdup(argv[i]));
|
||||
}
|
||||
|
||||
// Parse runtime arguments. Stop at first unrecognized option.
|
||||
bool zygote = false;
|
||||
bool startSystemServer = false;
|
||||
bool application = false;
|
||||
const char* niceName = NULL;
|
||||
String8 niceName;
|
||||
String8 className;
|
||||
|
||||
++i; // Skip unused "parent dir" argument.
|
||||
@@ -242,7 +253,7 @@ int main(int argc, char* const argv[])
|
||||
} else if (strcmp(arg, "--application") == 0) {
|
||||
application = true;
|
||||
} else if (strncmp(arg, "--nice-name=", 12) == 0) {
|
||||
niceName = arg + 12;
|
||||
niceName.setTo(arg + 12);
|
||||
} else if (strncmp(arg, "--", 2) != 0) {
|
||||
className.setTo(arg);
|
||||
break;
|
||||
@@ -287,9 +298,9 @@ int main(int argc, char* const argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (niceName && *niceName) {
|
||||
runtime.setArgv0(niceName);
|
||||
set_process_name(niceName);
|
||||
if (!niceName.isEmpty()) {
|
||||
runtime.setArgv0(niceName.string());
|
||||
set_process_name(niceName.string());
|
||||
}
|
||||
|
||||
if (zygote) {
|
||||
|
||||
@@ -271,6 +271,7 @@ AndroidRuntime::~AndroidRuntime()
|
||||
}
|
||||
|
||||
void AndroidRuntime::setArgv0(const char* argv0) {
|
||||
memset(mArgBlockStart, 0, mArgBlockLength);
|
||||
strlcpy(mArgBlockStart, argv0, mArgBlockLength);
|
||||
}
|
||||
|
||||
@@ -345,28 +346,6 @@ static bool runtime_isSensitiveThread() {
|
||||
return state && state->getStrictModePolicy() != 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add VM arguments to the to-be-executed VM
|
||||
* Stops at first non '-' argument (also stops at an argument of '--')
|
||||
* Returns the number of args consumed
|
||||
*/
|
||||
int AndroidRuntime::addVmArguments(int argc, const char* const argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i<argc; i++) {
|
||||
if (argv[i][0] != '-') {
|
||||
return i;
|
||||
}
|
||||
if (argv[i][1] == '-' && argv[i][2] == 0) {
|
||||
return i+1;
|
||||
}
|
||||
addOption(argv[i]);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
static int hasDir(const char* dir)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
@@ -45,6 +45,7 @@ public:
|
||||
};
|
||||
|
||||
void setArgv0(const char* argv0);
|
||||
void addOption(const char* optionString, void* extra_info = NULL);
|
||||
|
||||
/**
|
||||
* Register a set of methods in the specified class.
|
||||
@@ -63,8 +64,6 @@ public:
|
||||
*/
|
||||
static jclass findClass(JNIEnv* env, const char* className);
|
||||
|
||||
int addVmArguments(int argc, const char* const argv[]);
|
||||
|
||||
void start(const char *classname, const Vector<String8>& options);
|
||||
|
||||
void exit(int code);
|
||||
@@ -116,7 +115,6 @@ public:
|
||||
|
||||
private:
|
||||
static int startReg(JNIEnv* env);
|
||||
void addOption(const char* optionString, void* extra_info = NULL);
|
||||
bool parseRuntimeOption(const char* property,
|
||||
char* buffer,
|
||||
const char* runtimeArg,
|
||||
|
||||
Reference in New Issue
Block a user