Skip to content

Commit

Permalink
posix_spawn(3): add POSIX_SPAWN_DISABLE_ASLR_NP
Browse files Browse the repository at this point in the history
similar to Apple _POSIX_SPAWN_DISABLE_ASLR

Reviewed by:	emaste, kevans
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D44195
  • Loading branch information
kostikbel committed Mar 4, 2024
1 parent 80ac36c commit 822042f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/spawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t;
#define POSIX_SPAWN_SETSCHEDULER 0x08
#define POSIX_SPAWN_SETSIGDEF 0x10
#define POSIX_SPAWN_SETSIGMASK 0x20
#define POSIX_SPAWN_DISABLE_ASLR_NP 0x40

__BEGIN_DECLS
/*
Expand Down
13 changes: 11 additions & 2 deletions lib/libc/gen/posix_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "namespace.h"
#include <sys/param.h>
#include <sys/procctl.h>
#include <sys/queue.h>
#include <sys/wait.h>

Expand Down Expand Up @@ -91,7 +92,7 @@ static int
process_spawnattr(const posix_spawnattr_t sa)
{
struct sigaction sigact = { .sa_flags = 0, .sa_handler = SIG_DFL };
int i;
int aslr, i;

/*
* POSIX doesn't really describe in which order everything
Expand Down Expand Up @@ -139,6 +140,13 @@ process_spawnattr(const posix_spawnattr_t sa)
}
}

/* Disable ASLR. */
if ((sa->sa_flags & POSIX_SPAWN_DISABLE_ASLR_NP) != 0) {
aslr = PROC_ASLR_FORCE_DISABLE;
if (procctl(P_PID, 0, PROC_ASLR_CTL, &aslr) != 0)
return (errno);
}

return (0);
}

Expand Down Expand Up @@ -631,7 +639,8 @@ posix_spawnattr_setflags(posix_spawnattr_t *sa, short flags)
{
if ((flags & ~(POSIX_SPAWN_RESETIDS | POSIX_SPAWN_SETPGROUP |
POSIX_SPAWN_SETSCHEDPARAM | POSIX_SPAWN_SETSCHEDULER |
POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK)) != 0)
POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK |
POSIX_SPAWN_DISABLE_ASLR_NP)) != 0)
return (EINVAL);
(*sa)->sa_flags = flags;
return (0);
Expand Down

0 comments on commit 822042f

Please sign in to comment.