aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/cloudabi32/cloudabi32_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/cloudabi32/cloudabi32_module.c')
-rw-r--r--sys/compat/cloudabi32/cloudabi32_module.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/sys/compat/cloudabi32/cloudabi32_module.c b/sys/compat/cloudabi32/cloudabi32_module.c
index 3e4e4a733971..001c673a7d7a 100644
--- a/sys/compat/cloudabi32/cloudabi32_module.c
+++ b/sys/compat/cloudabi32/cloudabi32_module.c
@@ -63,10 +63,10 @@ cloudabi32_copyout_strings(struct image_params *imgp)
int
cloudabi32_fixup(register_t **stack_base, struct image_params *imgp)
{
- char canarybuf[64];
+ char canarybuf[64], pidbuf[16];
Elf32_Auxargs *args;
struct thread *td;
- void *argdata, *canary;
+ void *argdata, *canary, *pid;
size_t argdatalen;
int error;
@@ -79,8 +79,9 @@ cloudabi32_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 @@ cloudabi32_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 @@ cloudabi32_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 },