this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mldr: Use the correct addresses for prctl calls

prctl actually expects pointers to (contiguous) string contents, not to string pointer arrays. This fixes `ps` output for mldr processes.

+19 -8
+19 -8
src/startup/mldr/stack.c
··· 157 157 } 158 158 159 159 // Fill in argv pointers 160 + // NOTE: the prctl code assumes that the current argv array points to contiguous strings. 161 + // this is not necessarily true, although AFAIK this is always true on Linux. 162 + // nonetheless, we should probably not assume this. 160 163 argv = sp; 161 - if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, argv, 0, 0) < 0) { 164 + uintptr_t arg_space_ptr = lr->argv[0]; 165 + if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, arg_space_ptr, 0, 0) < 0) { 162 166 // maybe arg_end was behind arg_start; try moving it first 163 - if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, argv, 0, 0) < 0) { 167 + if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, arg_space_ptr, 0, 0) < 0) { 164 168 fprintf(stderr, "Failed to set arg end\n"); 165 169 exit(1); 166 170 } 167 - if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, argv, 0, 0) < 0) { 171 + if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, arg_space_ptr, 0, 0) < 0) { 168 172 fprintf(stderr, "Failed to set arg start\n"); 169 173 exit(1); 170 174 } ··· 180 184 fprintf(stderr, "Failed to copy an argument pointer to stack\n"); 181 185 exit(1); 182 186 } 187 + arg_space_ptr += strlen(lr->argv[i]) + 1; 183 188 } 184 189 if (__put_user((user_long_t) 0, argv++)) 185 190 { 186 191 fprintf(stderr, "Failed to null-terminate the argument pointer array\n"); 187 192 exit(1); 188 193 } 189 - if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, argv, 0, 0) < 0) { 194 + if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, arg_space_ptr, 0, 0) < 0) { 190 195 fprintf(stderr, "Failed to set arg end\n"); 191 196 exit(1); 192 197 } 193 198 194 199 // Fill in envp pointers 200 + // NOTE: same as for argv; here we assume the envp strings are contiguous 195 201 envp = argv; 196 - if (prctl(PR_SET_MM, PR_SET_MM_ENV_START, envp, 0, 0) < 0) { 202 + uintptr_t env_space_ptr = lr->envp[0]; 203 + if (prctl(PR_SET_MM, PR_SET_MM_ENV_START, env_space_ptr, 0, 0) < 0) { 197 204 // maybe env_end was behind env_start; try moving it first 198 - if (prctl(PR_SET_MM, PR_SET_MM_ENV_END, envp, 0, 0) < 0) { 205 + if (prctl(PR_SET_MM, PR_SET_MM_ENV_END, env_space_ptr, 0, 0) < 0) { 199 206 fprintf(stderr, "Failed to set env end\n"); 200 207 exit(1); 201 208 } 202 - if (prctl(PR_SET_MM, PR_SET_MM_ENV_START, envp, 0, 0) < 0) { 209 + if (prctl(PR_SET_MM, PR_SET_MM_ENV_START, env_space_ptr, 0, 0) < 0) { 203 210 fprintf(stderr, "Failed to set env start\n"); 204 211 exit(1); 205 212 } ··· 216 223 // Don't pass these special env vars down to userland 217 224 #define SKIP_VAR(_name) \ 218 225 if (len > sizeof(_name) - 1 && strncmp(lr->envp[i], _name, sizeof(_name) - 1) == 0) { \ 226 + env_space_ptr += strlen(lr->envp[i]) + 1; \ 219 227 continue; \ 220 228 } 221 229 ··· 227 235 fprintf(stderr, "Failed to copy an environment variable pointer to stack\n"); 228 236 exit(1); 229 237 } 238 + 239 + env_space_ptr += strlen(lr->envp[i]) + 1; 230 240 } 231 241 if (__put_user((user_long_t) 0, envp++)) 232 242 { 233 243 fprintf(stderr, "Failed to null-terminate the environment variable pointer array\n"); 234 244 exit(1); 235 245 } 236 - if (prctl(PR_SET_MM, PR_SET_MM_ENV_END, envp, 0, 0) < 0) { 246 + // FIXME: this might include variables that we've skipped 247 + if (prctl(PR_SET_MM, PR_SET_MM_ENV_END, env_space_ptr, 0, 0) < 0) { 237 248 fprintf(stderr, "Failed to set env end\n"); 238 249 exit(1); 239 250 }