diff options
Diffstat (limited to 'sys/compat/cloudabi64/cloudabi64_module.c')
-rw-r--r-- | sys/compat/cloudabi64/cloudabi64_module.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/sys/compat/cloudabi64/cloudabi64_module.c b/sys/compat/cloudabi64/cloudabi64_module.c index da1ea1149a4b..9c71b87b08f4 100644 --- a/sys/compat/cloudabi64/cloudabi64_module.c +++ b/sys/compat/cloudabi64/cloudabi64_module.c @@ -63,10 +63,10 @@ cloudabi64_copyout_strings(struct image_params *imgp) int cloudabi64_fixup(register_t **stack_base, struct image_params *imgp) { - char canarybuf[64]; + char canarybuf[64], pidbuf[16]; Elf64_Auxargs *args; struct thread *td; - void *argdata, *canary; + void *argdata, *canary, *pid; size_t argdatalen; int error; @@ -79,8 +79,9 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp) td = curthread; td->td_proc->p_osrel = __FreeBSD_version; - /* Store canary for stack smashing protection. */ argdata = *stack_base; + + /* Store canary for stack smashing protection. */ arc4rand(canarybuf, sizeof(canarybuf), 0); *stack_base -= howmany(sizeof(canarybuf), sizeof(register_t)); canary = *stack_base; @@ -89,6 +90,20 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp) return (error); /* + * Generate a random UUID that identifies the process. Right now + * we don't store this UUID in the kernel. Ideally, it should be + * exposed through ps(1). + */ + arc4rand(pidbuf, sizeof(pidbuf), 0); + pidbuf[6] = (pidbuf[6] & 0x0f) | 0x40; + pidbuf[8] = (pidbuf[8] & 0x3f) | 0x80; + *stack_base -= howmany(sizeof(pidbuf), sizeof(register_t)); + pid = *stack_base; + error = copyout(pidbuf, pid, sizeof(pidbuf)); + if (error != 0) + return (error); + + /* * Compute length of program arguments. As the argument data is * binary safe, we had to add a trailing null byte in * exec_copyin_data_fds(). Undo this by reducing the length. @@ -111,9 +126,10 @@ cloudabi64_fixup(register_t **stack_base, struct image_params *imgp) VAL(CLOUDABI_AT_PAGESZ, args->pagesz), PTR(CLOUDABI_AT_PHDR, args->phdr), VAL(CLOUDABI_AT_PHNUM, args->phnum), - VAL(CLOUDABI_AT_TID, td->td_tid), + PTR(CLOUDABI_AT_PID, pid), PTR(CLOUDABI_AT_SYSINFO_EHDR, imgp->proc->p_sysent->sv_shared_page_base), + VAL(CLOUDABI_AT_TID, td->td_tid), #undef VAL #undef PTR { .a_type = CLOUDABI_AT_NULL }, |